Documentation
¶
Overview ¶
Package admin provisions mash endpoints: the permission template a NATS user needs, and the streams, consumer and directory record behind it. mash never mints users or holds account seeds; the operator's own tooling issues the user with these permissions.
Index ¶
- Constants
- Variables
- func AliasHolder(err error) string
- func CheckProvision(rule *namerule.Rule, owner, name string) error
- func IsPartial(err error) bool
- func IsRefusal(err error) bool
- func NSCFlags(owner, name string) []string
- func NewFormPermissions(id sap.EndpointIdentity, extra []string) (jwt.Permissions, error)
- func NewFormUserPermissions(id sap.EndpointIdentity, alias *store.Alias, existing []store.Record, ...) (jwt.Permissions, error)
- func Permissions(owner, name string) jwt.Permissions
- func PermissionsTo(owner, name string, recipients []string) jwt.Permissions
- func RefuseCompiledForNewForm(compiled bool) error
- func ValidKey(key string) bool
- func ValidateGrant(subject string) error
- func VerifyAlias(id sap.EndpointIdentity, alias store.Alias, existing []store.Record) (sap.EndpointIdentity, error)
- func WindowBridge(id, alias sap.EndpointIdentity) (jwt.Permissions, error)
- func ZonePermissions(owner, zone string, wildcardZones []string) jwt.Permissions
- type Admin
- func (a *Admin) ApplyLimits(ctx context.Context, names ...string) ([]string, error)
- func (a *Admin) Audit(ctx context.Context) (AuditSnapshot, error)
- func (a *Admin) Conn() *nats.Conn
- func (a *Admin) Deprovision(ctx context.Context, name string) (err error)
- func (a *Admin) DeprovisionDrained(ctx context.Context, name, id string, seq uint64) (err error)
- func (a *Admin) DeprovisionIfUser(ctx context.Context, name, user string) (err error)
- func (a *Admin) EnsureInbox(ctx context.Context, name string) ([]string, error)
- func (a *Admin) Exists(ctx context.Context, name string) (bool, error)
- func (a *Admin) Init(ctx context.Context) error
- func (a *Admin) List(ctx context.Context) ([]store.Record, error)
- func (a *Admin) Provision(ctx context.Context, name, user, account, note string, meta Meta) (rec store.Record, err error)
- func (a *Admin) ProvisionIdentity(ctx context.Context, id sap.EndpointIdentity, alias *store.Alias, ...) (rec store.Record, err error)
- func (a *Admin) Resume(ctx context.Context, name string) (err error)
- func (a *Admin) SetLimits(l store.Limits) error
- func (a *Admin) SetMeta(ctx context.Context, name string, u MetaUpdate) (store.Record, error)
- func (a *Admin) SetUser(ctx context.Context, name, account, oldUser, newUser string) (store.Record, error)
- func (a *Admin) SetUserLocked(ctx context.Context, l NameLock, name, account, oldUser, newUser string) (store.Record, error)
- func (a *Admin) SetZone(ctx context.Context, name, zone string) (_ store.Record, err error)
- func (a *Admin) Suspend(ctx context.Context, name string) (_ SuspendState, err error)
- func (a *Admin) Suspended(ctx context.Context, name string) (SuspendState, error)
- func (a *Admin) UserOf(ctx context.Context, name string) (user, account string, err error)
- func (a *Admin) UserOfLocked(ctx context.Context, l NameLock, name string) (user, account string, err error)
- func (a *Admin) WithNameLock(ctx context.Context, name string, ...) (err error)
- func (a *Admin) WithNameRule(rule *namerule.Rule) *Admin
- func (a *Admin) WithRevoker(h RevokeHook) *Admin
- type AuditBadRecord
- type AuditConsumer
- type AuditLease
- type AuditRetired
- type AuditRetiredMarker
- type AuditSnapshot
- type AuditStream
- type Meta
- type MetaUpdate
- type NameLock
- type RevokeHook
- type SuspendState
Constants ¶
const ( AllowTag = "allow" DenyTag = "deny" // NoDenyTag is the placeholder deny tag EVERY user carries, whether or not its zone has a deny exception. // nats-server refuses to authenticate a user whose scoped key has a {{tag(deny)}} template in a deny list and // that has no deny tag ("generated invalid subject"; allow lists just drop the line), and every zone key carries // that template from its first compile, so every user needs one deny tag: this one. Its value "_none" is a valid // subject token, and no endpoint or zone name can be "_none" (names start with a letter), so // agents.mail.*.<owner>._none addresses nothing. Because every user carries it from the start, the first real deny // exception of a zone changes only the JWTs of the endpoints it names, never the zone key. NoDenyTag = DenyTag + ":_none" )
Tag names a user's JWT carries to widen or narrow what its zone's signing key grants, and the templates that expand them. A tag is "<name>:<zone>.<endpoint>" (or "<name>:<zone>.*"), lower case, and its value must be a valid subject tail: it is placed in a permission subject as it stands.
Variables ¶
var ( // ErrRecordOtherUser: the directory record's user is not the key given. ErrRecordOtherUser = errors.New("its record belongs to another user key (left in place)") // ErrRecordChanged: the record was replaced or changed between the read and the delete. ErrRecordChanged = errors.New("the record changed; left in place") // ErrAliased: a new-form record's alias names this legacy endpoint. ErrAliased = errors.New("a new-form endpoint aliases it (left in place)") // ErrNoRecord: there is no directory record, so nothing proves who owns the name (or its inbox stream). ErrNoRecord = errors.New("it has no directory record, so nothing proves the key owns it (left in place)") )
The refusals of DeprovisionIfUser: each leaves the record, the lease and the inbox as they were.
var ErrLockExpiring = errors.New("the name lock is about to expire")
ErrLockExpiring is the cause of a bound context that ended because its lock was about to expire.
var ErrMarkerFinalOtherUser = errors.New("its name is already retired (INV-002) by a final retired marker for another user key (left as it is)")
ErrMarkerFinalOtherUser: the name's retired marker is final (the name is burned, INV-002) yet a live record carries another user key. Nothing is removed and the name stays refused.
Functions ¶
func AliasHolder ¶ added in v0.4.0
AliasHolder returns the new-form endpoint (its flat name) that blocks a deprovision with ErrAliased, or "" when err is not that refusal.
func CheckProvision ¶ added in v0.4.0
CheckProvision applies rule to the legacy identity of name under owner, as provisioning does. A refusal is an error that names the rule and carries its message. A name or owner that is not a legacy identity passes here: the code that follows refuses it on its own terms.
func IsPartial ¶ added in v0.3.3
IsPartial reports whether err says the endpoint's NATS user was revoked but the removal did not complete: the credentials are dead and the same command run again finishes the removal.
func IsRefusal ¶ added in v0.3.3
IsRefusal reports whether err is a refusal of DeprovisionIfUser: the call touched nothing. Any other error from it may come after the record was deleted (the lease fence or the inbox delete failed, or the connection broke).
func NewFormPermissions ¶ added in v0.4.0
func NewFormPermissions(id sap.EndpointIdentity, extra []string) (jwt.Permissions, error)
NewFormPermissions is the DEFAULT, un-policied permission set of the new-form endpoint id, plus the validated extra grants. It takes no policy input on purpose: new-form provisioning (step 1.6) MUST use it for every three-token identity and MUST refuse any policy-compiled permission set (RefuseCompiledForNewForm), because the compiler's zone wildcard unit is unruled (amendment 2). Anything not listed is denied; there is no response permission.
Publish: peer lines to any endpoint of the same owner with the same literal agent token (mail, prompt, status; no wildcard in the agent position), its own exact heartbeat, replies, the service API, and fixedPub's JetStream and KV lines keyed on the flat identity. Subscribe: its private inbox, its own prompt and status subjects, $SRV.>, and the heartbeats of its own owner and agent token.
extra are configured grants (REQ-027 validated). Each must start with "agents." and carry the verb mail, prompt or status (never hb or any other verb: heartbeat publication is granted only on the endpoint's own exact subjects); it is added to publish allow only.
func NewFormUserPermissions ¶ added in v0.4.0
func NewFormUserPermissions(id sap.EndpointIdentity, alias *store.Alias, existing []store.Record, extra []string) (jwt.Permissions, error)
NewFormUserPermissions is the permission set of a new-form endpoint's user: NewFormPermissions(id, extra), plus WindowBridge for the alias when there is one, allow lists merged and deduplicated. It takes no policy input, so a policy-compiled set cannot reach it (RefuseCompiledForNewForm is for the caller that holds that flag).
existing is the directory's records. A non-nil alias is verified here with VerifyAlias against existing, and refused on error before WindowBridge is called, so verification cannot be skipped. The caller passes a directory read made while it holds the locks that keep the alias's legacy record in place.
func Permissions ¶
func Permissions(owner, name string) jwt.Permissions
Permissions is the complete permission set of endpoint name under owner (spec section 8). Anything not listed is denied.
func PermissionsTo ¶ added in v0.3.2
func PermissionsTo(owner, name string, recipients []string) jwt.Permissions
PermissionsTo is Permissions with the three peer-addressing publish lines (mail, prompt and status to any endpoint of the owner) narrowed to recipients: one line per recipient and verb, agents.<verb>.*.<owner>.<recipient>. A nil recipients keeps the wildcard lines, so PermissionsTo(owner, name, nil) is Permissions. The wildcard mail line comes twice, the legacy 5-token form and the zoned 6-token form (ADR 0054); the recipient form keeps its one legacy line per recipient. An empty non-nil slice grants no mail, prompt or status line at all; the fixed lines (own heartbeat, inbox, directory read, lease) remain, so the block is never empty. Recipients must be valid endpoint names: they are placed in subjects as they are.
func RefuseCompiledForNewForm ¶ added in v0.4.0
RefuseCompiledForNewForm is the policy-compiled-user refusal of amendment 2: ADR 0053's compiler uses the zone as its wildcard unit, so a policy-compiled user cannot carry a three-token identity until Randy rules on the zone question. It returns an error when compiled is true.
func ValidKey ¶ added in v0.4.0
ValidKey reports whether key names an endpoint the suspend, resume and drained-removal verbs accept: a legacy name (config.ValidName) or a new-form flat key (agent_owner_name).
func ValidateGrant ¶ added in v0.4.0
ValidateGrant checks one subject grant against REQ-027: a grant that applies to the agents. subject space must not carry '*' or '>' in the range (agent) token position, which is token index 2 of agents.<verb>.<agent>.<owner>.<name>, or at or before it. A grant is accepted only if every token is a literal or a lone '*', '>' appears only as the last token, no token is empty or has whitespace, and no token mixes a wildcard character with other text. A grant that starts with a wildcard applies to the agents. space too, so it is held to the same rule. An agents. grant needs at least four tokens (verb, agent and owner are named). Subjects outside the agents. space pass the structural checks only.
func VerifyAlias ¶ added in v0.4.0
func VerifyAlias(id sap.EndpointIdentity, alias store.Alias, existing []store.Record) (sap.EndpointIdentity, error)
VerifyAlias is the one check of a new-form record's legacy alias (ADR 0076, "Validation at provisioning"). The permission set WindowBridge builds trusts its alias, so nothing else guards the grants that name another endpoint's exact prompt, status and heartbeat subjects: provisioning and any permission assembly must call this first.
existing is the directory's records. It returns the alias as a legacy identity, or an error when
- id is not a valid new-form identity;
- the alias owner or name fails the legacy name rule (sap.Legacy);
- the alias owner equals id's owner (the legacy wildcard filter would reach id), or the alias overlaps id;
- no unzoned legacy record has exactly that owner and name (a zoned one is named in the refusal);
- another new-form record, one not keyed by id's own flat key, already claims the alias.
The record under id's own flat key is id itself, so verifying an already provisioned record passes.
func WindowBridge ¶ added in v0.4.0
func WindowBridge(id, alias sap.EndpointIdentity) (jwt.Permissions, error)
WindowBridge is what the window adds for new-form id that has legacy alias (amendment 1, removed in 3.2): publish to legacy endpoints of the alias's owner for mail, prompt and status only (wildcard in the name position only, literal agent token cc), the heartbeat of the alias's own exact subject and no other, and exact subscribe grants for the alias's prompt and status subjects.
It also adds the transition JetStream publish grants: the lines fixedPubKeyed gives a legacy endpoint for its inbox stream, for the alias's legacy inbox stream only (inbox-<alias name>) and the shared durable consumer only, so the new-form user can read stream and consumer info, fetch its queued mail through the existing durable and acknowledge it, and read the stream by direct get. No wildcard stream or consumer name, and no create, update, delete or purge subject, is granted. The user's own reply prefix already covers the replies, so no subscribe grant is added.
It also adds the alias's own lease key lines, the two fixedPubKeyed gives a legacy endpoint for its lease (publish to $KV.<lease bucket>.<alias name>: create, update, delete, purge; and direct get of that one key), because during the window the new-form endpoint holds the legacy lease key while it reads the legacy stream. The stream info line for the lease bucket is already in the user's own lease lines. No wildcard key, bucket-level subject or other key is granted.
It refuses an id that shares the alias's owner (admission's rule: the legacy wildcard filter would reach it) or overlaps it.
WindowBridge trusts alias. The grants name another endpoint's exact prompt and status subjects and its heartbeat, so the caller (provisioning, step 1.6) MUST verify the alias mapping first, and no check here can: the alias's legacy owner and name pass the legacy rule, a legacy record with exactly that owner and name exists, and no other new-form record claims it (one alias per record and per legacy identity).
func ZonePermissions ¶ added in v0.3.2
func ZonePermissions(owner, zone string, wildcardZones []string) jwt.Permissions
ZonePermissions is the permission template of the scoped signing key of zone under owner. Only MAIL carries the zone token (ADR 0054): agents.mail.<kind>.<owner>.<zone>.<name>. Prompt, status and heartbeat keep SAP's five-token subjects, so the key grants those as they are. Every endpoint of the zone is a user signed by this key and gets, by expansion, its own copy of the fixed per-endpoint lines ({{name()}} is the user's name) and these peer-addressing lines:
- one MAIL publish line per wildcard zone: agents.mail.*.<owner>.<zone>.*, so every endpoint of the zone may mail every endpoint of each wildcardZones entry;
- the mail exception line agents.mail.*.<owner>.{{tag(allow)}}, one subject per "allow:" tag of the user; a user with no allow tag gets none;
- the mail deny line agents.mail.*.<owner>.{{tag(deny)}}, one subject per "deny:" tag of the user: a deny beats any allow, so a user's deny tags remove peers from what the mail wildcards grant. The key carries it always, so adding a zone's first deny exception never changes the key. nats-server refuses a user with no deny tag under this template, so every user carries NoDenyTag at least;
- two fixed, open lines, agents.prompt.*.<owner>.* and agents.status.*.<owner>.*: live prompts and status probes to any endpoint of the owner are not policed until a later decision (ADR 0054).
The endpoint's own prompt and status subscriptions are the five-token sap.For subjects with {{name()}}. Nothing else addresses a peer. The block is never empty. The templates need the scoped-key user to carry empty permissions of its own. zone names the key; no line spells it out except through the mail wildcards it is a recipient of.
Types ¶
type Admin ¶
type Admin struct {
// contains filtered or unexported fields
}
Admin provisions endpoints with the account's admin credentials.
func (*Admin) ApplyLimits ¶ added in v0.3.1
ApplyLimits raises the configured limits on existing inboxes in place with a stream update: max_bytes and max_age where they are below the configured value, and max_consumers where it differs. With no names it covers every directory endpoint. Lowering max_bytes or max_age is refused with an error naming the endpoint and field (nothing changes for that endpoint), because it could discard stored mail; the other endpoints are still processed and the errors are joined. It returns one line per endpoint saying what changed.
func (*Admin) Audit ¶ added in v0.4.0
func (a *Admin) Audit(ctx context.Context) (AuditSnapshot, error)
Audit reads the directory, the inbox streams and the lease keys and changes nothing. A value that does not parse is reported in BadRecords, not as an error, so one damaged record does not hide the rest. A key or stream that disappears while it is read is skipped.
func (*Admin) Conn ¶ added in v0.3.3
Conn is the connection the Admin was made with. The caller owns it.
func (*Admin) Deprovision ¶
Deprovision removes name's directory record and inbox stream and fences its lease with a tombstone. The fence comes first: a session that is live or starting cannot take the lease back once its endpoint is gone (#10). A new-form identity's retired marker goes pending -> purge -> final (see beginRetire): the marker is written pending before the user is revoked or anything is removed, and made final once the record is purged.
func (*Admin) DeprovisionDrained ¶ added in v0.3.3
DeprovisionDrained is Deprovision for an inbox that was suspended and read through sequence seq (the last_seq that Suspend reported); id is the suspension id Suspend reported. Under the name's lock it reads the stream fresh and refuses, touching nothing, unless the inbox is still suspended, carries a suspension id equal to id (an empty id never matches, so a re-provisioned endpoint of the same name is safe from an old command) and its last sequence is exactly seq: another admin's Resume, and any mail stored after it, make the check fail instead of losing mail. A name with no inbox stream is refused: nothing proves it is the one drained.
name is a legacy name or a new-form flat key (agent_owner_name). A new-form identity's retired marker goes pending -> revoke and purge -> final exactly as in Deprovision (see beginRetire), and a re-run after a stop that followed the purge finishes it. A legacy name is refused while a new-form record names it as its alias (guardLegacyAlias).
func (*Admin) DeprovisionIfUser ¶ added in v0.3.2
DeprovisionIfUser is Deprovision for a record that must still belong to user (a public user key): it reads the record's value and revision, refuses unless its user equals user, and deletes the record with a revision guard (Purge with LastRevision), so a record replaced between the read and the delete is never removed. A revision conflict re-reads the record (up to setMetaTries times): a metadata-only change by another admin leaves the user unchanged, so the delete is retried on the new revision; a changed user, a vanished record or exhausted retries refuse.
Order: guard and guarded record delete first, then the lease fence and the inbox delete. A refused call therefore touches nothing: no tombstone, no stream delete. The whole call runs under the name's lock (ADR-0048), so another admin's Provision of the name waits until the fence and the inbox delete are done and is never fenced and never has its inbox deleted. For sessions the gap between the record delete and the fence is safe because a session cannot hold a record-less name: Open re-reads the directory record after taking the lease and gives the lease back when it is gone (see Open), and a session that already held the lease is stopped by the tombstone at its next refresh, exactly as in Deprovision. The cost of this order against Deprovision's is that a failure between the two steps leaves a record-less name with an inbox and no fence; re-running `deprovision` (without --user) finishes it.
With no record nothing proves ownership, so it refuses even when the inbox stream exists (a provision that failed before writing its record): remove that stream with a plain deprovision. The one exception is a new-form key with a retired marker, the remains of an interrupted removal, which it finishes; with no marker it changes nothing.
func (*Admin) EnsureInbox ¶
EnsureInbox makes sure name's inbox stream and its durable consumer exist, creating whichever is missing with the same configuration Provision uses. It is for an endpoint whose directory record already exists (Provision refuses those) and reports what it had to create: "stream", "consumer", both, or neither. An existing stream or consumer is only checked, never updated: one that differs from that configuration in any field mail depends on is an error naming the field, because fixing it in place could discard stored mail (a lower MaxBytes or MaxAge would). The user decides to deprovision it, which removes whatever the inbox holds, and provisions again.
func (*Admin) Exists ¶ added in v0.3.3
Exists reports whether name has a directory record, an inbox stream or a live lease (not just the tombstone a deprovision leaves): any of them is something a deprovision removes or fences. Deprovision itself stays idempotent (rollbacks rely on it); a CLI verb asks this first to refuse a name that was never there.
func (*Admin) Init ¶
Init creates the directory, lease and retired-name buckets. It is idempotent. A bucket from before buckets had a size cap (no MaxBytes) is bounded in place with a stream update, keeping its keys; a bucket whose MaxBytes is smaller than the configured limit is raised to it; a larger one is kept (a limit is never lowered), and nothing is purged. The lease bucket does not allow rollup: Init creates it hardened and hardens an existing one (see store.HardenLeaseBucket), and fails if it cannot.
func (*Admin) Provision ¶
func (a *Admin) Provision(ctx context.Context, name, user, account, note string, meta Meta) (rec store.Record, err error)
Provision creates name's inbox stream, its consumer and, last, its directory record, so a half-done provision can simply be re-run.
func (*Admin) ProvisionIdentity ¶ added in v0.4.0
func (a *Admin) ProvisionIdentity(ctx context.Context, id sap.EndpointIdentity, alias *store.Alias, user, account, note string, meta Meta) (rec store.Record, err error)
ProvisionIdentity provisions the new-form endpoint id (ADR 0074). The configured name rule is applied first, to all three tokens of id (not to alias), before the keys are validated and before anything is read or written. It creates the directory record keyed by id's flat identity, the inbox stream inbox-<flat> filtered on id's exact mail subject, and the durable consumer. alias, when set, is the legacy identity the endpoint answers to during the transition window (ADR 0076); it is verified by VerifyAlias before anything is written. A new-form identity is never zoned, so meta.Zone must be empty.
Discipline is Provision's: the flat key's lock, then the directory-wide admission lock (a leaf), held while the directory is listed, admitted against and written, with both re-checked before the record. The record is written last, so a provision that stopped part-way is finished by running the same call again; a finished one is refused as already provisioned. A retired new-form identity is refused (INV-002): the new-form deprovision writes a durable marker into the no-TTL bucket store.RetiredBucket (key = flat identity; value: store.Retired, its tokens, the retired user public key, the time and a state, never a seed) as pending before it revokes or removes anything, and makes it final once the record is purged. This call checks it under the admission lock; a pending marker blocks exactly like a final one. A deprovision deletes only the pending marker its own call wrote, when it refuses before the purge; there is no release path for a marker that outlives a call: releasing one would need a contract ruling and an audit record. A legacy name is not marked (Provision clears its tombstone on purpose), so it stays reusable. The bucket must hold room for one more marker and must have no TTL, or provisioning is refused.
func (*Admin) Resume ¶ added in v0.3.3
Resume restores the subjects Suspend saved and clears its metadata. It is idempotent: an inbox that is not suspended is left as it is. Stale metadata on live subjects is cleared and the subjects kept; parked subjects with no usable saved list are an error, never a guess.
func (*Admin) SetLimits ¶ added in v0.3.1
SetLimits sets the caps Init, Provision and EnsureInbox use (default: store.DefaultLimits). It validates them.
func (*Admin) SetMeta ¶
SetMeta changes name's role, host and labels, only those given. It merges into the stored JSON object, so every other field, including ones a newer mash wrote, survives, and writes with a compare-and-set against the revision it read, re-reading and retrying if another write got in between.
func (*Admin) SetUser ¶ added in v0.3.3
func (a *Admin) SetUser(ctx context.Context, name, account, oldUser, newUser string) (store.Record, error)
SetUser is a compare-and-set of name's directory record's user key from oldUser to newUser (public user keys), for a key rotation. It takes the name's lock like SetMeta, reads the record and writes it back against the revision it read, re-reading and retrying if another write got in between, and keeps every other field. It refuses a name with no record, a record whose account is not account, and a record whose user is neither oldUser nor newUser. It is idempotent: a record that already carries newUser is returned as it is.
func (*Admin) SetUserLocked ¶ added in v0.3.3
func (a *Admin) SetUserLocked(ctx context.Context, l NameLock, name, account, oldUser, newUser string) (store.Record, error)
SetUserLocked is SetUser for a caller that already holds name's lock l (from WithNameLock): it does not take the lock again, and re-checks it before the write.
func (*Admin) SetZone ¶ added in v0.3.3
SetZone moves the existing endpoint name into zone without touching stored mail. It first appends the zone's mail filter to the inbox stream's subjects (an update that changes nothing else and purges nothing, so mail that a sender not yet updated publishes to the legacy subject still lands), then rewrites the directory record's zone and mail subject against the revision it read, keeping every other field. It is idempotent: an endpoint already in zone is returned as it is. An endpoint in another zone is refused, as no endpoint returns to legacy or changes zone in this version.
func (*Admin) Suspend ¶ added in v0.3.3
Suspend parks name's inbox stream: it saves the stream's subjects in its metadata and replaces them with the one subject mash.suspended.<name>, so a sender's publish finds no stream. Only the subjects and metadata change and nothing is purged. It also stores a fresh random suspension id. It is idempotent: a suspended inbox is reported as it is, with its existing id. The state's LastSeq is read after the update and settled, so it is the final one.
func (*Admin) Suspended ¶ added in v0.3.3
Suspended reads whether name's inbox is suspended, since when, and the stream's message count and last sequence.
func (*Admin) UserOf ¶ added in v0.3.3
UserOf reads name's directory record and returns its user key and account. It returns ErrNoRecord when there is none. It does not take the name's lock; inside WithNameLock use UserOfLocked (the read is the same).
func (*Admin) UserOfLocked ¶ added in v0.3.3
func (a *Admin) UserOfLocked(ctx context.Context, l NameLock, name string) (user, account string, err error)
UserOfLocked is UserOf for a caller that holds name's lock l (from WithNameLock); it refuses a lock that is not held or not name's.
func (*Admin) WithNameLock ¶ added in v0.3.3
func (a *Admin) WithNameLock(ctx context.Context, name string, fn func(ctx context.Context, l NameLock) error) (err error)
WithNameLock takes name's lock, runs fn with a context that ends before the lock expires and releases the lock. fn does its reads and writes through UserOfLocked and SetUserLocked (the lock is not reentrant: SetUser or UserOf inside fn would wait for it) and re-checks the lock with Check before any write of its own. An error from fn that is the context ending because the lock was about to expire is worded to say so.
func (*Admin) WithNameRule ¶ added in v0.4.0
WithNameRule returns a copy of a whose Provision applies rule to the identity it provisions, before the directory is read (docs/name-rule.md). A nil rule accepts everything. a itself is unchanged.
func (*Admin) WithRevoker ¶ added in v0.3.3
func (a *Admin) WithRevoker(h RevokeHook) *Admin
WithRevoker returns a copy of a whose Deprovision, DeprovisionIfUser and DeprovisionDrained call h, when it is not nil, with the user key of the directory record read under the lock (see RevokeHook). Plain Deprovision calls it only when the name has a readable record. a itself is unchanged.
type AuditBadRecord ¶ added in v0.4.0
type AuditBadRecord struct {
Key string
Error string
User string // the raw value's "user" field if it still yields one; used only to claim the creds, never trusted
}
AuditBadRecord is a directory key whose value does not parse as a record.
type AuditConsumer ¶ added in v0.4.0
type AuditConsumer struct {
Pending uint64 // messages not yet delivered
AckPending int // delivered and not yet acknowledged
DeliverPolicy string // all, last, new, by_start_sequence, by_start_time or last_per_subject
StartSeq uint64 // the configured start sequence (0 unless by_start_sequence)
StartTime string // the configured start time, RFC 3339 UTC (empty unless by_start_time)
FilterSubjects []string // the configured filter subject(s), sorted; empty when unfiltered
AckFloor uint64 // the stream sequence at or below which every message is acknowledged
Delivered uint64 // the highest stream sequence delivered
DeliveredConsumer uint64 // the consumer sequence of the last delivery
AckFloorConsumer uint64 // the consumer sequence of the ack floor
DeliveredLast *time.Time // when the last delivery was made; nil when the server reports none
AckFloorLast *time.Time // when the ack floor last moved; nil when the server reports none
NumRedelivered int // messages redelivered and not yet acknowledged
Created time.Time // when the consumer was created; zero when the server reports none
}
AuditConsumer is the drain state of an inbox stream's durable consumer (store.Consumer).
type AuditLease ¶ added in v0.4.0
AuditLease is one lease key. Tombstone is the fence a deprovision leaves until it expires.
type AuditRetired ¶ added in v0.4.0
type AuditRetired struct {
Present bool
Markers []AuditRetiredMarker // sorted by key
Bytes uint64 // bytes the bucket's stream stores
MaxBytes int64 // the bucket's configured cap; 0 when it reports none
ConfigError string // store.VerifyRetiredStatus's refusal, empty when the bucket is as mash makes it
}
AuditRetired is the retired-name bucket as the server holds it. Present is false when there is no bucket (no retirement ever happened, or the deployment predates it); the audit never creates it.
type AuditRetiredMarker ¶ added in v0.4.0
type AuditRetiredMarker struct {
Key string
Marker store.Retired
Error string // set when the value does not parse; Marker is then empty
}
AuditRetiredMarker is one key of the retired-name bucket: the marker, or why its value could not be read.
type AuditSnapshot ¶ added in v0.4.0
type AuditSnapshot struct {
Records []store.Record // sorted by directory key
BadRecords []AuditBadRecord
Streams []AuditStream // every inbox-* stream, sorted by name
Leases []AuditLease // every lease key except the admin locks, sorted by key
Retired AuditRetired // the retired-name bucket
LeaseRollup bool // the lease bucket exists and its stream still allows rollup writes (it has not been hardened)
LeaseError string // the lease bucket exists and its stream configuration could not be read; empty otherwise
}
AuditSnapshot is mash's side of the population as the server holds it, each list sorted. It is read only.
type AuditStream ¶ added in v0.4.0
type AuditStream struct {
Name string // the stream name, inbox-<key>
Msgs uint64
FirstSeq uint64
LastSeq uint64
Bytes uint64 // bytes the stream stores
MaxBytes int64 // the stream's configured byte cap; 0 or less when it reports none
Created time.Time // when the stream was created; zero when the server reports none
LastTime time.Time // when the stream last stored a message; zero for a stream that never held one
Subjects []string // as configured; for a suspended stream the parked subject
Suspended bool
Deliver *AuditConsumer // nil when the stream has no deliver consumer
}
AuditStream is what the server shows of one inbox stream.
type Meta ¶
type Meta struct {
Role, Host string
Labels map[string]string
Description string
Caps []string
// Zone, when set, provisions the endpoint into that zone: a 6-token mail subject, and an inbox that takes both
// the zone and the legacy subject (ADR 0054). Empty is the legacy 5-token subject.
Zone string
}
Meta is a record's optional directory metadata.
type MetaUpdate ¶
type MetaUpdate struct {
Role, Host *string
Labels map[string]string
Description *string
AddCaps []string
DropCaps []string
ClearCaps bool
}
MetaUpdate names the metadata fields SetMeta changes; a nil field is left alone and a pointer to "" clears it. Labels is applied per key: a value sets that label, an empty value clears it, other labels are left alone. Description is set like Role. Caps are applied as a merge: AddCaps are added, DropCaps removed, and ClearCaps removes every capability first (then AddCaps still apply).
type NameLock ¶ added in v0.3.3
type NameLock struct {
// contains filtered or unexported fields
}
NameLock is a held name lock (ADR 0048, ADR 0058), handed to the func WithNameLock runs. It is valid only inside that func.
type RevokeHook ¶ added in v0.3.3
RevokeHook revokes the NATS user key user (a public key) of an endpoint that is about to be removed. It runs under the endpoint's name lock, after every guard of the removal has passed and before anything is removed; an error aborts the removal with nothing removed.
type SuspendState ¶ added in v0.3.3
type SuspendState struct {
Suspended bool
Since string // RFC 3339 UTC; empty when not suspended
ID string // names this one suspension; empty when not suspended or when parked by hand without one
Msgs uint64
LastSeq uint64
}
SuspendState is whether an endpoint's inbound mail is parked (ADR 0057), when, and where its inbox stands. Msgs and LastSeq are the stream's, read fresh; while the state holds, LastSeq is final.