run grafana as a pod in the cluster
The Deployment swarm-grafana replaces the swarm-grafana container: one replica on a static local volume that is the container's data directory, an init container that fetches the OIDC client secret and creates the administrator password, the datasources' bearer and the encryption key in the secret store, and a sidecar that keeps the controller's Viewer token. The datasources reach the stores through the gateway with that bearer, and Grafana's /metrics asks for the stores' kind of credential, which the vhost sends. The five host units, the journal forwarder, its client glue and the unix-socket directory go with the container.
This commit is contained in:
parent
26ef09b0d7
commit
9f62e71dae
1 changed files with 1938 additions and 1953 deletions
|
|
@ -31,14 +31,6 @@ let
|
|||
deploy.grafana.package = grafanaStub;
|
||||
};
|
||||
|
||||
# A host that tries to move the socket directory; reading the option throws.
|
||||
grafanaSocketDirSet = hive {
|
||||
deploy.grafana.enable = true;
|
||||
deploy.grafana.socketDir = "/run/test-grafana-sock";
|
||||
deploy.grafana.plugins = [ ];
|
||||
deploy.grafana.package = grafanaStub;
|
||||
};
|
||||
|
||||
# Same pairing `nix/module-eval/bao-otel-collector.nix` uses for its own
|
||||
# cases: the store's container with its own collector on, so
|
||||
# `.containers.swarm-bao.config` carries a real, evaluated
|
||||
|
|
@ -104,6 +96,9 @@ let
|
|||
#
|
||||
# Matched on the option name the message names, not on its prose, so the
|
||||
# wording stays rewordable: the option name is the part an operator has to
|
||||
# What a host's Grafana pod is rendered from.
|
||||
rendered = m: m.services.hyperhive.deploy.grafana.rendered;
|
||||
|
||||
# act on, and a message that stopped naming it would be the actual defect.
|
||||
grafanaRefusedFor =
|
||||
m: option:
|
||||
|
|
@ -115,24 +110,34 @@ let
|
|||
) m.assertions;
|
||||
cases = [
|
||||
{
|
||||
# The socket's directory is its access control, so it must stay dedicated
|
||||
# to this one socket. `readOnly` is what makes that inexpressible: a
|
||||
# definition anywhere — here at the `deploy` path — has to fail the eval,
|
||||
# and an unset host has to render the default into nginx's upstream.
|
||||
name = "grafana's socket directory cannot be set and renders its default";
|
||||
# The UI is reached by name, through the gateway, so the vhost dials the
|
||||
# pod's Service and the host binds nothing for it: no socket directory
|
||||
# option, no directory of it. The Service's name is in a variable that
|
||||
# nginx resolves per request.
|
||||
name = "grafana has no socket directory and its vhost dials the pod's Service by name";
|
||||
ok =
|
||||
!(builtins.tryEval grafanaSocketDirSet.services.hyperhive.deploy.grafana.socketDir).success
|
||||
let
|
||||
g = grafanaHere.services.hyperhive.swarm.grafana;
|
||||
locs = grafanaHere.services.nginx.virtualHosts.${g.domain}.locations;
|
||||
in
|
||||
!(grafanaHere.services.hyperhive.deploy.grafana ? socketDir)
|
||||
&& locs."= /metrics".proxyPass == "http://$swarm_grafana_upstream/metrics$is_args$args"
|
||||
&& locs."/".proxyPass == "http://$swarm_grafana_upstream"
|
||||
&&
|
||||
grafanaHere.services.nginx.virtualHosts.${grafanaHere.services.hyperhive.swarm.grafana.domain}.locations."= /metrics".proxyPass
|
||||
== "http://unix:/run/swarm-grafana/grafana.sock:/metrics";
|
||||
lib.hasInfix "set $swarm_grafana_upstream swarm-grafana.hyperhive.svc.cluster.local:3000;"
|
||||
locs."/".extraConfig
|
||||
&& !(lib.any (lib.hasInfix "/run/swarm-grafana") grafanaHere.systemd.tmpfiles.rules);
|
||||
}
|
||||
{
|
||||
# Grafana serves `/metrics` unauthenticated, so the published name gates
|
||||
# it on the collector's auth subrequest: no `error_page 401 =302` (a
|
||||
# scraper would parse a login page as metrics) and no `/__hive_authelia`.
|
||||
# `=` is what catches the normalised variants and still leaves the rest
|
||||
# of Grafana proxied.
|
||||
name = "grafana's published vhost serves /metrics only behind the collector's auth subrequest";
|
||||
# Grafana serves `/metrics` to anyone who reaches the port, so the
|
||||
# published name gates it on the collector's auth subrequest: no
|
||||
# `error_page 401 =302` (a scraper would parse a login page as metrics)
|
||||
# and no `/__hive_authelia`. `=` is what catches the normalised variants
|
||||
# and still leaves the rest of Grafana proxied. After that check the
|
||||
# vhost sends the listener credential the pod's `[metrics]` section asks
|
||||
# for; `/` sends none, because Grafana's own login is the credential
|
||||
# there.
|
||||
name = "grafana's published vhost serves /metrics only behind the collector's auth subrequest, with the pod's credential";
|
||||
ok =
|
||||
let
|
||||
g = grafanaHere.services.hyperhive.swarm.grafana;
|
||||
|
|
@ -144,10 +149,43 @@ let
|
|||
&& locs."= /metrics".return == null
|
||||
&& checksOf locs."= /metrics" == [ "auth_request /__grafana_metrics_authz;" ]
|
||||
&& !(lib.hasInfix "error_page" locs."= /metrics".extraConfig)
|
||||
&& lib.hasInfix "include /var/lib/swarm-store-auth/grafana.conf;" locs."= /metrics".extraConfig
|
||||
&& !(lib.hasInfix "swarm-store-auth" locs."/".extraConfig)
|
||||
&& authz.proxyPass == "https://auth.t.local/api/authz/auth-request"
|
||||
&& lib.hasInfix "internal;" authz.extraConfig
|
||||
&& !(grafanaHere.services.nginx.virtualHosts ? "grafana-metrics")
|
||||
&& lib.hasPrefix "http://unix:" locs."/".proxyPass;
|
||||
&& !(grafanaHere.services.nginx.virtualHosts ? "grafana-metrics");
|
||||
}
|
||||
{
|
||||
# The credential the vhost sends is the one the pod's settings ask for:
|
||||
# the same user name, the password from the Secret's credential, and the
|
||||
# endpoint on. Grafana reads both keys at start (`pkg/setting/setting.go`
|
||||
# in the pinned release), and the pod's login is the only other way in to
|
||||
# `/metrics`.
|
||||
name = "grafana's metrics endpoint asks for the listener credential the vhost sends";
|
||||
ok =
|
||||
let
|
||||
s = (rendered grafanaHere).settings;
|
||||
in
|
||||
s.metrics.enabled
|
||||
&& s.metrics.basic_auth_username == "swarm-store"
|
||||
&& s.metrics.basic_auth_password == "$__file{/run/credentials/swarm-grafana.service/store-auth}"
|
||||
&& lib.elem "store-auth" grafanaHere.services.hyperhive.deploy.grafana.unit.serviceConfig.LoadCredential;
|
||||
}
|
||||
{
|
||||
# The UI and the API are Grafana's own to authenticate: no anonymous
|
||||
# access, a Viewer or otherwise, and the listener is the pod's port on all
|
||||
# its addresses because the Service is what reaches it.
|
||||
name = "grafana takes no anonymous access and listens on the pod's port";
|
||||
ok =
|
||||
let
|
||||
s = (rendered grafanaHere).settings;
|
||||
in
|
||||
!(s ? "auth.anonymous")
|
||||
&& !(s."auth.basic".enabled or true == false)
|
||||
&& s.server.protocol == "http"
|
||||
&& s.server.http_addr == "0.0.0.0"
|
||||
&& s.server.http_port == 3000
|
||||
&& s.server.root_url == "https://grafana.t.local/";
|
||||
}
|
||||
{
|
||||
# This fixture enables grafana and NOT authelia, so the login-form toggle
|
||||
|
|
@ -155,7 +193,7 @@ let
|
|||
# this host". Its vhost is on the public gateway, so a password box there
|
||||
# is a way in whatever the topology.
|
||||
name = "grafana disables its local login form even where authelia is not on this host";
|
||||
ok = grafanaHere.containers.swarm-grafana.config.services.grafana.settings.auth.disable_login_form;
|
||||
ok = (rendered grafanaHere).settings.auth.disable_login_form;
|
||||
}
|
||||
{
|
||||
# The absence class this whole file is for, and the reported defect in one
|
||||
|
|
@ -169,7 +207,7 @@ let
|
|||
name = "grafana's OIDC block names the swarm's IdP, wherever that IdP runs";
|
||||
ok =
|
||||
let
|
||||
oauth = m: m.containers.swarm-grafana.config.services.grafana.settings."auth.generic_oauth";
|
||||
oauth = m: (rendered m).settings."auth.generic_oauth";
|
||||
remote = oauth grafanaRemoteAuthelia;
|
||||
local = oauth grafanaWithAuthelia;
|
||||
in
|
||||
|
|
@ -181,25 +219,28 @@ let
|
|||
}
|
||||
{
|
||||
# 🩸 The arm that guards the ruling this slice landed under. There is ONE
|
||||
# delivery route: the store reader, on every host that runs Grafana. The
|
||||
# negative names the deleted unit rather than a generic absence, because
|
||||
# the way this regresses is someone re-adding the co-located copy as an
|
||||
# optimisation — a second writer of one path, and a second shape of "the
|
||||
# secret is wrong" to debug.
|
||||
name = "grafana's OIDC secret has exactly one delivery unit, the store reader, in both topologies";
|
||||
# delivery route: the pod's init container, with the store, on every host
|
||||
# that runs Grafana. The negatives name the deleted units rather than a
|
||||
# generic absence, because the way this regresses is someone re-adding a
|
||||
# co-located copy as an optimisation — a second writer of one path, and a
|
||||
# second shape of "the secret is wrong" to debug.
|
||||
name = "grafana's OIDC secret has exactly one delivery route, the pod's init container, in both topologies";
|
||||
ok =
|
||||
let
|
||||
local = grafanaWithAuthelia.systemd.services;
|
||||
remote = grafanaRemoteAuthelia.systemd.services;
|
||||
init = m: (rendered m).scripts.fetch;
|
||||
in
|
||||
local ? swarm-bao-grafana-oidc
|
||||
&& remote ? swarm-bao-grafana-oidc
|
||||
lib.hasInfix "secret/swarm/services/swarm-grafana/oidc/client" (init grafanaWithAuthelia)
|
||||
&& lib.hasInfix "secret/swarm/services/swarm-grafana/oidc/client" (init grafanaRemoteAuthelia)
|
||||
&& !(local ? swarm-bao-grafana-oidc)
|
||||
&& !(remote ? swarm-bao-grafana-oidc)
|
||||
&& !(local ? swarm-grafana-oidc-secret)
|
||||
&& !(remote ? swarm-grafana-oidc-secret);
|
||||
}
|
||||
{
|
||||
# What the deleted warning became. The shape is unchanged — a Grafana host
|
||||
# holding no store leaf — but silence there is a container nobody can log
|
||||
# holding no store leaf — but silence there is a pod nobody can log
|
||||
# into for a reason no log names, and a warning is read back by nothing.
|
||||
# The second arm is what makes this a refusal about the IDENTITY: this
|
||||
# fixture names an IdP, so a message about `swarm.authelia.url` here would
|
||||
|
|
@ -232,110 +273,75 @@ let
|
|||
# reset, a database created before the setting keeps `admin`.
|
||||
#
|
||||
# The reset's `--config` must be the file the server reads, or it resets
|
||||
# a different database: compared by store path against the server's own
|
||||
# command line.
|
||||
name = "grafana's admin password is minted into the store and applied to new and existing databases";
|
||||
# a different database: the same store path in both commands.
|
||||
name = "grafana's admin password is created in the store and applied to new and existing databases";
|
||||
ok =
|
||||
let
|
||||
unit = grafanaRemoteAuthelia.systemd.services.swarm-bao-grafana-admin;
|
||||
grafana = grafanaRemoteAuthelia.containers.swarm-grafana.config.services.grafana;
|
||||
service = grafanaRemoteAuthelia.containers.swarm-grafana.config.systemd.services.grafana;
|
||||
resetConfig = lib.head (
|
||||
lib.head (lib.filter lib.isList (builtins.split "--config ([^ ]+)" service.preStart))
|
||||
);
|
||||
r = rendered grafanaRemoteAuthelia;
|
||||
init = r.scripts.fetch;
|
||||
start = r.scripts.start;
|
||||
in
|
||||
lib.hasInfix "bao kv put -cas=0 secret/swarm/services/swarm-grafana/admin/password value=-" unit.script
|
||||
&& lib.hasInfix "openssl rand -hex 32" unit.script
|
||||
&& lib.hasInfix "atomic_write_secret 0400 196:0 /run/swarm-grafana-secrets/admin-password" unit.script
|
||||
&& lib.elem "container@swarm-grafana.service" unit.before
|
||||
&& unit.environment.BAO_CLIENT_CERT == "/etc/pki/bao-grafana-oidc.pem"
|
||||
&& grafana.settings.security.admin_password == "$__file{/run/swarm-grafana-secrets/admin-password}"
|
||||
&& lib.hasInfix "admin reset-admin-password --password-from-stdin < /run/swarm-grafana-secrets/admin-password" service.preStart
|
||||
&& lib.hasInfix "-config ${resetConfig}" service.script;
|
||||
lib.hasInfix "bao kv put -cas=0 \"$1\" value=-" init
|
||||
&& lib.hasInfix "put admin-password \"$(seeded secret/swarm/services/swarm-grafana/admin/password)\"" init
|
||||
&& lib.hasInfix "openssl rand -hex 32" init
|
||||
&& r.settings.security.admin_password == "$__file{/run/grafana-secrets/admin-password}"
|
||||
&& lib.hasInfix "admin reset-admin-password --password-from-stdin < /run/grafana-secrets/admin-password" start
|
||||
&& lib.hasInfix "--config ${r.configFile}" start
|
||||
&& lib.length (lib.splitString "--config ${r.configFile}" start) == 3;
|
||||
}
|
||||
{
|
||||
# Grafana's datasource-encryption key reaches Grafana from the store,
|
||||
# seeded from the file an earlier release generated in the container,
|
||||
# which stays on disk. A different key leaves Grafana unable to read its
|
||||
# stored datasource secrets, so nothing may mint ahead of that seed, and
|
||||
# the superseded in-container generator must be gone: left in place it
|
||||
# would write a second key beside the delivered one. The last two arms
|
||||
# are the presence controls for the absence arms: the guest's `grafana`
|
||||
# unit is found by the same lookup, and the admin password's legacy file
|
||||
# is among the removals.
|
||||
name = "grafana's datasource key is seeded into the store from the earlier file, delivered from /run, and the earlier file is kept";
|
||||
# Grafana's datasource-encryption key reaches Grafana from the store. A
|
||||
# different key leaves Grafana unable to read its stored datasource
|
||||
# secrets, so the store's value wins, `-cas=0` never replaces one, and a
|
||||
# lost race reads the winner's back. No file of an earlier release is
|
||||
# read: a host that never held a stored key gets a new one, and the
|
||||
# provisioned datasources are written again at start.
|
||||
name = "grafana's datasource key is created in the store once and delivered from the pod's memory";
|
||||
ok =
|
||||
let
|
||||
m = grafanaRemoteAuthelia;
|
||||
unit = m.systemd.services.swarm-bao-grafana-secret-key;
|
||||
guest = m.containers.swarm-grafana.config;
|
||||
earlier = "/var/lib/nixos-containers/swarm-grafana/var/lib/grafana-secret/secret_key";
|
||||
r = rendered grafanaRemoteAuthelia;
|
||||
init = r.scripts.fetch;
|
||||
in
|
||||
lib.hasInfix "bao kv put -cas=0 \"\$leaf\" value=-" unit.script
|
||||
&& lib.hasInfix "grafana_secret_key secret/swarm/services/swarm-grafana/secret-key ${earlier} openssl rand -hex 32" unit.script
|
||||
&& lib.length (lib.splitString earlier unit.script) == 2
|
||||
&& lib.hasInfix "atomic_write_secret 0400 196:0 /run/swarm-grafana-secrets/secret-key" unit.script
|
||||
&& lib.elem "container@swarm-grafana.service" unit.before
|
||||
&& unit.environment.BAO_CLIENT_CERT == "/etc/pki/bao-grafana-oidc.pem"
|
||||
&&
|
||||
guest.services.grafana.settings.security.secret_key
|
||||
== "$__file{/run/swarm-grafana-secrets/secret-key}"
|
||||
&& !(guest.systemd.services ? swarm-grafana-secret-key)
|
||||
&& guest.systemd.services ? grafana
|
||||
&& !(lib.any (lib.hasInfix "/var/lib/grafana-secret") m.systemd.tmpfiles.rules)
|
||||
&& lib.any (lib.hasInfix "/var/lib/grafana-admin") m.systemd.tmpfiles.rules
|
||||
&& lib.elem "r /var/lib/nixos-containers/swarm-grafana/var/lib/grafana-admin/password" m.systemd.tmpfiles.rules;
|
||||
lib.hasInfix "put secret-key \"$(seeded secret/swarm/services/swarm-grafana/secret-key)\"" init
|
||||
&& lib.hasInfix "value=\"$(stored \"$1\")\"" init
|
||||
&& r.settings.security.secret_key == "$__file{/run/grafana-secrets/secret-key}"
|
||||
&& !(lib.hasInfix "/var/lib/grafana-secret" init)
|
||||
&& !(lib.any (lib.hasInfix "/var/lib/grafana-secret") grafanaRemoteAuthelia.systemd.tmpfiles.rules);
|
||||
}
|
||||
{
|
||||
# swarm-controller reads alerts with this token, so the account it
|
||||
# belongs to is created and kept a Viewer, the token lands at the path
|
||||
# the controller's grant reads, and an attempt against a Grafana or a
|
||||
# store that never answers ends and retries. The timer re-runs it, so
|
||||
# the unit must not stay active.
|
||||
name = "the controller's Grafana token is a Viewer account's, stored under Grafana's leaf, and each attempt is bounded";
|
||||
# the controller's grant reads, and a call against a Grafana or a store
|
||||
# that never answers ends and is retried on the next pass.
|
||||
name = "the controller's Grafana token is a Viewer account's, stored under Grafana's leaf, and each call is bounded";
|
||||
ok =
|
||||
let
|
||||
unit = grafanaRemoteAuthelia.systemd.services.swarm-bao-grafana-controller-token;
|
||||
s = unit.script;
|
||||
s = (rendered grafanaRemoteAuthelia).scripts.controllerToken;
|
||||
in
|
||||
!(lib.elem (toString (unit.serviceConfig.TimeoutStartSec or "infinity")) [
|
||||
"infinity"
|
||||
"0"
|
||||
])
|
||||
&& lib.hasInfix "curl --silent --show-error --connect-timeout 5 --max-time 15" s
|
||||
lib.hasInfix "curl --silent --show-error --connect-timeout 5 --max-time 15" s
|
||||
&& lib.hasInfix "--data '{\"name\":\"swarm-controller\",\"role\":\"Viewer\",\"isDisabled\":false}'" s
|
||||
&& lib.hasInfix "--data '{\"role\":\"Viewer\",\"isDisabled\":false}'" s
|
||||
&& lib.hasInfix "bao kv put secret/swarm/controller/swarm-controller/grafana/token value=-" s
|
||||
&& lib.hasInfix "--unix-socket /run/swarm-grafana/grafana.sock" s
|
||||
&& unit.environment.BAO_CLIENT_CERT == "/etc/pki/bao-grafana-oidc.pem"
|
||||
&& unit.serviceConfig.Restart == "on-failure"
|
||||
&& !(unit.serviceConfig.RemainAfterExit or false)
|
||||
&& lib.elem "swarm-bao-grafana-admin.service" unit.after
|
||||
&& grafanaRemoteAuthelia.systemd.timers ? swarm-bao-grafana-controller-token;
|
||||
&& lib.hasInfix "base=http://127.0.0.1:3000" s
|
||||
&& !(lib.hasInfix "--unix-socket" s)
|
||||
&& lib.hasInfix "sleep 300" s;
|
||||
}
|
||||
{
|
||||
# The container is ready when the guest's boot finishes, which can be
|
||||
# before Grafana listens, so the unit waits for the socket inside its own
|
||||
# start job, ahead of every call that needs it. The wait is bounded and
|
||||
# sits inside the unit's own timeout, or systemd kills the job first.
|
||||
name = "the controller's Grafana token waits a bounded time for Grafana's socket before its first call";
|
||||
# The pod is ready when its containers start, which can be before Grafana
|
||||
# listens, so the sidecar asks `/api/health` first and sleeps and asks
|
||||
# again when it does not answer. The pass is only called on the answer.
|
||||
name = "the controller's Grafana token sidecar calls Grafana only after /api/health answers";
|
||||
ok =
|
||||
let
|
||||
unit = grafanaRemoteAuthelia.systemd.services.swarm-bao-grafana-controller-token;
|
||||
s = unit.script;
|
||||
parts = lib.splitString "if ! retry_in_job " s;
|
||||
budget = lib.toInt (lib.head (lib.splitString " " (lib.elemAt parts 1)));
|
||||
s = (rendered grafanaRemoteAuthelia).scripts.controllerToken;
|
||||
at = needle: lib.stringLength (lib.head (lib.splitString needle s));
|
||||
loop = lib.last (lib.splitString "while true; do" s);
|
||||
in
|
||||
lib.length parts == 2
|
||||
&& lib.hasInfix "retry_in_job() {" s
|
||||
&& lib.hasInfix "${toString budget} grafana_listening; then" s
|
||||
&& lib.hasInfix "http://localhost/api/health" s
|
||||
&& budget > 0
|
||||
&& budget <= 120
|
||||
&& unit.serviceConfig.TimeoutStartSec == "4min"
|
||||
&& at "retry_in_job ${toString budget} grafana_listening" < at "no Grafana admin password at"
|
||||
&& at "retry_in_job ${toString budget} grafana_listening" < at "status=\"$(grafana \"$admin\" GET";
|
||||
lib.hasInfix "\"$base/api/health\"" loop
|
||||
&& lib.hasInfix "pass || echo" loop
|
||||
&& at "\"$base/api/health\"" > at "while true; do"
|
||||
&& at "pass || echo" > at "\"$base/api/health\""
|
||||
&& lib.hasInfix "sleep 5" loop;
|
||||
}
|
||||
{
|
||||
# Same 403-not-a-miss reason as the matrix and queue arms below: the
|
||||
|
|
@ -346,7 +352,7 @@ let
|
|||
name = "grafana's OIDC secret is read from the prefix the mint writes";
|
||||
ok =
|
||||
let
|
||||
s = grafanaRemoteAuthelia.systemd.services.swarm-bao-grafana-oidc.script;
|
||||
s = (rendered grafanaRemoteAuthelia).scripts.fetch;
|
||||
in
|
||||
lib.hasInfix "secret/swarm/services/swarm-grafana/oidc/client" s
|
||||
&& !(lib.hasInfix "secret/swarm/hives/" s);
|
||||
|
|
@ -354,67 +360,54 @@ let
|
|||
{
|
||||
# Authelia's mint writes the secret a moment after a fresh swarm's first
|
||||
# boot, so a read that finds nothing yet has to fail and be asked again.
|
||||
# A unit that exits 0 there is done until the refresh timer, ten minutes
|
||||
# on, and Grafana has no login in the meantime.
|
||||
name = "grafana's OIDC delivery unit fails on no value yet, so the store retry asks again";
|
||||
# An init container that exits 0 there starts Grafana with no login: the
|
||||
# init fails, and the kubelet starts it again.
|
||||
name = "grafana's init container fails on no OIDC value yet, so the pod starts it again";
|
||||
ok =
|
||||
let
|
||||
u = grafanaRemoteAuthelia.systemd.services.swarm-bao-grafana-oidc;
|
||||
afterRead = lib.last (lib.splitString "bao kv get" u.script);
|
||||
beforeWrite = lib.head (lib.splitString "atomic_write_secret" afterRead);
|
||||
s = (rendered grafanaRemoteAuthelia).scripts.fetch;
|
||||
afterRead = lib.last (lib.splitString "oidc=\"$(stored" s);
|
||||
beforeWrite = lib.head (lib.splitString "put swarm-grafana.secret" afterRead);
|
||||
in
|
||||
# Both arms: the read that returns nothing and the one that returns an
|
||||
# empty value.
|
||||
lib.length (lib.splitString "exit 75" beforeWrite) == 3
|
||||
lib.hasInfix "exit 1" beforeWrite
|
||||
&& !(lib.hasInfix "exit 0" beforeWrite)
|
||||
&& u.serviceConfig.Restart == "on-failure";
|
||||
&& lib.hasInfix "set -euo pipefail" s;
|
||||
}
|
||||
{
|
||||
# A copy on persistent disk outlives the secret's rotation and lands in
|
||||
# backups of the container's root.
|
||||
name = "grafana's OIDC secret, admin password and metrics bearer are written to the host's /run only, and the old copies removed";
|
||||
# backups. The pod writes them to its memory-backed runtime directory,
|
||||
# which the settings name, and the host keeps no copy, no unit and no
|
||||
# directory for them.
|
||||
name = "grafana's OIDC secret, admin password, bearer and key are written to the pod's memory only, and the host has no copy";
|
||||
ok =
|
||||
let
|
||||
m = grafanaRemoteAuthelia;
|
||||
r = rendered m;
|
||||
services = m.systemd.services;
|
||||
mount = m.containers.swarm-grafana.bindMounts."/run/swarm-grafana-secrets";
|
||||
rules = m.systemd.tmpfiles.rules;
|
||||
guest = m.containers.swarm-grafana.config.services.grafana;
|
||||
init = r.scripts.fetch;
|
||||
persistent = s: lib.hasInfix "/var/lib/nixos-containers" s || lib.hasInfix "/var/lib/grafana-" s;
|
||||
oidc = services.swarm-bao-grafana-oidc.script;
|
||||
admin = services.swarm-bao-grafana-admin.script;
|
||||
bearer = services.swarm-bao-grafana-metrics-bearer.script;
|
||||
# The bind source must exist when the store refuses the login, so the
|
||||
# directory is made ahead of it in every delivery script.
|
||||
dirBeforeLogin =
|
||||
s:
|
||||
lib.hasInfix "install -d -m 0755 /run/swarm-grafana-secrets" (
|
||||
lib.head (lib.splitString "bao login -method=cert" s)
|
||||
);
|
||||
in
|
||||
lib.hasInfix "atomic_write_secret 0400 196:0 /run/swarm-grafana-secrets/swarm-grafana.secret" oidc
|
||||
&& lib.hasInfix "atomic_write_secret 0400 196:0 /run/swarm-grafana-secrets/metrics-bearer" bearer
|
||||
&& dirBeforeLogin oidc
|
||||
&& dirBeforeLogin admin
|
||||
&& dirBeforeLogin bearer
|
||||
&& !(persistent oidc)
|
||||
&& !(persistent admin)
|
||||
&& !(persistent bearer)
|
||||
&& !(persistent services.swarm-bao-grafana-controller-token.script)
|
||||
&& lib.hasInfix "< /run/swarm-grafana-secrets/admin-password" services.swarm-bao-grafana-controller-token.script
|
||||
&& mount.hostPath == "/run/swarm-grafana-secrets"
|
||||
&& mount.isReadOnly
|
||||
lib.hasInfix "put swarm-grafana.secret \"$oidc\"" init
|
||||
&& lib.hasInfix "put metrics-bearer \"Bearer $(seeded secret/swarm/services/swarm-grafana/metrics/bearer)\"" init
|
||||
&& lib.hasInfix "umask 0277" init
|
||||
&& lib.hasInfix "d=/run/grafana-secrets" init
|
||||
&& !(persistent init)
|
||||
&& !(persistent r.scripts.controllerToken)
|
||||
&& lib.hasInfix "< /run/grafana-secrets/admin-password" r.scripts.controllerToken
|
||||
&&
|
||||
guest.settings."auth.generic_oauth".client_secret
|
||||
== "$__file{/run/swarm-grafana-secrets/swarm-grafana.secret}"
|
||||
r.settings."auth.generic_oauth".client_secret
|
||||
== "$__file{/run/grafana-secrets/swarm-grafana.secret}"
|
||||
&& lib.any (
|
||||
d: d.secureJsonData.httpHeaderValue1 or null == "$__file{/run/swarm-grafana-secrets/metrics-bearer}"
|
||||
) guest.provision.datasources.settings.datasources
|
||||
&& lib.elem "d /run/swarm-grafana-secrets 0755 root root -" rules
|
||||
&& lib.elem "r /var/lib/nixos-containers/swarm-grafana/var/lib/grafana-oidc/swarm-grafana.secret" rules
|
||||
&& lib.elem "r /var/lib/nixos-containers/swarm-grafana/var/lib/grafana-admin/password" rules
|
||||
&& lib.elem "r /var/lib/nixos-containers/swarm-grafana/var/lib/grafana-metrics/bearer" rules
|
||||
&& !(lib.any (lib.hasPrefix "f /run/swarm-grafana-secrets") rules);
|
||||
d: d.secureJsonData.httpHeaderValue1 or null == "$__file{/run/grafana-secrets/metrics-bearer}"
|
||||
) r.provision.datasources.settings.datasources
|
||||
&& !(services ? swarm-bao-grafana-admin)
|
||||
&& !(services ? swarm-bao-grafana-metrics-bearer)
|
||||
&& !(services ? swarm-bao-grafana-secret-key)
|
||||
&& !(services ? swarm-bao-grafana-controller-token)
|
||||
&& !(m.systemd.timers ? swarm-bao-grafana-controller-token)
|
||||
&& !(lib.any (lib.hasInfix "swarm-grafana-secrets") rules)
|
||||
&& !(m.containers ? swarm-grafana);
|
||||
}
|
||||
{
|
||||
# Both halves of the co-location assumption, which was one host's
|
||||
|
|
@ -440,7 +433,7 @@ let
|
|||
name = "the forge dashboard ships, and its CI runs tab queries the metric names the CI run poller and the controller record";
|
||||
ok =
|
||||
let
|
||||
provider = lib.head grafanaWithAuthelia.containers.swarm-grafana.config.services.grafana.provision.dashboards.settings.providers;
|
||||
provider = lib.head grafanaWithAuthelia.services.hyperhive.deploy.grafana.rendered.provision.dashboards.settings.providers;
|
||||
shipped = lib.attrNames provider.options.path.entries;
|
||||
board = builtins.fromJSON (builtins.readFile ../host-modules/swarm-grafana/dashboards/forge.json);
|
||||
exprs = lib.concatMap (el: map (q: q.spec.query.spec.expr or "") el.spec.data.spec.queries) (
|
||||
|
|
@ -484,7 +477,7 @@ let
|
|||
name = "the review classifier dashboard ships, and queries the metric names the controller and the classifier record";
|
||||
ok =
|
||||
let
|
||||
provider = lib.head grafanaWithAuthelia.containers.swarm-grafana.config.services.grafana.provision.dashboards.settings.providers;
|
||||
provider = lib.head grafanaWithAuthelia.services.hyperhive.deploy.grafana.rendered.provision.dashboards.settings.providers;
|
||||
shipped = lib.attrNames provider.options.path.entries;
|
||||
board = builtins.fromJSON (
|
||||
builtins.readFile ../host-modules/swarm-grafana/dashboards/review-classifier.json
|
||||
|
|
@ -644,7 +637,7 @@ let
|
|||
name = "the builds dashboard ships, and reads the fields hive-c0re logs on a container build";
|
||||
ok =
|
||||
let
|
||||
provider = lib.head grafanaWithAuthelia.containers.swarm-grafana.config.services.grafana.provision.dashboards.settings.providers;
|
||||
provider = lib.head grafanaWithAuthelia.services.hyperhive.deploy.grafana.rendered.provision.dashboards.settings.providers;
|
||||
shipped = lib.attrNames provider.options.path.entries;
|
||||
board = builtins.fromJSON (builtins.readFile ../host-modules/swarm-grafana/dashboards/builds.json);
|
||||
exprs = map (e: (lib.head e.spec.data.spec.queries).spec.query.spec.expr) (
|
||||
|
|
@ -687,7 +680,7 @@ let
|
|||
name = "the host dashboard ships, and every panel query filters on host";
|
||||
ok =
|
||||
let
|
||||
provider = lib.head grafanaWithAuthelia.containers.swarm-grafana.config.services.grafana.provision.dashboards.settings.providers;
|
||||
provider = lib.head grafanaWithAuthelia.services.hyperhive.deploy.grafana.rendered.provision.dashboards.settings.providers;
|
||||
shipped = lib.attrNames provider.options.path.entries;
|
||||
board = builtins.fromJSON (builtins.readFile ../host-modules/swarm-grafana/dashboards/host.json);
|
||||
exprs = lib.concatMap (p: map (t: t.expr) p.targets) board.panels;
|
||||
|
|
@ -708,7 +701,7 @@ let
|
|||
let
|
||||
h = grafanaHere.services.hyperhive;
|
||||
groups =
|
||||
grafanaHere.containers.swarm-grafana.config.services.grafana.provision.alerting.rules.settings.groups;
|
||||
grafanaHere.services.hyperhive.deploy.grafana.rendered.provision.alerting.rules.settings.groups;
|
||||
rules = lib.concatMap (g: g.rules) groups;
|
||||
expr =
|
||||
uid:
|
||||
|
|
@ -751,7 +744,7 @@ let
|
|||
name = "the egress dashboard ships, and reads the field layout of squid's log lines";
|
||||
ok =
|
||||
let
|
||||
provider = lib.head grafanaWithAuthelia.containers.swarm-grafana.config.services.grafana.provision.dashboards.settings.providers;
|
||||
provider = lib.head grafanaWithAuthelia.services.hyperhive.deploy.grafana.rendered.provision.dashboards.settings.providers;
|
||||
shipped = lib.attrNames provider.options.path.entries;
|
||||
board = builtins.fromJSON (builtins.readFile ../host-modules/swarm-grafana/dashboards/egress.json);
|
||||
exprs = map (e: (lib.head e.spec.data.spec.queries).spec.query.spec.expr) (
|
||||
|
|
@ -845,7 +838,7 @@ let
|
|||
ok =
|
||||
let
|
||||
datasources =
|
||||
grafanaWithAuthelia.containers.swarm-grafana.config.services.grafana.provision.datasources.settings.datasources;
|
||||
grafanaWithAuthelia.services.hyperhive.deploy.grafana.rendered.provision.datasources.settings.datasources;
|
||||
metrics = lib.findFirst (d: d.uid == "swarm-victoriametrics") null datasources;
|
||||
logs = lib.findFirst (d: d.uid == "swarm-victorialogs") null datasources;
|
||||
in
|
||||
|
|
@ -862,7 +855,7 @@ let
|
|||
name = "the logs datasource's plugin is handed Grafana's environment";
|
||||
ok =
|
||||
let
|
||||
grafana = grafanaWithAuthelia.containers.swarm-grafana.config.services.grafana;
|
||||
grafana = grafanaWithAuthelia.services.hyperhive.deploy.grafana.rendered;
|
||||
logs = lib.findFirst (
|
||||
d: d.uid == "swarm-victorialogs"
|
||||
) null grafana.provision.datasources.settings.datasources;
|
||||
|
|
@ -888,7 +881,7 @@ let
|
|||
ok =
|
||||
let
|
||||
sources =
|
||||
grafanaHere.containers.swarm-grafana.config.services.grafana.provision.datasources.settings.datasources;
|
||||
grafanaHere.services.hyperhive.deploy.grafana.rendered.provision.datasources.settings.datasources;
|
||||
logs = lib.head (lib.filter (d: d.uid == "swarm-victorialogs") sources);
|
||||
rules = logs.jsonData.logLevelRules or [ ];
|
||||
# `overwrite_text` makes the stored text the OpenTelemetry short name
|
||||
|
|
@ -916,7 +909,7 @@ let
|
|||
ok =
|
||||
let
|
||||
groups =
|
||||
grafanaHere.containers.swarm-grafana.config.services.grafana.provision.alerting.rules.settings.groups;
|
||||
grafanaHere.services.hyperhive.deploy.grafana.rendered.provision.alerting.rules.settings.groups;
|
||||
rules = lib.concatMap (g: g.rules) groups;
|
||||
rule = lib.findFirst (r: r.uid == "hh-agent-turn-failed") null rules;
|
||||
expr = (lib.head rule.data).model.expr;
|
||||
|
|
@ -934,7 +927,7 @@ let
|
|||
ok =
|
||||
let
|
||||
groups =
|
||||
grafanaHere.containers.swarm-grafana.config.services.grafana.provision.alerting.rules.settings.groups;
|
||||
grafanaHere.services.hyperhive.deploy.grafana.rendered.provision.alerting.rules.settings.groups;
|
||||
rules = lib.concatMap (g: g.rules) groups;
|
||||
rule = lib.findFirst (r: r.uid == "hh-review-classifier-run-failed") null rules;
|
||||
expr = (lib.head rule.data).model.expr;
|
||||
|
|
@ -960,7 +953,7 @@ let
|
|||
ok =
|
||||
let
|
||||
groups =
|
||||
grafanaHere.containers.swarm-grafana.config.services.grafana.provision.alerting.rules.settings.groups;
|
||||
grafanaHere.services.hyperhive.deploy.grafana.rendered.provision.alerting.rules.settings.groups;
|
||||
rules = lib.concatMap (g: g.rules) groups;
|
||||
source = builtins.readFile ../../hive-c0re/src/stats/otel_metrics.rs;
|
||||
expected = {
|
||||
|
|
@ -994,7 +987,7 @@ let
|
|||
ok =
|
||||
let
|
||||
groups =
|
||||
grafanaHere.containers.swarm-grafana.config.services.grafana.provision.alerting.rules.settings.groups;
|
||||
grafanaHere.services.hyperhive.deploy.grafana.rendered.provision.alerting.rules.settings.groups;
|
||||
rules = lib.concatMap (g: g.rules) groups;
|
||||
rule = lib.findFirst (r: r.uid == "hh-hive-degraded") null rules;
|
||||
expr = (lib.head rule.data).model.expr;
|
||||
|
|
@ -1016,7 +1009,7 @@ let
|
|||
ok =
|
||||
let
|
||||
groups =
|
||||
grafanaHere.containers.swarm-grafana.config.services.grafana.provision.alerting.rules.settings.groups;
|
||||
grafanaHere.services.hyperhive.deploy.grafana.rendered.provision.alerting.rules.settings.groups;
|
||||
rules = lib.concatMap (g: g.rules) groups;
|
||||
source = builtins.readFile ../../swarm-secret-client/src/cert.rs;
|
||||
threshold =
|
||||
|
|
@ -1052,7 +1045,7 @@ let
|
|||
ok =
|
||||
let
|
||||
groups =
|
||||
grafanaHere.containers.swarm-grafana.config.services.grafana.provision.alerting.rules.settings.groups;
|
||||
grafanaHere.services.hyperhive.deploy.grafana.rendered.provision.alerting.rules.settings.groups;
|
||||
rules = lib.concatMap (g: g.rules) groups;
|
||||
source = builtins.readFile ../../hive-agent/src/otel_turn_metrics.rs;
|
||||
rule = lib.findFirst (r: r.uid == "hh-claude-usage-ahead-of-clock") null rules;
|
||||
|
|
@ -1091,7 +1084,7 @@ let
|
|||
ok =
|
||||
let
|
||||
groups =
|
||||
grafanaHere.containers.swarm-grafana.config.services.grafana.provision.alerting.rules.settings.groups;
|
||||
grafanaHere.services.hyperhive.deploy.grafana.rendered.provision.alerting.rules.settings.groups;
|
||||
rules = lib.concatMap (g: g.rules) groups;
|
||||
source = builtins.readFile ../../hive-c0re/src/stats/otel_metrics.rs;
|
||||
rule = uid: lib.findFirst (r: r.uid == uid) null rules;
|
||||
|
|
@ -1121,7 +1114,7 @@ let
|
|||
ok =
|
||||
let
|
||||
groups =
|
||||
grafanaHere.containers.swarm-grafana.config.services.grafana.provision.alerting.rules.settings.groups;
|
||||
grafanaHere.services.hyperhive.deploy.grafana.rendered.provision.alerting.rules.settings.groups;
|
||||
rules = lib.concatMap (g: g.rules) groups;
|
||||
source = builtins.readFile ../../hive-c0re/src/stats/otel_metrics.rs;
|
||||
rule = uid: lib.findFirst (r: r.uid == uid) null rules;
|
||||
|
|
@ -1151,7 +1144,7 @@ let
|
|||
ok =
|
||||
let
|
||||
groups =
|
||||
grafanaHere.containers.swarm-grafana.config.services.grafana.provision.alerting.rules.settings.groups;
|
||||
grafanaHere.services.hyperhive.deploy.grafana.rendered.provision.alerting.rules.settings.groups;
|
||||
rules = lib.concatMap (g: g.rules) groups;
|
||||
source = builtins.readFile ../../swarm-controller/src/observability/held_deploys.rs;
|
||||
rule = uid: lib.findFirst (r: r.uid == uid) null rules;
|
||||
|
|
|
|||
Loading…
Reference in a new issue