swarm-nats-auth: fix four doc comments, and record why the request goes unchecked
- request.rs pointed at module docs on main.rs for why the request signature
is not verified; they said nothing. It now says why, here and in
docs/4-implementation/swarm/credentials.md ("What authenticates a callout
request"), and so do xkey::open and main.rs's module docs: only the
responder's own key can publish to the request subject, a forger with a
valid bearer gets what a normal connect gets, and nats-server makes a new
xkey at each start and has no option to set it, so there is no key to pin.
The guard is the module-eval case "the callout account has exactly one member
and no system account is configured"; the docs say to revisit this if that
changes.
- request.rs said base64url is written out rather than pulled in; it calls
data_encoding, a direct dependency.
- respond.rs said `now` is injected into sign(); sign() takes no clock.
- oidc_secret.rs named swarm-bao.nix for natsAuthReaders; it is in
swarm-bao-readers.nix.
This commit is contained in:
parent
fd1761f105
commit
31274ebf7f
6 changed files with 40 additions and 12 deletions
|
|
@ -142,6 +142,25 @@ the create that makes a new key. No principal hyperhive configures may
|
|||
delete either path's metadata, so run the two deletes with a token that may,
|
||||
such as the root token.
|
||||
|
||||
## What authenticates a callout request
|
||||
|
||||
The responder never reads the signature segment of the request JWT.
|
||||
`request::decode` splits the three segments and decodes the claims, and
|
||||
nothing checks the third. The responder takes a request as the server's when
|
||||
it opens: the server seals the request (a curve25519 box) to the callout
|
||||
xkey, and the `Nats-Server-Xkey` header carries the key it sealed with. The
|
||||
responder uses that key as sent, compares it with no key it holds, and seals
|
||||
the reply back to it. A request without the header, or one that doesn't open,
|
||||
gets no reply.
|
||||
|
||||
The signature and the sender key stay unchecked on purpose, for three reasons.
|
||||
|
||||
- Only the responder's own key can publish to `$SYS.REQ.USER.AUTH`. It's the one member of the callout account (`AUTH`) and the one `auth_users` bypass in `swarm-nats.nix`. The server has no system account, and no account shares anything with `AUTH`. Whoever holds that seed can already read the issuer seed and mint any user JWT, so a forged request gives them nothing new.
|
||||
- A forger with a valid bearer gets what a normal connect gets: the responder decides the permissions from the bearer inside the request.
|
||||
- Pinning has no key to pin. `nats-server` 2.14.4 makes a new random nkey and xkey at each start and has no option to set either, so the responder holds no server key to compare the header with. Under FIPS mode the server makes no xkey, so no header arrives and the responder refuses the request.
|
||||
|
||||
The guard is the module-eval case `the callout account has exactly one member and no system account is configured` in `nix/module-eval/nats-authelia.nix`. An extra member of `AUTH` could subscribe to the subject and read every client's token, which no signature check would stop. Revisit this decision if that case changes: when `AUTH` gains a member, or the server gets a system account.
|
||||
|
||||
## Per-principal identities
|
||||
|
||||
Bao matches a cert-auth role on the certificate's subject, so a certificate is an
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@
|
|||
//!
|
||||
//! Every request is opened with the callout xkey, and its reply is sealed
|
||||
//! back to the server; see `xkey`. A request that does not open gets no
|
||||
//! reply: the server this answers always seals. The `ensure-callout-keys`
|
||||
//! verb creates that key and the two nkeys (see `nkey`) in the secret store,
|
||||
//! and runs before the server does.
|
||||
//! reply: the server this answers always seals. The signature is never read, on
|
||||
//! purpose (see `docs/4-implementation/swarm/credentials.md`). `ensure-callout-keys`
|
||||
//! first creates that key and the two nkeys (see `nkey`) in the store.
|
||||
//!
|
||||
//! # Secrets
|
||||
//!
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ use crate::keystore::KeyStore;
|
|||
|
||||
/// The path under the store's KV mount holding `client_id`'s secret.
|
||||
/// Authelia's mint (`authelia-swarm-secrets`) writes it, at the path
|
||||
/// `swarm-secret-publisher.nix` lists, and `natsAuthReaders` in `swarm-bao.nix`
|
||||
/// `swarm-secret-publisher.nix` lists, and `natsAuthReaders` in `swarm-bao-readers.nix`
|
||||
/// grants this responder's role the read.
|
||||
///
|
||||
/// # Errors
|
||||
|
|
|
|||
|
|
@ -63,8 +63,13 @@ pub struct Claims {
|
|||
|
||||
/// Split a NATS JWT and deserialize its claim set.
|
||||
///
|
||||
/// The signature is **not** verified here — see the module docs on
|
||||
/// `main.rs` for why that is a decision and not an oversight.
|
||||
/// The signature is **not** verified here, on purpose: only the responder's own
|
||||
/// key can publish to the request subject, and a forger gains nothing the key
|
||||
/// holder lacks. The guard is the module-eval case "the callout account has
|
||||
/// exactly one member and no system account is configured"; revisit this if
|
||||
/// `AUTH` gains a member or a system account appears. The reasoning is in
|
||||
/// `docs/4-implementation/swarm/credentials.md`, "What authenticates a callout
|
||||
/// request".
|
||||
pub fn decode(payload: &[u8]) -> Result<Claims> {
|
||||
let text = std::str::from_utf8(payload).context("auth request is not utf-8")?;
|
||||
let mut parts = text.split('.');
|
||||
|
|
@ -81,10 +86,8 @@ pub fn decode(payload: &[u8]) -> Result<Claims> {
|
|||
serde_json::from_slice(&raw).context("claim segment is not the expected JSON")
|
||||
}
|
||||
|
||||
/// base64url without padding, as JWT uses. Written out rather than pulled in:
|
||||
/// `data-encoding` is already in the tree via `nkeys`, but its no-pad URL
|
||||
/// alphabet spec is one line either way and this keeps the direct dependency
|
||||
/// list honest about what this crate actually needs.
|
||||
/// base64url without padding, as JWT uses, with `data-encoding`'s no-pad URL
|
||||
/// alphabet (a direct dependency of this crate).
|
||||
fn base64_url_decode(s: &str) -> Result<Vec<u8>> {
|
||||
data_encoding::BASE64URL_NOPAD
|
||||
.decode(s.as_bytes())
|
||||
|
|
|
|||
|
|
@ -79,8 +79,8 @@ struct AuthResponse {
|
|||
version: i64,
|
||||
}
|
||||
|
||||
/// Sign a claim set the way `nats-jwt` does. `now` is injected so the test
|
||||
/// can pin it; production passes the wall clock.
|
||||
/// Sign a claim set the way `nats-jwt` does. The claims already carry their
|
||||
/// times (`iat`, `exp`), set by the caller, so signing reads no clock.
|
||||
fn sign<T: Serialize>(mut claims: Claims<T>, key: &KeyPair) -> String {
|
||||
claims.jti = String::new();
|
||||
let unhashed = serde_json::to_string(&claims).expect("claims serialisation cannot fail");
|
||||
|
|
|
|||
|
|
@ -101,6 +101,12 @@ fn from_seed(seed: &str) -> Result<XKey> {
|
|||
/// `payload` opened with `own`, and the server key `server_key` names, which
|
||||
/// the reply is sealed to.
|
||||
///
|
||||
/// That key is taken as the header gives it, compared with none: `nats-server`
|
||||
/// makes a new xkey at each start and has no option to set it, so there is
|
||||
/// none to pin. (Under FIPS mode it makes none, so no header arrives and the
|
||||
/// request is refused.) See `docs/4-implementation/swarm/credentials.md`, "What
|
||||
/// authenticates a callout request".
|
||||
///
|
||||
/// # Errors
|
||||
/// When there is no [`SERVER_XKEY_HEADER`], when it is not a public xkey, and
|
||||
/// when the payload does not open with `own`.
|
||||
|
|
|
|||
Loading…
Reference in a new issue