Documentation
¶
Index ¶
- Variables
- func APIKeyNames(ctx context.Context, db *sqlx.DB, actors []string) (map[string]string, error)
- func AddOrgMember(ctx context.Context, db *sqlx.DB, m *models.OrgMember) error
- func AuditPredsBySeq(ctx context.Context, q ExecQuerier, seqs []int64) (map[int64]AuditPred, error)
- func Connect(cfg config.DatabaseConfig) (*sqlx.DB, error)
- func CountAPIKeys(ctx context.Context, db *sqlx.DB) (int, error)
- func CountActiveSessionsByActor(ctx context.Context, db *sqlx.DB, actor string) (int, error)
- func CountArtifacts(ctx context.Context, db *sqlx.DB, actor string) (int, error)
- func CountAuditLogs(ctx context.Context, db *sqlx.DB, sessionID *uuid.UUID, actor string) (int, error)
- func CountAuditLogsFiltered(ctx context.Context, db *sqlx.DB, f AuditFilter) (int, error)
- func CountFiles(ctx context.Context, db *sqlx.DB, sessionID uuid.UUID) (int, error)
- func CountOrgSessions(ctx context.Context, db *sqlx.DB, orgID uuid.UUID) (int, error)
- func CountOrgs(ctx context.Context, db *sqlx.DB) (int, error)
- func CountRuns(ctx context.Context, db *sqlx.DB, sessionID uuid.UUID) (int, error)
- func CountRunsGlobal(ctx context.Context, db *sqlx.DB) (int, error)
- func CountSessions(ctx context.Context, db *sqlx.DB) (int, error)
- func CountSessionsFiltered(ctx context.Context, db *sqlx.DB, actor, labelKey, labelValue string) (int, error)
- func CountSessionsForActor(ctx context.Context, db *sqlx.DB, actor, labelKey, labelValue string) (int, error)
- func CreateAPIKey(ctx context.Context, db *sqlx.DB, k *models.APIKey) error
- func CreateArtifact(ctx context.Context, db *sqlx.DB, a *models.SharedArtifact) error
- func CreateAuditLog(ctx context.Context, db sqlx.ExtContext, a *models.AuditLog) error
- func CreateOrg(ctx context.Context, db *sqlx.DB, o *models.Organization) error
- func CreateRun(ctx context.Context, db *sqlx.DB, r *models.Run) error
- func CreateSession(ctx context.Context, db *sqlx.DB, s *models.Session) error
- func CreateSnapshot(ctx context.Context, db *sqlx.DB, s *models.Snapshot) error
- func DeleteArtifact(ctx context.Context, db *sqlx.DB, id uuid.UUID) (string, error)
- func DeleteAuditSeqThrough(ctx context.Context, q ExecQuerier, seq int64) (int64, error)
- func DeleteFile(ctx context.Context, db *sqlx.DB, sessionID uuid.UUID, path string) error
- func DeleteOldAuditLogs(ctx context.Context, db *sqlx.DB, before time.Time) (int64, error)
- func DeleteOrg(ctx context.Context, db *sqlx.DB, id uuid.UUID) error
- func DeleteSnapshot(ctx context.Context, db *sqlx.DB, id uuid.UUID) (string, error)
- func DeleteUnchainedAuditBefore(ctx context.Context, q ExecQuerier, before time.Time, chainStart *time.Time) (int64, error)
- func FailSession(ctx context.Context, db *sqlx.DB, id uuid.UUID) error
- func FailStalePendingRuns(ctx context.Context, db *sqlx.DB, before time.Time) (int64, error)
- func FirstPrefixedAuditTime(ctx context.Context, db *sqlx.DB, prefix string) (*time.Time, error)
- func GetAPIKeyAllowedSecrets(ctx context.Context, db *sqlx.DB, id uuid.UUID) ([]string, error)
- func GetAPIKeyByHash(ctx context.Context, db *sqlx.DB, keyHash string) (*models.APIKey, error)
- func GetActorOrgs(ctx context.Context, db *sqlx.DB, principal string) ([]*models.OrgMember, error)
- func GetArtifact(ctx context.Context, db *sqlx.DB, id uuid.UUID) (*models.SharedArtifact, error)
- func GetFile(ctx context.Context, db *sqlx.DB, sessionID uuid.UUID, path string) (*models.File, error)
- func GetOrg(ctx context.Context, db *sqlx.DB, id uuid.UUID) (*models.Organization, error)
- func GetOrgBySlug(ctx context.Context, db *sqlx.DB, slug string) (*models.Organization, error)
- func GetOrgMember(ctx context.Context, db *sqlx.DB, orgID uuid.UUID, principal string) (*models.OrgMember, error)
- func GetOrgMemberRole(ctx context.Context, db *sqlx.DB, orgID uuid.UUID, principal string) (string, error)
- func GetRun(ctx context.Context, db *sqlx.DB, id uuid.UUID) (*models.Run, error)
- func GetSession(ctx context.Context, db *sqlx.DB, id uuid.UUID) (*models.Session, error)
- func GetSnapshot(ctx context.Context, db *sqlx.DB, id uuid.UUID) (*models.Snapshot, error)
- func InsertAuditChainHead(ctx context.Context, q ExecQuerier, h *AuditChainHead) error
- func LastChainedAuditEntry(ctx context.Context, q ExecQuerier) (seq int64, sig string, err error)
- func ListAPIKeys(ctx context.Context, db *sqlx.DB) ([]*models.APIKey, error)
- func ListActiveSessions(ctx context.Context, db *sqlx.DB) ([]*models.Session, error)
- func ListArtifacts(ctx context.Context, db *sqlx.DB, actor string, limit, offset int) ([]*models.SharedArtifact, error)
- func ListAuditLogs(ctx context.Context, db *sqlx.DB, sessionID *uuid.UUID, actor string, ...) ([]*models.AuditLog, error)
- func ListAuditLogsFiltered(ctx context.Context, db *sqlx.DB, f AuditFilter, limit, offset int) ([]*models.AuditLog, error)
- func ListAuditSince(ctx context.Context, db *sqlx.DB, since time.Time, limit int) ([]models.AuditLog, error)
- func ListFiles(ctx context.Context, db *sqlx.DB, sessionID uuid.UUID) ([]*models.File, error)
- func ListOrgMembers(ctx context.Context, db *sqlx.DB, orgID uuid.UUID) ([]*models.OrgMember, error)
- func ListOrgSessions(ctx context.Context, db *sqlx.DB, orgID uuid.UUID, limit, offset int) ([]*models.Session, error)
- func ListOrgs(ctx context.Context, db *sqlx.DB, limit, offset int) ([]*models.Organization, error)
- func ListRuns(ctx context.Context, db *sqlx.DB, sessionID uuid.UUID, limit, offset int) ([]*models.Run, error)
- func ListSessions(ctx context.Context, db *sqlx.DB, actor, labelKey, labelValue string, ...) ([]*models.Session, error)
- func ListSessionsForActor(ctx context.Context, db *sqlx.DB, actor, labelKey, labelValue string, ...) ([]*models.Session, error)
- func ListSnapshots(ctx context.Context, db *sqlx.DB, sessionID uuid.UUID) ([]*models.Snapshot, error)
- func PurgeAPIKey(ctx context.Context, db *sqlx.DB, id uuid.UUID) error
- func RemoveOrgMember(ctx context.Context, db *sqlx.DB, orgID uuid.UUID, principal string) error
- func RevokeAPIKey(ctx context.Context, db *sqlx.DB, id uuid.UUID) error
- func RunMigrations(db *sqlx.DB, migrationsPath string) error
- func SetAPIKeyAllowedSecrets(ctx context.Context, db *sqlx.DB, id uuid.UUID, allowed []string) error
- func StopSession(ctx context.Context, db *sqlx.DB, id uuid.UUID) error
- func SumWorkspaceBytes(ctx context.Context, db *sqlx.DB, sessionID uuid.UUID) (int64, error)
- func TotalArtifactBytes(ctx context.Context, db *sqlx.DB, actor string) (int64, error)
- func UpdateAPIKeyLastUsed(ctx context.Context, db *sqlx.DB, id uuid.UUID) error
- func UpdateAuditChainHead(ctx context.Context, q ExecQuerier, h *AuditChainHead) error
- func UpdateRun(ctx context.Context, db *sqlx.DB, p UpdateRunParams) error
- func UpdateSessionLabels(ctx context.Context, db *sqlx.DB, id uuid.UUID, labels models.JSONB) error
- func UpdateSessionStatus(ctx context.Context, db *sqlx.DB, id uuid.UUID, status string, ...) error
- func UpsertFile(ctx context.Context, db *sqlx.DB, f *models.File) error
- type AuditChainHead
- type AuditFilter
- type AuditPred
- type ExecQuerier
- type OrgWithRole
- type UpdateRunParams
Constants ¶
This section is empty.
Variables ¶
var ErrKeyStillActive = errors.New("api key is still active")
ErrKeyStillActive is returned by PurgeAPIKey for a key that has not been revoked.
Functions ¶
func APIKeyNames ¶ added in v0.4.7
APIKeyNames maps actor identifiers (API key UUIDs, or "master") to key names. Identifiers that are not UUIDs or belong to a deleted key are left out, so callers fall back to showing the raw identifier.
func AuditPredsBySeq ¶ added in v0.4.6
AuditPredsBySeq returns the signature and timestamp stored for each requested sequence number.
func CountActiveSessionsByActor ¶
CountActiveSessionsByActor returns the number of active (not stopped) sessions for a given actor. Used to enforce per-actor session limits.
func CountArtifacts ¶
func CountAuditLogs ¶
func CountAuditLogs(ctx context.Context, db *sqlx.DB, sessionID *uuid.UUID, actor string) (int, error)
CountAuditLogs mirrors the filter logic of ListAuditLogs for accurate totals.
func CountAuditLogsFiltered ¶ added in v0.4.2
func CountFiles ¶
func CountOrgSessions ¶
func CountSessionsFiltered ¶
func CountSessionsFiltered(ctx context.Context, db *sqlx.DB, actor, labelKey, labelValue string) (int, error)
CountSessionsFiltered returns the number of active sessions matching the same filters as ListSessions (actor + optional label key/value).
func CountSessionsForActor ¶
func CountSessionsForActor(ctx context.Context, db *sqlx.DB, actor, labelKey, labelValue string) (int, error)
CountSessionsForActor mirrors ListSessionsForActor for pagination totals.
func CreateArtifact ¶
func CreateAuditLog ¶
func CreateSnapshot ¶
func DeleteArtifact ¶
func DeleteAuditSeqThrough ¶ added in v0.4.6
DeleteAuditSeqThrough deletes the chained entries numbered 1 through seq and returns how many rows went. The caller has already checked that they form an intact, old prefix of the chain.
func DeleteFile ¶
func DeleteOldAuditLogs ¶
DeleteOldAuditLogs removes audit log entries whose timestamp is older than the given cutoff. Returns the number of rows deleted. Called by the background cleanup goroutine when AUDIT_LOG_RETENTION_DAYS > 0.
func DeleteSnapshot ¶
func DeleteUnchainedAuditBefore ¶ added in v0.4.6
func DeleteUnchainedAuditBefore(ctx context.Context, q ExecQuerier, before time.Time, chainStart *time.Time) (int64, error)
DeleteUnchainedAuditBefore deletes entries that never had a chain number and are older than before. When chainStart is set, only those written before chaining began count: an unnumbered entry from later is not legacy, it is an entry whose number was removed, and it is evidence.
func FailSession ¶ added in v0.4.1
FailSession marks a session whose container could not be created. It sets stopped_at as well so the session no longer counts as active (quota, listings).
func FailStalePendingRuns ¶
FailStalePendingRuns marks as "failed" any runs that are still in the "pending" state and were created before the given cutoff timestamp.
This is called at startup to clean up runs that were mid-flight when the previous server instance was killed (e.g., a crash or SIGKILL during an in-memory queue drain). Without this cleanup, such runs sit in "pending" forever and are never surfaced to callers as failures.
For the Redis Streams backend, the reaper goroutine handles re-delivery; this function is a last-resort safety net for both queue backends.
func FirstPrefixedAuditTime ¶ added in v0.4.4
FirstPrefixedAuditTime returns the timestamp of the earliest audit entry whose signature starts with prefix, or nil when there is none.
func GetAPIKeyAllowedSecrets ¶ added in v0.4.1
GetAPIKeyAllowedSecrets returns the key's secret allowlist; a nil slice means the key is unrestricted.
func GetAPIKeyByHash ¶
func GetActorOrgs ¶
GetActorOrgs returns all org memberships for the given actor.
func GetArtifact ¶
func GetOrgBySlug ¶
func GetOrgMember ¶
func GetOrgMemberRole ¶
func GetOrgMemberRole(ctx context.Context, db *sqlx.DB, orgID uuid.UUID, principal string) (string, error)
GetOrgMemberRole returns the role for the given actor in the given org, or sql.ErrNoRows if they are not a member.
func GetSession ¶
func GetSnapshot ¶
func InsertAuditChainHead ¶ added in v0.4.5
func InsertAuditChainHead(ctx context.Context, q ExecQuerier, h *AuditChainHead) error
InsertAuditChainHead creates the head row unless it exists.
func LastChainedAuditEntry ¶ added in v0.4.5
LastChainedAuditEntry returns the highest-numbered chained entry, or sql.ErrNoRows.
func ListActiveSessions ¶
ListActiveSessions returns sessions that are still running (for cleanup jobs).
func ListArtifacts ¶
func ListAuditLogs ¶
func ListAuditLogs(ctx context.Context, db *sqlx.DB, sessionID *uuid.UUID, actor string, limit, offset int) ([]*models.AuditLog, error)
ListAuditLogs returns audit log entries. When actor is non-empty only that actor's log entries are returned (tenant isolation). When sessionID is set it takes precedence. Master key passes actor="". Initialises the slice to non-nil so JSON always encodes [] instead of null.
func ListAuditLogsFiltered ¶ added in v0.4.2
func ListAuditSince ¶
func ListAuditSince(ctx context.Context, db *sqlx.DB, since time.Time, limit int) ([]models.AuditLog, error)
ListAuditSince returns up to limit audit entries created after since, ordered by timestamp ASC.
func ListOrgMembers ¶
func ListOrgSessions ¶
func ListOrgSessions(ctx context.Context, db *sqlx.DB, orgID uuid.UUID, limit, offset int) ([]*models.Session, error)
ListOrgSessions returns active sessions belonging to the given org.
func ListSessions ¶
func ListSessions(ctx context.Context, db *sqlx.DB, actor, labelKey, labelValue string, limit, offset int) ([]*models.Session, error)
ListSessions returns active sessions. When actor is non-empty only that actor's sessions are returned (tenant isolation). Master key passes "". labelKey/labelValue optionally filter by a specific label (both must be set). Initialises the slice to non-nil so JSON always encodes [] instead of null.
func ListSessionsForActor ¶
func ListSessionsForActor(ctx context.Context, db *sqlx.DB, actor, labelKey, labelValue string, limit, offset int) ([]*models.Session, error)
ListSessionsForActor returns all active sessions visible to the actor: own sessions UNION sessions in any org the actor belongs to. When actor is empty (master), all sessions are returned.
func ListSnapshots ¶
func PurgeAPIKey ¶ added in v0.4.4
PurgeAPIKey deletes a revoked key's row (freeing its name for reuse). Active keys are refused: revoking first keeps deletion from being a one-step way to lose a key that is still in use.
func RemoveOrgMember ¶
func SetAPIKeyAllowedSecrets ¶ added in v0.4.1
func SetAPIKeyAllowedSecrets(ctx context.Context, db *sqlx.DB, id uuid.UUID, allowed []string) error
SetAPIKeyAllowedSecrets replaces the key's secret allowlist (nil = unrestricted).
func SumWorkspaceBytes ¶
SumWorkspaceBytes returns the total size in bytes of all files tracked for the given session. Used by the upload handler to enforce MAX_WORKSPACE_MB.
func TotalArtifactBytes ¶
TotalArtifactBytes returns the sum of size_bytes for all artifacts owned by actor. Pass an empty actor to sum across all actors (master use).
func UpdateAPIKeyLastUsed ¶
func UpdateAuditChainHead ¶ added in v0.4.5
func UpdateAuditChainHead(ctx context.Context, q ExecQuerier, h *AuditChainHead) error
func UpdateSessionLabels ¶
UpdateSessionLabels replaces the labels map for a session.
func UpdateSessionStatus ¶
Types ¶
type AuditChainHead ¶ added in v0.4.5
type AuditChainHead struct {
Seq int64 `db:"seq"`
LastSig string `db:"last_sig"`
PrunedThrough int64 `db:"pruned_through"`
StartedAt time.Time `db:"started_at"`
MAC string `db:"mac"`
}
AuditChainHead is the single audit_chain row: the newest chained entry, how far retention has pruned the chain and when chaining began. MAC is computed by the audit package.
func GetAuditChainHead ¶ added in v0.4.5
func GetAuditChainHead(ctx context.Context, q ExecQuerier, lock bool) (*AuditChainHead, error)
GetAuditChainHead reads the chain head; lock takes a row lock (inside a tx). sql.ErrNoRows means chaining has not started.
type AuditFilter ¶ added in v0.4.2
type AuditFilter struct {
SessionID *uuid.UUID
Actor string
ActionPrefix string
From, To *time.Time // From inclusive, To exclusive
// Seq and ID pick out a single entry (the dashboard links to the entries an
// integrity warning names). BySeq orders by chain position instead of time.
Seq *int64
ID *uuid.UUID
BySeq bool
}
AuditFilter narrows an audit log query. SessionID and Actor are the access scope (SessionID wins, matching the long-standing behaviour); ActionPrefix, From and To are optional user filters.
type AuditPred ¶ added in v0.4.6
AuditPred is what a chained entry needs to know about its predecessor.
type ExecQuerier ¶ added in v0.4.5
type ExecQuerier interface {
sqlx.ExtContext
GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
}
ExecQuerier is the part of *sqlx.DB and *sqlx.Tx the audit chain needs.
type OrgWithRole ¶ added in v0.3.2
type OrgWithRole struct {
models.Organization
Role string `db:"role" json:"role"`
}
OrgWithRole is an organization plus the caller's membership role.
func ListOrgsForActor ¶ added in v0.3.2
ListOrgsForActor returns organizations the principal belongs to, with role.