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
1 changed files with 808 additions and 72 deletions
|
|
@ -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