Documentation
¶
Index ¶
- Constants
- func CloseTunnel(sessionID string) error
- func CommitAsync(session *scheduler.Session, commissioned bool)
- func RunTunnelWorker(targetAddr string)
- type Address
- type AuthManager
- type BaseRequest
- type Command
- type CommandData
- type CommandResult
- type CommandRunner
- type ComparableData
- type Content
- type ControlClient
- func (cc *ControlClient) Close()
- func (cc *ControlClient) CloseAndReconnect(ctx context.Context)
- func (cc *ControlClient) Connect()
- func (cc *ControlClient) GetWSPath() string
- func (cc *ControlClient) HandleMessage(message []byte)
- func (cc *ControlClient) IsConnected() bool
- func (cc *ControlClient) RunForever(ctx context.Context)
- func (cc *ControlClient) WriteJSON(data interface{}) error
- type ControlMessage
- type Disk
- type File
- type FtpClient
- type FtpCommand
- type FtpConfigData
- type FtpContent
- type FtpData
- type FtpResult
- type GroupData
- type Interface
- type IsAlpconRequest
- type IsAlpconResponse
- type MFAResponse
- type OSData
- type Partition
- type PtyClient
- type ServerData
- type SessionInfo
- type SudoApprovalRequest
- type SudoApprovalResponse
- type SudoRequest
- type SystemData
- type TimeData
- type TunnelClient
- type UserData
- type WebsocketClient
- func (wc *WebsocketClient) Close()
- func (wc *WebsocketClient) CloseAndReconnect(ctx context.Context)
- func (wc *WebsocketClient) CommandRequestHandler(message []byte)
- func (wc *WebsocketClient) Connect()
- func (wc *WebsocketClient) ReadMessage() (messageType int, message []byte, err error)
- func (wc *WebsocketClient) Restart()
- func (wc *WebsocketClient) RestartCollector()
- func (wc *WebsocketClient) RunForever(ctx context.Context)
- func (wc *WebsocketClient) SendPingQuery() error
- func (wc *WebsocketClient) SendPongResponse() error
- func (wc *WebsocketClient) ShutDown()
- func (wc *WebsocketClient) WriteJSON(data interface{}) error
Constants ¶
const ( DOWNLOAD transferType = "download" UPLOAD transferType = "upload" )
const ( IFF_UP = 1 << 0 // Interface is up IFF_LOOPBACK = 1 << 3 // Loopback interface IFF_POINTOPOINT = 1 << 4 // Point-to-point link IFF_RUNNING = 1 << 6 // Interface is running )
const ( ErrPermissionDenied = "permission denied" ErrOperationNotPermitted = "operation not permitted" ErrTooLargeDepth = "depth has reached its limit. please try a lower depth" ErrInvalidArgument = "invalid argument" ErrNoSuchFileOrDirectory = "no such file or directory" ErrFileExists = "file exists" ErrDirectoryNotEmpty = "directory not empty" ErrInfiniteRecursion = "causing infinite recursion" )
const (
ConnectionReadTimeout = 35 * time.Minute
)
Variables ¶
This section is empty.
Functions ¶
func CloseTunnel ¶ added in v1.3.1
CloseTunnel closes an active tunnel by session ID.
func CommitAsync ¶
func RunTunnelWorker ¶ added in v1.3.1
func RunTunnelWorker(targetAddr string)
RunTunnelWorker runs the tunnel worker subprocess. It connects to the target address and relays data between stdin/stdout and the TCP connection. This function is called by the tunnel-worker subcommand and runs with demoted user credentials.
Types ¶
type Address ¶
type Address struct {
ID string `json:"id,omitempty"`
Address string `json:"address"`
Broadcast string `json:"broadcast"`
InterfaceName string `json:"interface_name,omitempty"`
Mask string `json:"mask"`
}
func (Address) GetComparableData ¶ added in v1.3.1
func (a Address) GetComparableData() ComparableData
func (Address) GetData ¶
func (a Address) GetData() ComparableData
type AuthManager ¶ added in v1.3.1
type AuthManager struct {
// contains filtered or unexported fields
}
func GetAuthManager ¶ added in v1.3.1
func GetAuthManager(controlClient *ControlClient, session *scheduler.Session) *AuthManager
func (*AuthManager) AddPIDSessionMapping ¶ added in v1.3.1
func (am *AuthManager) AddPIDSessionMapping(pid int, session *SessionInfo)
func (*AuthManager) HandleSudoApprovalResponse ¶ added in v1.3.1
func (am *AuthManager) HandleSudoApprovalResponse(response SudoApprovalResponse) error
HandleSudoApprovalResponse is used to handle the sudo_approval response from the alpacon-server
func (*AuthManager) RemovePIDSessionMapping ¶ added in v1.3.1
func (am *AuthManager) RemovePIDSessionMapping(pid int)
func (*AuthManager) Start ¶ added in v1.3.1
func (am *AuthManager) Start(ctx context.Context)
func (*AuthManager) Stop ¶ added in v1.3.1
func (am *AuthManager) Stop()
type BaseRequest ¶ added in v1.3.1
type BaseRequest struct {
Type string `json:"type"`
}
type CommandData ¶
type CommandData struct {
SessionID string `json:"session_id"`
URL string `json:"url"`
Rows uint16 `json:"rows"`
Cols uint16 `json:"cols"`
Username string `json:"username"`
Groupname string `json:"groupname"`
Groupnames []string `json:"groupnames"`
HomeDirectory string `json:"home_directory"`
HomeDirectoryPermission string `json:"home_directory_permission"`
PurgeHomeDirectory bool `json:"purge_home"`
UID uint64 `json:"uid"`
GID uint64 `json:"gid"`
Comment string `json:"comment"`
Shell string `json:"shell"`
Groups []uint64 `json:"groups"`
Type string `json:"type"`
Content string `json:"content"`
Path string `json:"path"`
Paths []string `json:"paths"`
Files []File `json:"files,omitempty"`
AllowOverwrite bool `json:"allow_overwrite,omitempty"`
AllowUnzip bool `json:"allow_unzip,omitempty"`
UseBlob bool `json:"use_blob,omitempty"`
Keys []string `json:"keys"`
ChainName string `json:"chain_name"`
Method string `json:"method"`
Chain string `json:"chain"`
Protocol string `json:"protocol"`
PortStart int `json:"port_start"`
PortEnd int `json:"port_end"`
DPorts []int `json:"dports"`
ICMPType string `json:"icmp_type"`
Source string `json:"source"`
Destination string `json:"destination"`
Target string `json:"target"`
Description string `json:"description"`
Priority int `json:"priority"`
RuleType string `json:"rule_type"`
Rules []map[string]interface{} `json:"rules"`
Operation string `json:"operation"` // batch, flush, delete, add, update
RuleID string `json:"rule_id"` // for rule-specific operations (add/update: new rule ID)
OldRuleID string `json:"old_rule_id"` // for update operation: old rule ID to delete
AssignmentID string `json:"assignment_id"`
ServerID string `json:"server_id"`
ChainNames []string `json:"chain_names"` // for firewall-reorder-chains
TargetPort int `json:"target_port"` // for tunneling
}
type CommandResult ¶
type CommandResult struct {
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Path string `json:"path,omitempty"`
Dst string `json:"dst,omitempty"`
Code int `json:"code,omitempty"`
Size int64 `json:"size,omitempty"`
Children []CommandResult `json:"children,omitempty"`
ModTime *time.Time `json:"mod_time,omitempty"`
Message string `json:"message,omitempty"`
PermissionString string `json:"permission_str,omitempty"`
PermissionOctal string `json:"permission_octal,omitempty"`
Owner string `json:"owner,omitempty"`
Group string `json:"group,omitempty"`
Target string `json:"target,omitempty"` // Symlink target path
}
func GetFtpErrorCode ¶
func GetFtpErrorCode(command FtpCommand, result CommandResult) (CommandResult, int)
type CommandRunner ¶
type CommandRunner struct {
// contains filtered or unexported fields
}
func NewCommandRunner ¶
func NewCommandRunner(wsClient *WebsocketClient, apiSession *scheduler.Session, command Command, data CommandData) *CommandRunner
func (*CommandRunner) Run ¶
func (cr *CommandRunner) Run()
type ComparableData ¶
type ComparableData interface {
GetID() string
GetKey() interface{}
GetData() ComparableData // For transmission (includes all raw data)
GetComparableData() ComparableData // For comparison (excludes fields not stored by server)
}
Defines the ComparableData interface for comparing different types. Ensures data retrieval for each key, excluding the ID field, while minimizing the use of reflection for better performance.
type ControlClient ¶ added in v1.3.1
ControlClient handles WebSocket connection for control messages (sudo_approval, etc.)
func NewControlClient ¶ added in v1.3.1
func NewControlClient() *ControlClient
NewControlClient creates a new ControlClient
func (*ControlClient) Close ¶ added in v1.3.1
func (cc *ControlClient) Close()
Close cleanly closes the WebSocket connection
func (*ControlClient) CloseAndReconnect ¶ added in v1.3.1
func (cc *ControlClient) CloseAndReconnect(ctx context.Context)
CloseAndReconnect closes current connection and reconnects
func (*ControlClient) Connect ¶ added in v1.3.1
func (cc *ControlClient) Connect()
Connect establishes WebSocket connection to control endpoint
func (*ControlClient) GetWSPath ¶ added in v1.3.1
func (cc *ControlClient) GetWSPath() string
GetWSPath returns the WebSocket URL for control endpoint
func (*ControlClient) HandleMessage ¶ added in v1.3.1
func (cc *ControlClient) HandleMessage(message []byte)
HandleMessage processes incoming control messages
func (*ControlClient) IsConnected ¶ added in v1.3.1
func (cc *ControlClient) IsConnected() bool
IsConnected returns whether the client is connected
func (*ControlClient) RunForever ¶ added in v1.3.1
func (cc *ControlClient) RunForever(ctx context.Context)
RunForever maintains the control WebSocket connection and handles messages
func (*ControlClient) WriteJSON ¶ added in v1.3.1
func (cc *ControlClient) WriteJSON(data interface{}) error
WriteJSON sends JSON data through the WebSocket connection
type ControlMessage ¶ added in v1.3.2
type ControlMessage struct {
Query string `json:"query"`
Data json.RawMessage `json:"data"`
}
ControlMessage represents the wrapper message from alpacon-server via Redis
type Disk ¶
type Disk struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
SerialNumber string `json:"serial_number"`
Label string `json:"label"`
}
func (Disk) GetComparableData ¶ added in v1.3.1
func (d Disk) GetComparableData() ComparableData
func (Disk) GetData ¶
func (d Disk) GetData() ComparableData
type FtpClient ¶
type FtpClient struct {
// contains filtered or unexported fields
}
func NewFtpClient ¶
func NewFtpClient(data FtpConfigData) *FtpClient
func (*FtpClient) RunFtpBackground ¶
func (fc *FtpClient) RunFtpBackground()
type FtpCommand ¶
type FtpCommand string
const ( List FtpCommand = "list" Mkd FtpCommand = "mkd" Cwd FtpCommand = "cwd" Pwd FtpCommand = "pwd" Dele FtpCommand = "dele" Rmd FtpCommand = "rmd" Mv FtpCommand = "mv" Cp FtpCommand = "cp" Chmod FtpCommand = "chmod" Chown FtpCommand = "chown" )
type FtpConfigData ¶
type FtpContent ¶
type FtpContent struct {
Command FtpCommand `json:"command"`
Data FtpData `json:"data"`
}
type FtpData ¶
type FtpData struct {
Path string `json:"path,omitempty"`
Depth int `json:"depth,omitempty"`
Recursive bool `json:"recursive,omitempty"`
ShowHidden bool `json:"show_hidden,omitempty"`
AllowOverwrite bool `json:"allow_overwrite,omitempty"`
Src string `json:"src,omitempty"`
Dst string `json:"dst,omitempty"`
Mode string `json:"mode,omitempty"`
Username string `json:"username,omitempty"`
Groupname string `json:"groupname,omitempty"`
}
type FtpResult ¶
type FtpResult struct {
Command FtpCommand `json:"command"`
Success bool `json:"success"`
Code int `json:"code,omitempty"`
Data CommandResult `json:"data,omitempty"`
}
type GroupData ¶
type GroupData struct {
ID string `json:"id,omitempty"`
GID int `json:"gid"`
GroupName string `json:"groupname"`
}
func (GroupData) GetComparableData ¶ added in v1.3.1
func (g GroupData) GetComparableData() ComparableData
func (GroupData) GetData ¶
func (g GroupData) GetData() ComparableData
type Interface ¶
type Interface struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Mac string `json:"mac"`
Type int `json:"type"`
Flags int `json:"flags"`
MTU int `json:"mtu"`
LinkSpeed int `json:"link_speed"`
}
func (Interface) GetComparableData ¶ added in v1.3.1
func (i Interface) GetComparableData() ComparableData
func (Interface) GetData ¶
func (i Interface) GetData() ComparableData
type IsAlpconRequest ¶ added in v1.3.1
type IsAlpconResponse ¶ added in v1.3.1
type MFAResponse ¶ added in v1.3.1
type OSData ¶
type OSData struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Version string `json:"version"`
Major int `json:"major"`
Minor int `json:"minor"`
Patch int `json:"patch"`
Platform string `json:"platform"`
PlatformLike string `json:"platform_like"`
}
func (OSData) GetComparableData ¶ added in v1.3.1
func (o OSData) GetComparableData() ComparableData
func (OSData) GetData ¶
func (o OSData) GetData() ComparableData
type Partition ¶
type Partition struct {
ID string `json:"id,omitempty"`
MountPoints []string `json:"mount_points"`
Name string `json:"name"`
DiskName string `json:"disk_name"`
Fstype string `json:"fs_type"`
IsVirtual bool `json:"is_virtual"`
}
func (Partition) GetComparableData ¶ added in v1.3.1
func (p Partition) GetComparableData() ComparableData
func (Partition) GetData ¶
func (p Partition) GetData() ComparableData
type PtyClient ¶
type PtyClient struct {
// contains filtered or unexported fields
}
func NewPtyClient ¶
func NewPtyClient(data CommandData, apiSession *scheduler.Session) *PtyClient
func (*PtyClient) RunPtyBackground ¶
func (pc *PtyClient) RunPtyBackground()
type ServerData ¶
type SessionInfo ¶ added in v1.3.1
type SessionInfo struct {
SessionID string
PID int
PtyClient *PtyClient
Requests map[string]*SudoRequest
}
type SudoApprovalRequest ¶ added in v1.3.1
type SudoApprovalRequest struct {
RequestID string `json:"request_id"`
Type string `json:"type"`
Username string `json:"username"`
Groupname string `json:"groupname"`
PID int `json:"pid"`
PPID int `json:"ppid"`
Command string `json:"command"`
IsAlpconUser bool `json:"is_alpacon_user"`
SessionID string `json:"session_id"`
}
type SudoApprovalResponse ¶ added in v1.3.1
type SudoApprovalResponse struct {
RequestID string `json:"request_id"`
Type string `json:"type"`
Username string `json:"username"`
Groupname string `json:"groupname"`
PID int `json:"pid"`
PPID int `json:"ppid"`
Command string `json:"command"`
IsAlpconUser bool `json:"is_alpacon_user"`
SessionID string `json:"session_id"`
Approved bool `json:"approved"`
Reason string `json:"reason"`
}
type SudoRequest ¶ added in v1.3.1
type SystemData ¶
type SystemData struct {
ID string `json:"id,omitempty"`
UUID string `json:"uuid"`
CPUType string `json:"cpu_type"`
CPUBrand string `json:"cpu_brand"`
CPUPhysicalCores int `json:"cpu_physical_cores"`
CPULogicalCores int `json:"cpu_logical_cores"`
PhysicalMemory uint64 `json:"physical_memory"`
HardwareVendor string `json:"hardware_vendor"`
HardwareModel string `json:"hardware_model"`
HardwareSerial string `json:"hardware_serial"`
ComputerName string `json:"computer_name"`
Hostname string `json:"hostname"`
LocalHostname string `json:"local_hostname"`
}
func (SystemData) GetComparableData ¶ added in v1.3.1
func (s SystemData) GetComparableData() ComparableData
func (SystemData) GetData ¶
func (s SystemData) GetData() ComparableData
func (SystemData) GetID ¶
func (s SystemData) GetID() string
func (SystemData) GetKey ¶
func (s SystemData) GetKey() interface{}
type TimeData ¶
type TimeData struct {
ID string `json:"id,omitempty"`
Datetime string `json:"datetime"`
BootTime uint64 `json:"boot_time"`
Timezone string `json:"timezone"`
Uptime uint64 `json:"uptime"`
}
func (TimeData) GetComparableData ¶ added in v1.3.1
func (t TimeData) GetComparableData() ComparableData
func (TimeData) GetData ¶
func (t TimeData) GetData() ComparableData
type TunnelClient ¶ added in v1.3.1
type TunnelClient struct {
// contains filtered or unexported fields
}
TunnelClient manages the smux-multiplexed tunnel connection to the proxy server. It accepts streams from the server and relays them to local services.
func GetActiveTunnel ¶ added in v1.3.1
func GetActiveTunnel(sessionID string) (*TunnelClient, bool)
GetActiveTunnel returns an active tunnel by session ID.
func NewTunnelClient ¶ added in v1.3.1
func NewTunnelClient(sessionID string, targetPort int, url string) *TunnelClient
NewTunnelClient creates a new tunnel client for the given WebSocket URL.
func (*TunnelClient) Close ¶ added in v1.3.1
func (tc *TunnelClient) Close()
Close cleanly shuts down the tunnel connection.
func (*TunnelClient) RunTunnelBackground ¶ added in v1.3.1
func (tc *TunnelClient) RunTunnelBackground()
RunTunnelBackground starts the tunnel connection in a goroutine.
type UserData ¶
type UserData struct {
ID string `json:"id,omitempty"`
UID int `json:"uid"`
GID int `json:"gid"`
Username string `json:"username"`
Description string `json:"description"`
Directory string `json:"directory"`
Shell string `json:"shell"`
ShadowExpireDate *int64 `json:"shadow_expire_date,omitempty"` // /etc/shadow: raw expiration date (days since epoch)
ValidShells []string `json:"valid_shells,omitempty"` // /etc/shells: full list of valid login shells
}
func (UserData) GetComparableData ¶ added in v1.3.1
func (u UserData) GetComparableData() ComparableData
GetComparableData returns data for comparison, excluding fields not stored by server. ValidShells is excluded because the server doesn't store it (system-wide, rarely changes). ShadowExpireDate is included because the server stores it for real-time expiration checks.
func (UserData) GetData ¶
func (u UserData) GetData() ComparableData
type WebsocketClient ¶
type WebsocketClient struct {
Conn *websocket.Conn
RestartChan chan struct{}
ShutDownChan chan struct{}
CollectorRestartChan chan struct{}
// contains filtered or unexported fields
}
func NewWebsocketClient ¶
func NewWebsocketClient(session *scheduler.Session) *WebsocketClient
func (*WebsocketClient) Close ¶
func (wc *WebsocketClient) Close()
Cleanly close the websocket connection by sending a close message Do not close quitChan, as the purpose here is to disconnect the WebSocket, not to terminate RunForever.
func (*WebsocketClient) CloseAndReconnect ¶
func (wc *WebsocketClient) CloseAndReconnect(ctx context.Context)
func (*WebsocketClient) CommandRequestHandler ¶
func (wc *WebsocketClient) CommandRequestHandler(message []byte)
func (*WebsocketClient) Connect ¶
func (wc *WebsocketClient) Connect()
func (*WebsocketClient) ReadMessage ¶
func (wc *WebsocketClient) ReadMessage() (messageType int, message []byte, err error)
func (*WebsocketClient) Restart ¶
func (wc *WebsocketClient) Restart()
func (*WebsocketClient) RestartCollector ¶
func (wc *WebsocketClient) RestartCollector()
func (*WebsocketClient) RunForever ¶
func (wc *WebsocketClient) RunForever(ctx context.Context)
func (*WebsocketClient) SendPingQuery ¶
func (wc *WebsocketClient) SendPingQuery() error
func (*WebsocketClient) SendPongResponse ¶ added in v1.3.0
func (wc *WebsocketClient) SendPongResponse() error
func (*WebsocketClient) ShutDown ¶
func (wc *WebsocketClient) ShutDown()
func (*WebsocketClient) WriteJSON ¶
func (wc *WebsocketClient) WriteJSON(data interface{}) error