swarm-logs: an agent's CLI for the swarm log store
An agent can reach VictoriaLogs only through the gateway, and since the
machine query route landed the way to read it has been to hand-roll a
client_credentials token request and a curl, per query. This is the CLI
that closes that: `swarm-logs query '<LogsQL>'`, matched log lines on
stdout, so the answer pipes into grep like any other command's.
Built to the plan posted on the tracker thread: own crate, own
docs/tools reference generated off the clap tree, `query` as the one
verb, and the JSON error body surfaced on a non-200 rather than
swallowed. No `tail`: streaming is a different endpoint with a different
response shape, and folding it in here would be a fatter scope than the
ask.
Minting the token is NOT implemented here — swarm-queue-client already
owns the client_credentials request, its error type and its CA handling,
and a token-endpoint fix has to be findable in one place. What this crate
adds is the agent-shaped half: the client id arrives as a *file* beside
the secret, so nothing outside nix/agent-modules/queue.nix spells
`hive-<name>-agent` twice. That is the same problem hive-agent's
swarm_queue module solves, and swarm-logs/src/auth.rs is its `decide`
restated over this binary's inputs.
⚠️ The plan named one thing to verify empirically before calling the auth
settled: whether authelia's bearer policy for the logs vhost accepts the
agent client's audience. Measured from inside a container: it does not.
The client minted a token fine but with `aud: []` and `scp: []`, asking
for the logs URL as an audience answered `invalid_target`, and presenting
the audience-less token to the gateway answered a bare 401. So
swarm-authelia.nix's agentClients gains `authelia.bearer.authz` and the
query URL as a second audience — authelia authorises a bearer token by
the URL being requested, and that URL is now one binding read by three
places rather than three spellings of one address.
The URL reaches an agent the same way its queue coordinates do: computed
on the host (a container cannot derive a gateway address), forwarded by
hive_c0re::meta into the container's option set, and consumed by a new
agent module that installs the binary *wrapped* with its coordinates —
the shape swarm-controller.nix installs swarmctl in. Gated on the queue
credential as well as on the URL: a binary that can only answer 401 is
worse than no binary, because an agent reads a 401 as "no logs", which is
the exact confusion the store's machine route was added to end.
This commit is contained in:
parent
2186b82485
commit
a39399f037
18 changed files with 939 additions and 5 deletions
|
|
@ -23,6 +23,13 @@ let
|
|||
# side can discover the other's spelling, so a rename is a rename there too.
|
||||
secretCredential = "hive-queue-agent-secret";
|
||||
clientIdCredential = "hive-queue-agent-client-id";
|
||||
|
||||
# Where systemd materialises this unit's credentials. `%d` above is the
|
||||
# same directory, but `%d` only expands *inside* a unit — a consumer that
|
||||
# is not one (the `swarm-logs` wrapper, see ./logs.nix) needs the literal,
|
||||
# and deriving it from the unit name here is what keeps the two from
|
||||
# disagreeing about which unit's credentials they mean.
|
||||
credentialsDir = "/run/credentials/hive-agent.service";
|
||||
in
|
||||
{
|
||||
options.hyperhive.queue = {
|
||||
|
|
@ -59,6 +66,38 @@ in
|
|||
"no queue coordinates".
|
||||
'';
|
||||
};
|
||||
|
||||
# One declaration, two readers. The credential ids are this module's —
|
||||
# `hive_c0re::lifecycle::host_config` and the `LoadCredential=` below are
|
||||
# the pair that has to agree on them — and a second consumer that spelled
|
||||
# them again would be a second source of truth for a string whose
|
||||
# mismatch is a file that is simply not there.
|
||||
clientIdFile = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
readOnly = true;
|
||||
default = "${credentialsDir}/${clientIdCredential}";
|
||||
description = ''
|
||||
Path the agent's OIDC client id is delivered at, for a consumer
|
||||
outside the harness unit. Read-only: it is a fact about where the
|
||||
credential lands, not a knob — see {option}`hyperhive.logs.queryUrl`
|
||||
for the consumer this exists for.
|
||||
'';
|
||||
};
|
||||
|
||||
clientSecretFile = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
readOnly = true;
|
||||
default = "${credentialsDir}/${secretCredential}";
|
||||
description = ''
|
||||
Path the agent's OIDC client secret is delivered at. Read-only for
|
||||
the same reason as {option}`hyperhive.queue.clientIdFile`.
|
||||
|
||||
🩸 A PATH and never a value. The file is `0400` to the agent user and
|
||||
is read at the moment of a token request; nothing in this tree puts
|
||||
its contents in an environment variable, where `/proc/<pid>/environ`
|
||||
would publish them to every process in the container.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf configured {
|
||||
|
|
|
|||
Loading…
Reference in a new issue