Documentation
¶
Overview ¶
Package connectors is muster's secure connector store: named credentials for external platforms that agents USE without ever HOLDING.
🔴 THE SECRET NEVER ENTERS AN AGENT POD. An agent reaches a platform through muster's proxy — /connect/{connector}/{host}/{path} — and muster injects the credential (a bearer token, a custom header, or HTTP basic) on the way out (proxy.go). The secret is stored only as AES-256-GCM ciphertext (seal.go) and no API, page or log line ever returns it after it was entered: the Connector type has no field that could carry it.
⚠ A RESPONSE IS NOT A GUARANTEED-CLEAN CHANNEL. An upstream that reflects the request (an echo endpoint, an error quoting a header) could hand the credential back; the proxy redacts the forms it knows and refuses the response shapes that would bypass that (proxy.go, secretForms). That is defence in depth, not a proof — the guarantee is that the secret is never in the pod, and only an approved agent reaches only the connector's own hosts.
🔴 ACCESS IS RECORDED PER AGENT, BUT AN APPROVAL IS SHARED BY THE OWNER'S AGENTS. Any agent may ASK for any connector by name; the first ask files a pending Grant. When the owner approves one, a StandingGrant is recorded for the owner, keyed on the connector, its credential source and — for the GitHub App's one-repository token — the agent's repository: a later request from ANY of the owner's agents with the same key is approved at request time (decided_via 'standing', naming the standing grant), and requests already waiting with that key are approved in the same step. Only when no standing grant matches is the owner prompted. An approved agent keeps access until it is destroyed (the grant row cascades with the agent), the grant or its standing grant is revoked, or the connector is deleted (its grants and standing grants go with it). There is no time-based expiry. A denial is final for that request, and is never shared.
⚠ HTTP ONLY. HTTPS APIs and git's smart-HTTP protocol go through the proxy. Non-HTTP platforms (a database, SSH) are out of scope: a future "handout" scheme would hand the secret to the pod on approval and would need its own opt-in, its own warning and its own audit shape — Scheme is the seam where it would be added, and nothing here accepts it today.
Index ¶
- Constants
- Variables
- func GitHubGrantLookup(s Store) func(ctx context.Context, agentID int64) (string, error)
- func Hosts(ctx context.Context, s Store) (map[string][]string, error)
- func NormalizeHost(h string) (string, error)
- func ReachesGitHub(name string, hosts map[string][]string) bool
- func SourceFor(ctx context.Context, s Store, name string) string
- func StandingRepo(source, repo string) (string, bool)
- func ValidateName(name string) error
- func ValidateSecret(s string) error
- type Access
- type AuditEntry
- type Caller
- type Connector
- type DecisionSource
- type Grant
- type NewConnector
- type PGStore
- func (s *PGStore) ApproveFromStanding(ctx context.Context, id, sg int64) (Grant, error)
- func (s *PGStore) Audit(ctx context.Context, e AuditEntry) error
- func (s *PGStore) CreateConnector(ctx context.Context, nc NewConnector) (Connector, error)
- func (s *PGStore) CreateStandingGrant(ctx context.Context, connector, source, repo string, origin int64) (StandingGrant, bool, error)
- func (s *PGStore) Credential(ctx context.Context, name string) (Connector, string, error)
- func (s *PGStore) DecideGrant(ctx context.Context, id int64, approve bool, by, source string) (Grant, error)
- func (s *PGStore) DecideGrantFrom(ctx context.Context, id int64, approve bool, by, source string, ...) (Grant, error)
- func (s *PGStore) DeleteConnector(ctx context.Context, name string) error
- func (s *PGStore) GetConnector(ctx context.Context, name string) (Connector, error)
- func (s *PGStore) GetGrant(ctx context.Context, id int64) (Grant, error)
- func (s *PGStore) LatestGrant(ctx context.Context, agentID int64, connector string) (Grant, error)
- func (s *PGStore) ListAudit(ctx context.Context, limit int) ([]AuditEntry, error)
- func (s *PGStore) ListConnectors(ctx context.Context) ([]Connector, error)
- func (s *PGStore) ListGrants(ctx context.Context) ([]Grant, error)
- func (s *PGStore) ListPendingGrants(ctx context.Context) ([]Grant, error)
- func (s *PGStore) ListStandingGrants(ctx context.Context) ([]StandingGrant, error)
- func (s *PGStore) MatchStandingGrant(ctx context.Context, agentID int64, connector, source, repo string) (StandingGrant, error)
- func (s *PGStore) PruneAudit(ctx context.Context, before time.Time) (int64, error)
- func (s *PGStore) ReopenGrant(ctx context.Context, id int64) (Grant, bool, error)
- func (s *PGStore) RequestGrant(ctx context.Context, agentID int64, connector, reason string) (Grant, bool, error)
- func (s *PGStore) RevokeGrant(ctx context.Context, id int64, by string) (Grant, error)
- func (s *PGStore) RevokeStandingGrant(ctx context.Context, id int64, by string) (StandingGrant, []Grant, error)
- func (s *PGStore) RotateSecret(ctx context.Context, name, secret string) error
- func (s *PGStore) TouchConnector(ctx context.Context, name string) error
- func (s *PGStore) TouchGrant(ctx context.Context, id int64) error
- type Policy
- type Preset
- type Proxy
- type RefusalBody
- type Scheme
- type StandingGrant
- type Store
- type Virtual
Constants ¶
const ( StatusPending = "pending" StatusApproved = "approved" StatusDenied = "denied" StatusRevoked = "revoked" )
Grant statuses (mirrors the connector_grants.status CHECK constraint).
const ( SourceStored = "stored" SourceApp = "app" )
Grant sources: which credential an approval was about.
const DecidedByStanding = "standing-grant"
DecidedByStanding is decided_by on a grant approved by a standing grant. It is deliberately not "operator": the owner did not decide this request.
const DecidedViaMCP = "mcp"
DecidedViaMCP is decided_via for a decision made through connector_request_decide, from one of the operator's own mirrored Claude Code sessions (migration 0035).
const DecidedViaStanding = "standing"
DecidedViaStanding is decided_via for a grant approved automatically by a StandingGrant (migration 0043): no human decided THIS request — the owner approved an earlier one with the same key. decided_by is DecidedByStanding.
const KeySize = 32
KeySize is the encryption key's length: AES-256.
const MaxPendingGrantsPerAgent = 5
MaxPendingGrantsPerAgent is how many requests one agent may have waiting on the operator at once.
🔴 EVERY NEW REQUEST PUSHES A NOTIFICATION. Without a cap, an agent looping over invented connector names (or a client retrying across names) files a row and buzzes the operator's phone per name. Past the cap a request is refused with ErrTooManyPending: nothing is filed and nothing is pushed. A request for a connector the agent ALREADY has a live grant for is answered with that grant and does not count.
const MinSecretLen = 8
MinSecretLen is the shortest secret accepted. It is a floor on what the proxy can REDACT: a response that reflects the credential has the forms the redactor knows replaced (proxy.go, secretForms), and replacing a two-character string would mangle bodies while protecting nothing.
const RedactedMarker = "[REDACTED-BY-MUSTER]"
RedactedMarker replaces every occurrence of the credential in a response.
Variables ¶
var ErrDecrypt = errors.New("connectors: the stored secret could not be decrypted with the configured key")
ErrDecrypt is returned when a stored secret does not open under the configured key — the wrong key, a ciphertext that was moved to another row, or a row whose bound fields (binding) were changed after the secret was sealed.
🔴 IT FAILS CLOSED: no fallback key, no plaintext column, no "try without additional data". The proxy answers 502 and forwards nothing.
var ErrForbiddenAddress = errors.New("connectors: refusing to connect to a non-public address")
ErrForbiddenAddress is the dial refusal for a non-public destination.
var ErrInvalid = errors.New("connectors: invalid")
ErrInvalid wraps every validation refusal, so a handler can answer 400.
var ErrManaged = fmt.Errorf("%w: this connector is provided by the server's configuration", ErrInvalid)
ErrManaged refuses an operator write to a virtual connector's name.
var ErrNotFound = errors.New("connectors: not found")
ErrNotFound is returned when a connector or grant does not exist.
var ErrNotPending = errors.New("connectors: the request is no longer pending")
ErrNotPending is returned when a decision targets a grant that was already decided (or revoked).
var ErrRoleUncertain = errors.New("connectors: the agent's owner's role could not be read; retry shortly")
ErrRoleUncertain refuses access decided on a fallback role (the caller's owner's role could not be read). Retryable.
var ErrTargetRefused = errors.New("connectors: refused for this agent")
ErrTargetRefused is a virtual connector's refusal of one request's target.
var ErrTooManyPending = fmt.Errorf("connectors: this agent already has %d requests waiting for the operator; "+ "wait for them to be decided (or ask the operator) before requesting another connector", MaxPendingGrantsPerAgent)
ErrTooManyPending is the refusal past MaxPendingGrantsPerAgent.
var GitHubPreset = Preset{ Key: "github", Label: "GitHub", Hosts: []string{"api.github.com", "github.com"}, Scheme: SchemeBasic, Username: "x-access-token", SecretLabel: "Personal access token", Help: "A fine-grained personal access token scoped to the repositories the agents should reach " + "(Contents read/write, Pull requests read/write, Metadata read). It is used for the REST API " + "and for git over HTTPS.", }
GitHubPreset covers the REST API and git's smart-HTTP protocol.
🔴 BASIC WITH USERNAME `x-access-token`, NOT BEARER, BECAUSE ONE CONNECTOR SERVES BOTH HOSTS. git over HTTPS to github.com authenticates with basic auth (token as the password); api.github.com accepts the same basic pair as well as a bearer header. Basic is the one shape both accept.
var VirtualCreatedAt = time.Now()
VirtualCreatedAt is a stable "created" time for a virtual connector's description: when this process started.
Functions ¶
func GitHubGrantLookup ¶
GitHubGrantLookup answers, for one agent, the connector of an APPROVED grant it holds that reaches GitHub (ReachesGitHub), or "" when it holds none.
A nil store is a deployment with no connector store: no grant can exist, so the answer is always "". That is stated here rather than left to a nil check at the caller, so the caller can treat a MISSING lookup as unknown.
func NormalizeHost ¶
NormalizeHost validates one allowlist entry and returns it lowercased.
An entry is a DNS hostname with at least one dot, optionally followed by ":port". IP literals are refused: an allowlist that names an address cannot be checked against the private-range rule by name, and every real platform has a hostname. Wildcards are refused: the allowlist is exact by design.
func ReachesGitHub ¶
ReachesGitHub reports whether a grant on connector name could put a GitHub credential in the agent's pod: the `github` connector, a connector with a github.com host, or — failing closed — one whose hosts are unknown.
ONE PREDICATE, THREE DOORS: a pool worker holding an approved grant it matches is not eligible for a job, an approval of one for a pool worker is refused (internal/api jobs_grants.go), and a worker-pool agent holding one is never started with job-lane permission bypass (internal/agentprovision).
func SourceFor ¶
SourceFor is the credential source connector name has for ctx's principal: SourceApp when a virtual connector presents it, SourceStored otherwise.
func StandingRepo ¶
StandingRepo is the repository part of a standing grant's key for an agent dispatched with repo, under credential source: the repository trimmed and lowercased (GitHub names are case-insensitive, and the App compares them so: githubapp.App.Credential) for SourceApp, and "" for a stored credential, which is keyed on the connector alone. ok is false when there is no key: a SourceApp approval for an agent with no repository grants nothing usable, so it is never shared.
func ValidateName ¶
ValidateName refuses a connector name that is not lowercase [a-z0-9-], starting and ending alphanumeric, at most 63 characters.
func ValidateSecret ¶
ValidateSecret refuses a too-short secret or one that cannot travel in a header.
Types ¶
type Access ¶
type Access struct {
Grant Grant
Usable bool
// Filed is true when THIS check filed a new pending request.
Filed bool
}
Access is the outcome of checking a caller's grant.
type AuditEntry ¶
type AuditEntry struct {
ID int64 `json:"id"`
At time.Time `json:"at"`
Kind string `json:"kind"` // "proxy" | "grant"
AgentID int64 `json:"agentId,omitempty"`
AgentName string `json:"agentName"`
Connector string `json:"connector"`
Method string `json:"method,omitempty"`
Host string `json:"host,omitempty"`
Path string `json:"path,omitempty"`
Status int `json:"status,omitempty"`
Detail string `json:"detail,omitempty"`
}
AuditEntry is one line of the audit trail. It carries no body and no header.
type Caller ¶
type Caller struct {
AgentID int64
AgentName string
// Repo is the agent's own repository (owner/name), "" when it was dispatched
// without one. A virtual connector that scopes its credential to the agent's
// repository (the GitHub App) reads it; a stored connector ignores it.
Repo string
}
Caller is the authenticated agent a proxied request is made for.
type Connector ¶
type Connector struct {
ID int64 `json:"id"`
Name string `json:"name"`
Platform string `json:"platform"`
Hosts []string `json:"hosts"`
Scheme Scheme `json:"scheme"`
HeaderName string `json:"headerName,omitempty"`
Username string `json:"username,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
RotatedAt *time.Time `json:"rotatedAt,omitempty"`
LastUsedAt *time.Time `json:"lastUsedAt,omitempty"`
}
Connector is one stored credential's PUBLIC description.
🔴 THERE IS NO SECRET FIELD, AND THAT ABSENCE IS THE GUARANTEE that no list, page or JSON projection can leak one: the secret exists in plaintext only on the stack of the proxy call that injects it (Store.Credential).
func (Connector) AllowsHost ¶
AllowsHost reports whether host (as it appears in a proxy path) is one of the connector's declared hosts. Comparison is case-insensitive and exact: no suffix, wildcard or subdomain matching.
type DecisionSource ¶
DecisionSource is where the operator decided a request when it was NOT the Connectors tab: Via (DecidedViaMCP) and the mirrored session it came from (Host, the session's mirror host — proven by the host's token; Session, the Claude session id the caller named — a claim). The zero value is the tab.
func (DecisionSource) String ¶
func (src DecisionSource) String() string
String is "<host>/<session>", "" for the tab.
func (DecisionSource) ViaSession ¶
func (src DecisionSource) ViaSession() bool
ViaSession reports whether src names a mirrored session (an MCP decision).
type Grant ¶
type Grant struct {
ID int64 `json:"id"`
AgentID int64 `json:"agentId"`
AgentName string `json:"agentName"`
Connector string `json:"connector"`
Status string `json:"status"`
Reason string `json:"reason,omitempty"`
RequestedAt time.Time `json:"requestedAt"`
DecidedAt *time.Time `json:"decidedAt,omitempty"`
DecidedBy string `json:"decidedBy,omitempty"`
LastUsedAt *time.Time `json:"lastUsedAt,omitempty"`
// Source is the credential the approval was about: SourceStored or
// SourceApp (migration 0033). See ReconcileGrant.
Source string `json:"source,omitempty"`
// DecidedVia is where the operator decided it when that was NOT the
// Connectors tab (migration 0035): the zero value for the tab, for a grant
// not yet decided, a revoked one, and every decision recorded before 0035.
// DecidedViaStanding for an automatic approval (migration 0043).
DecidedVia DecisionSource `json:"-"`
// StandingGrantID is the standing grant that approved this grant
// automatically (migration 0043); 0 for every other grant.
StandingGrantID int64 `json:"standingGrantId,omitempty"`
}
Grant is one agent's request for, and the operator's decision on, one connector.
func ReconcileGrant ¶
ReconcileGrant puts an approved grant back to pending when its connector's credential source (for ctx's principal, the grant's owner) is no longer the one the approval was about — the GitHub App configured over a stored token, or removed from under one. reopened reports that this call did it, so the caller can prompt the owner. Any other grant is returned unchanged.
🔴 THIS IS THE ONE PLACE THE RULE LIVES; every reader that turns a grant into "may this agent use the connector" calls it first (Proxy.CheckAccess, the agent's connector status and request routes).
type NewConnector ¶
type NewConnector struct {
Name string
Platform string
Hosts []string
Scheme Scheme
HeaderName string
Username string
Secret string
}
NewConnector is what an operator submits to create a connector.
func (NewConnector) Validate ¶
func (nc NewConnector) Validate() (NewConnector, error)
Validate refuses a NewConnector that could not be safely used, and returns it normalised (hosts lowercased, deduplicated and sorted).
type PGStore ¶
type PGStore struct {
// contains filtered or unexported fields
}
PGStore is the Postgres-backed Store. Secrets are sealed with the key given to NewPG before they reach a query, and opened only by PGStore.Credential.
func (*PGStore) ApproveFromStanding ¶
ApproveFromStanding approves pending grant id from live standing grant sg.
🔴 THE STANDING GRANT'S ROW IS LOCKED (FOR SHARE) FOR THE APPROVAL, so it serialises with RevokeStandingGrant (which updates that row first): either the revoke commits first and this finds it revoked (ErrNotPending), or this commits first and the revoke's cascade — a later statement — sees the grant and revokes it. An approval can never land after its standing grant's revoke has swept.
func (*PGStore) Audit ¶
func (s *PGStore) Audit(ctx context.Context, e AuditEntry) error
Audit appends one entry.
func (*PGStore) CreateConnector ¶
CreateConnector validates, seals and inserts a connector. A duplicate name is ErrInvalid.
func (*PGStore) CreateStandingGrant ¶
func (s *PGStore) CreateStandingGrant(ctx context.Context, connector, source, repo string, origin int64) (StandingGrant, bool, error)
CreateStandingGrant records the standing grant for (connector, source, repo), owned by the owner of grant origin (the approval it comes from), or returns the live one that already holds the key.
func (*PGStore) Credential ¶
Credential returns the connector with its decrypted secret. A secret that does not open under the configured key is ErrDecrypt.
The secret opens only under the row's CURRENT name, hosts, scheme, header and username (seal.go), so the connector returned is exactly the one the secret was sealed for: a row edited outside muster is ErrDecrypt, not a credential sent somewhere new.
func (*PGStore) DecideGrant ¶
func (s *PGStore) DecideGrant(ctx context.Context, id int64, approve bool, by, source string) (Grant, error)
DecideGrant approves or denies a pending grant, recording the credential source the decision was about (SourceStored / SourceApp). It is a decision on the Connectors tab: no provenance (DecideGrantFrom with the zero source).
func (*PGStore) DecideGrantFrom ¶
func (s *PGStore) DecideGrantFrom(ctx context.Context, id int64, approve bool, by, source string, via DecisionSource) (Grant, error)
DecideGrantFrom is DecideGrant recording where the operator made the decision (migration 0035). The zero via writes NULLs — the tab.
🔴 ONE CONDITIONAL UPDATE FOR BOTH DOORS, so a decision from a mirrored session and one from the tab cannot drift apart, and two of them racing on one request cannot both land: the loser is ErrNotPending. 0035's CHECK refuses a half-written provenance or one on an undecided row.
func (*PGStore) DeleteConnector ¶
DeleteConnector removes a connector AND every grant and standing grant naming it, in one transaction, so a connector later re-created under the same name starts with no approvals — shared or not.
func (*PGStore) GetConnector ¶
GetConnector returns one connector's public description.
func (*PGStore) LatestGrant ¶
LatestGrant returns the newest grant row for the pair.
func (*PGStore) ListConnectors ¶
ListConnectors returns every connector, by name.
func (*PGStore) ListGrants ¶
ListGrants returns every live (pending or approved) grant.
func (*PGStore) ListPendingGrants ¶
ListPendingGrants returns the requests awaiting the operator, oldest first.
func (*PGStore) ListStandingGrants ¶
func (s *PGStore) ListStandingGrants(ctx context.Context) ([]StandingGrant, error)
ListStandingGrants returns the live standing grants, by connector.
func (*PGStore) MatchStandingGrant ¶
func (s *PGStore) MatchStandingGrant(ctx context.Context, agentID int64, connector, source, repo string) (StandingGrant, error)
MatchStandingGrant is the live standing grant for the key that may approve agentID's request.
🔴 OWNER: THE AGENT'S, STATED IN THE QUERY. Row-level security already hides another owner's standing grants from a user principal; the explicit `owner_id = <the agent's owner>` is what keeps a scope-all (System) caller from approving one owner's agent with another owner's approval (TestAStandingGrantNeverCrossesOwners).
🔴 A PER-AGENT "NO" OUTLIVES THE SHARED "YES": a grant on this connector that the owner revoked or denied for THIS agent after the standing grant was made keeps the standing grant from approving the agent again — revoking one agent on the Connectors tab is not undone by the agent simply asking again.
func (*PGStore) PruneAudit ¶
PruneAudit deletes entries older than before.
func (*PGStore) ReopenGrant ¶
ReopenGrant puts an APPROVED grant back to pending (see ReconcileGrant). It is conditional on the row still being approved: false, nil when it was not. An undecided row carries no decision, so its provenance is cleared too.
func (*PGStore) RequestGrant ¶
func (s *PGStore) RequestGrant(ctx context.Context, agentID int64, connector, reason string) (Grant, bool, error)
RequestGrant returns the live grant for (agent, connector) or files a pending one.
func (*PGStore) RevokeGrant ¶
RevokeGrant ends a pending or approved grant. A revocation is made on the Connectors tab, so it clears an MCP decision's provenance with the rest of the decision it replaces (decided_by/decided_at describe the revocation); the audit trail keeps where the approval came from.
func (*PGStore) RevokeStandingGrant ¶
func (s *PGStore) RevokeStandingGrant(ctx context.Context, id int64, by string) (StandingGrant, []Grant, error)
RevokeStandingGrant revokes standing grant id and, in the same transaction, every APPROVED grant it gave: those it approved automatically, and the approval it was created from. A revoke is an off-switch for the shared approval, not only for the ones still to come.
func (*PGStore) RotateSecret ¶
RotateSecret replaces a connector's secret. Grants are kept: rotation changes what is sent, not who may send it.
🔴 THE OLD SECRET MUST OPEN UNDER THE ROW AS IT STANDS, OR NOTHING IS WRITTEN (ErrDecrypt). The new ciphertext is bound to the row's current hosts and auth shape; re-sealing a row someone edited out of band would bind the secret to THEIR hosts and launder the edit. The UPDATE also matches the ciphertext it verified, so a concurrent change to the row is not overwritten. A connector whose secret no longer opens (wrong key, altered row) is deleted and created again.
func (*PGStore) TouchConnector ¶
TouchConnector stamps last_used_at.
type Policy ¶
type Policy struct {
// AllowLoopback admits loopback destinations (127.0.0.0/8, ::1). Every other
// non-public range stays refused.
AllowLoopback bool
// InsecureHTTP speaks plain HTTP to the upstream instead of HTTPS.
InsecureHTTP bool
// Resolve replaces the system resolver. nil means net.DefaultResolver.
Resolve func(ctx context.Context, host string) ([]netip.Addr, error)
}
Policy is the proxy's network policy for upstream connections.
🔴 THE ZERO VALUE IS PRODUCTION, AND IT IS THE STRICT ONE: HTTPS only, the system resolver, and no non-public destination. Each field below LOOSENS it and exists for tests (a fake upstream on loopback); cmd/muster-server never sets one outside a binary built with the e2e tag.
func (Policy) AllowedAddr ¶
AllowedAddr reports whether the policy permits connecting to ip.
func (Policy) Transport ¶
Transport builds the upstream transport for this policy.
🔴 Proxy IS nil, DELIBERATELY: an HTTPS_PROXY in muster's environment would otherwise carry every injected credential through a third party, and the address checks above would be checking the proxy rather than the platform.
type Preset ¶
type Preset struct {
Key string
Label string
Hosts []string
Scheme Scheme
HeaderName string
Username string
SecretLabel string
Help string
}
Preset is a ready-made connector shape for a known platform.
type Proxy ¶
type Proxy struct {
Store Store
Policy Policy
Logger *log.Logger
// OnGrantRequested is called (synchronously; keep it cheap) when a proxied
// request files a NEW pending grant, so the operator can be prompted.
OnGrantRequested func(context.Context, Grant)
// AutoApprove, when set, is offered every request a check FILES, BEFORE
// OnGrantRequested: it returns the grant approved and true when an owner's
// standing grant covers it (the api package's approveFromStanding, the one
// rule every door shares), and the owner is then not prompted. false leaves
// the grant as it was. A grant RE-OPENED because its connector's credential
// source changed is not offered: that change asks the owner again (0033),
// and their approval is then shared as any other.
AutoApprove func(context.Context, Grant) (Grant, bool)
// StreamsEnd is the server's shutdown signal for streams: once it is done, a
// proxied GET EVENT STREAM in flight ends, and one that starts later ends at
// once (endsAtShutdown says which exchanges, and why only GET).
// Every other proxied request is left alone. nil means never (a Proxy built
// directly, as tests do). The api package hands it the same signal
// api.Server.EndStreams cancels, so ending its own streams and the ones relayed
// here is ONE event, fired by the one EndStreams call at the top of
// cmd/muster-server's shutdown, before either listener drains. See
// endOnShutdown.
StreamsEnd context.Context
// contains filtered or unexported fields
}
Proxy forwards an agent's request to a connector's upstream with the credential injected.
func (*Proxy) CheckAccess ¶
func (p *Proxy) CheckAccess(ctx context.Context, caller Caller, connector, reason string) (Access, error)
CheckAccess resolves whether the caller may use the connector now, filing a pending request when the caller has never asked.
🔴 A DENIAL OR A REVOCATION IS NOT RE-FILED HERE. A retrying client would otherwise turn one "no" into a prompt per retry. The agent must ask again explicitly (the request route / the connector_request tool), which is a deliberate act the operator then sees as a new request.
func (*Proxy) Serve ¶
func (p *Proxy) Serve(w http.ResponseWriter, r *http.Request, caller Caller, connector, host, rest string)
Serve proxies one request. connector and host are the path's first two segments after /connect/, and rest is everything after the host segment, still escaped (no leading slash).
func (*Proxy) SetTransport ¶
func (p *Proxy) SetTransport(rt http.RoundTripper)
SetTransport overrides the upstream transport (tests). Call it before the first Serve: the transport is fixed from then on.
type RefusalBody ¶
type RefusalBody struct {
Error string `json:"error"`
Connector string `json:"connector,omitempty"`
// Grant is the caller's grant status for the connector, when the refusal is
// about access: "pending", "denied", "revoked".
Grant string `json:"grant,omitempty"`
GrantID int64 `json:"grantId,omitempty"`
}
RefusalBody is the JSON every refusal from the proxy carries.
type Scheme ¶
type Scheme string
Scheme is how a connector's secret is presented to its upstream.
const ( // SchemeBearer sends `Authorization: Bearer <secret>`. SchemeBearer Scheme = "bearer" // SchemeHeader sends `<HeaderName>: <secret>` (e.g. an API-key header). SchemeHeader Scheme = "header" // SchemeBasic sends `Authorization: Basic base64(<Username>:<secret>)`. SchemeBasic Scheme = "basic" )
type StandingGrant ¶
type StandingGrant struct {
ID int64 `json:"id"`
Connector string `json:"connector"`
Source string `json:"source"`
Repo string `json:"repo,omitempty"`
// OriginGrantID is the per-agent grant whose approval created it.
OriginGrantID int64 `json:"originGrantId,omitempty"`
CreatedAt time.Time `json:"createdAt"`
RevokedAt *time.Time `json:"revokedAt,omitempty"`
}
StandingGrant is one owner-wide approval (migration 0043): while it is live (RevokedAt nil), a request from any of the owner's agents for Connector whose credential source is Source — and, for the GitHub App (SourceApp), whose agent's repository is Repo — is approved automatically.
type Store ¶
type Store interface {
ListConnectors(ctx context.Context) ([]Connector, error)
GetConnector(ctx context.Context, name string) (Connector, error)
CreateConnector(ctx context.Context, nc NewConnector) (Connector, error)
RotateSecret(ctx context.Context, name, secret string) error
DeleteConnector(ctx context.Context, name string) error
// Credential returns the connector and its DECRYPTED secret. The proxy is
// its only production caller.
Credential(ctx context.Context, name string) (Connector, string, error)
TouchConnector(ctx context.Context, name string) error
// RequestGrant returns the live (pending or approved) grant for the pair,
// creating a pending one when there is none. created reports which.
RequestGrant(ctx context.Context, agentID int64, connector, reason string) (g Grant, created bool, err error)
// LatestGrant returns the most recent grant row for the pair, live or not.
LatestGrant(ctx context.Context, agentID int64, connector string) (Grant, error)
GetGrant(ctx context.Context, id int64) (Grant, error)
// DecideGrant approves or denies a PENDING grant; ErrNotPending otherwise.
DecideGrant(ctx context.Context, id int64, approve bool, by, source string) (Grant, error)
// DecideGrantFrom is DecideGrant recording where the decision was made
// (via; the zero value is the Connectors tab, exactly DecideGrant).
DecideGrantFrom(ctx context.Context, id int64, approve bool, by, source string, via DecisionSource) (Grant, error)
// ReopenGrant puts an approved grant back to pending; reopened is false when
// it was no longer approved.
ReopenGrant(ctx context.Context, id int64) (g Grant, reopened bool, err error)
RevokeGrant(ctx context.Context, id int64, by string) (Grant, error)
ListPendingGrants(ctx context.Context) ([]Grant, error)
// ListGrants returns every pending and approved grant (the live set).
ListGrants(ctx context.Context) ([]Grant, error)
TouchGrant(ctx context.Context, id int64) error
// CreateStandingGrant records the owner's standing grant for the key
// (connector, source, repo — see StandingRepo), from the approval of grant
// origin; when a live one already exists it is returned and created is false.
// It retires the connector's live standing grants under the OTHER source.
CreateStandingGrant(ctx context.Context, connector, source, repo string, origin int64) (sg StandingGrant, created bool, err error)
// MatchStandingGrant returns the owner's live standing grant for the key that
// may approve agentID's request, or ErrNotFound. A standing grant does not
// apply to an agent whose grant on the connector the owner revoked or denied
// after the standing grant was created: that agent's own decision stands.
MatchStandingGrant(ctx context.Context, agentID int64, connector, source, repo string) (StandingGrant, error)
// ApproveFromStanding approves PENDING grant id from live standing grant sg
// (recording the standing grant's credential source); ErrNotPending when the
// grant is no longer pending or the standing grant is no longer live.
ApproveFromStanding(ctx context.Context, id, sg int64) (Grant, error)
// RevokeStandingGrant revokes a live standing grant AND every approved grant
// it gave (the ones it approved automatically, and the approval it was
// created from), returning the grants it revoked. ErrNotPending when it was
// already revoked.
RevokeStandingGrant(ctx context.Context, id int64, by string) (StandingGrant, []Grant, error)
// ListStandingGrants returns the owner's live standing grants.
ListStandingGrants(ctx context.Context) ([]StandingGrant, error)
Audit(ctx context.Context, e AuditEntry) error
ListAudit(ctx context.Context, limit int) ([]AuditEntry, error)
PruneAudit(ctx context.Context, before time.Time) (int64, error)
}
Store persists connectors, grants and the audit trail.
type Virtual ¶
type Virtual interface {
// Describe is the connector's public description. Its Name is the name it
// answers to; its Hosts are the allowlist the proxy enforces BEFORE asking for
// a credential.
Describe() Connector
// Credential returns the secret to inject for caller's request to host/rest
// (rest as the proxy received it: escaped, no leading slash). host is already
// on Describe().Hosts. anonymous=true means forward the request with NO
// credential at all (secret is then ""). A request the connector refuses for
// this caller is [ErrTargetRefused]; any other error means no credential
// could be produced, and its text is shown to the agent and the operator, so
// it must never carry a secret.
Credential(ctx context.Context, caller Caller, host, rest string) (secret string, anonymous bool, err error)
// Rejected tells the connector the upstream answered 401 to a request that
// carried the secret Credential returned for caller, so a cached credential
// can be dropped.
Rejected(caller Caller)
// Problem is the operator-facing reason this connector cannot currently serve
// agentID (0: any agent), or "" when nothing is known to be wrong.
Problem(agentID int64) string
}
Virtual is a connector whose credential is minted per request.