Documentation
¶
Overview ¶
Package apply pushes a compiled policy to the MASH account (ADR 0052, 0053): one scoped signing key per zone in the account JWT. It looks the current account JWT up on the resolver through the system account, replaces or adds only the scoped signing keys of the policy's zones, signs the result with the operator key, pushes it, and reads it back to verify. It removes or replaces a zone key only when asked (--replace-zone-key, --remove-zone), refuses a zone the file lacks unless told to remove or keep it, and it is not a transaction across NATS claims, JetStream resources and local files; a partial result says what was and was not done. Seed text is never put in output or errors.
Index ¶
- Constants
- Variables
- func KeyRevoked(ctx context.Context, p RevokeParams, pub string) (bool, error)
- func Run(ctx context.Context, p Params, out io.Writer) int
- func SignerPublished(ctx context.Context, p RevokeParams, signerPub, role string) (bool, error)
- func VerifyAccountJWT(token string, accountPub string, trust Trust) (*jwt.AccountClaims, error)
- type Finding
- type Mode
- type NATS
- func (n NATS) Lookup(ctx context.Context, account string) (string, error)
- func (n NATS) LookupAll(ctx context.Context, account string, expect int) ([]string, error)
- func (n NATS) Push(ctx context.Context, token string, expect []string) ([]ServerAck, error)
- func (n NATS) Servers(ctx context.Context) (ServerSet, error)
- type Params
- type Resolver
- type RevokeParams
- type RevokeResult
- type ServerAck
- type ServerSet
- type Trust
Constants ¶
const ( KindBudget = "over-budget" KindZoneMissing = "zone-missing-on-server" KindZoneTemplate = "zone-template-differs" KindKeyConflict = "zone-key-differs" KindZoneNotInFile = "zone-not-in-file" KindUnknownKey = "signing-key-unknown" // Findings of the servers' agreement on the account JWT. KindServersDiffer = "servers-differ" KindServersSilent = "servers-silent" KindServersUnverified = "servers-unverified" )
Finding kinds of AccountFindings.
const NotATransaction = "" /* 189-byte string literal not displayed */
NotATransaction is the one sentence every run ends with.
Variables ¶
var ErrNotConfirmed = errors.New("the revocation was pushed but not confirmed")
ErrNotConfirmed wraps every failure after the revocation was pushed: the update may be on some servers or all of them, but it was not confirmed on every one. Running the revoke again is safe.
var ErrServerSetRefused = errors.New("server set refused")
ErrServerSetRefused is wrapped by Servers when more than maxServers distinct servers answered or a server or cluster name is over maxNameBytes. The set it returns is partial; a caller must refuse and not act on it.
Functions ¶
func KeyRevoked ¶
KeyRevoked reports whether any server's copy of the account JWT revokes the user public key pub (at any time). It refuses to answer "not revoked" unless it has seen every server (see accountClaims). Servers may hold different copies, so one copy that lacks a revocation proves nothing; the key is revoked if any copy names it.
func Run ¶
Run executes p and writes its report to out; the result is the process exit code (0 ok, 1 refused or partial; `diff` included: a refusal is exit 1, a report of differences is 0).
func SignerPublished ¶
SignerPublished reports whether every server's copy of the account JWT lists signerPub as a scoped signing key whose role is role (the zone a new user JWT will be signed for). A user JWT signed by a key that some server's account JWT lacks cannot connect there. It is false if any copy lacks the key or scopes it to another role; a silent, unverifiable or incomplete server set is an error (see accountClaims).
func VerifyAccountJWT ¶
VerifyAccountJWT decodes token as an account JWT and requires: a valid signature by its stated issuer, the subject accountPub, and an issuer that trust accepts. Anything else is an error that names public keys only.
Types ¶
type Finding ¶
type Finding struct {
Kind string `json:"kind"`
Subject string `json:"subject,omitempty"`
Detail string `json:"detail"`
Lines []string `json:"lines,omitempty"`
}
Finding is one way the account JWT on the resolver differs from the policy file (`mashctl policy drift`, state "account"). Subject is the zone; Lines are the permission lines added ("+") and removed ("-") going from the server's template to the file's.
func AccountFindings ¶
AccountFindings compares the policy file's compiled zones with the scoped signing keys of the account JWT the resolver holds, with the same code `policy diff` uses, and reports every difference and every refusal condition apply would report (a server key that is not the key store's, a zone the file lacks) as a finding. It changes nothing: no key is created and nothing is pushed. p.Compiled, p.Keys and p.Resolver are used; the result is empty when the resolver's copy matches. It builds the comparison from the newest copy any server holds (highest iat) and also asks every server (Resolver.LookupAll): servers that answer with different JWTs, fewer answers than the known server count, or an unverifiable server set are findings too. Params.Servers is the operator's server count.
type NATS ¶
type NATS struct {
Conn *nats.Conn
// Inventory is the operator's server count (--servers; 0 none): the ping stops waiting once that many replied.
Inventory int
}
NATS is a Resolver over a connection authenticated as a system account user.
func (NATS) LookupAll ¶
LookupAll asks every server's resolver for the account's JWT and collects the replies on a fresh inbox. It waits up to lookupTimeout for the first; then, with expect > 0, until expect replies arrived or ackWait has passed since the first; with expect <= 0 until settleTimeout passes without a new reply.
func (NATS) Push ¶
Push sends the claims update and collects the answers. With a known server set it waits until every one of them has answered or ackWait has passed; with none it takes the first answer within pushTimeout and then every one that follows within settleTimeout of the last.
func (NATS) Servers ¶
Servers pings the system account and collects the replies: it waits up to pingFirst for the first one and then until pingSettle passes without a new one. If the set is still not complete (see ServerSet.Complete) it keeps listening until pingTotal has passed since the ping, so a slow server is not left out of the expected set.
type Params ¶
type Params struct {
Mode Mode
Compiled *policy.Compiled
Keys *ctlkeys.Authority
Resolver Resolver
// Budget measures the compile; nil means policy.Budget. A seam for tests.
Budget func(*policy.Compiled) (policy.BudgetReport, error)
// VerifyTries and VerifyWait bound the read-back after a push (defaults 5 and 200ms): a clustered resolver
// may take a moment to answer with the new claims everywhere.
VerifyTries int
VerifyWait time.Duration
// ReplaceZoneKeys names zones whose scoped signer on the server may be replaced by the key apply holds
// (--replace-zone-key): credentials signed by the old key stop working.
ReplaceZoneKeys []string
// RemoveZones and KeepZones say what to do with a scoped signer on the server whose role is a zone the policy
// file lacks (--remove-zone, --keep-zone). Without one of them apply refuses.
RemoveZones, KeepZones []string
// Servers is the number of servers in the deployment (--servers, MASH_SERVERS); 0 means not given.
Servers int
// LockWait is how long an apply waits for the key directory lock (default 5s).
LockWait time.Duration
// contains filtered or unexported fields
}
Params is one run.
type Resolver ¶
type Resolver interface {
// Lookup returns the account's current JWT, or "" when the resolver has none.
Lookup(ctx context.Context, account string) (string, error)
// LookupAll returns the account JWT of every server that answered the claims lookup, one entry per reply ("" is a
// server that has none). expect is how many servers are known (0: unknown, so only a quiet period ends the wait);
// a transport stops early once that many answered. Fewer entries than expect means a server did not answer.
LookupAll(ctx context.Context, account string, expect int) ([]string, error)
// Servers returns what a system-account ping learned: the servers that answered and how many the cluster says
// it has. The set that must acknowledge a push is ServerSet.Names; only a Complete set is authoritative.
Servers(ctx context.Context) (ServerSet, error)
// Push sends the account JWT as a claims update and returns the answer of every server that replied; expect is
// the known server set (nil when unknown), which a transport may wait for.
Push(ctx context.Context, token string, expect []string) ([]ServerAck, error)
}
Resolver is the system-account view of the account resolver.
type RevokeParams ¶
type RevokeParams struct {
Keys *ctlkeys.Authority
Resolver Resolver
// Servers is the number of servers in the deployment (--servers); 0 means not given.
Servers int
// LockWait is how long to wait for the key directory lock (default 5s).
LockWait time.Duration
// VerifyTries and VerifyWait bound the read-back after the push (defaults 5 and 200ms).
VerifyTries int
VerifyWait time.Duration
// Now is the revocation time; nil means time.Now. NATS refuses a user JWT issued at or before it.
Now func() time.Time
}
RevokeParams is one revocation of user keys in the account JWT.
type RevokeResult ¶
type RevokeResult struct {
// Revoked are the keys whose revocation this call set or raised (Raised is the subset that had an older one);
// Already are the keys whose existing revocation already covers now (left as it was).
Revoked, Already, Raised []string
// Acked is how many servers acknowledged the update (0 when nothing was pushed).
Acked int
// Complete says the acknowledging servers are the whole server set (always true when nothing was pushed).
Complete bool
// Warning is a neutral line when some servers held an older copy of the account JWT than the one the revocation
// was built from ("" when all agreed).
Warning string
}
RevokeResult says what a RevokeUsers call did.
func RevokeUsers ¶
func RevokeUsers(ctx context.Context, p RevokeParams, users []string) (RevokeResult, error)
RevokeUsers adds a revocation for each user public key to the account JWT, re-signs it with the operator key and pushes it to every known server. A key whose revocation is older than now is raised to now (a JWT issued after the old time would otherwise stay valid); one that already covers now is left as it is. A revocation is never lowered or removed. Every key is validated before any I/O.
type ServerSet ¶
type ServerSet struct {
// Names are the distinct servers that replied, as the servers sent them (raw: they are the identity acknowledgements
// match on; print one through config.Clean).
Names []string
// Expected is the largest 1 + route peers any reply reported: how many servers the cluster has.
Expected int
// Gateways is set when any reply reports gateways: super-cluster membership cannot be verified from here.
Gateways bool
// Cluster is the cluster name any reply gave ("" when no reply names a cluster: a standalone server).
Cluster string
// ClusterConflict is set when replies name different clusters: the set spans clusters and is not authoritative.
ClusterConflict bool
}
ServerSet is the answer to the system-account ping.
func (ServerSet) Complete ¶
Complete says the set is authoritative. It needs at least one reply, no gateways, and as many replies as the routes report and as the operator's inventory says (--servers; 0 is none given). Without an inventory, a reply that names a cluster is not enough, even with zero routes: an isolated cluster member sees no peers, so the number of servers cannot be verified from here. A reply naming no cluster is a standalone server.
type Trust ¶
type Trust struct {
// contains filtered or unexported fields
}
Trust is the set of public keys mashctl accepts as the issuer of the account JWT it fetches: its own operator key and, when an operator JWT is known, the operator's identity key and declared signing keys.
func NewTrust ¶
NewTrust builds the accepted issuers from operatorPub (the operator key mashctl holds) and operatorJWT (the operator JWT, "" when none is known). The operator JWT must carry a valid signature by its own subject or one of its signing keys, and its subject and signing keys must include operatorPub.