worksession

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 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"
	// StatusPaused holds an active session until a person resumes or ends it.
	StatusPaused    = "paused"
	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 ClusterList added in v1.20.0

func ClusterList(ws *WorkSession) string

ClusterList is ServerList for the cluster a kube session targets.

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 IsClusterSession added in v1.20.0

func IsClusterSession(ws *WorkSession) bool

IsClusterSession reports whether ws targets a cluster, counting one the caller does not reach, which the server leaves out of Clusters.

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 ServerList added in v1.20.0

func ServerList(ws *WorkSession) string

ServerList is the servers ws targets as one line for a reader, saying how many more the caller does not reach, such as "web-1 and 1 more".

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 AccountFlag added in v1.20.0

type AccountFlag struct {
	Code          string   `json:"code"`
	Servers       []string `json:"servers"`
	ServersHidden *int     `json:"servers_hidden,omitempty"`
}

AccountFlag says the account the session runs as belongs to another person on some servers. Servers holds bare server IDs, only those the caller reaches; ServersHidden counts the rest.

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 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 PendingModificationRequest added in v1.20.0

type PendingModificationRequest struct {
	ID        string          `json:"id"`
	Changes   json.RawMessage `json:"changes"`
	AddedAt   time.Time       `json:"added_at"`
	CanCancel bool            `json:"can_cancel"`
}

PendingModificationRequest is a change to the session waiting on approval. Changes stays raw so every key the server sends, changes.servers_hidden among them, reaches the JSON output.

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"`
	OldHidden *int                  `json:"old_hidden,omitempty"`
	NewHidden *int                  `json:"new_hidden,omitempty"`
}

ServerDiff holds the requested (old) and granted (new) server lists. OldHidden and NewHidden count the servers each side leaves out because the caller does not reach them.

type SessionFilter added in v1.20.2

type SessionFilter struct {
	ClusterID     string
	ServerID      string
	Status        string
	RequesterType string
	AssignedUser  string
}

SessionFilter narrows a work session list. Empty fields are not sent; Status takes several statuses separated by commas. A server that ignores a filter still answers, so callers check targets locally.

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"`
	BroadPatterns     *[]string `json:"broad_patterns,omitempty"` // Read-only classification from the server.
}

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 {
	ID                     string              `json:"id"        table:"-"`
	Time                   utils.Timestamp     `json:"timestamp" table:"Time"`
	Type                   string              `json:"type"      table:"Type"`
	Server                 string              `json:"server"    table:"Server"`
	User                   string              `json:"user"      table:"User"`
	Details                utils.TruncatedText `json:"details"   table:"Details"`
	event.CommandRejection `table:"-"`
	SudoRefusalReason      types.SentString `json:"sudo_refusal_reason,omitzero" 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
	// The error code of the command's latest refused sudo, such as
	// work_session_scope_not_allowed; null when none was refused. Sent stays
	// false for a server that does not send the key.
	SudoRefusalReason types.SentString `json:"sudo_refusal_reason,omitzero"`

	// 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 {
	ConsoleURL    string                `json:"console_url,omitempty"`
	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"`
	// ServersHidden and ClustersHidden count the targets left out of Servers and Clusters because
	// the caller does not reach them; nil from a server older than Alpacon Server 2.48.0.
	ServersHidden *int `json:"servers_hidden,omitempty"`
	// 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"`
	// ClustersHidden counts the clusters left out of Clusters, as ServersHidden does for servers.
	ClustersHidden       *int               `json:"clusters_hidden,omitempty"`
	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"`
	ProposedSudoPolicies []SudoPolicyInline `json:"proposed_sudo_policies,omitempty"`
	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"`

	// PendingModificationRequest is the open change request on the session, nil when there is none.
	PendingModificationRequest *PendingModificationRequest `json:"pending_modification_request"`

	// AccountFlag is set when a target server binds the session's account to another person.
	// A server older than 2.44.0 sends no key, so a nil flag is left out rather than invented.
	AccountFlag *AccountFlag `json:"account_flag,omitempty"`

	// TargetAccountUsername is the account the session declares; empty when it declares none.
	TargetAccountUsername string `json:"target_account_username,omitempty"`
}

func CreateWorkSessionWithContext added in v1.20.2

func CreateWorkSessionWithContext(ctx context.Context, ac *client.AlpaconClient, req WorkSessionCreateRequest) (*WorkSession, error)

CreateWorkSessionWithContext is CreateWorkSession ended early by ctx; a request cut off without an answer may still have created the session.

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 GetWorkSession

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

func GetWorkSessionWithContext added in v1.20.0

func GetWorkSessionWithContext(ctx context.Context, ac *client.AlpaconClient, id string) (*WorkSession, error)

GetWorkSessionWithContext is GetWorkSession bounded by ctx.

func ListWorkSessions added in v1.20.2

func ListWorkSessions(ac *client.AlpaconClient, filter SessionFilter) ([]WorkSession, error)

ListWorkSessions returns whole work sessions, optionally narrowed to one server or cluster.

func ListWorkSessionsWithContext added in v1.20.2

func ListWorkSessionsWithContext(ctx context.Context, ac *client.AlpaconClient, filter SessionFilter) ([]WorkSession, error)

ListWorkSessionsWithContext is ListWorkSessions ended early by ctx.

func UpdateWorkSessionWithStatus added in v1.20.0

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

UpdateWorkSessionWithStatus patches a work session and returns the HTTP status. A 200 can still include a pending modification from an earlier request.

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        utils.AnnotatedText `json:"servers"                   table:"Servers"`
	Clusters       utils.AnnotatedText `json:"clusters"                  table:"Clusters"`
	ExpiresAt      utils.Timestamp     `json:"expires_at"                table:"Expires At"`
	Description    utils.TruncatedText `json:"description"               table:"Description"`
	ServersHidden  *int                `json:"servers_hidden,omitempty"  table:"-"`
	ClustersHidden *int                `json:"clusters_hidden,omitempty" table:"-"`
}

WorkSessionAttributes is a work session's list row; the Servers and Clusters table text adds the hidden count, which JSON carries in ServersHidden and ClustersHidden instead.

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