Documentation
¶
Overview ¶
Package issue is the issue service (REQ-013, ADR 0104): it takes a request that holds a sender's PUBLIC key and the address the key is for, countersigned by the requester on the sender's host, and returns a user JWT for that key, signed with the owner group's scoped signing key and carrying the tags mash's own table gives that address.
No private key is made, received, stored or logged on this path. Nothing in a request except the address, the public key and the proof decides what is signed: tags, permissions, limits, a name and an expiry in a request are ignored.
Index ¶
- Constants
- Variables
- func CanonicalBytes(address, publicKey, host, nonce string, expires int64) []byte
- func Parse(data []byte) (Request, *Refusal)
- func ParseListSet(data []byte) (listset.ListSet, error)
- func Serve(nc *nats.Conn, is *Issuer, rng, version string) (stop func() error, err error)
- func SignProof(requester nkeys.KeyPair, address, publicKey, host, nonce string, expires int64) (string, error)
- func Subject(rng, owner string) string
- type AccountClaims
- type FileListSet
- type Issued
- type Issuer
- type ListSetInForce
- type Record
- type Refusal
- type Request
- type RequesterRegistry
- type Response
- type Signer
Constants ¶
const ( // MaxRequestBytes is the largest request the service reads. A request is about 500 bytes. MaxRequestBytes = 4096 // MaxWindow is how far ahead of the service's clock a request's expiry may lie. It also bounds how long a nonce is // held, so it bounds the replay set. MaxWindow = 5 * time.Minute // MinNonceBytes and MaxNonceBytes bound the decoded nonce. MinNonceBytes = 16 MaxNonceBytes = 64 // MaxHostLen is the longest host name accepted. MaxHostLen = 253 )
const ( CodeMalformed = "malformed_request" CodeTooLarge = "request_too_large" CodeBadKey = "invalid_public_key" CodeExpired = "expired" CodeWindow = "expiry_too_far" CodeReplay = "replayed_nonce" CodeUnregistered = "requester_not_registered" CodeBadProof = "bad_proof" CodeUnlisted = "address_not_listed" CodeRevoked = "key_revoked" CodeBound = "key_bound_elsewhere" CodeNoSigningKey = "signing_key_unavailable" CodeNoScope = "signing_key_not_scoped" CodeTemplate = "template_mismatch" CodeNoListSet = "no_list_set" CodeRecordFailed = "record_failed" CodeSubject = "address_subject_mismatch" CodeBusy = "busy" CodeInternal = "internal" CodeBadPurpose = "invalid_purpose" CodeNoRegistry = "no_registry" )
The stable refusal codes.
const MaxNonces = 65536
MaxNonces caps the replay set; a service holding that many unexpired nonces refuses more (CodeBusy). A requester issues a few requests an hour, so the cap is never met by honest use.
const ProofPrefix = "mash-issue-v1"
ProofPrefix opens the canonical bytes the requester signs; it names the format so a signature made for another purpose cannot be taken for an issue proof.
const RequestVersion = 1
RequestVersion is the only version of the request this service accepts.
const ScopeTTL = 3 * time.Second
ScopeTTL is how long a verdict on an owner group's signing key is served without asking the account JWT again. A change of the account JWT (the key unpublished, made unscoped, or given another template) is therefore seen by the service within ScopeTTL at the latest; a verdict is also dropped at once when the list set's template for the group or the key itself changes, because both are part of what it was made for.
const ServiceName = "mash-issue"
ServiceName is the name the issue service registers as a NATS micro service.
const SubjectPrefix = "agents.issue"
SubjectPrefix opens the issue subject: agents.issue.<range>.<owner>. Its second token, "issue", is none of the mail, prompt, status or hb verbs (agents.<verb>.<range>.<owner>.<name>), and no permission template mash compiles has a line that reaches it, so an endpoint cannot publish to it. A requester's permission to publish on it, and to receive the reply, belongs to account setup.
Variables ¶
var ErrNotConfigured = errors.New("issue: the issuer is missing a registry, list set, signer, record, account claims or account key")
ErrNotConfigured is returned by Validate for an Issuer with a part missing.
Functions ¶
func CanonicalBytes ¶
CanonicalBytes are the bytes the requester signs:
mash-issue-v1\n<address>\n<public_key>\n<host>\n<nonce>\n<expires>
with the address, public key, host and nonce as the request carries them and expires in decimal. The address is inside the signed bytes, so a proof made for one address cannot be used for another. Validate has already refused a newline in any field.
func Parse ¶
Parse decodes a request, refusing one over MaxRequestBytes, one that is not a JSON object, and one with a field that is not shaped as the format says. Fields it does not know are dropped unread.
func ParseListSet ¶
ParseListSet decodes the JSON form of a list set.
func Serve ¶
Serve registers the issue service on nc, listening on agents.issue.<rng>.* in the queue group of the service, and returns a stop func. Every request is answered with one Response; the purpose is always store.PurposeIssue.
func SignProof ¶
func SignProof(requester nkeys.KeyPair, address, publicKey, host, nonce string, expires int64) (string, error)
SignProof is the requester side: the proof of a request, signed with the requester's key pair. It is here so tests and the requester's own code share one definition of the canonical bytes.
Types ¶
type AccountClaims ¶
type AccountClaims interface {
Fetch(ctx context.Context) (*jwt.AccountClaims, error)
}
AccountClaims fetches the account's current JWT claims, verified: the issue service asks it which signing keys the account publishes and with what template.
type FileListSet ¶
type FileListSet struct {
Path string
// contains filtered or unexported fields
}
FileListSet is the ListSetInForce that reads a list set from a JSON file. DEC-004 leaves the list set's file format open, so the file is a JSON object shaped like listset.ListSet: {"Range": "...", "Switches": [{"Group", "Verb", "Switch"}], "Senders": [{"Sender", "Allow", "Deny"}]} (field names match without regard to case; an unknown field is refused). It is read and compiled again whenever its bytes change, and a file that cannot be read or does not compile is no list set in force (fail closed). The generation is 0 until the policy gate lands.
The list set decides who may be issued a credential, so every read applies custody checks: the file is opened without following a symlink and must be a regular file owned by the effective uid that no group or other user can write (mode & 0022 == 0); its directory must be a real directory the effective uid owns that no group or other user can write. Reading by others is allowed: the list set is not secret. The checks run on every read, so a file that is swapped or loosened after start is refused rather than served from the table compiled earlier.
type Issuer ¶
type Issuer struct {
Registry RequesterRegistry
ListSet ListSetInForce
Signer Signer
Record Record
// Claims reads the account JWT the signing key is verified against (see ScopeTTL).
Claims AccountClaims
AccountPub string
Log *slog.Logger
// Now is the clock; nil means time.Now.
Now func() time.Time
// contains filtered or unexported fields
}
Issuer signs user JWTs for public keys. Its replay set lives in memory only: a restart forgets it. A replay after a restart is refused all the same once the request's expiry has passed, and the expiry is at most MaxWindow ahead of the moment the request was made, so a restart opens a replay window of at most MaxWindow.
func (*Issuer) Issue ¶
Issue signs a user JWT for r.PublicKey and records it, or returns a *Refusal (or an error for a failure that is not a refusal of the request) and signs and records nothing. purpose is store.PurposeIssue for the NATS service and store.PurposeRotation for the rotation code of REQ-014.
type ListSetInForce ¶
ListSetInForce is the list set the account runs under: its compiled form and the generation it has. The generation is 0 until the policy gate lands.
type Record ¶
type Record interface {
// Lookup returns the record of publicKey, nil when there is none.
Lookup(ctx context.Context, publicKey string) (*store.Issued, error)
// RecordChecked writes the entry as a compare-and-set that refuses, at the revision it writes at, a key whose
// record has revoked_at set (store.ErrKeyRevoked) or is bound to another address (store.ErrKeyBoundElsewhere).
// An error means nothing may be issued: the write is the arbiter, the Lookup before it only an early refusal.
RecordChecked(ctx context.Context, r store.Issued) error
}
Record is the issue record as the service needs it.
type Refusal ¶
type Refusal struct{ Code, Msg string }
Refusal is the error Issue returns when it declines to sign. Its Msg is safe to send back to the requester.
type Request ¶
type Request struct {
Version int `json:"version"`
Address string `json:"address"` // range.owner.name
PublicKey string `json:"public_key"` // a NATS user public key; never a seed
Host string `json:"host"` // the name the requester is registered under
Nonce string `json:"nonce"` // base64url, at least MinNonceBytes random bytes
Expires int64 `json:"expires"` // unix seconds
Proof string `json:"proof"` // base64url ed25519 signature by the requester over CanonicalBytes
Requester string `json:"requester"` // the requester's public key
}
Request is an issue request. Its JSON object may carry other fields (tags, permissions, ...): they are not decoded and never read.
func (Request) AddressParts ¶
AddressParts is the owner, group and instance of the request's address. The policy path calls the owner token the range and the group token the owner.
type RequesterRegistry ¶ added in v0.5.5
RequesterRegistry says which requester public keys are registered for a host and an owner group. How a requester's key comes to be registered is open (DEC-002), so the issue service only asks. A nil or empty result registers no one.