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
- Variables
- func IsNoCredential(err error) bool
- func ValidateAccountName(name string) error
- func ValidateClaudeToken(tok string) error
- func ValidateOpenRouterKey(key string) error
- type PGStore
- func (s *PGStore) ClaudeNames(ctx context.Context, owner int64) ([]string, error)
- func (s *PGStore) ClaudeTokens(ctx context.Context, owner int64) (map[string]string, error)
- func (s *PGStore) Delete(ctx context.Context, kind, name string) (bool, error)
- func (s *PGStore) HasOpenRouterKey(ctx context.Context, owner int64) (bool, error)
- func (s *PGStore) List(ctx context.Context) ([]Summary, error)
- func (s *PGStore) OpenRouterKey(ctx context.Context, owner int64) (string, bool, error)
- func (s *PGStore) PutClaude(ctx context.Context, name, token string) error
- func (s *PGStore) PutOpenRouter(ctx context.Context, key string) error
- type Personal
- type Plane
- func (p *Plane) Accounts(ctx context.Context, owner int64) (map[string]string, error)
- func (p *Plane) OpenRouterKey(ctx context.Context, owner int64) (string, error)
- func (p *Plane) Unavailable(ctx context.Context, owner int64, kinds []string) map[string]string
- func (p *Plane) UsesEnvironment(ctx context.Context, owner int64) bool
- type RoleReader
- type Summary
Constants ¶
const ( KindClaude = "claude" KindOpenRouter = "openrouter" )
The two credential kinds.
const ( ActionSave = "credential.save" ActionDelete = "credential.delete" )
The audit_log actions a credential write records.
const ( NeedClaude = "Add your Claude setup token in Account → Credentials to use Claude Code agents." NeedOpenRouter = "Add your OpenRouter key in Account → Credentials to use Standard agents." )
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.
const ClaudeTokenPrefix = "sk-ant-oat01-"
ClaudeTokenPrefix is the shape of a `claude setup-token` value.
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.
const OpenRouterKeyPrefix = "sk-or-"
OpenRouterKeyPrefix is the shape of an OpenRouter API key.
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 ¶
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).
var ErrInvalid = errors.New("invalid credential")
ErrInvalid: an entered value is not the shape asked for. Its message never carries the value.
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.
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 ¶
IsNoCredential reports whether err is a missing-credential refusal.
func ValidateAccountName ¶
ValidateAccountName is ccpool's rule: an account name becomes part of an agent row and is shown on a card.
func ValidateClaudeToken ¶
ValidateClaudeToken checks a setup-token's SHAPE. The error never echoes it.
func ValidateOpenRouterKey ¶
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 ¶
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 ¶
ClaudeNames returns owner's Claude account names, opening nothing.
func (*PGStore) ClaudeTokens ¶
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 ¶
Delete removes the acting user's credential (kind, name). Reports whether a row existed.
func (*PGStore) HasOpenRouterKey ¶
HasOpenRouterKey reports whether owner has an OpenRouter key, opening nothing.
func (*PGStore) List ¶
List returns the acting user's credentials, Claude accounts by name then the OpenRouter key. No secret leaves this method.
func (*PGStore) OpenRouterKey ¶
OpenRouterKey returns owner's OpenRouter API key — the one their gateway agents are given — or ok=false when they have none.
func (*PGStore) PutOpenRouter ¶
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
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 ¶
Accounts implements ccpool.Source: owner's Claude accounts.
func (*Plane) OpenRouterKey ¶
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 ¶
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.
type RoleReader ¶
RoleReader reads a user's role (internal/users.PGStore.Role).