worksession

package
v1.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	StatusPending   = "pending"
	StatusApproved  = "approved"
	StatusActive    = "active"
	StatusCompleted = "completed"
	StatusExpired   = "expired"
	StatusRevoked   = "revoked"
	StatusRejected  = "rejected"
	StatusCancelled = "cancelled"
)

Variables

This section is empty.

Functions

func ActivateWorkSession

func ActivateWorkSession(ac *client.AlpaconClient, id string) error

func CancelWorkSession added in v1.9.0

func CancelWorkSession(ac *client.AlpaconClient, id string) error

CancelWorkSession withdraws a pending session. Unlike the superuser-only RevokeWorkSession, the server restricts it to the creator or a superuser, and it rejects a session no longer pending.

func ClusterNames added in v1.18.0

func ClusterNames(ws *WorkSession) []string

ClusterNames lists the names of the clusters ws targets.

func CompleteWorkSession

func CompleteWorkSession(ac *client.AlpaconClient, id string) error

func EndedStatuses added in v1.17.0

func EndedStatuses() []string

func FormatDuration added in v1.18.0

func FormatDuration(d time.Duration) string

FormatDuration renders d the way the server reads a duration, HH:MM:SS with the hours left unbounded, rounding up to the whole second so a sub-second remainder is never dropped to zero.

func FormatExpiresAt added in v1.18.0

func FormatExpiresAt(t time.Time) string

FormatExpiresAt leaves blank the expiry of a session created with a duration, which has none until it activates.

func GetTerminalRecording added in v1.16.0

func GetTerminalRecording(ac *client.AlpaconClient, id, webshSessionID string) (record, addedAt string, found bool, err error)

GetTerminalRecording reads one Websh session's recording through the work session's records route, joining the chunks in order. addedAt is the first chunk's added_at, and found is false when the session has no recording.

func GetWorkSessionRaw

func GetWorkSessionRaw(ac *client.AlpaconClient, id string) ([]byte, error)

func IsEndedStatus added in v1.17.0

func IsEndedStatus(status string) bool

func IsTerminal added in v1.19.0

func IsTerminal(item *TimelineItem) bool

IsTerminal reports whether a timeline item is a Websh terminal, the unit that `recording --index` counts. Tunnels are Websh sessions the server lists under their own type and have no recording, so they are not terminals.

func ListTerminalSessionIDs added in v1.16.0

func ListTerminalSessionIDs(ac *client.AlpaconClient, id string) ([]string, error)

ListTerminalSessionIDs returns the ids of a work session's Websh terminals in timeline order.

func RevokeWorkSession

func RevokeWorkSession(ac *client.AlpaconClient, id string) error

func ServerNames added in v1.18.0

func ServerNames(ws *WorkSession) []string

ServerNames lists the names of the servers ws targets.

func TargetsCluster added in v1.18.0

func TargetsCluster(ws *WorkSession, clusterID string) bool

TargetsCluster reports whether ws names clusterID among its targets.

Types

type Adjustments added in v1.9.0

type Adjustments struct {
	Scopes  *ScopeDiff  `json:"scopes,omitempty"`
	Servers *ServerDiff `json:"servers,omitempty"`
}

Adjustments is the approver's diff; each dimension is set only when changed, nil when unchanged.

type ClusterSessionFilter added in v1.18.0

type ClusterSessionFilter struct {
	ClusterID     string
	Status        string
	RequesterType string
	AssignedUser  string
}

ClusterSessionFilter narrows GetClusterWorkSessions. Empty fields are not sent; Status takes several statuses separated by commas.

type PendingExtensionRequest added in v1.14.0

type PendingExtensionRequest struct {
	ID                 string    `json:"id"`
	RequestedExpiresAt time.Time `json:"requested_expires_at"`
	ExpiresAt          time.Time `json:"expires_at"`
	Reason             string    `json:"reason"`
	AddedAt            time.Time `json:"added_at"`
}

PendingExtensionRequest is the open request 'extend' filed instead of applying at once. ExpiresAt is the request's own deadline, never later than the session's expiry when it was filed; WorkSession.ExpiresAt keeps its prior value until the request is decided.

type Recommendation added in v1.9.0

type Recommendation struct {
	ID            string `json:"id"`
	Text          string `json:"text"`
	Severity      string `json:"severity"`
	Source        string `json:"source"`
	AutoCheckable bool   `json:"auto_checkable"`
}

Recommendation is an admin-confirmed note attached at approval time.

type RecordChunk added in v1.16.0

type RecordChunk struct {
	AddedAt string `json:"added_at"`
	Record  string `json:"record"`
}

RecordChunk is one entry of the per-session recording route's cursor envelope.

type ScopeDiff added in v1.9.0

type ScopeDiff struct {
	Old []string `json:"old"`
	New []string `json:"new"`
}

ScopeDiff holds the requested (old) and granted (new) scope lists.

type ServerDiff added in v1.9.0

type ServerDiff struct {
	Old []types.ServerSummary `json:"old"`
	New []types.ServerSummary `json:"new"`
}

ServerDiff holds the requested (old) and granted (new) server lists.

type SudoPolicyInline added in v1.5.0

type SudoPolicyInline struct {
	ID                string   `json:"id,omitempty"`
	Commands          []string `json:"commands"`
	Reason            string   `json:"reason,omitempty"`
	SessionAuthorized bool     `json:"session_authorized"`
}

SudoPolicyInline is a sudo policy bound to a work session, read from a WorkSession and sent on create and update. Commands are the allowed patterns, wildcards permitted. SessionAuthorized lets matching sudo run in the approved session without an MFA prompt, the only way a non-interactive caller can sudo. There is no Users field: the server binds the policy to the session assignee.

ID is set only on read and on update. An update's sudo_policies is the full desired set: send existing policies back with their ID and new ones without, since a policy left out is deleted.

func (SudoPolicyInline) MarshalJSON added in v1.18.0

func (p SudoPolicyInline) MarshalJSON() ([]byte, error)

MarshalJSON sends both names so older servers receive the same policy.

func (*SudoPolicyInline) UnmarshalJSON added in v1.18.0

func (p *SudoPolicyInline) UnmarshalJSON(data []byte) error

type TimelineAttributes added in v1.4.8

type TimelineAttributes struct {
	Time                   string `json:"timestamp" table:"Time"`
	Type                   string `json:"type"      table:"Type"`
	Server                 string `json:"server"    table:"Server"`
	User                   string `json:"user"      table:"User"`
	Details                string `json:"details"   table:"Details"`
	event.CommandRejection `table:"-"`
}

type TimelineItem added in v1.4.8

type TimelineItem struct {
	Type      string  `json:"type"`
	Timestamp *string `json:"timestamp"`
	ID        string  `json:"id"`
	ServerID  *string `json:"server_id"`

	// shared across session-like types (websh_session, tunnel_session, ftp_session)
	Username   string  `json:"username"`
	Groupname  string  `json:"groupname"`
	ClosedAt   *string `json:"closed_at"`
	ClientType string  `json:"client_type"`

	// command
	Shell              string  `json:"shell"`
	Line               string  `json:"line"`
	Success            *bool   `json:"success"`
	Denied             bool    `json:"denied"`
	ElapsedTime        float64 `json:"elapsed_time"`
	VerificationStatus string  `json:"verification_status"`
	event.CommandRejection

	// tunnel_session
	IsTunnel   bool `json:"is_tunnel"`
	TargetPort *int `json:"target_port"`

	// file_upload / file_download
	Name string `json:"name"`
	Size int64  `json:"size"`

	// sudo_grant
	GrantType string  `json:"grant_type"`
	Status    string  `json:"status"`
	Command   *string `json:"command"`
	OneTime   bool    `json:"one_time"`

	// websh_session: record_chunks_total is nil both when the server sends null
	// (it could not count) and when it sends no key (it predates the count), so
	// neither reads as "no recording".
	RecordChunksTotal *int `json:"record_chunks_total"`
}

TimelineItem represents a single event in a work session's activity timeline. All event types share this struct; type-specific fields are zero-valued for other types.

func GetWorkSessionTimeline added in v1.4.8

func GetWorkSessionTimeline(ac *client.AlpaconClient, id string) ([]TimelineItem, error)

GetWorkSessionTimeline reads a work session's timeline by cursor. Its items carry no recordings; read one with GetTerminalRecording.

func (TimelineItem) IsRejected added in v1.19.0

func (t TimelineItem) IsRejected() bool

IsRejected says a command item was refused before it ran; every rejection, the agent's signature refusal included, leaves verification_status rejected.

type WorkSession

type WorkSession struct {
	ID            string                `json:"id"`
	Title         string                `json:"title"`
	Description   string                `json:"description"`
	Status        string                `json:"status"`
	RequesterType string                `json:"requester_type"`
	Scopes        []string              `json:"scopes"`
	Servers       []types.ServerSummary `json:"servers"`
	// Clusters is the one cluster a kube work session targets; a session
	// targets either servers or a cluster, never both.
	Clusters          []types.ClusterSummary `json:"clusters"`
	CreatedBy         *types.UserSummary     `json:"created_by"`
	AssignedUser      *types.UserSummary     `json:"assigned_user"`
	ApprovalRequestID string                 `json:"approval_request_id"`
	StartsAt          *time.Time             `json:"starts_at"`
	ExpiresAt         time.Time              `json:"expires_at"`
	StartedAt         *time.Time             `json:"started_at"`
	CompletedAt       *time.Time             `json:"completed_at"`
	AddedAt           time.Time              `json:"added_at"`
	UpdatedAt         time.Time              `json:"updated_at"`
	SudoPolicies      []SudoPolicyInline     `json:"sudo_policies"`
	Adjustments       *Adjustments           `json:"adjustments"`
	Recommendations   []Recommendation       `json:"recommendations"`

	// PendingExtensionRequest is the open extension request, nil when there is none. 'extend'
	// answers 202 with it set when the workspace's approval policy holds the request, and later
	// reads keep it set until the request is approved, rejected, cancelled, or lapses.
	PendingExtensionRequest *PendingExtensionRequest `json:"pending_extension_request"`
}

func ExtendWorkSession

func ExtendWorkSession(ac *client.AlpaconClient, id string, req WorkSessionExtendRequest) (*WorkSession, int, error)

ExtendWorkSession requests a new expires_at for a running session and returns the HTTP status: 200 when the session is already extended, 202 when the workspace's approval policy holds the request and PendingExtensionRequest is populated. Branch on the status, not the field: a 200 body can still carry a stale request, such as a lapsed one the server has not yet cleared.

func GetClusterWorkSessions added in v1.18.0

func GetClusterWorkSessions(ac *client.AlpaconClient, filter ClusterSessionFilter) ([]WorkSession, error)

GetClusterWorkSessions returns, whole, the work sessions that target one cluster, through the server's cluster filter.

func GetWorkSession

func GetWorkSession(ac *client.AlpaconClient, id string) (*WorkSession, error)

func UpdateWorkSession added in v1.5.0

func UpdateWorkSession(ac *client.AlpaconClient, id string, req WorkSessionUpdateRequest) (*WorkSession, error)

UpdateWorkSession PATCHes a work session. The server may queue the change for approval, in which case it takes effect only once approved.

type WorkSessionAttributes

type WorkSessionAttributes struct {
	// Active is "*" on the workspace's active session and empty otherwise;
	// cmd/worksession.MarkActive sets it.
	Active      string `json:"-"           table:"Active"`
	ID          string `json:"id"          table:"ID"`
	Status      string `json:"status"      table:"Status"`
	Scopes      string `json:"scopes"      table:"Scopes"`
	Servers     string `json:"servers"     table:"Servers"`
	Clusters    string `json:"clusters"    table:"Clusters"`
	ExpiresAt   string `json:"expires_at"  table:"Expires At"`
	Description string `json:"description" table:"Description"`
}

func GetWorkSessionList

func GetWorkSessionList(ac *client.AlpaconClient, status, requesterType, assignedUser string) ([]WorkSessionAttributes, error)

func ProjectAttributes

func ProjectAttributes(ws *WorkSession) WorkSessionAttributes

ProjectAttributes converts a WorkSession into its table row.

type WorkSessionCreateRequest

type WorkSessionCreateRequest struct {
	Description   string             `json:"description"`
	RequesterType string             `json:"requester_type"`
	Scopes        []string           `json:"scopes"`
	Servers       []string           `json:"servers,omitempty"`
	Clusters      []string           `json:"clusters,omitempty"`
	ExpiresAt     string             `json:"expires_at,omitempty"`
	Duration      string             `json:"duration,omitempty"`
	SudoPolicies  []SudoPolicyInline `json:"sudo_policies,omitempty"`
	// TargetAccountUsername is the account the work runs as on the servers.
	// Left out, the server decides the account itself.
	TargetAccountUsername string `json:"target_account_username,omitempty"`
}

WorkSessionCreateRequest targets either Servers or Clusters, never both. The lifetime is either ExpiresAt, an absolute RFC3339 time, or Duration, which the server counts from activation so an approval wait does not shorten it.

type WorkSessionExtendRequest

type WorkSessionExtendRequest struct {
	ExpiresAt string `json:"expires_at"`
	Reason    string `json:"reason,omitempty"`
}

WorkSessionExtendRequest is the payload for the extend action. The server requires Reason (work_session_extension_reason_required otherwise); it is omitted when empty so a caller without --reason gets that refusal rather than an empty string sent.

type WorkSessionUpdateRequest added in v1.5.0

type WorkSessionUpdateRequest struct {
	Title        string             `json:"title,omitempty"`
	Description  string             `json:"description,omitempty"`
	Scopes       []string           `json:"scopes,omitempty"`
	Servers      []string           `json:"servers,omitempty"`
	StartsAt     string             `json:"starts_at,omitempty"`
	ExpiresAt    string             `json:"expires_at,omitempty"`
	SudoPolicies []SudoPolicyInline `json:"sudo_policies,omitempty"`
}

WorkSessionUpdateRequest is a partial update: omitempty leaves unset fields untouched. SudoPolicies replaces the whole set, so existing policies must be sent back or they are deleted; an empty slice is omitted, so this request cannot clear policies.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL