credentials

package
v0.279.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package credentials is the per-owner model-provider credential store: the Claude Code `setup-token`s and the OpenRouter API key a MEMBER brings to muster, and the one place that decides whose credentials an owner's agents run on (Plane).

The operator decision this implements (accounts plan, 2026-10-11)

Members BRING THEIR OWN credentials. A member's agents only ever use that member's credentials. The environment-configured pool (MUSTER_AGENT_CC_ACCOUNTS + MUSTER_AGENT_CC_TOKEN_*) and the operator's OpenRouter key (MUSTER_AGENT_OPENROUTER_KEY) stay the ADMIN's. A member with no credential for a kind cannot use that kind — NEVER a fallback to the admin's.

Storage

One table, user_credentials (migration 0011), owned and under FORCE row-level security like every other owned table. Each secret is sealed (seal.go) with the owner, kind and name bound in the associated data, so a ciphertext copied to another owner's row does not open.

🔴 A SECRET IS NEVER RETURNED TO A BROWSER. The listing (Summary) carries a name, a fingerprint and timestamps — nothing a page could echo back. Opening a secret is PGStore.ClaudeTokens and PGStore.OpenRouterKey, whose only callers are the pod-spec path (internal/agentprovision, through Plane) and, for the OpenRouter key, muster's server-side OpenRouter calls listed below (all through Plane). None hands it to a page.

OpenRouter: an ordinary API key, used as entered

The member pastes an ordinary OpenRouter API key (operator decision on #69); it is sealed like a setup-token and placed, as entered, in the member's gateway pods as OPENROUTER_API_KEY. muster's own server-side calls with it, each through Plane.OpenRouterKey and each about that member's own sessions, on their key:

  • session focus's summarizer (internal/focus.ScaleDown): summarizes a session's transcript;
  • suggested replies (internal/suggest.OpenRouter): suggests replies for a mirrored session's composer and an ask;
  • the chief nudges' stall classifier (internal/chiefnudge.Classifier, Jev over OpenRouter's Decisions API): classifies a stalled session's last message.

Index

Constants

View Source
const (
	KindClaude     = "claude"
	KindOpenRouter = "openrouter"
)

The two credential kinds.

View Source
const (
	ActionSave   = "credential.save"
	ActionDelete = "credential.delete"
)

The audit_log actions a credential write records.

View Source
const (
	NeedClaude     = "Add your Claude setup token in Account → Your AI accounts to use Claude Code agents."
	NeedOpenRouter = "Add your OpenRouter key in Account → Your AI accounts to use Standard agents."
	// TeamNoGateway is a team's gateway-kind refusal (team sharing phase 4):
	// a team's agents are Claude Code agents on the server pool.
	TeamNoGateway = "A team's agents are Claude Code agents; Standard agents are not available to a team."
	// TeamPoolNotConfigured is a LISTED team's claude-code refusal when the
	// server has no Claude pool (EnvClaude nil): the team is on the server
	// pool, and the pool has no accounts to lend.
	TeamPoolNotConfigured = "This team is listed on the server pool, but this server has no Claude pool configured."
)

The messages a member sees for a kind they have no credential for. One spelling each, shared by the dispatch form, the refusal and the tests.

View Source
const ClaudeTokenPrefix = "sk-ant-oat01-"

ClaudeTokenPrefix is the shape of a `claude setup-token` value.

View Source
const KeySize = 32

KeySize is the length of the key NewPG takes: the CONNECTOR store's key (MUSTER_CONNECTOR_ENCRYPTION_KEY), which this store derives its own from.

View Source
const OpenRouterKeyPrefix = "sk-or-"

OpenRouterKeyPrefix is the shape of an OpenRouter API key.

View Source
const OpenRouterName = "default"

OpenRouterName is the name of a user's one OpenRouter credential: the table's uniqueness is (owner, kind, name), and a user has exactly one OpenRouter key.

Variables

View Source
var ErrDecrypt = errors.New("credentials: the stored secret could not be decrypted with the configured key")

ErrDecrypt is returned when a stored secret does not open with the configured key and the row's binding — a different key, or a ciphertext that was moved to another owner's row (or another credential's).

View Source
var ErrInvalid = errors.New("invalid credential")

ErrInvalid: an entered value is not the shape asked for. Its message never carries the value.

View Source
var ErrNoCredential = errors.New("no credential")

ErrNoCredential: the owner has no credential of the kind asked for. It is a REFUSAL, and its message is the one a member sees.

View Source
var ErrNoStore = errors.New("credentials: this deployment has no credential store (MUSTER_CONNECTOR_ENCRYPTION_KEY is unset)")

ErrNoStore: this deployment has no credential store (no encryption key).

Functions

func IsNoCredential

func IsNoCredential(err error) bool

IsNoCredential reports whether err is a missing-credential refusal.

func ValidateAccountName

func ValidateAccountName(name string) error

ValidateAccountName is ccpool's rule: an account name becomes part of an agent row and is shown on a card.

func ValidateClaudeToken

func ValidateClaudeToken(tok string) error

ValidateClaudeToken checks a setup-token's SHAPE. The error never echoes it.

func ValidateOpenRouterKey

func ValidateOpenRouterKey(key string) error

ValidateOpenRouterKey checks an OpenRouter key's SHAPE.

Types

type PGStore

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

PGStore is the Postgres-backed credential store (table user_credentials, migration 0011).

🔴 EVERY READ AND WRITE NAMES ITS OWNER EXPLICITLY (`owner_id = $n`), AS THE CONNECTOR STORE DOES. Row-level security already scopes a user principal to its own rows; the explicit predicate is what keeps a scope-all caller (the pod-spec path may run under authz.System) from ever resolving "a" credential across users. Writes take the owner from the acting principal and never from an argument: a member can only ever write their own.

func NewPG

func NewPG(pool *pgxpool.Pool, key []byte) (*PGStore, error)

NewPG builds the store. key is the connector store's 32-byte key; this store derives its own from it (seal.go).

func (*PGStore) ClaudeNames

func (s *PGStore) ClaudeNames(ctx context.Context, owner int64) ([]string, error)

ClaudeNames returns owner's Claude account names, opening nothing.

func (*PGStore) ClaudeTokens

func (s *PGStore) ClaudeTokens(ctx context.Context, owner int64) (map[string]string, error)

ClaudeTokens returns owner's Claude accounts, name → setup-token. An empty map (never an error) means the owner has none.

🔴 ONE OF THE TWO METHODS THAT OPEN A SECRET. Its caller is Plane, whose callers are pod-spec building and account selection — never a page.

func (*PGStore) Delete

func (s *PGStore) Delete(ctx context.Context, kind, name string) (bool, error)

Delete removes the acting user's credential (kind, name). Reports whether a row existed.

func (*PGStore) HasOpenRouterKey

func (s *PGStore) HasOpenRouterKey(ctx context.Context, owner int64) (bool, error)

HasOpenRouterKey reports whether owner has an OpenRouter key, opening nothing.

func (*PGStore) List

func (s *PGStore) List(ctx context.Context) ([]Summary, error)

List returns the acting user's credentials, Claude accounts by name then the OpenRouter key. No secret leaves this method.

func (*PGStore) OpenRouterKey

func (s *PGStore) OpenRouterKey(ctx context.Context, owner int64) (string, bool, error)

OpenRouterKey returns owner's OpenRouter API key — the one their gateway agents are given — or ok=false when they have none.

func (*PGStore) PutClaude

func (s *PGStore) PutClaude(ctx context.Context, name, token string) error

PutClaude adds (or replaces) the acting user's Claude account `name`.

func (*PGStore) PutOpenRouter

func (s *PGStore) PutOpenRouter(ctx context.Context, key string) error

PutOpenRouter stores (or replaces) the acting user's OpenRouter API key — an ORDINARY key, used as entered by their gateway agents.

⚠ AN AGENT ALREADY RUNNING KEEPS THE KEY ITS POD WAS GIVEN: Stop then Start the agent to re-apply its spec with the new key (agentprovision re-resolves on every build). Revoking the old key is the member's to do at OpenRouter.

type Personal

type Personal interface {
	ClaudeTokens(ctx context.Context, owner int64) (map[string]string, error)
	OpenRouterKey(ctx context.Context, owner int64) (string, bool, error)
	HasOpenRouterKey(ctx context.Context, owner int64) (bool, error)
}

Personal is what Plane reads from the per-owner store (PGStore).

type Plane

type Plane struct {
	// EnvClaude is the environment pool (nil: the claude-code kind is off).
	EnvClaude ccpool.Source
	// EnvOpenRouterKey is MUSTER_AGENT_OPENROUTER_KEY ("" is today's
	// admin behaviour: a gateway pod with no key placed).
	EnvOpenRouterKey string
	// Personal is the per-owner store (nil: none configured — every member
	// then has no credential).
	Personal Personal
	// Roles reads an owner's role. nil: user 1 is admin, everyone else a
	// member (the seeded row, as internal/api's roleOf does with no store).
	Roles RoleReader
	// TeamsOnServerPool is MUSTER_TEAMS_ON_SERVER_POOL (team sharing phase 4,
	// slice 4.5): the TEAMS whose Claude Code agents run on the environment's
	// pool (EnvClaude), as an admin's do. cmd/muster-server refuses to boot
	// when an id in it is a person or names nobody, so every key is a team.
	// It lends the pool ONLY: a listed team gets no OpenRouter key (gateway
	// agents are not team agents), and an unlisted team gets nothing at all.
	TeamsOnServerPool map[int64]bool
	Logger            *log.Logger
}

Plane decides whose model-provider credentials an OWNER's agents run on.

🔴 [Plane.usesEnvironment] IS THE ONE PREDICATE, AND EVERY QUESTION GOES THROUGH IT: which Claude accounts the dispatch form lists, which account a dispatch may select, which token a pod is built with, which OpenRouter key a gateway pod gets, and whether a kind is available at all. An admin uses the environment (the pool and MUSTER_AGENT_OPENROUTER_KEY); anyone else uses ONLY what they entered — and when they entered nothing, the answer is a refusal, never the environment's. A second copy of this decision (one in the api, one in the provisioner) is how a member's dispatch would one day list only their own accounts while their pod was built from the admin's.

func (*Plane) Accounts

func (p *Plane) Accounts(ctx context.Context, owner int64) (map[string]string, error)

Accounts implements ccpool.Source: owner's Claude accounts.

func (*Plane) EnvPoolOwner added in v0.230.0

func (p *Plane) EnvPoolOwner(ctx context.Context) (int64, bool)

EnvPoolOwner is the ONE answer to "whose id is the environment pool's shared account state kept under": the pool's rate-limit and auth-failure marks (Plane.MarksOwner) and the usage poller's readings, which also reads and clears those marks as this owner (the poller reads it off the plane, ccusage.PoolOwned). It is the lowest-id enabled admin.

🔴 NOT authz.OperatorUserID. Marks are keyed (owner, account name), and user 1 is a person who can be demoted: a fixed owner of 1 then filed every admin's and listed team's pool marks under user 1's PERSONAL accounts of the same name, steering user 1's own dispatches (and theirs steered the pool). An admin's own accounts ARE the pool, so an admin's id holds no personal marks to collide with.

With no Roles (no database) it is user 1, as [Plane.usesEnvironment] answers then. A read error is false: no owner, nothing shared.

func (*Plane) MarksOwner added in v0.230.0

func (p *Plane) MarksOwner(ctx context.Context, owner int64) (int64, bool)

MarksOwner implements ccpool.SharedAccounts: every owner on the environment's pool shares its accounts, so their rate-limit and auth-failure marks are kept once, under Plane.EnvPoolOwner — the owner the usage poller reads and clears them as (internal/ccusage PoolOwned). A member's own accounts are theirs, and so are their marks (false).

No pool owner (its read failed): false, so each owner keeps its own marks — unshared for a moment, never filed under somebody's personal accounts.

func (*Plane) OpenRouterKey

func (p *Plane) OpenRouterKey(ctx context.Context, owner int64) (string, error)

OpenRouterKey is the key owner's gateway pods are given. For a member with no key it is ErrNoCredential — never the environment's.

func (*Plane) Unavailable

func (p *Plane) Unavailable(ctx context.Context, owner int64, kinds []string) map[string]string

Unavailable returns, for each of kinds owner may NOT use for want of a credential, the sentence that says what to add. A kind absent from the map is available.

func (*Plane) UsesEnvironment

func (p *Plane) UsesEnvironment(ctx context.Context, owner int64) bool

UsesEnvironment is [Plane.usesEnvironment] for the credentials page, which tells an admin where their credentials come from.

type RoleReader

type RoleReader interface {
	Role(ctx context.Context, id int64) (authz.Role, error)
	FirstAdmin(ctx context.Context) (int64, error)
}

RoleReader reads a user's role (internal/users.PGStore.Role) and the lowest-id enabled admin (internal/users.PGStore.FirstAdmin: the server pool's marks owner, Plane.EnvPoolOwner).

type Summary

type Summary struct {
	Kind        string
	Name        string
	Fingerprint string
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

Summary is what a listing shows about one credential. 🔴 No secret, not even a truncation of one: the fingerprint is a one-way 48-bit hash.

Jump to

Keyboard shortcuts

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