models

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionStatusCreated = "created"
	SessionStatusRunning = "running"
	SessionStatusStopped = "stopped"
	SessionStatusError   = "error"

	RunStatusPending   = "pending"
	RunStatusRunning   = "running"
	RunStatusCompleted = "completed"
	RunStatusFailed    = "failed"
	RunStatusTimeout   = "timeout"
)
View Source
const (
	ActionSessionCreated  = "session.created"
	ActionSessionDeleted  = "session.deleted"
	ActionFileUploaded    = "file.uploaded"
	ActionFileDownloaded  = "file.downloaded"
	ActionCommandStarted  = "command.started"
	ActionCommandFinished = "command.finished"
	ActionCommandFailed   = "command.failed"
	ActionAPIKeyCreated   = "apikey.created"
	ActionAPIKeyRevoked   = "apikey.revoked"
	ActionAPIKeySecrets   = "apikey.secrets_updated"
	ActionSecretDenied    = "secret.denied"
	ActionFileDeleted     = "file.deleted"
	ActionSessionExpired  = "session.expired" // emitted by background cleanup goroutine

	// Org actions
	ActionOrgCreated       = "org.created"
	ActionOrgDeleted       = "org.deleted"
	ActionOrgMemberAdded   = "org.member.added"
	ActionOrgMemberRemoved = "org.member.removed"

	// Snapshot actions
	ActionSnapshotCreated = "snapshot.created"
	ActionSnapshotDeleted = "snapshot.deleted"

	// Artifact actions
	ActionArtifactCreated = "artifact.created"
	ActionArtifactDeleted = "artifact.deleted"

	// Session replay actions
	ActionCheckpointCreated  = "checkpoint.created"
	ActionCheckpointRestored = "checkpoint.restored"
	ActionCheckpointForked   = "checkpoint.forked"
	ActionCheckpointDeleted  = "checkpoint.deleted"

	// Session template actions
	ActionTemplateCreated     = "template.created"
	ActionTemplateUpdated     = "template.updated"
	ActionTemplateDeleted     = "template.deleted"
	ActionSessionFromTemplate = "session.created_from_template"

	// Multi-agent collaboration actions
	ActionAgentJoined          = "agent.joined"
	ActionCollaborationEnabled = "collaboration.enabled"
)
View Source
const (
	OrgRoleViewer   = "viewer"   // read-only: list/get sessions, runs, files, audit
	OrgRoleExecutor = "executor" // viewer + create sessions, run commands, upload/delete files
	OrgRoleAdmin    = "admin"    // executor + delete sessions, manage org members
)

Org RBAC roles

Variables

This section is empty.

Functions

func RoleAtLeast

func RoleAtLeast(have, need string) bool

RoleAtLeast returns true when have is at least as permissive as need. Unknown role names map to 0 and always return false.

Types

type APIKey

type APIKey struct {
	ID         uuid.UUID  `db:"id"           json:"id"`
	Name       string     `db:"name"         json:"name"`
	KeyHash    string     `db:"key_hash"     json:"-"`
	Prefix     string     `db:"prefix"       json:"prefix"`
	CreatedAt  time.Time  `db:"created_at"   json:"created_at"`
	LastUsedAt *time.Time `db:"last_used_at" json:"last_used_at,omitempty"`
	ExpiresAt  *time.Time `db:"expires_at"   json:"expires_at,omitempty"`
	RevokedAt  *time.Time `db:"revoked_at"   json:"revoked_at,omitempty"`
	Active     bool       `db:"active"       json:"active"`
	OrgID      *uuid.UUID `db:"org_id"     json:"org_id,omitempty"`
	// AllowedSecrets restricts which secret names the key may inject into runs.
	// nil means unrestricted; an empty list means no secrets.
	AllowedSecrets pq.StringArray `db:"allowed_secrets" json:"allowed_secrets"`
}

type AuditLog

type AuditLog struct {
	ID        uuid.UUID  `db:"id"         json:"id"`
	Timestamp time.Time  `db:"timestamp"  json:"timestamp"`
	Actor     string     `db:"actor"      json:"actor"`
	SessionID *uuid.UUID `db:"session_id" json:"session_id,omitempty"`
	RunID     *uuid.UUID `db:"run_id"     json:"run_id,omitempty"`
	Action    string     `db:"action"     json:"action"`
	Metadata  JSONB      `db:"metadata"   json:"metadata"`
	// Sig is an HMAC-SHA256 hex digest over the immutable fields of this entry.
	// It is empty when AUDIT_HMAC_KEY is not configured. Non-empty values can be
	// verified with VerifyAuditSig to detect tampering after the fact.
	Sig string `db:"sig" json:"sig,omitempty"`
	// SigValid is computed on read, never stored: true when Sig matches the
	// entry, false when it does not or the entry is unsigned. It is only
	// present when AUDIT_HMAC_KEY is configured.
	SigValid *bool `db:"-" json:"sig_valid,omitempty"`
}

type File

type File struct {
	ID          uuid.UUID `db:"id"           json:"id"`
	SessionID   uuid.UUID `db:"session_id"   json:"session_id"`
	Path        string    `db:"path"         json:"path"`
	SizeBytes   int64     `db:"size_bytes"   json:"size_bytes"`
	ContentType string    `db:"content_type" json:"content_type"`
	CreatedAt   time.Time `db:"created_at"   json:"created_at"`
	UpdatedAt   time.Time `db:"updated_at"   json:"updated_at"`
}

type JSONB

type JSONB map[string]interface{}

JSONB is a map that implements sql Scanner/Valuer for Postgres JSONB.

func (*JSONB) Scan

func (j *JSONB) Scan(src interface{}) error

func (JSONB) Value

func (j JSONB) Value() (driver.Value, error)

type OrgMember

type OrgMember struct {
	OrgID     uuid.UUID `db:"org_id"    json:"org_id"`
	Principal string    `db:"principal" json:"principal"`
	Role      string    `db:"role"      json:"role"`
	CreatedAt time.Time `db:"created_at" json:"created_at"`
}

type Organization

type Organization struct {
	ID        uuid.UUID `db:"id"         json:"id"`
	Name      string    `db:"name"       json:"name"`
	Slug      string    `db:"slug"       json:"slug"`
	CreatedAt time.Time `db:"created_at" json:"created_at"`
	UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
}

type Run

type Run struct {
	ID             uuid.UUID   `db:"id"              json:"id"`
	SessionID      uuid.UUID   `db:"session_id"      json:"session_id"`
	Command        string      `db:"command"         json:"command"`
	Args           StringArray `db:"args"            json:"args"`
	Env            JSONB       `db:"env"             json:"-"` // may contain secrets — never expose to callers
	WorkingDir     string      `db:"working_dir"     json:"working_dir"`
	Status         string      `db:"status"          json:"status"`
	ExitCode       *int        `db:"exit_code"       json:"exit_code,omitempty"`
	Stdout         *string     `db:"stdout"          json:"stdout,omitempty"`
	Stderr         *string     `db:"stderr"          json:"stderr,omitempty"`
	DurationMS     *int64      `db:"duration_ms"     json:"duration_ms,omitempty"`
	TimeoutSeconds int         `db:"timeout_seconds" json:"timeout_seconds"`
	CreatedAt      time.Time   `db:"created_at"      json:"created_at"`
	UpdatedAt      time.Time   `db:"updated_at"      json:"updated_at"`
	StartedAt      *time.Time  `db:"started_at"       json:"started_at,omitempty"`
	FinishedAt     *time.Time  `db:"finished_at"      json:"finished_at,omitempty"`
	// CallbackURL is stored but never returned in API responses (may contain secrets).
	CallbackURL *string `db:"callback_url"     json:"-"`
	// Session Replay (migration 011). Linked when a checkpoint was recorded for
	// this run, or when the run was started after restoring a checkpoint.
	CheckpointID             *uuid.UUID `db:"checkpoint_id"               json:"checkpoint_id,omitempty"`
	RestoredFromCheckpointID *uuid.UUID `db:"restored_from_checkpoint_id" json:"restored_from_checkpoint_id,omitempty"`
	// OutputTruncated is not persisted; set in-memory when docker capped output.
	OutputTruncated bool `db:"-"                json:"output_truncated,omitempty"`
}

type SSOUser

type SSOUser struct {
	ID          uuid.UUID  `db:"id"            json:"id"`
	Email       string     `db:"email"         json:"email"`
	Name        string     `db:"name"          json:"name"`
	Provider    string     `db:"provider"      json:"provider"`
	ExternalID  string     `db:"external_id"   json:"-"` // OIDC sub or SAML NameID
	APIKeyID    *uuid.UUID `db:"api_key_id"    json:"-"`
	CreatedAt   time.Time  `db:"created_at"    json:"created_at"`
	LastLoginAt time.Time  `db:"last_login_at" json:"last_login_at"`
}

SSOUser maps an external identity (OIDC sub / SAML NameID) to a VaultRun API key.

type Session

type Session struct {
	ID             uuid.UUID `db:"id"               json:"id"`
	Name           *string   `db:"name"             json:"name,omitempty"`
	Image          string    `db:"image"            json:"image"`
	Status         string    `db:"status"           json:"status"`
	ContainerID    *string   `db:"container_id"     json:"container_id,omitempty"`
	NetworkEnabled bool      `db:"network_enabled"  json:"network_enabled"`
	CPULimit       float64   `db:"cpu_limit"        json:"cpu_limit"`
	MemoryLimitMB  int       `db:"memory_limit_mb"  json:"memory_limit_mb"`
	TimeoutSeconds int       `db:"timeout_seconds"  json:"timeout_seconds"`
	WorkspacePath  string    `db:"workspace_path"   json:"-"` // internal host path — never expose to callers
	Labels         JSONB     `db:"labels"           json:"labels"`
	// AllowedHosts is an optional list of hostnames or CIDRs the container may
	// reach when NetworkEnabled is true. An empty list means unrestricted bridge
	// access. Entries are resolved to /etc/hosts at container creation time.
	// For full egress enforcement, operators should pair this with host iptables.
	AllowedHosts StringArray `db:"allowed_hosts"    json:"allowed_hosts,omitempty"`
	CreatedBy    string      `db:"created_by"       json:"created_by"`
	CreatedAt    time.Time   `db:"created_at"       json:"created_at"`
	UpdatedAt    time.Time   `db:"updated_at"       json:"updated_at"`
	StoppedAt    *time.Time  `db:"stopped_at"       json:"stopped_at,omitempty"`
	OrgID        *uuid.UUID  `db:"org_id"           json:"org_id,omitempty"`

	// Session Replay (migration 011). Checkpoints are only recorded when
	// ReplayEnabled is true.
	ReplayEnabled          bool       `db:"replay_enabled"             json:"replay_enabled"`
	ForkedFromCheckpointID *uuid.UUID `db:"forked_from_checkpoint_id"  json:"forked_from_checkpoint_id,omitempty"`

	// Cost Intelligence (migration 012). Running totals maintained by the
	// tracker; the authoritative per-period records live in cost_metrics.
	TotalCost      *float64   `db:"total_cost"       json:"total_cost,omitempty"`
	LastCostUpdate *time.Time `db:"last_cost_update" json:"last_cost_update,omitempty"`

	// Session Templates (migration 013). Set when the session was created from
	// a marketplace template.
	TemplateID *uuid.UUID `db:"template_id" json:"template_id,omitempty"`

	// Multi-Agent Collaboration (migration 014).
	MaxAgents          *int  `db:"max_agents"          json:"max_agents,omitempty"`
	AllowCollaboration *bool `db:"allow_collaboration" json:"allow_collaboration,omitempty"`
}

type SharedArtifact

type SharedArtifact struct {
	ID           uuid.UUID  `db:"id"            json:"id"`
	Name         string     `db:"name"          json:"name"`
	ArtifactPath string     `db:"artifact_path" json:"-"` // host path — never expose
	SizeBytes    int64      `db:"size_bytes"    json:"size_bytes"`
	ContentType  string     `db:"content_type"  json:"content_type"`
	CreatedBy    string     `db:"created_by"    json:"created_by"`
	SessionID    *uuid.UUID `db:"session_id"    json:"session_id,omitempty"`
	CreatedAt    time.Time  `db:"created_at"    json:"created_at"`
}

type Snapshot

type Snapshot struct {
	ID          uuid.UUID `db:"id"           json:"id"`
	SessionID   uuid.UUID `db:"session_id"   json:"session_id"`
	Name        string    `db:"name"         json:"name"`
	CreatedBy   string    `db:"created_by"   json:"created_by"`
	SizeBytes   int64     `db:"size_bytes"   json:"size_bytes"`
	ArchivePath string    `db:"archive_path" json:"-"` // host path — never expose
	CreatedAt   time.Time `db:"created_at"   json:"created_at"`
}

type StringArray

type StringArray []string

StringArray handles Postgres text[] arrays. Delegates to pq.StringArray which serialises to/from the native Postgres array literal format {"a","b"} — NOT JSON ["a","b"]. The previous json.Marshal implementation produced JSON which caused "pq: malformed array literal" errors at INSERT time.

func (*StringArray) Scan

func (a *StringArray) Scan(src interface{}) error

func (StringArray) Value

func (a StringArray) Value() (driver.Value, error)

Value serialises the slice, mapping a nil slice to an empty array rather than NULL.

pq returns NULL for a nil slice, but every column this type is bound to (sessions.allowed_hosts, runs.args) is NOT NULL DEFAULT '{}'. A nil slice is the normal state — a run without arguments, a template without an allowed-host list — so passing NULL turned those ordinary requests into constraint violations.

Jump to

Keyboard shortcuts

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