Documentation
¶
Index ¶
- Constants
- Variables
- func ExitOnWaitError(operation string, session *wsapi.WorkSession, next utils.NextAction, err error, ...)
- func IsKubeScope(scope string) bool
- func KubeLoginAction(clusterName, id string) utils.NextAction
- func MarkActive(rows []wsapi.WorkSessionAttributes, activeUUID string)
- func NormalizeClusterScopes(scopes []string) ([]string, error)
- func PrintSessionAdvisories(session *wsapi.WorkSession)
- func Resolve(ac *client.AlpaconClient, flagValue string) (string, error)
- func ResolveOrExit(ac *client.AlpaconClient, flagValue string) string
- func RunComplete(ac *client.AlpaconClient, id string) (bool, error)
- func RunCurrent(ac *client.AlpaconClient) (string, *wsapi.WorkSession, error)
- func RunRevoke(ac *client.AlpaconClient, id string) (bool, error)
- func RunUnset() error
- func RunUse(ac *client.AlpaconClient, uuid string) (string, error)
- func RunUseSession(ac *client.AlpaconClient, uuid string) (*wsapi.WorkSession, error)
- func TargetErrorHint(err error) string
- func ValidateAgentScopes(requesterType string, scopes []string) error
- func WaitForApproval(ac *client.AlpaconClient, id string, untilActive bool, ...) (*wsapi.WorkSession, error)
- func WriteCurrentRaw(ac *client.AlpaconClient, uuid string) error
- func WriteCurrentTable(ac *client.AlpaconClient, uuid string) error
Constants ¶
const ( ScopeKube = "kube" ScopeKubeExec = "kube_exec" )
The scopes a cluster work session holds: kube for the Kubernetes API, and kube_exec on top of it for exec, attach and port-forward into pods.
const ( // ApprovalPollInterval is the base gap between polls of a session waiting // on approval; utils.NextPollTick widens it as the wait ages. ApprovalPollInterval = 10 * time.Second )
const WorkSessionEnvVar = "ALPACON_WORK_SESSION"
WorkSessionEnvVar is the environment variable consulted when no --work-session flag is given.
Variables ¶
var ErrClusterSessionNotAttachable = errors.New("a cluster session cannot be the active work-session")
ErrClusterSessionNotAttachable refuses to set a cluster session as the active one.
var WorkSessionCmd = &cobra.Command{ Use: "work-session", Aliases: []string{"session"}, Short: "Create and manage work sessions", Long: `Create, inspect, and manage work sessions. Work sessions are approval-gated units that authorize access-path operations on Alpacon. Gated operations (require an active WorkSession under interactive auth): websh—'alpacon websh' (browser-based terminal) command—'alpacon exec' (remote command execution) webftp—'alpacon cp' (file transfer) tunnel—'alpacon tunnel' (port forwarding) sudo—'Privilege elevation' on Alpacon web (binding op: pending/approved/active allowed) kube—'alpacon kube login' and 'kube config' (Kubernetes API; needs a session that targets the cluster with --cluster); kube_exec adds exec, attach and port-forward Bypass: Token auth (API token or Service token) skips the requirement for 'exec', 'cp', 'edit', and 'websh SERVER COMMAND', but cannot run an interactive 'websh' terminal, 'websh watch', 'websh join', 'websh invite', or 'tunnel'—those need 'alpacon login' without -t (on a machine without a browser, open the printed URL on another device). Lifecycle: pending → approved → active → complete | expired | revoked (pending only → rejected | cancelled) Error codes returned when a session check fails: work_session_required no session selected for this shell work_session_not_active session not active (pending, approved, completed, revoked, or cancelled) work_session_expired session has expired work_session_scope_not_allowed operation not in session scopes work_session_server_not_allowed target server not in session work_session_cluster_not_allowed target cluster not in session work_session_assignee_mismatch session assigned to another principal work_session_agent_session_required the CLI runs under an AI agent; use an agent session work_session_not_usable session is no longer usable Run 'alpacon whoami' to check your WorkSession requirement and active session.`, RunE: func(cmd *cobra.Command, args []string) error { return utils.RequireSubcommand(cmd, "Approval and rejection happen in the Alpacon console (web) or Slack.") }, }
Functions ¶
func ExitOnWaitError ¶ added in v1.18.0
func ExitOnWaitError(operation string, session *wsapi.WorkSession, next utils.NextAction, err error, pendingNext ...utils.NextAction)
ExitOnWaitError ends the process for a wait on session that did not reach its goal. Both outcomes match 'alpacon event wait': a settled negative outcome exits 6, and a wait that ran out with the outcome still open exits 4 and offers next, the step to take once the session is approved. Only a polling failure falls through to the general-error code.
func IsKubeScope ¶ added in v1.18.0
IsKubeScope reports whether scope belongs to a cluster session.
func KubeLoginAction ¶ added in v1.18.0
func KubeLoginAction(clusterName, id string) utils.NextAction
KubeLoginAction is the follow-up for a cluster session: 'kube login' opens a kube session under it and writes the kubeconfig context. It takes the session by ID for a person and an agent alike, since a cluster session is never attached as the active one.
func MarkActive ¶
func MarkActive(rows []wsapi.WorkSessionAttributes, activeUUID string)
MarkActive puts "*" in the Active column of the row whose ID is activeUUID unless that session has ended, since one ended outside this CLI stays in config. Safe with an empty activeUUID or slice.
func NormalizeClusterScopes ¶ added in v1.18.0
NormalizeClusterScopes checks a scope list for a cluster session and puts it in the order the server lists it. kube_exec implies kube, which every cluster session holds, so it is added rather than refused, the way --sudo adds the sudo scope; anything but kube and kube_exec is refused.
func PrintSessionAdvisories ¶ added in v1.18.0
func PrintSessionAdvisories(session *wsapi.WorkSession)
PrintSessionAdvisories shows what the approver changed or recommended, such as a scope dropped from the request. Text mode only—JSON callers return before reaching this.
func Resolve ¶
func Resolve(ac *client.AlpaconClient, flagValue string) (string, error)
Resolve returns the effective work-session UUID using flag > env var > config priority. The config fallback reads ac's pinned workspace, so the UUID matches where the request goes.
func ResolveOrExit ¶ added in v1.7.0
func ResolveOrExit(ac *client.AlpaconClient, flagValue string) string
ResolveOrExit resolves the work-session UUID and exits on error.
func RunComplete ¶ added in v1.16.0
func RunComplete(ac *client.AlpaconClient, id string) (bool, error)
RunComplete completes the session; see endSession.
func RunCurrent ¶
func RunCurrent(ac *client.AlpaconClient) (string, *wsapi.WorkSession, error)
RunCurrent returns the active work-session UUID and its server-side details. Returns ("", nil, nil) when nothing is set, or (uuid, nil, err) if set but unreachable.
func RunRevoke ¶ added in v1.16.0
func RunRevoke(ac *client.AlpaconClient, id string) (bool, error)
RunRevoke revokes the session; see endSession.
func RunUnset ¶
func RunUnset() error
RunUnset clears the active work-session for the current workspace; it is a no-op when nothing is set.
func RunUse ¶
func RunUse(ac *client.AlpaconClient, uuid string) (string, error)
RunUse validates the work-session via the server, then stores it in config. Returns the human-readable description on success.
func RunUseSession ¶ added in v1.6.0
func RunUseSession(ac *client.AlpaconClient, uuid string) (*wsapi.WorkSession, error)
RunUseSession validates the work-session via the server, then stores it in config.
func TargetErrorHint ¶ added in v1.18.0
TargetErrorHint says what to do about the server's refusal of a work session's targets, scopes or lifetime, or returns "" for any other error.
func ValidateAgentScopes ¶ added in v1.18.0
ValidateAgentScopes returns an error when requester_type is "agent" and scopes contains one an agent session cannot hold (websh, kube_exec), which the server disallows.
func WaitForApproval ¶ added in v1.18.0
func WaitForApproval(ac *client.AlpaconClient, id string, untilActive bool, interval, timeout time.Duration) (*wsapi.WorkSession, error)
WaitForApproval polls until the session reaches a terminal state or timeout elapses. It returns on approved or active, or only on active when untilActive is set. It is deadline-based, so a timeout under one interval still waits the full duration. A fatal 4xx ends the wait at once and other transient failures end it at MaxConsecutivePollFailures; 429s are bounded by the throttle budget and the deadline instead.
func WriteCurrentRaw ¶ added in v1.16.0
func WriteCurrentRaw(ac *client.AlpaconClient, uuid string) error
func WriteCurrentTable ¶ added in v1.16.0
func WriteCurrentTable(ac *client.AlpaconClient, uuid string) error
WriteCurrentTable projects the session through ProjectAttributes so the columns match 'work-session ls', and marks it as 'ls' does.
Types ¶
This section is empty.
Source Files
¶
- cluster_session.go
- resolve.go
- worksession.go
- worksession_activate.go
- worksession_approve.go
- worksession_cancel.go
- worksession_complete.go
- worksession_create.go
- worksession_current.go
- worksession_describe.go
- worksession_extend.go
- worksession_extend_errors.go
- worksession_list.go
- worksession_output.go
- worksession_recording.go
- worksession_reject.go
- worksession_revoke.go
- worksession_timeline.go
- worksession_update.go
- worksession_use.go