Documentation
¶
Index ¶
- Constants
- Variables
- func ActivateWorkSession(ac *client.AlpaconClient, id string) error
- func CancelWorkSession(ac *client.AlpaconClient, id string) error
- func ClusterNames(ws *WorkSession) []string
- func CompleteWorkSession(ac *client.AlpaconClient, id string) error
- func EndedStatuses() []string
- func FormatDuration(d time.Duration) string
- func FormatExpiresAt(t time.Time) string
- func GetTerminalRecording(ac *client.AlpaconClient, id, webshSessionID string) (record, addedAt string, found bool, err error)
- func GetWorkSessionRaw(ac *client.AlpaconClient, id string) ([]byte, error)
- func IsEndedStatus(status string) bool
- func ListTerminalSessionIDs(ac *client.AlpaconClient, id string) ([]string, error)
- func RevokeWorkSession(ac *client.AlpaconClient, id string) error
- func ServerNames(ws *WorkSession) []string
- func TargetsCluster(ws *WorkSession, clusterID string) bool
- type Adjustments
- type ClusterSessionFilter
- type PendingExtensionRequest
- type Recommendation
- type RecordChunk
- type ScopeDiff
- type ServerDiff
- type SudoPolicyInline
- type TimelineAttributes
- type TimelineItem
- type WorkSession
- func CreateWorkSession(ac *client.AlpaconClient, req WorkSessionCreateRequest) (*WorkSession, error)
- func ExtendWorkSession(ac *client.AlpaconClient, id string, req WorkSessionExtendRequest) (*WorkSession, int, error)
- func GetClusterWorkSessions(ac *client.AlpaconClient, filter ClusterSessionFilter) ([]WorkSession, error)
- func GetWorkSession(ac *client.AlpaconClient, id string) (*WorkSession, error)
- func UpdateWorkSession(ac *client.AlpaconClient, id string, req WorkSessionUpdateRequest) (*WorkSession, error)
- type WorkSessionAttributes
- type WorkSessionCreateRequest
- type WorkSessionExtendRequest
- type WorkSessionUpdateRequest
Constants ¶
const ( StatusPending = "pending" StatusApproved = "approved" StatusActive = "active" StatusCompleted = "completed" StatusExpired = "expired" StatusRevoked = "revoked" StatusRejected = "rejected" StatusCancelled = "cancelled" )
Variables ¶
var ErrTimelinePaginated = errors.New(
"this server paginates the work session timeline, which this version of alpacon reads only whole, " +
"so it would show the first page as the whole session; run 'alpacon update' to install a version " +
"that reads the timeline page by page and its recordings through the per-session recording route",
)
ErrTimelinePaginated is returned when a whole-timeline read is answered with a `next`, so a page is never shown as the whole session.
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
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
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 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. Tunnels are Websh sessions the server lists under their own type and have no recording, so they are not terminals.
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
RecordChunk is one entry of the per-session recording route's cursor envelope.
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 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"`
// 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_record
SessionID string `json:"session_id"`
MaskedRecord string `json:"masked_record"`
}
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, includeRecords bool) ([]TimelineItem, error)
GetWorkSessionTimeline reads a work session's activity timeline. A request naming `cursor`, even empty, is paginated and its pages carry no recordings; one naming no `cursor` gets the whole timeline with recordings and no `next` key. So includeRecords picks the shape. `include_records` rides on the paginated read too, for a server that does not paginate this route.
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 CreateWorkSession ¶
func CreateWorkSession(ac *client.AlpaconClient, req WorkSessionCreateRequest) (*WorkSession, error)
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.