sessionrecord

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package sessionrecord records the hub's proxy sessions durably (Task 20383): the git proxy's lease-path and workspace sessions, the Kubernetes monitor's sessions and every run's egress session, in statedb's proxy_sessions (migrations/0058_proxy_sessions.sql), so the hub process that adopts a run after the one serving it stops can restore them; and the CI relay's sessions, in ci_sessions (migrations/0060_ci_sessions.sql, Task 20390), so the hub process that receives a job's next call after the one serving it stops can restore the job's session.

It is the seam between three registries that must not know about the database — pkg/gitproxy, pkg/kubeguard, pkg/egressbroker each define a SessionStore — and the table. Each store writes as the hub process its Holder names, the cluster member id the run's lease is recorded under, and every write after the insert is fenced on it: a session another process took over with its run is that process's to extend, checkpoint and close.

What goes in a row is what the registries keep in memory instead of a credential: the SHA-256 of the token a sandbox presents, and the scope the session enforces. The record types it is handed have no field a credential could travel in, and tests/security scans the table after a realistic run for anything that did.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoHolder = errors.New("this hub process has no cluster member id to record sessions under")

ErrNoHolder: the process has no cluster member id to record a session under, so nothing could take it over.

Functions

func EgressCounters

EgressCounters decodes an egress row's counters, zero when they do not parse.

func EgressRecord

EgressRecord reads a row back into what egressbroker.Broker.RestoreSession takes.

func GitRecord

GitRecord reads a row back into what gitproxy.Registry.Restore takes.

func KubeRecord

KubeRecord reads a row back into what kubeguard.Registry.Restore takes.

Types

type CIProvenance

type CIProvenance struct {
	RuleName   string          `json:"rule_name,omitempty"`
	Project    string          `json:"project,omitempty"`
	Subject    string          `json:"subject,omitempty"`
	Repository string          `json:"repository,omitempty"`
	Ref        string          `json:"ref,omitempty"`
	Workflow   string          `json:"workflow,omitempty"`
	Actor      string          `json:"actor,omitempty"`
	RunID      string          `json:"run_id,omitempty"`
	RunURL     string          `json:"run_url,omitempty"`
	Claims     json.RawMessage `json:"claims,omitempty"`
}

CIProvenance is a CI relay session's provenance_json (Task 20390): which pipeline its rule admitted. Claims is the verified payload of the OIDC token the session was minted for — the job's identity, not a credential: the token's signature is not kept, so nothing here can be exchanged again.

func CIRecord

CIRecord reads a row back into what claudeproxy.Registry.Restore takes, and its provenance.

type CIStore

type CIStore struct {
	// contains filtered or unexported fields
}

CIStore is a claudeproxy.SessionStore over the control plane's database, recording CI relay sessions in ci_sessions (Task 20390). Its writes after the insert are fenced on the holder, like the other stores'.

func NewCIStore

func NewCIStore(db *statedb.DB, holder func() string, instance string,
	onError func(kind, id, what string, err error)) CIStore

NewCIStore returns a store writing as holder, for the hub instance named instance.

func (CIStore) CheckpointSession

func (c CIStore) CheckpointSession(id string, u claudeproxy.Usage, lastUsed time.Time) error

CheckpointSession implements claudeproxy.SessionStore. A checkpoint that lands on no row is an error, so the registry writes it again next time rather than believing the record holds it.

func (CIStore) CloseSession

func (c CIStore) CloseSession(id, reason string, at time.Time, u claudeproxy.Usage) error

CloseSession implements claudeproxy.SessionStore.

func (CIStore) SaveSession

func (c CIStore) SaveSession(rec claudeproxy.SessionRecord) error

SaveSession implements claudeproxy.SessionStore.

type EgressScope

type EgressScope struct {
	Grant  egressbroker.Grant `json:"grant"`
	Labels map[string]string  `json:"labels,omitempty"`
}

EgressScope is an egress session's scope_json.

type EgressStore

type EgressStore struct {
	// contains filtered or unexported fields
}

EgressStore is an egressbroker.SessionStore over the control plane's database.

func NewEgressStore

func NewEgressStore(db *statedb.DB, holder func() string, onError func(kind, id, what string, err error)) EgressStore

NewEgressStore returns a store writing as holder.

func (EgressStore) CheckpointSession

func (e EgressStore) CheckpointSession(id string, c egressbroker.SessionCounters) error

CheckpointSession implements egressbroker.SessionStore. A checkpoint that lands on no row is an error, so the broker writes it again next time rather than believing the record holds it.

func (EgressStore) CloseSession

func (e EgressStore) CloseSession(id, reason string, at time.Time, c egressbroker.SessionCounters) error

CloseSession implements egressbroker.SessionStore.

func (EgressStore) ExtendSession

func (e EgressStore) ExtendSession(id string, expiresAt time.Time) error

ExtendSession implements egressbroker.SessionStore.

func (EgressStore) SaveSession

func (e EgressStore) SaveSession(rec egressbroker.SessionRecord) error

SaveSession implements egressbroker.SessionStore.

type GitScope

type GitScope struct {
	RepoPath     string   `json:"repo_path,omitempty"`
	RepoPatterns []string `json:"repo_patterns,omitempty"`
	Upstream     string   `json:"upstream"`
	// ForgeHost is the forge host the session's credential is good against
	// (Task 20423). Absent from a record written before hosts were recorded,
	// which gitproxy reads as github.com for a scoped session and the
	// upstream's host for a pinned one.
	ForgeHost string          `json:"forge_host,omitempty"`
	Policy    gitproxy.Policy `json:"policy"`
}

GitScope is a git session's scope_json.

func GitScopeOf

func GitScopeOf(row statedb.ProxySessionRow) (GitScope, error)

GitScopeOf decodes a git row's scope.

type GitStore

type GitStore struct {
	// contains filtered or unexported fields
}

GitStore is a gitproxy.SessionStore over the control plane's database.

func NewGitStore

func NewGitStore(db *statedb.DB, holder func() string, onError func(kind, id, what string, err error)) GitStore

NewGitStore returns a store writing as holder.

func (GitStore) CloseSession

func (g GitStore) CloseSession(id, reason string, at time.Time) error

CloseSession implements gitproxy.SessionStore.

func (GitStore) RenewSession added in v0.0.6

func (g GitStore) RenewSession(id string, expiresAt, renewedAt time.Time) error

RenewSession implements gitproxy.SessionStore.

func (GitStore) SaveSession

func (g GitStore) SaveSession(rec gitproxy.SessionRecord) error

SaveSession implements gitproxy.SessionStore.

type KubeScope

type KubeScope struct {
	ClusterURL string           `json:"cluster_url"`
	Context    string           `json:"context,omitempty"`
	Policy     kubeguard.Policy `json:"policy"`
}

KubeScope is a Kubernetes monitor session's scope_json.

func KubeScopeOf

func KubeScopeOf(row statedb.ProxySessionRow) (KubeScope, error)

KubeScopeOf decodes a kube row's scope.

type KubeStore

type KubeStore struct {
	// contains filtered or unexported fields
}

KubeStore is a kubeguard.SessionStore over the control plane's database.

func NewKubeStore

func NewKubeStore(db *statedb.DB, holder func() string, onError func(kind, id, what string, err error)) KubeStore

NewKubeStore returns a store writing as holder.

func (KubeStore) CloseSession

func (k KubeStore) CloseSession(id, reason string, at time.Time) error

CloseSession implements kubeguard.SessionStore.

func (KubeStore) SaveSession

func (k KubeStore) SaveSession(rec kubeguard.SessionRecord) error

SaveSession implements kubeguard.SessionStore.

Jump to

Keyboard shortcuts

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