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 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) ListSessions(_ context.Context, _ *k8shelldv1.ListSessionsRequest) (*k8shelldv1.ListSessionsResponse, 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) ListSessions(ctx context.Context, req *k8shelldv1.ListSessionsRequest) (*k8shelldv1.ListSessionsResponse, 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
- func (s *SystemServiceServer) GetBlueprint(_ context.Context, _ *k8shelldv1.GetBlueprintRequest) (*k8shelldv1.GetBlueprintResponse, error)
- func (s *SystemServiceServer) GetLogsPage(ctx context.Context, req *k8shelldv1.GetLogsPageRequest) (*k8shelldv1.GetLogsPageResponse, error)
- func (s *SystemServiceServer) GetLogsStream(req *k8shelldv1.SystemLogsStreamRequest, ...) error
- func (s *SystemServiceServer) Handshake(ctx context.Context, req *k8shelldv1.HandshakeRequest) (*k8shelldv1.HandshakeResponse, error)
- func (s *SystemServiceServer) SystemInfo(ctx context.Context, _ *k8shelldv1.SystemInfoRequest) (*k8shelldv1.SystemInfoResponse, error)
- func (s *SystemServiceServer) SystemInfoHistory(_ context.Context, req *k8shelldv1.SystemInfoHistoryRequest) (*k8shelldv1.SystemInfoHistoryResponse, error)
- 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 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
Exec runs a command as `<shell> -c <command>`, like sshd, optionally attached to a PTY. The shell is the shell_binary hint if it exists in the workspace, otherwise the user's passwd login shell, otherwise /bin/sh.
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
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, 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) ListSessions ¶ added in v0.16.0
func (s *ShellHandler) ListSessions(_ context.Context, _ *k8shelldv1.ListSessionsRequest) (*k8shelldv1.ListSessionsResponse, error)
ListSessions implements SshServiceServer.ListSessions. It returns the set of live PTY sessions that AcquireSession would currently accept: no client attached and no unexpired lock held, along with the OS user each session runs as.
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) ListSessions ¶ added in v0.16.0
func (s *SshServiceServer) ListSessions(ctx context.Context, req *k8shelldv1.ListSessionsRequest) (*k8shelldv1.ListSessionsResponse, 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) GetBlueprint ¶ added in v0.16.0
func (s *SystemServiceServer) GetBlueprint(_ context.Context, _ *k8shelldv1.GetBlueprintRequest) (*k8shelldv1.GetBlueprintResponse, error)
GetBlueprint returns the raw blueprint YAML content this workspace was created from.
func (*SystemServiceServer) GetLogsPage ¶ added in v0.16.0
func (s *SystemServiceServer) GetLogsPage(ctx context.Context, req *k8shelldv1.GetLogsPageRequest) (*k8shelldv1.GetLogsPageResponse, error)
GetLogsPage returns one page of k8shelld daemon logs strictly older than the requested BeforeId, for "load more" / infinite-scroll style backward pagination independent of GetLogsStream's live tail.
func (*SystemServiceServer) GetLogsStream ¶ added in v0.16.0
func (s *SystemServiceServer) GetLogsStream(req *k8shelldv1.SystemLogsStreamRequest, stream k8shelldv1.SystemService_GetLogsStreamServer) error
GetLogsStream streams k8shelld daemon logs (the same logs shown by `kbox logs`). With Follow=false it sends the currently buffered entries and closes the stream; with Follow=true it keeps streaming new entries as they are produced until the client cancels.
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.
func (*SystemServiceServer) SystemInfoHistory ¶ added in v0.16.0
func (s *SystemServiceServer) SystemInfoHistory(_ context.Context, req *k8shelldv1.SystemInfoHistoryRequest) (*k8shelldv1.SystemInfoHistoryResponse, error)
SystemInfoHistory returns historical system/mount/docker usage samples for charting. See the proto comment on SystemInfoHistoryRequest for the precedence of range vs from/to and how step coarsening works.
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