Documentation
¶
Index ¶
- type AppServiceServer
- func (s *AppServiceServer) GetLogs(ctx context.Context, req *k8shelldv1.GetLogsRequest) (*k8shelldv1.GetLogsResponse, error)
- func (s *AppServiceServer) GetLogsStream(req *k8shelldv1.GetLogsStreamRequest, ...) error
- func (s *AppServiceServer) InstallApp(ctx context.Context, req *k8shelldv1.InstallAppRequest) (*k8shelldv1.InstallAppResponse, error)
- func (s *AppServiceServer) ListApps(ctx context.Context, req *k8shelldv1.ListAppsRequest) (*k8shelldv1.ListAppsResponse, error)
- func (s *AppServiceServer) StartApp(ctx context.Context, req *k8shelldv1.StartAppRequest) (*k8shelldv1.StartAppResponse, error)
- func (s *AppServiceServer) StopApp(ctx context.Context, req *k8shelldv1.StopAppRequest) (*k8shelldv1.StopAppResponse, error)
- type CommandServiceServer
- type DetachedSessionInfo
- type ExecData
- type ExecHandler
- type GRPCService
- func (a *GRPCService) DetachShellSession(sessionId string, ttl *time.Duration) error
- func (a *GRPCService) GetAllStreamData() ([]StoreRecord, error)
- func (a *GRPCService) ListDetachedSessions() []DetachedSessionInfo
- func (a *GRPCService) NumSessions() uint32
- func (a *GRPCService) ResizeSession(sessionId string, width, height uint32) error
- func (a *GRPCService) Serve(ctx context.Context) error
- func (a *GRPCService) ServeRESTAttach(sessionId string, conn net.Conn) error
- func (a *GRPCService) SetInitTracker(t *models.InitTracker)
- func (a *GRPCService) ValidateSessionForAttach(sessionId string) (int, error)
- type PortForwardData
- type PortForwardHandler
- type RingBuffer
- type SessionData
- type ShellHandler
- func (s *ShellHandler) AcquireSession(ctx context.Context, req *k8shelldv1.AcquireSessionRequest) (*k8shelldv1.AcquireSessionResponse, error)
- func (s *ShellHandler) GetCWD(_ context.Context, req *k8shelldv1.GetCWDRequest) (*k8shelldv1.GetCWDResponse, error)
- func (s *ShellHandler) GetSessionData(ctx context.Context) (*SessionData, error)
- func (s *ShellHandler) GetSessionID(ctx context.Context) (string, error)
- func (s *ShellHandler) ResizeTerminal(ctx context.Context, req *k8shelldv1.ResizeTerminalRequest) (*k8shelldv1.ResizeTerminalResponse, error)
- func (s *ShellHandler) Shell(...) error
- type SshServiceServer
- func (s *SshServiceServer) AcquireSession(ctx context.Context, req *k8shelldv1.AcquireSessionRequest) (*k8shelldv1.AcquireSessionResponse, error)
- func (s *SshServiceServer) Exec(...) error
- func (s *SshServiceServer) GetCWD(ctx context.Context, req *k8shelldv1.GetCWDRequest) (*k8shelldv1.GetCWDResponse, error)
- func (s *SshServiceServer) PortForward(...) error
- func (s *SshServiceServer) ResizeTerminal(ctx context.Context, req *k8shelldv1.ResizeTerminalRequest) (*k8shelldv1.ResizeTerminalResponse, error)
- func (s *SshServiceServer) Shell(...) error
- func (s *SshServiceServer) UnixSocket(...) error
- type StoreRecord
- type SystemServiceServer
- type UnixSocketHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppServiceServer ¶
type AppServiceServer struct {
k8shelldv1.UnimplementedAppServiceServer
// contains filtered or unexported fields
}
AppServiceServer implements the gRPC server for application management.
func NewAppServiceServer ¶
func NewAppServiceServer(appManager *apps.AppManager) *AppServiceServer
NewAppServiceServer creates a new AppServiceServer instance.
func (*AppServiceServer) GetLogs ¶
func (s *AppServiceServer) GetLogs(ctx context.Context, req *k8shelldv1.GetLogsRequest) (*k8shelldv1.GetLogsResponse, error)
GetLogs retrieves the logs of the specified type (install/app) for the given app name.
func (*AppServiceServer) GetLogsStream ¶
func (s *AppServiceServer) GetLogsStream(req *k8shelldv1.GetLogsStreamRequest, stream k8shelldv1.AppService_GetLogsStreamServer) error
GetLogsStream streams the logs of the specified type (install/app) for the given app name.
func (*AppServiceServer) InstallApp ¶
func (s *AppServiceServer) InstallApp(ctx context.Context, req *k8shelldv1.InstallAppRequest) (*k8shelldv1.InstallAppResponse, error)
InstallApp installs the specified application by name.
func (*AppServiceServer) ListApps ¶
func (s *AppServiceServer) ListApps(ctx context.Context, req *k8shelldv1.ListAppsRequest) (*k8shelldv1.ListAppsResponse, error)
ListApps lists the status of all applications.
func (*AppServiceServer) StartApp ¶
func (s *AppServiceServer) StartApp(ctx context.Context, req *k8shelldv1.StartAppRequest) (*k8shelldv1.StartAppResponse, error)
StartApp starts the specified application by name.
func (*AppServiceServer) StopApp ¶
func (s *AppServiceServer) StopApp(ctx context.Context, req *k8shelldv1.StopAppRequest) (*k8shelldv1.StopAppResponse, error)
StopApp stops the specified application by name.
type CommandServiceServer ¶
type CommandServiceServer struct {
k8shelldv1.UnimplementedCommandServiceServer
// contains filtered or unexported fields
}
CommandServiceServer implements the gRPC server for command execution.
It manages a single active logical connection (bidi stream) from a client. Other parts of the server can send commands to that client via SendCommand, and await the reply. Replies from the client are correlated using command_id.
func NewCommandServiceServer ¶
func NewCommandServiceServer() *CommandServiceServer
NewCommandServiceServer creates a new CommandServiceServer instance.
func (*CommandServiceServer) CommandListener ¶
func (s *CommandServiceServer) CommandListener(stream k8shelldv1.CommandService_CommandListenerServer) error
CommandListener implements the bidi streaming RPC defined in the proto. Only a single active client is supported at a time; a new connection replaces any previous one.
func (*CommandServiceServer) SendCommand ¶
SendCommand sends a command to exactly one connected client and waits for reply.
type DetachedSessionInfo ¶
type DetachedSessionInfo struct {
Id string `json:"id"`
CmdShell string `json:"cmd_shell"`
Pid int `json:"pid"`
Created string `json:"created"`
DetachedAt string `json:"detached_at"`
}
DetachedSessionInfo is returned by ListDetachedSessions.
type ExecData ¶
type ExecData struct {
Id string
Command string
Created time.Time
Deleted time.Time
BytesIn uint64
BytesOut uint64
}
exec data structure
type ExecHandler ¶
type ExecHandler struct {
// contains filtered or unexported fields
}
ExecHandler is the service that handles the exec GRPC service server
func (*ExecHandler) Exec ¶
func (s *ExecHandler) Exec(stream grpc.BidiStreamingServer[k8shelldv1.ExecRequest, k8shelldv1.ExecResponse]) error
type GRPCService ¶
type GRPCService struct {
Config *config.Config // The main configuration
ExecStore *sync.Map // The store for the exec data
PortForwardStore *sync.Map // The store for the port forwarding data
SessionStore *sync.Map // The store for the session data
UnixSocketStore *sync.Map // The store for the unix socket data
CommandService *CommandServiceServer // The command service
SessionLockStore *sync.Map // stores *sessionLock keyed by lock ID
// contains filtered or unexported fields
}
GRPCApiService is the main service that handles the gRPC API
func NewGRPCService ¶
func NewGRPCService(config *config.Config, blueprint *commonmodels.Blueprint, user *models.User, jwtVerifier *authz.JWTVerifier, procWatcher *system.ProcessWatcher, apiClient *apiClient.Client, appManager *apps.AppManager, sysInfo *system.SystemInfo) (*GRPCService, error)
NewGRPCAPI creates a new GRPCApiService
func (*GRPCService) DetachShellSession ¶
func (a *GRPCService) DetachShellSession(sessionId string, ttl *time.Duration) error
DetachShellSession triggers a detach on the currently attached client for the given session, optionally setting a per-session TTL override. The shell process and ring buffer stay alive.
func (*GRPCService) GetAllStreamData ¶
func (a *GRPCService) GetAllStreamData() ([]StoreRecord, error)
func (*GRPCService) ListDetachedSessions ¶
func (a *GRPCService) ListDetachedSessions() []DetachedSessionInfo
ListDetachedSessions returns sessions that are alive but have no attached client
func (*GRPCService) NumSessions ¶
func (a *GRPCService) NumSessions() uint32
NumSessions returns the number of active sessions
func (*GRPCService) ResizeSession ¶
func (a *GRPCService) ResizeSession(sessionId string, width, height uint32) error
ResizeSession resizes the PTY of any shell session (attached or detached).
func (*GRPCService) Serve ¶
func (a *GRPCService) Serve(ctx context.Context) error
Serve starts the gRPC server and registers the services. It also sets up the TLS configuration and the interceptor.
func (*GRPCService) ServeRESTAttach ¶
func (a *GRPCService) ServeRESTAttach(sessionId string, conn net.Conn) error
ServeRESTAttach attaches a hijacked HTTP conn to the session: replays the ring-buffer scrollback, registers the conn as the current sender, then bridges PTY I/O until the session ends or the client calls `kbox detach`. Blocks until the session is destroyed or detached.
func (*GRPCService) SetInitTracker ¶
func (a *GRPCService) SetInitTracker(t *models.InitTracker)
SetInitTracker wires the init script tracker into the gRPC service so that new PTY shell sessions can display init progress before handing off to the shell.
func (*GRPCService) ValidateSessionForAttach ¶
func (a *GRPCService) ValidateSessionForAttach(sessionId string) (int, error)
ValidateSessionForAttach checks that a session exists, is a live PTY session, and has no client currently attached.
type PortForwardData ¶
type PortForwardData struct {
Id string
Destination string
Port uint16
Created time.Time
Deleted time.Time
BytesIn uint64
BytesOut uint64
}
Port-forward data structure
type PortForwardHandler ¶
type PortForwardHandler struct {
// contains filtered or unexported fields
}
PortForwardHandler is the service that handles the port-forwarding GRPC service server
func (*PortForwardHandler) GetPortForwardData ¶
func (s *PortForwardHandler) GetPortForwardData(ctx context.Context) (*PortForwardData, error)
Get the port-forward data from the store. It uses the port-forward ID retrieved from the metadata
func (*PortForwardHandler) GetPortForwardID ¶
func (s *PortForwardHandler) GetPortForwardID(ctx context.Context) (string, error)
Get the port-forward ID from the gRPC metadata "portforward-id"
func (*PortForwardHandler) PortForward ¶
func (s *PortForwardHandler) PortForward( stream grpc.BidiStreamingServer[k8shelldv1.PortForwardRequest, k8shelldv1.PortForwardResponse], ) error
PortForward sets up a TCP <-> gRPC bidi bridge. First request must be Destination. Then we stream bytes both ways until client closes, TCP closes, context cancels, or an error occurs.
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer is a thread-safe fixed-capacity circular byte buffer. When full, new writes overwrite the oldest data (like a terminal scrollback).
func (*RingBuffer) Mark ¶
func (r *RingBuffer) Mark()
Mark records the current write position. A subsequent SnapshotSinceMark call will return only bytes written after this point.
func (*RingBuffer) Snapshot ¶
func (r *RingBuffer) Snapshot() []byte
Snapshot returns a copy of all buffered data in order (oldest to newest).
func (*RingBuffer) SnapshotSinceMark ¶
func (r *RingBuffer) SnapshotSinceMark() []byte
SnapshotSinceMark returns only the bytes written since the last Mark call. If no mark has been set, it behaves like Snapshot. If more bytes were written than the buffer capacity since the mark, all currently buffered bytes are returned (the oldest ones were overwritten).
func (*RingBuffer) Write ¶
func (r *RingBuffer) Write(data []byte)
Write appends data to the buffer, overwriting the oldest bytes when full.
type SessionData ¶
type SessionData struct {
Id string
CmdShell string
Cmd *exec.Cmd
Ptmx *os.File
Pid int
Created time.Time
Deleted time.Time
BytesIn uint64
BytesOut uint64
// PTY session state (nil/zero for non-PTY sessions)
DetachedAt time.Time // set when a client detaches from a live session
DetachTTL *time.Duration // per-session TTL override; nil = use server default; 0 = never expire
// contains filtered or unexported fields
}
SessionData stores the data of a shell session.
type ShellHandler ¶
type ShellHandler struct {
// contains filtered or unexported fields
}
ShellHandler is the service that handles the shell GRPC service server
func (*ShellHandler) AcquireSession ¶
func (s *ShellHandler) AcquireSession(ctx context.Context, req *k8shelldv1.AcquireSessionRequest) (*k8shelldv1.AcquireSessionResponse, error)
AcquireSession implements SshServiceServer.AcquireSession. It validates that the requested session exists, is a live detached PTY session with no client attached and no unexpired lock, then creates and returns a lock ID
func (*ShellHandler) GetCWD ¶
func (s *ShellHandler) GetCWD(_ context.Context, req *k8shelldv1.GetCWDRequest) (*k8shelldv1.GetCWDResponse, error)
GetCWD returns the current working directory of the shell process identified by the shell_id in the request. The CWD is resolved by reading the /proc/<pid>/cwd symlink of the shell process.
func (*ShellHandler) GetSessionData ¶
func (s *ShellHandler) GetSessionData(ctx context.Context) (*SessionData, error)
Get the session data from the store. It uses the session ID retrieved from the metadata
func (*ShellHandler) GetSessionID ¶
func (s *ShellHandler) GetSessionID(ctx context.Context) (string, error)
Get the port-forward ID from the gRPC metadata "portforward-id"
func (*ShellHandler) ResizeTerminal ¶
func (s *ShellHandler) ResizeTerminal(ctx context.Context, req *k8shelldv1.ResizeTerminalRequest) (*k8shelldv1.ResizeTerminalResponse, error)
ResizeTerminal is a gRPC method that resizes the terminal of a shell session.
func (*ShellHandler) Shell ¶
func (s *ShellHandler) Shell(stream grpc.BidiStreamingServer[k8shelldv1.ShellRequest, k8shelldv1.ShellResponse]) error
Shell is a gRPC method that starts a shell session. It is a bidirectional streaming RPC that sends the shell output to the client and receives the client input to send to the shell.
type SshServiceServer ¶
type SshServiceServer struct {
k8shelldv1.UnimplementedSshServiceServer
// contains filtered or unexported fields
}
SshServiceServer implements k8shelldv1.SshServiceServer by composing the individual service implementations.
func NewSshServiceServer ¶
func NewSshServiceServer(grpcapi *GRPCService) *SshServiceServer
NewSshServiceServer creates a new SshServiceServer.
func (*SshServiceServer) AcquireSession ¶
func (s *SshServiceServer) AcquireSession(ctx context.Context, req *k8shelldv1.AcquireSessionRequest) (*k8shelldv1.AcquireSessionResponse, error)
func (*SshServiceServer) Exec ¶
func (s *SshServiceServer) Exec(stream grpc.BidiStreamingServer[k8shelldv1.ExecRequest, k8shelldv1.ExecResponse]) error
func (*SshServiceServer) GetCWD ¶
func (s *SshServiceServer) GetCWD(ctx context.Context, req *k8shelldv1.GetCWDRequest) (*k8shelldv1.GetCWDResponse, error)
func (*SshServiceServer) PortForward ¶
func (s *SshServiceServer) PortForward(stream grpc.BidiStreamingServer[k8shelldv1.PortForwardRequest, k8shelldv1.PortForwardResponse]) error
func (*SshServiceServer) ResizeTerminal ¶
func (s *SshServiceServer) ResizeTerminal(ctx context.Context, req *k8shelldv1.ResizeTerminalRequest) (*k8shelldv1.ResizeTerminalResponse, error)
func (*SshServiceServer) Shell ¶
func (s *SshServiceServer) Shell(stream grpc.BidiStreamingServer[k8shelldv1.ShellRequest, k8shelldv1.ShellResponse]) error
func (*SshServiceServer) UnixSocket ¶
func (s *SshServiceServer) UnixSocket(stream grpc.BidiStreamingServer[k8shelldv1.UnixSocketRequest, k8shelldv1.UnixSocketResponse]) error
type StoreRecord ¶
type SystemServiceServer ¶
type SystemServiceServer struct {
k8shelldv1.UnimplementedSystemServiceServer
// contains filtered or unexported fields
}
SystemServiceServer is the gRPC server for the system service
func NewSystemServiceServer ¶
func NewSystemServiceServer(grpcapi *GRPCService) *SystemServiceServer
NewSystemServiceServer creates a new SystemServiceServer
func (*SystemServiceServer) Handshake ¶
func (s *SystemServiceServer) Handshake(ctx context.Context, req *k8shelldv1.HandshakeRequest) (*k8shelldv1.HandshakeResponse, error)
Handshake validates version compatibility. Returns the server version and Accepted=true on success; returns a descriptive Message and Accepted=false (not a gRPC error) for version mismatches so the caller can surface a helpful message to the user.
func (*SystemServiceServer) SystemInfo ¶
func (s *SystemServiceServer) SystemInfo(ctx context.Context, _ *k8shelldv1.SystemInfoRequest) (*k8shelldv1.SystemInfoResponse, error)
SystemInfo returns system metrics + mount usage + docker usage over gRPC. Mirrors the REST /sysinfo payload.
type UnixSocketHandler ¶
type UnixSocketHandler struct {
// contains filtered or unexported fields
}
UnixSocketHandler is the service that handles the shell GRPC service server
func (*UnixSocketHandler) GetUnixSocketData ¶
func (s *UnixSocketHandler) GetUnixSocketData(ctx context.Context) (*SessionData, error)
Get the unix socket data from the store. It uses the unix socket ID retrieved from the metadata
func (*UnixSocketHandler) GetUnixSocketID ¶
func (s *UnixSocketHandler) GetUnixSocketID(ctx context.Context) (string, error)
Get the unix socket ID from the gRPC metadata "unixsocket-id"
func (*UnixSocketHandler) UnixSocket ¶
func (s *UnixSocketHandler) UnixSocket(stream grpc.BidiStreamingServer[k8shelldv1.UnixSocketRequest, k8shelldv1.UnixSocketResponse]) error