the log and metrics stores ask every request for a credential the gateway supplies
Each store runs with -httpAuth.* and a credential from the secret store, published to the namespace as a Secret by the host. The gateway's locations send it after auth_request has passed, and the collector's scrape and push take the same one, so a process on the node that bypasses the gateway is refused.
This commit is contained in:
parent
ba0df0ec82
commit
f54aae7927
2 changed files with 808 additions and 72 deletions
|
|
@ -170,7 +170,7 @@ let
|
|||
_: u: (u.environment.BAO_CLIENT_CERT or null) == granterCertFile
|
||||
) baoGrantWithConsumers.systemd.services;
|
||||
|
||||
# The twenty-two units that write a `swarm-*` grant, by name, for the
|
||||
# The twenty-three units that write a `swarm-*` grant, by name, for the
|
||||
# discovery control below.
|
||||
grantingUnitNames = [
|
||||
"swarm-bao-controller-policy"
|
||||
|
|
@ -198,6 +198,7 @@ let
|
|||
"swarm-bao-stt-policy"
|
||||
"swarm-bao-attic-policy"
|
||||
"swarm-bao-archive-policy"
|
||||
"swarm-bao-store-auth-policy"
|
||||
];
|
||||
|
||||
# Comment lines dropped first: both the HCL and the scripts explain
|
||||
|
|
@ -1146,24 +1147,24 @@ let
|
|||
}
|
||||
{
|
||||
# A store host without the granter's pair writes its grants some other
|
||||
# way, so none of the twenty-two units may exist. Without this arm
|
||||
# way, so none of the twenty-three units may exist. Without this arm
|
||||
# `lib.mkIf haveGranter` could be dropped from any of them and every other
|
||||
# case here would still pass.
|
||||
name = "without the granter's pair none of the twenty-two granting units render";
|
||||
name = "without the granter's pair none of the twenty-three granting units render";
|
||||
ok =
|
||||
let
|
||||
s = baoGranterOptOut.systemd.services;
|
||||
in
|
||||
lib.all (unit: !(s ? ${unit})) (grantingUnitNames ++ [ "swarm-bao-granter-role" ])
|
||||
# The control: the same store with the pair renders all twenty-two.
|
||||
# The control: the same store with the pair renders all twenty-three.
|
||||
&& lib.all (unit: baoGrantHere.systemd.services ? ${unit}) grantingUnitNames;
|
||||
}
|
||||
{
|
||||
# 🩸 What replaced the silent skip. With no bootstrap token the twenty-two
|
||||
# 🩸 What replaced the silent skip. With no bootstrap token the twenty-three
|
||||
# still render, and a refused granter fails them with the step that fixes it.
|
||||
# A store host that never named a token is told to name one, since the
|
||||
# unit that sets the granter up renders only where it has.
|
||||
name = "a store host without a bootstrap token renders the twenty-two, each failing loudly with the one-time step";
|
||||
name = "a store host without a bootstrap token renders the twenty-three, each failing loudly with the one-time step";
|
||||
ok =
|
||||
let
|
||||
s = baoGranterNoToken.systemd.services;
|
||||
|
|
@ -2242,6 +2243,38 @@ let
|
|||
in
|
||||
lib.hasInfix "/stt.pem ]" s && lib.hasInfix "swarm-stt \"\" clientAuth" s;
|
||||
}
|
||||
{
|
||||
# Create without update: the first value stored is the one every later
|
||||
# run reads, and no run replaces it. The two leaves are the stores'.
|
||||
name = "the store credential publisher's grant is create and read on the two stores' credentials and nothing else, and the PKI unit signs its leaf";
|
||||
ok =
|
||||
let
|
||||
s = baoGrantHere.systemd.services.swarm-bao-store-auth-policy.script;
|
||||
grants = grantsIn s;
|
||||
pki = baoGrantHere.systemd.services.swarm-bao-pki.script;
|
||||
in
|
||||
(grantFor grants "secret/data/swarm/services/victorialogs/store-auth").caps == [
|
||||
"create"
|
||||
"read"
|
||||
]
|
||||
&&
|
||||
(grantFor grants "secret/data/swarm/services/victoriametrics/store-auth").caps == [
|
||||
"create"
|
||||
"read"
|
||||
]
|
||||
&& lib.length grants == 2
|
||||
&& lib.hasInfix "auth/cert/certs/swarm-store-auth" s
|
||||
&& lib.hasInfix "allowed_common_names=swarm-store-auth" s
|
||||
&& lib.hasInfix "token_policies=swarm-store-auth" s
|
||||
&& lib.hasInfix "/store-auth.pem ]" pki
|
||||
&& lib.hasInfix "swarm-store-auth \"\" clientAuth" pki
|
||||
# Nothing else names either leaf, and the list is not empty for want of
|
||||
# a match: the publisher's own unit is the one it finds.
|
||||
&&
|
||||
lib.filter (
|
||||
u: lib.hasInfix "/store-auth" baoGrantHere.systemd.services.${u}.script
|
||||
) grantingUnitNames == [ "swarm-bao-store-auth-policy" ];
|
||||
}
|
||||
{
|
||||
name = "the PKI unit signs the notification router's leaf under its own subject";
|
||||
ok =
|
||||
|
|
@ -2677,8 +2710,8 @@ let
|
|||
}
|
||||
{
|
||||
# What makes the case above mean something: discovery by the granter's
|
||||
# certificate reaches all twenty-two units, and each yields calls.
|
||||
name = "the granter-policy check sees all twenty-two granting units, and parses calls from each";
|
||||
# certificate reaches all twenty-three units, and each yields calls.
|
||||
name = "the granter-policy check sees all twenty-three granting units, and parses calls from each";
|
||||
ok =
|
||||
lib.sort lib.lessThan (lib.attrNames granterUnits) == lib.sort lib.lessThan grantingUnitNames
|
||||
&& lib.all (u: baoCalls u.script != [ ]) (lib.attrValues granterUnits)
|
||||
|
|
|
|||
|
|
@ -2049,6 +2049,8 @@ let
|
|||
"-storageDataPath=/var/lib/victorialogs"
|
||||
"-httpListenAddr=:9428"
|
||||
"-retentionPeriod=30d"
|
||||
"-httpAuth.username=swarm-store"
|
||||
"-httpAuth.password=file:///run/credentials/victoria-logs.service/store-auth"
|
||||
]
|
||||
&&
|
||||
c.livenessProbe.httpGet == {
|
||||
|
|
@ -2094,10 +2096,26 @@ let
|
|||
&& !(spec ? initContainers)
|
||||
&& !(lib.any (v: v.name == "tls") spec.volumes)
|
||||
&& lib.any (v: v.name == "tls") (podSpec "swarm-controller").volumes
|
||||
# It logs in to nothing, so it has no account, no token and no secret.
|
||||
# It logs in to nothing, so it has no account and no token. Its one
|
||||
# credential is the Secret the host publishes, mounted where the
|
||||
# password flag names it.
|
||||
&& !(spec ? serviceAccountName)
|
||||
&& !(objects ? "swarm-victorialogs/serviceaccount")
|
||||
&& !(lib.any (v: v.name == "bao-token" || v.name == "credentials") spec.volumes)
|
||||
&& !(lib.any (v: v.name == "bao-token") spec.volumes)
|
||||
&&
|
||||
(lib.findFirst (v: v.name == "credentials") null spec.volumes).secret == {
|
||||
secretName = "swarm-victorialogs-credentials";
|
||||
defaultMode = 288;
|
||||
items = [
|
||||
{
|
||||
key = "store-auth";
|
||||
path = "store-auth";
|
||||
}
|
||||
];
|
||||
}
|
||||
&& lib.any (
|
||||
m: m.name == "credentials" && m.mountPath == "/run/credentials/victoria-logs.service" && m.readOnly
|
||||
) c.volumeMounts
|
||||
&& (podSpec "swarm-stt") ? serviceAccountName
|
||||
# Its Service is the only way in, and only the node reaches it.
|
||||
&&
|
||||
|
|
@ -2116,6 +2134,114 @@ let
|
|||
&& lib.elem "d ${dir} - - - -" onCluster.systemd.tmpfiles.rules
|
||||
&& !(lib.any (lib.hasPrefix "d ${dir} ") noNode.systemd.tmpfiles.rules);
|
||||
}
|
||||
{
|
||||
# The credential has three ends that must agree: the unit that creates
|
||||
# it, the file the gateway's store locations include, and the Secret the
|
||||
# pod loads. Each absence arm has a presence control beside it.
|
||||
name = "the stores' listener credentials are created and published by one unit and sent by every location that dials the store, and by no other";
|
||||
ok =
|
||||
let
|
||||
h = allLocal.services.hyperhive;
|
||||
unit = allLocal.systemd.services.swarm-bao-store-auth;
|
||||
rule = store: "f /var/lib/swarm-store-auth/${store}.conf 0600 root root -";
|
||||
# One store's vhost: every location that dials it includes the file,
|
||||
# and no other location does.
|
||||
vhost =
|
||||
{
|
||||
domain,
|
||||
variable,
|
||||
store,
|
||||
}:
|
||||
let
|
||||
locations = allLocal.services.nginx.virtualHosts.${domain}.locations;
|
||||
dialsStore = l: hasInfix variable (l.proxyPass or "");
|
||||
storeLocations = lib.filterAttrs (_: dialsStore) locations;
|
||||
otherLocations = lib.filterAttrs (_: l: !(dialsStore l)) locations;
|
||||
include = "include /var/lib/swarm-store-auth/${store}.conf;";
|
||||
in
|
||||
{
|
||||
inherit storeLocations otherLocations;
|
||||
sent =
|
||||
storeLocations != { }
|
||||
&& lib.all (l: hasInfix include l.extraConfig) (lib.attrValues storeLocations)
|
||||
&& lib.all (l: !(hasInfix "/var/lib/swarm-store-auth" (l.extraConfig or ""))) (
|
||||
lib.attrValues otherLocations
|
||||
);
|
||||
# The credential of the other store is not this one's.
|
||||
notTheOther = lib.all (
|
||||
l:
|
||||
!(hasInfix "/var/lib/swarm-store-auth/${if store == "victorialogs" then "victoriametrics" else "victorialogs"}" l.extraConfig)
|
||||
) (lib.attrValues storeLocations);
|
||||
};
|
||||
logs = vhost {
|
||||
domain = h.swarm.victorialogs.domain;
|
||||
variable = "$swarm_logs_store_upstream";
|
||||
store = "victorialogs";
|
||||
};
|
||||
metrics = vhost {
|
||||
domain = h.swarm.victoriametrics.domain;
|
||||
variable = "$swarm_metrics_store_upstream";
|
||||
store = "victoriametrics";
|
||||
};
|
||||
in
|
||||
# The log store's four: the operator's `/`, the collector's ingest, the
|
||||
# query API and the store's own metrics.
|
||||
lib.attrNames logs.storeLocations == [
|
||||
"/"
|
||||
"= /insert/opentelemetry/v1/logs"
|
||||
"= /metrics"
|
||||
"^~ /select/logsql/"
|
||||
]
|
||||
# The metrics store's: the read API, vmui, the push and its metrics, and
|
||||
# none of its import and admin routes, which have no location at all.
|
||||
&& lib.all (n: metrics.storeLocations ? ${n}) [
|
||||
"= /api/v1/query"
|
||||
"= /api/v1/export"
|
||||
"^~ /api/v1/label/"
|
||||
"= /vmui"
|
||||
"^~ /vmui/"
|
||||
"= /opentelemetry/api/v1/push"
|
||||
"= /metrics"
|
||||
]
|
||||
&& !(lib.any (n: hasInfix "import" n || hasInfix "admin" n || hasInfix "snapshot" n) (
|
||||
lib.attrNames metrics.storeLocations
|
||||
))
|
||||
&& logs.sent
|
||||
&& metrics.sent
|
||||
&& logs.notTheOther
|
||||
&& metrics.notTheOther
|
||||
# The control for the absence arms of `sent`: the responders' and the
|
||||
# identity provider's subrequests exist, are not the store's, and
|
||||
# carry no credential.
|
||||
&& lib.length (lib.attrNames logs.otherLocations) >= 5
|
||||
&& lib.any (n: hasInfix "agent_auth" n) (lib.attrNames logs.otherLocations)
|
||||
&& lib.any (n: hasInfix "agent_auth" n) (lib.attrNames metrics.otherLocations)
|
||||
# The unit creates the leaves the policy names, writes the files those
|
||||
# locations include, and publishes the Secrets the pods load.
|
||||
&& lib.all (store: hasInfix "secret/swarm/services/${store}/store-auth" unit.script) [
|
||||
"victorialogs"
|
||||
"victoriametrics"
|
||||
]
|
||||
&& lib.all (store: hasInfix "/var/lib/swarm-store-auth/${store}.conf" unit.script) [
|
||||
"victorialogs"
|
||||
"victoriametrics"
|
||||
]
|
||||
&& lib.all (store: hasInfix "swarm-${store}-credentials" unit.script) [
|
||||
"victorialogs"
|
||||
"victoriametrics"
|
||||
]
|
||||
&& hasInfix "--from-file=store-auth=/var/lib/swarm-store-auth/victoriametrics.password" unit.script
|
||||
&& unit.environment.BAO_CLIENT_CERT == h.deploy.bao.storeAuthClientCertFile
|
||||
&& hasInfix "store-auth.pem" h.deploy.bao.storeAuthClientCertFile
|
||||
&& lib.elem (rule "victorialogs") allLocal.systemd.tmpfiles.rules
|
||||
&& lib.elem (rule "victoriametrics") allLocal.systemd.tmpfiles.rules
|
||||
# Without either store there is no unit, no file and no location.
|
||||
&& !(noNode.systemd.services ? swarm-bao-store-auth)
|
||||
&& !(lib.elem (rule "victorialogs") noNode.systemd.tmpfiles.rules)
|
||||
&& !(lib.elem (rule "victoriametrics") noNode.systemd.tmpfiles.rules)
|
||||
&& !(noNode.services.nginx.virtualHosts ? ${h.swarm.victorialogs.domain})
|
||||
&& !(noNode.services.nginx.virtualHosts ? ${h.swarm.victoriametrics.domain});
|
||||
}
|
||||
{
|
||||
# The two `auth_request` responders hold no state and log in under one
|
||||
# role, so they are one pod with one account that may run on any node.
|
||||
|
|
@ -2230,6 +2356,8 @@ let
|
|||
"-storageDataPath=/var/lib/victoriametrics"
|
||||
"-httpListenAddr=:8428"
|
||||
"-retentionPeriod=5y"
|
||||
"-httpAuth.username=swarm-store"
|
||||
"-httpAuth.password=file:///run/credentials/victoria-metrics.service/store-auth"
|
||||
]
|
||||
&& c.livenessProbe.httpGet == probe
|
||||
&& c.readinessProbe.httpGet == probe
|
||||
|
|
@ -2273,7 +2401,22 @@ let
|
|||
&& lib.any (v: v.name == "tls") (podSpec "swarm-controller").volumes
|
||||
&& !(spec ? serviceAccountName)
|
||||
&& !(objects ? "swarm-victoriametrics/serviceaccount")
|
||||
&& !(lib.any (v: v.name == "bao-token" || v.name == "credentials") spec.volumes)
|
||||
&& !(lib.any (v: v.name == "bao-token") spec.volumes)
|
||||
&&
|
||||
(lib.findFirst (v: v.name == "credentials") null spec.volumes).secret == {
|
||||
secretName = "swarm-victoriametrics-credentials";
|
||||
defaultMode = 288;
|
||||
items = [
|
||||
{
|
||||
key = "store-auth";
|
||||
path = "store-auth";
|
||||
}
|
||||
];
|
||||
}
|
||||
&& lib.any (
|
||||
m:
|
||||
m.name == "credentials" && m.mountPath == "/run/credentials/victoria-metrics.service" && m.readOnly
|
||||
) c.volumeMounts
|
||||
&& (podSpec "swarm-stt") ? serviceAccountName
|
||||
&&
|
||||
objects."swarm-victoriametrics/service".spec.ports == [
|
||||
|
|
|
|||
Loading…
Reference in a new issue