run the log store and its auth responders as pods
swarm-logs-auth and swarm-metrics-auth take --listen for a TCP address beside --socket. The log store is a Deployment on a static local volume that is its old container's data directory, behind a ClusterIP Service the gateway dials by name. Its two auth_request responders are one unpinned pod with a jwt role. The renderer gains a plain HTTP listener, a probe path, fsGroupChangePolicy, and one policy for a pod with both a listener and egress.
This commit is contained in:
parent
62c206169c
commit
dca4720b7b
7 changed files with 1385 additions and 746 deletions
|
|
@ -842,10 +842,10 @@ let
|
|||
lib.hasInfix "/nats-auth.pem ]" s && lib.hasInfix "swarm-nats-auth \"\" clientAuth" s;
|
||||
}
|
||||
{
|
||||
# Every agent's queue secret, Grafana's metrics bearer and the store
|
||||
# container forwarder's client secret, all read-only, and nothing else:
|
||||
# this principal checks a presented secret and does nothing with it.
|
||||
name = "the log store responder's grant is every agent's queue secret and log/metric grant, Grafana's bearer and its container forwarder's client secret, read-only, and nothing else";
|
||||
# Every agent's queue secret and Grafana's metrics bearer, all read-only,
|
||||
# and nothing else: this principal checks a presented secret and does
|
||||
# nothing with it.
|
||||
name = "the log store responder's grant is every agent's queue secret and log/metric grant and Grafana's bearer, read-only, and nothing else";
|
||||
ok =
|
||||
let
|
||||
s = baoGrantHere.systemd.services.swarm-bao-logs-auth-policy.script;
|
||||
|
|
@ -863,10 +863,6 @@ let
|
|||
path = "secret/data/swarm/services/swarm-grafana/metrics/bearer";
|
||||
caps = [ "read" ];
|
||||
}
|
||||
{
|
||||
path = "secret/data/swarm/services/swarm-victorialogs-collector/oidc/client";
|
||||
caps = [ "read" ];
|
||||
}
|
||||
]
|
||||
&& lib.hasInfix "auth/cert/certs/swarm-logs-auth" s
|
||||
&& lib.hasInfix "allowed_common_names=swarm-logs-auth" s
|
||||
|
|
|
|||
|
|
@ -1276,7 +1276,17 @@ let
|
|||
leaf = "swarm/services/${allLocal.services.hyperhive.swarm.grafana.oidc.clientId}/metrics/bearer";
|
||||
in
|
||||
logs.secureJsonData.httpHeaderValue1 == metrics.secureJsonData.httpHeaderValue1
|
||||
&& lib.hasInfix "--store-path ${leaf}" allLocal.systemd.services.swarm-logs-grafana-auth.serviceConfig.ExecStart;
|
||||
&&
|
||||
(lib.findFirst (c: c.name == "grafana-auth") null (
|
||||
allLocal.services.hyperhive.k8s.rendered.services.swarm-logs-auth.objects."swarm-logs-auth/deployment".spec.template.spec.containers
|
||||
)).args == [
|
||||
"--listen"
|
||||
"0.0.0.0:8082"
|
||||
"--store-cert-role"
|
||||
"swarm-logs-auth"
|
||||
"--store-path"
|
||||
leaf
|
||||
];
|
||||
}
|
||||
{
|
||||
# The responder reads the store as itself, with the leaf the store's
|
||||
|
|
@ -1359,10 +1369,11 @@ let
|
|||
let
|
||||
l = allLocal.services.nginx.virtualHosts."logs.t.local".locations;
|
||||
http = allLocal.services.nginx.appendHttpConfig;
|
||||
unit = allLocal.systemd.services.swarm-logs-auth;
|
||||
grafanaUnit = allLocal.systemd.services.swarm-logs-grafana-auth;
|
||||
logs = allLocal.services.hyperhive.deploy.victorialogs;
|
||||
metrics = allLocal.services.hyperhive.deploy.victoriametrics;
|
||||
unit = logs.authUnit;
|
||||
pod =
|
||||
allLocal.services.hyperhive.k8s.rendered.services.swarm-logs-auth.objects."swarm-logs-auth/deployment".spec.template.spec;
|
||||
grafana = lib.findFirst (c: c.name == "grafana-auth") null pod.containers;
|
||||
in
|
||||
lib.hasInfix "map \$http_authorization \$swarm_logs_auth_target" http
|
||||
&& lib.hasInfix "\"~^Bearer swarm-agent\\.\" /__swarm_logs_agent_auth;" http
|
||||
|
|
@ -1371,17 +1382,26 @@ let
|
|||
&& lib.hasInfix "auth_request /__swarm_logs_auth;" l."^~ /select/logsql/".extraConfig
|
||||
&& lib.hasInfix "rewrite ^ \$swarm_logs_auth_target last;" l."= /__swarm_logs_auth".extraConfig
|
||||
&& lib.hasInfix "internal;" l."= /__swarm_logs_agent_auth".extraConfig
|
||||
&& l."= /__swarm_logs_agent_auth".proxyPass == "http://unix:/run/swarm-logs-auth/auth.sock:/"
|
||||
&& lib.hasInfix "--socket /run/swarm-logs-auth/auth.sock" unit.serviceConfig.ExecStart
|
||||
# Each hop dials the Service of its own pod, by the port that pod's
|
||||
# container listens on, and the variable it writes is the one it dials.
|
||||
&& l."= /__swarm_logs_agent_auth".proxyPass == "http://$swarm_logs_agent_auth_upstream/"
|
||||
&&
|
||||
lib.hasInfix "set $swarm_logs_agent_auth_upstream swarm-logs-auth.hyperhive.svc.cluster.local:8081;"
|
||||
l."= /__swarm_logs_agent_auth".extraConfig
|
||||
&& hasStorePath "${logs.authPackage}/bin/swarm-logs-auth " unit.serviceConfig.ExecStart
|
||||
&& lib.hasInfix "--listen 0.0.0.0:8081" unit.serviceConfig.ExecStart
|
||||
&& !(lib.hasInfix "--socket" unit.serviceConfig.ExecStart)
|
||||
&& lib.hasInfix "--surface logs" unit.serviceConfig.ExecStart
|
||||
&& lib.hasInfix "internal;" l."= /__swarm_logs_grafana_auth".extraConfig
|
||||
&& l."= /__swarm_logs_grafana_auth".proxyPass == "http://$swarm_logs_grafana_auth_upstream/"
|
||||
&&
|
||||
l."= /__swarm_logs_grafana_auth".proxyPass == "http://unix:/run/swarm-logs-grafana-auth/auth.sock:/"
|
||||
&& lib.hasInfix "--socket /run/swarm-logs-grafana-auth/auth.sock" grafanaUnit.serviceConfig.ExecStart
|
||||
&& hasStorePath "${logs.grafanaAuthPackage}/bin/swarm-metrics-auth " grafanaUnit.serviceConfig.ExecStart
|
||||
&& !(hasStorePath "${metrics.authPackage}" grafanaUnit.serviceConfig.ExecStart)
|
||||
&& hasStorePath "${logs.authPackage}/bin/swarm-logs-auth " unit.serviceConfig.ExecStart
|
||||
&& lib.hasInfix "--store-cert-role swarm-logs-auth" grafanaUnit.serviceConfig.ExecStart
|
||||
lib.hasInfix
|
||||
"set $swarm_logs_grafana_auth_upstream swarm-logs-grafana-auth.hyperhive.svc.cluster.local:8082;"
|
||||
l."= /__swarm_logs_grafana_auth".extraConfig
|
||||
&& builtins.elem "--listen" grafana.args
|
||||
&& builtins.elem "0.0.0.0:8082" grafana.args
|
||||
&& builtins.elem "swarm-logs-auth" grafana.args
|
||||
&& pod.serviceAccountName == "swarm-logs-auth"
|
||||
&& l ? "= /__hive_authelia";
|
||||
}
|
||||
{
|
||||
|
|
@ -1389,7 +1409,7 @@ let
|
|||
# `/run/private/` (0700 root:root), which nginx cannot traverse, so a
|
||||
# socket there answers every proxied request with a 502. Each `unix:`
|
||||
# upstream under `/run/<dir>/` is matched to the units creating `<dir>`.
|
||||
# The first two clauses are the control: the match finds both responders.
|
||||
# The first clauses are the control: the match finds the metrics store's responders.
|
||||
name = "no unix socket nginx proxies to sits in a DynamicUser's preserved runtime directory";
|
||||
ok =
|
||||
let
|
||||
|
|
@ -1423,9 +1443,7 @@ let
|
|||
"no"
|
||||
]);
|
||||
in
|
||||
owners ? swarm-logs-auth
|
||||
&& owners ? swarm-logs-grafana-auth
|
||||
&& owners ? swarm-metrics-auth
|
||||
owners ? swarm-metrics-auth
|
||||
&& owners ? swarm-metrics-agent-auth
|
||||
&& !(lib.any (u: hidden u.serviceConfig) (lib.attrValues owners));
|
||||
}
|
||||
|
|
@ -1439,8 +1457,8 @@ let
|
|||
let
|
||||
l = allLocal.services.nginx.virtualHosts."logs.t.local".locations;
|
||||
http = allLocal.services.nginx.appendHttpConfig;
|
||||
unit = allLocal.systemd.services.swarm-logs-auth;
|
||||
v = allLocal.services.hyperhive.deploy.victorialogs;
|
||||
unit = v.authUnit;
|
||||
in
|
||||
lib.hasInfix "limit_req_zone $binary_remote_addr zone=swarm_logs_agent_auth:1m rate=${v.authRate};" http
|
||||
&&
|
||||
|
|
@ -1458,12 +1476,14 @@ let
|
|||
ok =
|
||||
let
|
||||
v = allLocal.services.hyperhive.deploy.victorialogs;
|
||||
lc = allLocal.systemd.services.swarm-logs-auth.serviceConfig.LoadCredential;
|
||||
lc = v.authUnit.serviceConfig.LoadCredential;
|
||||
in
|
||||
lib.hasSuffix "/logs-auth.pem" v.authBaoClientCertFile
|
||||
&& lib.hasSuffix "/logs-auth-key.pem" v.authBaoClientKeyFile
|
||||
&& builtins.elem "bao-client.pem:${v.authBaoClientCertFile}" lc
|
||||
&& builtins.elem "bao-client-key.pem:${v.authBaoClientKeyFile}" lc;
|
||||
# The pod's unit names the ids and no host path.
|
||||
&& builtins.elem "bao-client.pem" lc
|
||||
&& builtins.elem "bao-client-key.pem" lc
|
||||
&& !(lib.any (lib.hasInfix ":") lc);
|
||||
}
|
||||
{
|
||||
# The absence arm for the case above, and the option's own rule — a
|
||||
|
|
@ -2471,9 +2491,10 @@ let
|
|||
&& h.deploy.nats.otel.telemetryPort == 8891
|
||||
&& h.deploy.swarm-otel.telemetryPort == 8889
|
||||
&& lib.hasInfix ":7777;" (locs h.swarm.nats.domain)."= /metrics".extraConfig
|
||||
&& (locs h.swarm.victorialogs.domain)."= /metrics".proxyPass == "http://$swarm_logs_store_upstream"
|
||||
&&
|
||||
(locs h.swarm.victorialogs.domain)."= /metrics".proxyPass
|
||||
== "http://unix:/run/swarm-victorialogs/victorialogs.sock:/metrics"
|
||||
lib.hasInfix "set $swarm_logs_store_upstream swarm-victorialogs.hyperhive.svc.cluster.local:9428;"
|
||||
(locs h.swarm.victorialogs.domain)."= /metrics".extraConfig
|
||||
&& (locs h.swarm.forge.domain)."/".proxyPass == "http://unix:/run/hive-forge/forgejo.sock:/"
|
||||
&& !allLocal.containers.hive-matrix.config.services.matrix-tuwunel.settings.global.allow_encryption
|
||||
&& env.SWARM_CONTROLLER_MATRIX_ADMIN_SYNC_IGNORE_USERS == ""
|
||||
|
|
@ -2871,7 +2892,6 @@ let
|
|||
"swarm-builder"
|
||||
"swarm-grafana"
|
||||
"swarm-otel"
|
||||
"swarm-victorialogs"
|
||||
"swarm-victoriametrics"
|
||||
]
|
||||
&& lib.all (carries allLocal) names
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ let
|
|||
deploy.claude-login.enable = false;
|
||||
deploy.swarm-controller.enable = false;
|
||||
deploy.nats.enable = false;
|
||||
deploy.victorialogs.enable = false;
|
||||
}
|
||||
);
|
||||
|
||||
|
|
@ -86,6 +87,10 @@ let
|
|||
lib.tail (lib.splitString "\"image\":\"" clusterText)
|
||||
);
|
||||
occurrences = needle: text: lib.length (lib.splitString needle text) - 1;
|
||||
# `lib.hasInfix` matches `.*needle.*` as a regular expression, which recurses
|
||||
# once per character of the text: on the manifests' JSON, thousands of
|
||||
# characters, it overflows the evaluator's stack. Splitting does not.
|
||||
hasInfix = needle: text: lib.length (lib.splitString needle text) > 1;
|
||||
|
||||
# The node on through one toggle alone, which only its option is read from.
|
||||
oneToggle = hive { deploy.notify-router.enable = true; };
|
||||
|
|
@ -122,7 +127,7 @@ let
|
|||
nodeNoBridge = hive { deploy.k8s.enable = true; };
|
||||
coreDnsKey = "hyperhive-host-services.override";
|
||||
refusals = lib.filter (a: !a.assertion) nodeRefused.assertions;
|
||||
refuses = needle: lib.any (a: lib.hasInfix needle a.message) refusals;
|
||||
refuses = needle: lib.any (a: hasInfix needle a.message) refusals;
|
||||
|
||||
render =
|
||||
config:
|
||||
|
|
@ -307,10 +312,10 @@ let
|
|||
name = "the manifests name each credential by id and never the host path it is loaded from";
|
||||
ok =
|
||||
lib.length credentialSources >= 7
|
||||
&& !(lib.any (s: lib.hasInfix s rendered) credentialSources)
|
||||
&& lib.all (id: lib.hasInfix "\"${id}\"" rendered) (lib.subtractLists clientCertIds credentialIds)
|
||||
&& !(lib.any (s: hasInfix s rendered) credentialSources)
|
||||
&& lib.all (id: hasInfix "\"${id}\"" rendered) (lib.subtractLists clientCertIds credentialIds)
|
||||
# The units load the client certificates and the pods do not.
|
||||
&& lib.all (id: lib.elem id credentialIds && !(lib.hasInfix "\"${id}\"" rendered)) clientCertIds
|
||||
&& lib.all (id: lib.elem id credentialIds && !(hasInfix "\"${id}\"" rendered)) clientCertIds
|
||||
&& !(lib.any (o: o.kind == "Secret") (lib.attrValues objects))
|
||||
&& secretLookupWorks
|
||||
&& !(lib.any usesSecret (podSpec "swarm-controller").volumes);
|
||||
|
|
@ -360,28 +365,29 @@ let
|
|||
let
|
||||
start = withNode.systemd.services.k3s.serviceConfig.ExecStart;
|
||||
in
|
||||
lib.hasInfix "--disable=traefik" start
|
||||
&& lib.hasInfix "--disable=metrics-server" start
|
||||
&& lib.hasInfix "--secrets-encryption" start
|
||||
&& lib.hasInfix "--cluster-cidr=10.200.0.0/16" start
|
||||
&& lib.hasInfix "--service-cidr=10.201.0.0/16" start
|
||||
&& !(lib.hasInfix "--disable=coredns" start)
|
||||
&& !(lib.hasInfix "--disable=local-storage" start);
|
||||
hasInfix "--disable=traefik" start
|
||||
&& hasInfix "--disable=metrics-server" start
|
||||
&& hasInfix "--secrets-encryption" start
|
||||
&& hasInfix "--cluster-cidr=10.200.0.0/16" start
|
||||
&& hasInfix "--service-cidr=10.201.0.0/16" start
|
||||
&& !(hasInfix "--disable=coredns" start)
|
||||
&& !(hasInfix "--disable=local-storage" start);
|
||||
}
|
||||
{
|
||||
# The images are the ones the manifests run, one per rendered service, the
|
||||
# controller's listener leaf, the queue's three more (server, exporter,
|
||||
# init): the eleven are the control that the list is not empty.
|
||||
# init), the log store's and its two responders': the fourteen are the
|
||||
# control that the list is not empty.
|
||||
name = "the node loads the image of every service the manifests run, and k3s's own";
|
||||
ok =
|
||||
let
|
||||
loaded = map toString withNode.services.k3s.images;
|
||||
rendered = map toString withNode.system.build.k8sImages;
|
||||
in
|
||||
lib.length rendered == 11
|
||||
lib.length rendered == 14
|
||||
&& lib.all (i: lib.elem i loaded) rendered
|
||||
&& lib.elem (toString withNode.services.k3s.package.airgap-images) loaded
|
||||
&& lib.length loaded == 12;
|
||||
&& lib.length loaded == 15;
|
||||
}
|
||||
{
|
||||
# The all-local host's assertions are the control: they all hold.
|
||||
|
|
@ -417,13 +423,13 @@ let
|
|||
&& cm.metadata.namespace == "kube-system"
|
||||
&& lib.length names >= 6
|
||||
&& lib.elem h.swarm.bao.domain names
|
||||
&& lib.all (n: lib.hasInfix (builtins.replaceStrings [ "." ] [ "[.]" ] n) text) names
|
||||
&& lib.hasInfix "template IN A {" text
|
||||
&& lib.hasInfix "template IN AAAA {" text
|
||||
&& lib.hasInfix "answer \"{{ .Name }} 60 IN A ${h.network.bridgeIp}\"" text
|
||||
&& lib.hasInfix " fallthrough\n}\n" text
|
||||
&& !(lib.hasInfix "127.0.0.1" text)
|
||||
&& !(lib.hasInfix "hosts" text)
|
||||
&& lib.all (n: hasInfix (builtins.replaceStrings [ "." ] [ "[.]" ] n) text) names
|
||||
&& hasInfix "template IN A {" text
|
||||
&& hasInfix "template IN AAAA {" text
|
||||
&& hasInfix "answer \"{{ .Name }} 60 IN A ${h.network.bridgeIp}\"" text
|
||||
&& hasInfix " fallthrough\n}\n" text
|
||||
&& !(hasInfix "127.0.0.1" text)
|
||||
&& !(hasInfix "hosts" text)
|
||||
&& lib.attrNames h.deploy.k8s.hostServices == lib.sort lib.lessThan names
|
||||
&& lib.all (s: s.address == h.network.bridgeIp) (lib.attrValues h.deploy.k8s.hostServices);
|
||||
}
|
||||
|
|
@ -466,14 +472,14 @@ let
|
|||
&& units.swarm-ci-metrics.environment.SWARM_CI_METRICS_OTLP_ENDPOINT == ownRoute
|
||||
&& (envOf "swarm-ci-metrics").SWARM_CI_METRICS_OTLP_ENDPOINT == ownRoute
|
||||
&& !((envOf "swarm-ci-metrics") ? OTEL_EXPORTER_OTLP_ENDPOINT)
|
||||
&& !(lib.any (e: lib.hasInfix "hive-collector" (e.value or "")) (container "swarm-ci-metrics").env)
|
||||
&& !(lib.any (e: hasInfix "hive-collector" (e.value or "")) (container "swarm-ci-metrics").env)
|
||||
&& !(envOf "swarm-notify-router" ? SWARM_CI_METRICS_OTLP_ENDPOINT)
|
||||
&& units.swarm-controller.environment.OTEL_EXPORTER_OTLP_ENDPOINT == controllerRoute
|
||||
&& (envOf "swarm-controller").OTEL_EXPORTER_OTLP_ENDPOINT == controllerRoute
|
||||
&&
|
||||
(envOf "swarm-controller").SWARM_CONTROLLER_OTEL_AUDIENCE
|
||||
== units.swarm-controller.environment.SWARM_CONTROLLER_OTEL_AUDIENCE
|
||||
&& !(lib.any (e: lib.hasInfix "hive-collector" (e.value or "")) (container "swarm-controller").env);
|
||||
&& !(lib.any (e: hasInfix "hive-collector" (e.value or "")) (container "swarm-controller").env);
|
||||
}
|
||||
{
|
||||
# The unchanged host is the control that the render itself succeeds.
|
||||
|
|
@ -503,7 +509,7 @@ let
|
|||
};
|
||||
};
|
||||
unit = c: c.systemd.services.opentelemetry-collector.serviceConfig;
|
||||
collectorAcls = c: lib.filter (lib.hasInfix "u:opentelemetry-collector:") c.systemd.tmpfiles.rules;
|
||||
collectorAcls = c: lib.filter (hasInfix "u:opentelemetry-collector:") c.systemd.tmpfiles.rules;
|
||||
in
|
||||
!((settings noNode).receivers ? "file_log/pods")
|
||||
&& !((settings noNode).service.pipelines ? "logs/pods")
|
||||
|
|
@ -533,13 +539,13 @@ let
|
|||
statements = lib.concatMap (
|
||||
l: l.statements
|
||||
) s.processors."transform/pod-service-name".log_statements;
|
||||
acls = lib.filter (lib.hasInfix "u:opentelemetry-collector:") withNode.systemd.tmpfiles.rules;
|
||||
acls = lib.filter (hasInfix "u:opentelemetry-collector:") withNode.systemd.tmpfiles.rules;
|
||||
in
|
||||
r.include == [ "/var/log/pods/*/*/*.log" ]
|
||||
&& r.include_file_path
|
||||
&& r.storage == "file_storage"
|
||||
&& (lib.head ops).type == "container"
|
||||
&& lib.all (l: lib.hasInfix l (op "regex_parser").regex) [
|
||||
&& lib.all (l: hasInfix l (op "regex_parser").regex) [
|
||||
"WARN"
|
||||
"ERROR"
|
||||
"INFO"
|
||||
|
|
@ -612,8 +618,9 @@ let
|
|||
allRoles = map lib.head (
|
||||
lib.filter lib.isList (builtins.split "auth/jwt-k8s/role/([a-z-]+)" script)
|
||||
);
|
||||
# The queue's two roles share one account: a case of their own.
|
||||
roles = lib.filter (r: !(lib.hasPrefix "swarm-nats" r)) allRoles;
|
||||
# The queue's two roles share one account, and the log store's
|
||||
# responders hold one role of their own: a case each.
|
||||
roles = lib.filter (r: !(lib.hasPrefix "swarm-nats" r) && r != "swarm-logs-auth") allRoles;
|
||||
ttl = "token_ttl=1h \\\n token_max_ttl=1h";
|
||||
roleText = name: ''
|
||||
bao write auth/jwt-k8s/role/${name} \
|
||||
|
|
@ -632,13 +639,13 @@ let
|
|||
== lib.sort lib.lessThan allRoles
|
||||
&& lib.all (
|
||||
name:
|
||||
lib.hasInfix (lib.removeSuffix "\n" (roleText name)) script
|
||||
&& lib.hasInfix "auth/cert/certs/${name}" certScript.${name}
|
||||
&& lib.hasInfix "token_policies=${name}" certScript.${name}
|
||||
&& lib.hasInfix "token_ttl=1h" certScript.${name}
|
||||
&& lib.hasInfix "token_max_ttl=1h" certScript.${name}
|
||||
hasInfix (lib.removeSuffix "\n" (roleText name)) script
|
||||
&& hasInfix "auth/cert/certs/${name}" certScript.${name}
|
||||
&& hasInfix "token_policies=${name}" certScript.${name}
|
||||
&& hasInfix "token_ttl=1h" certScript.${name}
|
||||
&& hasInfix "token_max_ttl=1h" certScript.${name}
|
||||
) roles
|
||||
&& lib.hasInfix "bao write auth/jwt-k8s/config -" script;
|
||||
&& hasInfix "bao write auth/jwt-k8s/config -" script;
|
||||
}
|
||||
{
|
||||
# The two roles are the leaf's and the responder's, each with its cert
|
||||
|
|
@ -658,11 +665,11 @@ let
|
|||
token_policies=${name} \
|
||||
'';
|
||||
in
|
||||
lib.hasInfix (role "swarm-nats") script
|
||||
&& lib.hasInfix (role "swarm-nats-auth") script
|
||||
&& lib.hasInfix "token_type=batch" s.swarm-bao-nats-auth-policy.script
|
||||
&& lib.hasInfix "auth/cert/certs/swarm-nats " s.swarm-bao-nats-tls-policy.script
|
||||
&& lib.hasInfix "auth/cert/certs/swarm-nats-auth" s.swarm-bao-nats-auth-policy.script
|
||||
hasInfix (role "swarm-nats") script
|
||||
&& hasInfix (role "swarm-nats-auth") script
|
||||
&& hasInfix "token_type=batch" s.swarm-bao-nats-auth-policy.script
|
||||
&& hasInfix "auth/cert/certs/swarm-nats " s.swarm-bao-nats-tls-policy.script
|
||||
&& hasInfix "auth/cert/certs/swarm-nats-auth" s.swarm-bao-nats-auth-policy.script
|
||||
&& lib.elem "swarm-nats" withNode.services.hyperhive.deploy.bao.k8sPrincipals
|
||||
&& lib.elem "swarm-nats-auth" withNode.services.hyperhive.deploy.bao.k8sPrincipals
|
||||
# The account the pod renders under is the one both roles bind.
|
||||
|
|
@ -678,14 +685,14 @@ let
|
|||
u = withNode.systemd.services.swarm-bao-k8s-jwt-policy;
|
||||
start = withNode.systemd.services.k3s.serviceConfig.ExecStart;
|
||||
in
|
||||
lib.hasInfix "/var/lib/rancher/k3s/server/tls/service.key" u.script
|
||||
&& lib.hasInfix "/var/lib/rancher/k3s/server/tls/service.current.key" u.script
|
||||
&& lib.hasInfix "openssl pkey -in \"$block\" -pubout" u.script
|
||||
&& lib.hasInfix "jwt_validation_pubkeys" u.script
|
||||
&& lib.hasInfix "https://kubernetes.default.svc.cluster.local" u.script
|
||||
&& lib.hasInfix "\"RS256\", \"ES256\"" u.script
|
||||
&& lib.hasInfix "--data-dir=/var/lib/rancher/k3s" start
|
||||
&& lib.hasInfix "--cluster-domain=cluster.local" start
|
||||
hasInfix "/var/lib/rancher/k3s/server/tls/service.key" u.script
|
||||
&& hasInfix "/var/lib/rancher/k3s/server/tls/service.current.key" u.script
|
||||
&& hasInfix "openssl pkey -in \"$block\" -pubout" u.script
|
||||
&& hasInfix "jwt_validation_pubkeys" u.script
|
||||
&& hasInfix "https://kubernetes.default.svc.cluster.local" u.script
|
||||
&& hasInfix "\"RS256\", \"ES256\"" u.script
|
||||
&& hasInfix "--data-dir=/var/lib/rancher/k3s" start
|
||||
&& hasInfix "--cluster-domain=cluster.local" start
|
||||
&& lib.elem "k3s.service" u.after
|
||||
&& lib.elem "k3s.service" u.wants;
|
||||
}
|
||||
|
|
@ -698,12 +705,12 @@ let
|
|||
g = withNode.systemd.services.swarm-bao-granter-role;
|
||||
hcl = builtins.readFile ../host-modules/bao-bootstrap-policy.hcl;
|
||||
in
|
||||
lib.hasInfix "bao auth enable -path=jwt-k8s jwt" g.script
|
||||
&& lib.hasInfix "path \"auth/jwt-k8s/config\" {\n capabilities = [\"create\", \"update\"]\n}" g.script
|
||||
&& lib.hasInfix "path \"auth/jwt-k8s/role/swarm-*\" {\n capabilities = [\"create\", \"update\"]\n}" g.script
|
||||
&& lib.hasInfix "path \"sys/auth/jwt-k8s\" {\n capabilities = [\"create\", \"update\", \"sudo\"]\n}" hcl
|
||||
&& !(lib.hasInfix "sys/auth/jwt-k8s" g.script)
|
||||
&& lib.hasInfix "swarm-bao-k8s-jwt-policy.service" g.serviceConfig.ExecStartPost;
|
||||
hasInfix "bao auth enable -path=jwt-k8s jwt" g.script
|
||||
&& hasInfix "path \"auth/jwt-k8s/config\" {\n capabilities = [\"create\", \"update\"]\n}" g.script
|
||||
&& hasInfix "path \"auth/jwt-k8s/role/swarm-*\" {\n capabilities = [\"create\", \"update\"]\n}" g.script
|
||||
&& hasInfix "path \"sys/auth/jwt-k8s\" {\n capabilities = [\"create\", \"update\", \"sudo\"]\n}" hcl
|
||||
&& !(hasInfix "sys/auth/jwt-k8s" g.script)
|
||||
&& hasInfix "swarm-bao-k8s-jwt-policy.service" g.serviceConfig.ExecStartPost;
|
||||
}
|
||||
{
|
||||
# The host with the node on is the control that each lookup finds what
|
||||
|
|
@ -716,14 +723,14 @@ let
|
|||
in
|
||||
(baoSettings withNode).listener ? pod
|
||||
&& withNode.systemd.services ? swarm-bao-k8s-jwt-policy
|
||||
&& lib.hasInfix "jwt-k8s" on.script
|
||||
&& lib.hasInfix "swarm-bao-k8s-jwt-policy" on.serviceConfig.ExecStartPost
|
||||
&& hasInfix "jwt-k8s" on.script
|
||||
&& hasInfix "swarm-bao-k8s-jwt-policy" on.serviceConfig.ExecStartPost
|
||||
&& withNode.networking.firewall.interfaces ? cni0
|
||||
&& !((baoSettings noNode).listener ? pod)
|
||||
&& !(noNode.systemd.services ? swarm-bao-k8s-jwt-policy)
|
||||
&& !(lib.hasInfix "jwt-k8s" off.script)
|
||||
&& !(lib.hasInfix "swarm-bao-k8s-jwt-policy" off.serviceConfig.ExecStartPost)
|
||||
&& lib.hasInfix "swarm-bao-operator-viewer-policy" off.serviceConfig.ExecStartPost
|
||||
&& !(hasInfix "jwt-k8s" off.script)
|
||||
&& !(hasInfix "swarm-bao-k8s-jwt-policy" off.serviceConfig.ExecStartPost)
|
||||
&& hasInfix "swarm-bao-operator-viewer-policy" off.serviceConfig.ExecStartPost
|
||||
&& !(noNode.networking.firewall.interfaces ? cni0)
|
||||
&& !(noNode.networking.firewall.interfaces ? "flannel.1");
|
||||
}
|
||||
|
|
@ -789,6 +796,16 @@ let
|
|||
&& !(onCluster.systemd.services ? "container@swarm-claude-login")
|
||||
&& !(onCluster.containers ? swarm-nats)
|
||||
&& !(onCluster.systemd.services ? "container-nats")
|
||||
# The log store and its responders: no container, no unit, no socket
|
||||
# directory. The metrics store beside it is the control that the lookups
|
||||
# find what a host still runs.
|
||||
&& !(onCluster.containers ? swarm-victorialogs)
|
||||
&& !(onCluster.systemd.services ? "container@swarm-victorialogs")
|
||||
&& !(onCluster.systemd.services ? swarm-logs-auth)
|
||||
&& !(onCluster.systemd.services ? swarm-logs-grafana-auth)
|
||||
&& !(lib.any (lib.hasPrefix "d /run/swarm-victorialogs ") onCluster.systemd.tmpfiles.rules)
|
||||
&& onCluster.containers ? swarm-victoriametrics
|
||||
&& onCluster.systemd.services ? swarm-metrics-auth
|
||||
&&
|
||||
manifestNames onCluster == [
|
||||
"coredns-custom"
|
||||
|
|
@ -796,10 +813,12 @@ let
|
|||
"swarm-ci-metrics"
|
||||
"swarm-claude-login"
|
||||
"swarm-controller"
|
||||
"swarm-logs-auth"
|
||||
"swarm-nats"
|
||||
"swarm-notify-router"
|
||||
"swarm-review-classifier"
|
||||
"swarm-stt"
|
||||
"swarm-victorialogs"
|
||||
]
|
||||
&& onCluster.services.k3s.manifests.hyperhive-namespace.content.kind == "Namespace"
|
||||
&&
|
||||
|
|
@ -821,6 +840,24 @@ let
|
|||
"PersistentVolume"
|
||||
"PersistentVolumeClaim"
|
||||
"ServiceAccount"
|
||||
]
|
||||
&&
|
||||
lib.sort lib.lessThan (map (o: o.kind) onCluster.services.k3s.manifests.swarm-logs-auth.content)
|
||||
== [
|
||||
"Deployment"
|
||||
"NetworkPolicy"
|
||||
"Service"
|
||||
"Service"
|
||||
"ServiceAccount"
|
||||
]
|
||||
&&
|
||||
lib.sort lib.lessThan (map (o: o.kind) onCluster.services.k3s.manifests.swarm-victorialogs.content)
|
||||
== [
|
||||
"Deployment"
|
||||
"NetworkPolicy"
|
||||
"PersistentVolume"
|
||||
"PersistentVolumeClaim"
|
||||
"Service"
|
||||
];
|
||||
}
|
||||
{
|
||||
|
|
@ -850,10 +887,10 @@ let
|
|||
]
|
||||
&& !(lib.any (v: v ? secret) volumes)
|
||||
&& secretLookupWorks
|
||||
&& lib.hasInfix "--from-file=bao-server-ca.pem=${serverCa}" caUnit.script
|
||||
&& lib.hasInfix "--from-file=hive-client-ca.pem=" caUnit.script
|
||||
&& lib.hasInfix "--from-file=swarm-services-root.pem=" caUnit.script
|
||||
&& lib.hasInfix "--from-file=trust-bundle.pem=" caUnit.script
|
||||
&& hasInfix "--from-file=bao-server-ca.pem=${serverCa}" caUnit.script
|
||||
&& hasInfix "--from-file=hive-client-ca.pem=" caUnit.script
|
||||
&& hasInfix "--from-file=swarm-services-root.pem=" caUnit.script
|
||||
&& hasInfix "--from-file=trust-bundle.pem=" caUnit.script
|
||||
&& lib.elem "multi-user.target" caUnit.wantedBy
|
||||
# A change to either file publishes again with no manual step, and the
|
||||
# host without the node has no path unit.
|
||||
|
|
@ -917,8 +954,8 @@ let
|
|||
memory = "0";
|
||||
cpu = "0";
|
||||
}
|
||||
&& !(lib.hasInfix "TasksMax" rendered)
|
||||
&& !(lib.hasInfix "SystemCallFilter" rendered)
|
||||
&& !(hasInfix "TasksMax" rendered)
|
||||
&& !(hasInfix "SystemCallFilter" rendered)
|
||||
&& lib.all (name: !((container name) ? resources)) [
|
||||
"swarm-controller"
|
||||
"swarm-notify-router"
|
||||
|
|
@ -1000,14 +1037,17 @@ let
|
|||
ports = [ (tcp 4222) ];
|
||||
}
|
||||
]
|
||||
# Only the controller (its listener), the queue and this pod have a policy:
|
||||
# the others have no egress and no listener.
|
||||
# Only the controller (its listener), the log store and its responders
|
||||
# (listeners), the queue and this pod have a policy: the others have no
|
||||
# egress and no listener.
|
||||
&&
|
||||
lib.sort lib.lessThan (lib.filter (n: lib.hasSuffix "/networkpolicy" n) (lib.attrNames objects))
|
||||
== [
|
||||
"swarm-controller/networkpolicy"
|
||||
"swarm-logs-auth/networkpolicy"
|
||||
"swarm-nats/networkpolicy"
|
||||
"swarm-stt/networkpolicy"
|
||||
"swarm-victorialogs/networkpolicy"
|
||||
];
|
||||
}
|
||||
{
|
||||
|
|
@ -1202,13 +1242,13 @@ let
|
|||
}
|
||||
'';
|
||||
in
|
||||
lib.hasInfix (lib.removeSuffix "\n" writes) login
|
||||
&& !(lib.hasInfix "claude-credentials" classifier)
|
||||
&& lib.hasInfix "anthropic-api-key" classifier
|
||||
&& lib.hasInfix "token_policies=swarm-claude-login " jwt
|
||||
&& lib.hasInfix "bound_subject=system:serviceaccount:hyperhive:swarm-claude-login" jwt
|
||||
&& lib.hasInfix "bound_subject=system:serviceaccount:hyperhive:swarm-review-classifier" jwt
|
||||
&& lib.hasInfix "token_policies=swarm-claude-login " login;
|
||||
hasInfix (lib.removeSuffix "\n" writes) login
|
||||
&& !(hasInfix "claude-credentials" classifier)
|
||||
&& hasInfix "anthropic-api-key" classifier
|
||||
&& hasInfix "token_policies=swarm-claude-login " jwt
|
||||
&& hasInfix "bound_subject=system:serviceaccount:hyperhive:swarm-claude-login" jwt
|
||||
&& hasInfix "bound_subject=system:serviceaccount:hyperhive:swarm-review-classifier" jwt
|
||||
&& hasInfix "token_policies=swarm-claude-login " login;
|
||||
}
|
||||
{
|
||||
# `swarmctl setup status` reads this file to tell that the root-only
|
||||
|
|
@ -1228,9 +1268,9 @@ let
|
|||
in
|
||||
lib.length touched == 2
|
||||
&& lib.length cleared == 2
|
||||
&& lib.hasInfix "rm -f ${marker}" (lib.elemAt touched 1)
|
||||
&& lib.hasInfix "exit 0" between
|
||||
&& lib.hasInfix "bao write auth/jwt-k8s/config" (lib.elemAt cleared 1);
|
||||
&& hasInfix "rm -f ${marker}" (lib.elemAt touched 1)
|
||||
&& hasInfix "exit 0" between
|
||||
&& hasInfix "bao write auth/jwt-k8s/config" (lib.elemAt cleared 1);
|
||||
}
|
||||
{
|
||||
# The poller's one credential in the pod is the store's public CA, from
|
||||
|
|
@ -1263,7 +1303,7 @@ let
|
|||
e: e.name == "BAO_CACERT" && e.value == "/run/credentials/swarm-ci-metrics.service/bao-ca.pem"
|
||||
) (lib.head spec.containers).env
|
||||
&& lib.all (v: lib.all (e: e.name != v) (lib.head spec.containers).env) clientVars
|
||||
&& !(lib.hasInfix "swarm-ci-metrics-credentials" rendered);
|
||||
&& !(hasInfix "swarm-ci-metrics-credentials" rendered);
|
||||
}
|
||||
{
|
||||
# The host with the controller on it is the control for every absence
|
||||
|
|
@ -1329,7 +1369,7 @@ let
|
|||
loc = c: path: c.services.nginx.virtualHosts."t.local".locations.${path};
|
||||
dials =
|
||||
c: path: needle:
|
||||
lib.hasInfix needle (loc c path).extraConfig;
|
||||
hasInfix needle (loc c path).extraConfig;
|
||||
verified =
|
||||
c: path:
|
||||
dials c path "proxy_ssl_name controller.t.local;"
|
||||
|
|
@ -1410,10 +1450,10 @@ let
|
|||
servicesRoot = "${onCluster.services.hyperhive.deploy.hive-controller.tls.stateDir}/swarm-services-root.pem";
|
||||
mountPath = x: (lib.findFirst (m: m.name == "tls") null x.volumeMounts).mountPath;
|
||||
in
|
||||
!(lib.hasInfix "install -d" podScript)
|
||||
&& !(lib.hasInfix "chgrp" podScript)
|
||||
&& lib.hasInfix "-checkhost \"$name\"" podScript
|
||||
&& lib.hasInfix "issue/swarm-controller-tls" podScript
|
||||
!(hasInfix "install -d" podScript)
|
||||
&& !(hasInfix "chgrp" podScript)
|
||||
&& hasInfix "-checkhost \"$name\"" podScript
|
||||
&& hasInfix "issue/swarm-controller-tls" podScript
|
||||
&& map (c: c.name) spec.initContainers == [ "tls-issue" ]
|
||||
&& init.name == "tls-issue"
|
||||
&& renew.name == "tls-renew"
|
||||
|
|
@ -1540,7 +1580,7 @@ let
|
|||
# The per-agent subjects keep their `$`: a pod's arguments are not
|
||||
# unescaped by systemd.
|
||||
&& lib.elem "$SWARM.term.{agent}" (named "swarm-nats").args
|
||||
&& !(lib.any (a: lib.hasInfix "$$" a) (named "swarm-nats").args)
|
||||
&& !(lib.any (a: hasInfix "$$" a) (named "swarm-nats").args)
|
||||
# The leaf's key is in memory; the store is a claim; nothing is capped.
|
||||
&& (volume "nats-tls").emptyDir.medium == "Memory"
|
||||
&& !((volume "tmp").emptyDir ? medium)
|
||||
|
|
@ -1617,7 +1657,7 @@ let
|
|||
&& !(objects ? "swarm-stt/persistentvolumeclaim")
|
||||
&& (stateVolume "swarm-ci-metrics").persistentVolumeClaim.claimName == "swarm-ci-metrics-store"
|
||||
&& objects ? "swarm-ci-metrics/persistentvolumeclaim"
|
||||
&& !(lib.any (n: lib.hasInfix "state-gate" n) (map toString withNode.system.build.k8sImages))
|
||||
&& !(lib.any (n: hasInfix "state-gate" n) (map toString withNode.system.build.k8sImages))
|
||||
&& objects ? "swarm-nats/persistentvolumeclaim";
|
||||
}
|
||||
{
|
||||
|
|
@ -1633,14 +1673,14 @@ let
|
|||
&& !(onCluster.systemd.services ? "container@swarm-nats")
|
||||
&& !(onCluster.systemd.services ? swarm-nats-auth-secrets)
|
||||
&& !(onCluster.systemd.services ? swarm-bao-nats-callout-xkey)
|
||||
&& !(lib.hasInfix "nixos-fw-nats" noNode.networking.firewall.extraCommands)
|
||||
&& lib.hasInfix "nixos-fw-nats" onCluster.networking.firewall.extraCommands
|
||||
&& !(hasInfix "nixos-fw-nats" noNode.networking.firewall.extraCommands)
|
||||
&& hasInfix "nixos-fw-nats" onCluster.networking.firewall.extraCommands
|
||||
&& !(lib.elem "container@swarm-nats.service" tls.before)
|
||||
&& !(lib.elem "container@swarm-nats.service" tls.wantedBy)
|
||||
&& onCluster.systemd.services ? swarm-nats-gateway-cert
|
||||
&& vhost onCluster == "http://\$swarm_nats_metrics_upstream/metrics"
|
||||
&& lib.hasInfix "resolver 10.42.0.1 valid=10s ipv6=off;" (extra onCluster)
|
||||
&& lib.hasInfix "set \$swarm_nats_metrics_upstream swarm-nats-metrics.hyperhive.svc.cluster.local:7777;" (
|
||||
&& hasInfix "resolver 10.42.0.1 valid=10s ipv6=off;" (extra onCluster)
|
||||
&& hasInfix "set \$swarm_nats_metrics_upstream swarm-nats-metrics.hyperhive.svc.cluster.local:7777;" (
|
||||
extra onCluster
|
||||
)
|
||||
&& onCluster.services.hyperhive.network.enable;
|
||||
|
|
@ -1704,7 +1744,7 @@ let
|
|||
};
|
||||
closed = rules (args // { openClient = false; });
|
||||
open = rules (args // { openClient = true; });
|
||||
has = lib.hasInfix;
|
||||
has = hasInfix;
|
||||
in
|
||||
has "-p tcp --dport 4222 -i br0 -j RETURN" closed
|
||||
&& has "-p tcp --dport 4222 -i cni0 -j RETURN" closed
|
||||
|
|
@ -1773,14 +1813,14 @@ let
|
|||
)
|
||||
)
|
||||
);
|
||||
idx = c: pat: lib.lists.findFirstIndex (lib.hasInfix pat) 1000 (rules c);
|
||||
idx = c: pat: lib.lists.findFirstIndex (hasInfix pat) 1000 (rules c);
|
||||
br = onCluster.services.hyperhive.network.bridgeName;
|
||||
published = ''iifname "${br}" oifname != "${br}" meta nfproto ipv4 meta l4proto tcp ct status dnat ct original ip daddr 10.42.0.1 ct original proto-dst { 4222 } accept'';
|
||||
in
|
||||
onCluster.services.hyperhive.deploy.hive-controller.egress.publishedPorts == [ 4222 ]
|
||||
&& noNode.services.hyperhive.deploy.hive-controller.egress.publishedPorts == [ ]
|
||||
&& lib.elem published (rules onCluster)
|
||||
&& !(lib.any (lib.hasInfix "ct original") (rules noNode))
|
||||
&& !(lib.any (hasInfix "ct original") (rules noNode))
|
||||
# After the named SSH connections and before the counter and the log:
|
||||
# a published flow is neither counted nor logged.
|
||||
&& idx onCluster "@agent_allow accept" < idx onCluster "ct original"
|
||||
|
|
@ -1864,12 +1904,187 @@ let
|
|||
&& ns."pod-security.kubernetes.io/warn" == "restricted"
|
||||
&& ns."pod-security.kubernetes.io/audit" == "restricted"
|
||||
&& ns."app.kubernetes.io/part-of" == "hyperhive"
|
||||
&& lib.length specs == 7
|
||||
&& lib.length specs == 9
|
||||
&& lib.all (s: problems s == [ ]) specs
|
||||
&& problems withHostPort != [ ]
|
||||
&& problems withCaps != [ ]
|
||||
&& problems withoutSeccomp != [ ];
|
||||
}
|
||||
{
|
||||
# The data is the container's own directory, so an upgrade moves the
|
||||
# process and not the bytes. Every arm has a control: the sibling pod
|
||||
# that has no volume, no selector or no ServiceAccount, and a pod that
|
||||
# has none of the settings only this one carries.
|
||||
name = "the log store's pod is the daemon on a static local volume that is its old container's data directory, with no store identity";
|
||||
ok =
|
||||
let
|
||||
spec = podSpec "swarm-victorialogs";
|
||||
c = container "swarm-victorialogs";
|
||||
dir = "/var/lib/nixos-containers/swarm-victorialogs/var/lib/victorialogs";
|
||||
pv = objects."swarm-victorialogs/persistentvolume";
|
||||
pvc = objects."swarm-victorialogs/persistentvolumeclaim";
|
||||
dep = objects."swarm-victorialogs/deployment".spec;
|
||||
label = "hyperhive.darkest.space/state-victorialogs";
|
||||
in
|
||||
c.args == [
|
||||
"-storageDataPath=/var/lib/victorialogs"
|
||||
"-httpListenAddr=:9428"
|
||||
"-retentionPeriod=30d"
|
||||
]
|
||||
&&
|
||||
c.livenessProbe.httpGet == {
|
||||
path = "/health";
|
||||
port = "api";
|
||||
}
|
||||
&& c.readinessProbe.httpGet.path == "/health"
|
||||
&&
|
||||
c.ports == [
|
||||
{
|
||||
name = "api";
|
||||
containerPort = 9428;
|
||||
}
|
||||
]
|
||||
&& dep.replicas == 1
|
||||
&& dep.strategy.type == "Recreate"
|
||||
&& pv.spec.local.path == dir
|
||||
&& pv.spec.persistentVolumeReclaimPolicy == "Retain"
|
||||
&& pvc.spec.volumeName == pv.metadata.name
|
||||
&& pvc.spec.storageClassName == pv.spec.storageClassName
|
||||
&&
|
||||
pv.spec.nodeAffinity.required.nodeSelectorTerms == [
|
||||
{
|
||||
matchExpressions = [
|
||||
{
|
||||
key = label;
|
||||
operator = "In";
|
||||
values = [ "true" ];
|
||||
}
|
||||
];
|
||||
}
|
||||
]
|
||||
&& spec.nodeSelector == { ${label} = "true"; }
|
||||
&&
|
||||
(lib.findFirst (v: v.name == "state") null spec.volumes).persistentVolumeClaim.claimName
|
||||
== pvc.metadata.name
|
||||
# The first start gives the pod's group the old tree; later ones look at
|
||||
# the root only. No other pod sets it.
|
||||
&& spec.securityContext.fsGroupChangePolicy == "OnRootMismatch"
|
||||
&& !((podSpec "swarm-nats").securityContext ? fsGroupChangePolicy)
|
||||
# Plain HTTP: no leaf, no init container, no in-memory volume. The
|
||||
# controller's pod is the control that those exist where a leaf does.
|
||||
&& !(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.
|
||||
&& !(spec ? serviceAccountName)
|
||||
&& !(objects ? "swarm-victorialogs/serviceaccount")
|
||||
&& !(lib.any (v: v.name == "bao-token" || v.name == "credentials") spec.volumes)
|
||||
&& (podSpec "swarm-stt") ? serviceAccountName
|
||||
# Its Service is the only way in, and only the node reaches it.
|
||||
&&
|
||||
objects."swarm-victorialogs/service".spec.ports == [
|
||||
{
|
||||
name = "api";
|
||||
protocol = "TCP";
|
||||
port = 9428;
|
||||
targetPort = "api";
|
||||
}
|
||||
]
|
||||
&& objects."swarm-victorialogs/networkpolicy".spec.policyTypes == [ "Ingress" ]
|
||||
&& !(objects."swarm-victorialogs/networkpolicy".spec ? ingress)
|
||||
# The directory is made on a host that never ran the container, and an
|
||||
# existing one is left as it is.
|
||||
&& lib.elem "d ${dir} - - - -" onCluster.systemd.tmpfiles.rules
|
||||
&& !(lib.any (lib.hasPrefix "d ${dir} ") noNode.systemd.tmpfiles.rules);
|
||||
}
|
||||
{
|
||||
# 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.
|
||||
name = "the log store's responders are one unpinned pod under one account, reached by the node alone, with the store and DNS as its only way out";
|
||||
ok =
|
||||
let
|
||||
spec = podSpec "swarm-logs-auth";
|
||||
named = n: lib.findFirst (c: c.name == n) null spec.containers;
|
||||
logs = named "swarm-logs-auth";
|
||||
grafana = named "grafana-auth";
|
||||
policy = objects."swarm-logs-auth/networkpolicy".spec;
|
||||
s = withNode.systemd.services;
|
||||
script = s.swarm-bao-k8s-jwt-policy.script;
|
||||
podLabels = {
|
||||
"app.kubernetes.io/name" = "swarm-logs-auth";
|
||||
"app.kubernetes.io/part-of" = "hyperhive";
|
||||
};
|
||||
service = n: objects.${n}.spec;
|
||||
in
|
||||
map (c: c.name) spec.containers == [
|
||||
"swarm-logs-auth"
|
||||
"grafana-auth"
|
||||
]
|
||||
&&
|
||||
logs.args == [
|
||||
"--listen"
|
||||
"0.0.0.0:8081"
|
||||
"--store-cert-role"
|
||||
"swarm-logs-auth"
|
||||
"--surface"
|
||||
"logs"
|
||||
"--verdict-ttl"
|
||||
"60"
|
||||
]
|
||||
&& lib.elem "0.0.0.0:8082" grafana.args
|
||||
&& !(lib.elem "--socket" (logs.args ++ grafana.args))
|
||||
# Each container logs in with the pod's token, on the same role.
|
||||
&&
|
||||
(lib.listToAttrs (map (e: lib.nameValuePair e.name e.value) logs.env)).BAO_JWT_ROLE
|
||||
== "swarm-logs-auth"
|
||||
&&
|
||||
(lib.listToAttrs (map (e: lib.nameValuePair e.name e.value) grafana.env)).BAO_JWT_ROLE
|
||||
== "swarm-logs-auth"
|
||||
&& !(lib.any (e: lib.hasPrefix "BAO_CLIENT" e.name) (logs.env ++ grafana.env))
|
||||
&& grafana.livenessProbe.httpGet.port == "health"
|
||||
&& spec.serviceAccountName == "swarm-logs-auth"
|
||||
&& objects."swarm-logs-auth/serviceaccount".metadata.name == "swarm-logs-auth"
|
||||
&& hasInfix "bound_subject=system:serviceaccount:hyperhive:swarm-logs-auth" script
|
||||
&& hasInfix "auth/jwt-k8s/role/swarm-logs-auth" script
|
||||
&& hasInfix "token_type=batch" s.swarm-bao-logs-auth-policy.script
|
||||
&& lib.elem "swarm-logs-auth" withNode.services.hyperhive.deploy.bao.k8sPrincipals
|
||||
# No state label: the store's pod is pinned, this one is not.
|
||||
&& !(spec ? nodeSelector)
|
||||
&& (podSpec "swarm-victorialogs") ? nodeSelector
|
||||
# One Service per responder, on the pod's labels.
|
||||
&& (service "swarm-logs-auth/service").selector == podLabels
|
||||
&&
|
||||
(service "swarm-logs-auth/service").ports == [
|
||||
{
|
||||
name = "api";
|
||||
protocol = "TCP";
|
||||
port = 8081;
|
||||
targetPort = "api";
|
||||
}
|
||||
]
|
||||
&& (service "swarm-logs-grafana-auth/service").selector == podLabels
|
||||
&& (lib.head (service "swarm-logs-grafana-auth/service").ports).port == 8082
|
||||
# One policy: nothing in but the node, and out to DNS and the store's pod
|
||||
# listener alone. The sibling's policy has no egress.
|
||||
&&
|
||||
policy.policyTypes == [
|
||||
"Ingress"
|
||||
"Egress"
|
||||
]
|
||||
&& !(policy ? ingress)
|
||||
&& lib.length policy.egress == 2
|
||||
&&
|
||||
(lib.elemAt policy.egress 1).ports == [
|
||||
{
|
||||
protocol = "TCP";
|
||||
port = 8208;
|
||||
}
|
||||
]
|
||||
&& !(objects."swarm-victorialogs/networkpolicy".spec ? egress)
|
||||
# No leaf: nothing here serves TLS.
|
||||
&& !(spec ? initContainers)
|
||||
&& !(lib.any (v: v.name == "tls") spec.volumes);
|
||||
}
|
||||
{
|
||||
# The host without the node is the control: it labels nothing.
|
||||
name = "the node labels itself as the entry node, and with a state label for each service whose data the cluster keeps";
|
||||
|
|
@ -1886,6 +2101,7 @@ let
|
|||
++ [
|
||||
"hyperhive.darkest.space/state-nats=true"
|
||||
"hyperhive.darkest.space/state-ci-metrics=true"
|
||||
"hyperhive.darkest.space/state-victorialogs=true"
|
||||
]
|
||||
)
|
||||
&&
|
||||
|
|
@ -1894,6 +2110,7 @@ let
|
|||
"svccontroller.k3s.cattle.io/enablelb" = "true";
|
||||
"hyperhive.darkest.space/state-nats" = "true";
|
||||
"hyperhive.darkest.space/state-ci-metrics" = "true";
|
||||
"hyperhive.darkest.space/state-victorialogs" = "true";
|
||||
}
|
||||
&& noNode.services.k3s.nodeLabel == [ ];
|
||||
}
|
||||
|
|
@ -1934,8 +2151,8 @@ let
|
|||
&& !(podSpec "swarm-controller" ? nodeSelector)
|
||||
&& !(podSpec "swarm-stt" ? nodeSelector)
|
||||
&& (podSpec "swarm-nats").nodeSelector == { "hyperhive.darkest.space/state-nats" = "true"; }
|
||||
&& lib.hasInfix "nodeAffinity" text
|
||||
&& !(lib.hasInfix "kubernetes.io/hostname" text)
|
||||
&& hasInfix "nodeAffinity" text
|
||||
&& !(hasInfix "kubernetes.io/hostname" text)
|
||||
&& lib.elem rule onCluster.systemd.tmpfiles.rules
|
||||
&& !(lib.elem rule noNode.systemd.tmpfiles.rules);
|
||||
}
|
||||
|
|
@ -1957,8 +2174,8 @@ let
|
|||
lib.all (a: a.assertion) withNode.assertions
|
||||
&& lib.any (
|
||||
a:
|
||||
lib.hasInfix "services.hyperhive.deploy.k8s.enable is false" a.message
|
||||
&& lib.all (n: lib.hasInfix "deploy.${n}.enable" a.message) [
|
||||
hasInfix "services.hyperhive.deploy.k8s.enable is false" a.message
|
||||
&& lib.all (n: hasInfix "deploy.${n}.enable" a.message) [
|
||||
"notify-router"
|
||||
"stt"
|
||||
"ci-metrics"
|
||||
|
|
@ -1975,7 +2192,7 @@ let
|
|||
name = "the controller's TLS listener is on and named from the swarm domain with nothing set, and an explicit value that can't work is refused naming it";
|
||||
ok =
|
||||
let
|
||||
refusesWith = needle: lib.any (a: lib.hasInfix needle a.message) nodeOffRefusals;
|
||||
refusesWith = needle: lib.any (a: hasInfix needle a.message) nodeOffRefusals;
|
||||
in
|
||||
oneToggle.services.hyperhive.swarm.controller.tcp.enable
|
||||
&& oneToggle.services.hyperhive.swarm.controller.tcp.domain == "controller.t.local"
|
||||
|
|
@ -1988,7 +2205,7 @@ let
|
|||
&& refusesWith "services.hyperhive.gateway.dns.enable"
|
||||
# The same assertion holds on the all-local host: the control that the
|
||||
# needle finds it.
|
||||
&& lib.any (a: a.assertion && lib.hasInfix "tcp.listenAddress" a.message) withNode.assertions;
|
||||
&& lib.any (a: a.assertion && hasInfix "tcp.listenAddress" a.message) withNode.assertions;
|
||||
}
|
||||
{
|
||||
# The registry host is spelled out here, so the module is not compared
|
||||
|
|
@ -2001,7 +2218,7 @@ let
|
|||
in
|
||||
registries == "mirrors:\n registry.hyperhive.invalid:\n"
|
||||
&& nodeNoBridge.environment.etc."rancher/k3s/registries.yaml".text == registries
|
||||
&& !(lib.hasInfix "*" registries)
|
||||
&& !(hasInfix "*" registries)
|
||||
&& lib.elem "--embedded-registry" onCluster.services.k3s.extraFlags
|
||||
&& lib.elem "--embedded-registry" nodeNoBridge.services.k3s.extraFlags
|
||||
&& onCluster.services.k3s.nodeIP == "192.168.1.10"
|
||||
|
|
@ -2025,13 +2242,13 @@ let
|
|||
(rule address "udp" "8472")
|
||||
(rule address "tcp" "5001")
|
||||
];
|
||||
nodeLines = lib.filter (l: lib.hasInfix "--dport" l && lib.hasInfix "nixos-fw -s" l) (
|
||||
nodeLines = lib.filter (l: hasInfix "--dport" l && hasInfix "nixos-fw -s" l) (
|
||||
lib.splitString "\n" rules
|
||||
);
|
||||
in
|
||||
lib.all (r: lib.hasInfix r rules) (forNodes "192.168.1.11" ++ forNodes "192.168.1.12")
|
||||
lib.all (r: hasInfix r rules) (forNodes "192.168.1.11" ++ forNodes "192.168.1.12")
|
||||
&& lib.length nodeLines == 8
|
||||
&& !(lib.hasInfix "--dport 6443" nodeNoBridge.networking.firewall.extraCommands)
|
||||
&& !(hasInfix "--dport 6443" nodeNoBridge.networking.firewall.extraCommands)
|
||||
&& !(lib.elem 6443 onCluster.networking.firewall.allowedTCPPorts)
|
||||
&& !(lib.elem 8472 onCluster.networking.firewall.allowedUDPPorts);
|
||||
}
|
||||
|
|
@ -2051,11 +2268,11 @@ let
|
|||
&&
|
||||
joined.environment.etc."rancher/k3s/registries.yaml".text
|
||||
== onCluster.environment.etc."rancher/k3s/registries.yaml".text
|
||||
&& lib.hasInfix "iptables -A nixos-fw -s 192.168.1.10 -p tcp --dport 6443 -j nixos-fw-accept" joined.networking.firewall.extraCommands
|
||||
&& hasInfix "iptables -A nixos-fw -s 192.168.1.10 -p tcp --dport 6443 -j nixos-fw-accept" joined.networking.firewall.extraCommands
|
||||
&& joinedUnit.before == [ "k3s.service" ]
|
||||
&& joinedUnit.wantedBy == [ "k3s.service" ]
|
||||
&& lib.hasInfix "secret/swarm/services/k8s/agent-token" joinedUnit.script
|
||||
&& lib.hasInfix "/run/k3s-join/token" joinedUnit.script
|
||||
&& hasInfix "secret/swarm/services/k8s/agent-token" joinedUnit.script
|
||||
&& hasInfix "/run/k3s-join/token" joinedUnit.script
|
||||
&& !(joined.systemd.services ? k3s-join-token-publish)
|
||||
&& withNode.systemd.services ? k3s-join-token-publish
|
||||
&& !(withNode.systemd.services ? k3s-join-token)
|
||||
|
|
@ -2074,7 +2291,7 @@ let
|
|||
};
|
||||
noIdentity = hive { deploy.k8s.join.server = "192.168.1.10"; };
|
||||
messages = c: map (a: a.message) (lib.filter (a: !a.assertion) c.assertions);
|
||||
mentions = needle: c: lib.any (lib.hasInfix needle) (messages c);
|
||||
mentions = needle: c: lib.any (hasInfix needle) (messages c);
|
||||
in
|
||||
mentions "k8s.join as a node of another" both
|
||||
&& mentions "baoHiveIdentityCertFile" noIdentity
|
||||
|
|
@ -2108,10 +2325,10 @@ let
|
|||
lib.length imageRefs >= 8
|
||||
&& lib.all (r: lib.hasPrefix registryPrefix r) imageRefs
|
||||
&& lib.any (r: lib.hasSuffix "-server" (lib.head (lib.splitString ":" r))) imageRefs
|
||||
&& lib.any (r: lib.hasInfix "-tls:" r) imageRefs
|
||||
&& lib.any (r: hasInfix "-tls:" r) imageRefs
|
||||
&& occurrences "\"imagePullPolicy\":\"IfNotPresent\"" clusterText >= 8
|
||||
&& !(lib.hasInfix "\"imagePullPolicy\":\"Never\"" clusterText)
|
||||
&& !(lib.hasInfix "docker.io" clusterText);
|
||||
&& !(hasInfix "\"imagePullPolicy\":\"Never\"" clusterText)
|
||||
&& !(hasInfix "docker.io" clusterText);
|
||||
}
|
||||
];
|
||||
in
|
||||
|
|
|
|||
|
|
@ -180,10 +180,6 @@ let
|
|||
machine = "swarm-grafana";
|
||||
option = "grafana";
|
||||
}
|
||||
{
|
||||
machine = "swarm-victorialogs";
|
||||
option = "victorialogs";
|
||||
}
|
||||
{
|
||||
machine = "hive-forge";
|
||||
option = "forge";
|
||||
|
|
@ -209,14 +205,6 @@ let
|
|||
key = "grafana-bao-key";
|
||||
port = 8896;
|
||||
}
|
||||
{
|
||||
machine = "swarm-victorialogs";
|
||||
option = "victorialogs";
|
||||
name = "victorialogs";
|
||||
cert = "bao-client.pem";
|
||||
key = "bao-client-key.pem";
|
||||
port = 8897;
|
||||
}
|
||||
{
|
||||
machine = "hive-forge";
|
||||
option = "forge";
|
||||
|
|
|
|||
|
|
@ -229,7 +229,6 @@ let
|
|||
[
|
||||
"swarm-ci-runner-collector"
|
||||
"swarm-grafana-collector"
|
||||
"swarm-victorialogs-collector"
|
||||
"swarm-forge-collector"
|
||||
"swarm-matrix-collector"
|
||||
"swarm-victoriametrics-collector"
|
||||
|
|
|
|||
|
|
@ -511,7 +511,7 @@ let
|
|||
in
|
||||
h.deploy.victorialogs.enable
|
||||
&& locs ? "= /metrics"
|
||||
&& locs."= /metrics".proxyPass == "http://unix:/run/swarm-victorialogs/victorialogs.sock:/metrics"
|
||||
&& locs."= /metrics".proxyPass == "http://$swarm_logs_store_upstream"
|
||||
&& checksOf locs."= /metrics" == [ "auth_request /__hive_authelia;" ]
|
||||
&& !(lib.hasInfix "error_page" locs."= /metrics".extraConfig)
|
||||
&& lib.hasInfix "error_page 401 =302" locs."/".extraConfig
|
||||
|
|
|
|||
|
|
@ -203,7 +203,6 @@ let
|
|||
"swarm-ci-runner"
|
||||
"swarm-grafana"
|
||||
"swarm-otel"
|
||||
"swarm-victorialogs"
|
||||
"swarm-victoriametrics"
|
||||
];
|
||||
|
||||
|
|
@ -265,7 +264,6 @@ let
|
|||
"grafana.service"
|
||||
"opentelemetry-collector.service"
|
||||
"tuwunel.service"
|
||||
"victorialogs.service"
|
||||
"victoriametrics.service"
|
||||
];
|
||||
}
|
||||
|
|
@ -772,7 +770,6 @@ let
|
|||
"swarm-authelia"
|
||||
"swarm-bao"
|
||||
"swarm-grafana"
|
||||
"swarm-victorialogs"
|
||||
"swarm-victoriametrics"
|
||||
"swarm-otel"
|
||||
"hive-matrix"
|
||||
|
|
@ -821,7 +818,7 @@ let
|
|||
# that lost a container can't pass by comparing fewer of them.
|
||||
name = "every service container restates its host-side privateNetwork";
|
||||
ok =
|
||||
lib.length (lib.attrNames serviceContainers) == 11
|
||||
lib.length (lib.attrNames serviceContainers) == 10
|
||||
&& lib.all (
|
||||
c: c.privateNetwork == (c.config.services.hyperhive.swarmContainer.privateNetwork or null)
|
||||
) (lib.attrValues serviceContainers);
|
||||
|
|
@ -1016,50 +1013,6 @@ let
|
|||
&& bridge.serviceConfig.Group == "gateway-nginx"
|
||||
&& lib.elem dir unit.serviceConfig.ReadWritePaths;
|
||||
}
|
||||
{
|
||||
# On the bridge by DHCP, listening on a socket only the gateway's group can
|
||||
# reach, so the store binds no host port. Every location that forwards to
|
||||
# it goes through the socket (the authelia subrequests are the `https://`
|
||||
# upstream); the read, ingest, scrape and catch-all locations are named so
|
||||
# an empty filter can't pass, and the old loopback port is named nowhere.
|
||||
name = "the log store runs on a netns of its own and the gateway reaches it over its socket";
|
||||
ok =
|
||||
let
|
||||
host = serviceContainersWithCi;
|
||||
net = host.services.hyperhive.network;
|
||||
c = host.containers.swarm-victorialogs;
|
||||
dir = "/run/swarm-victorialogs";
|
||||
sock = "${dir}/victorialogs.sock";
|
||||
viaSock = path: "http://unix:${sock}:${path}";
|
||||
locs =
|
||||
host.services.nginx.virtualHosts.${host.services.hyperhive.swarm.victorialogs.domain}.locations;
|
||||
toStore = lib.filter (
|
||||
p: p != null && !(lib.hasPrefix "https://" p) && !(lib.hasPrefix "http://unix:/run/swarm-logs" p)
|
||||
) (map (l: l.proxyPass) (lib.attrValues locs));
|
||||
unit = c.config.systemd.services.victorialogs;
|
||||
nginxGid = host.ids.gids.nginx;
|
||||
in
|
||||
c.privateNetwork
|
||||
&& c.hostBridge == net.bridgeName
|
||||
&& c.hostAddress == null
|
||||
&& c.localAddress == null
|
||||
&& c.config.networking.interfaces.eth0.useDHCP
|
||||
&& c.config.services.victorialogs.listenAddress == "unix:${sock}"
|
||||
&& locs."/".proxyPass == viaSock "/"
|
||||
&& locs."= /insert/opentelemetry/v1/logs".proxyPass == viaSock "/insert/opentelemetry/v1/logs"
|
||||
&& locs."^~ /select/logsql/".proxyPass == "http://unix:${sock}"
|
||||
&& locs."= /metrics".proxyPass == viaSock "/metrics"
|
||||
&& toStore != [ ]
|
||||
&& lib.all (lib.hasPrefix "http://unix:${sock}") toStore
|
||||
&& !(lib.any (lib.hasInfix "127.0.0.1") toStore)
|
||||
&& c.bindMounts.${dir}.hostPath == dir
|
||||
&& builtins.elem "d ${dir} 0770 root ${toString nginxGid} - -" host.systemd.tmpfiles.rules
|
||||
&& c.config.users.groups.gateway-nginx.gid == nginxGid
|
||||
&& unit.serviceConfig.Group == "gateway-nginx"
|
||||
&& !unit.serviceConfig.DynamicUser
|
||||
&& unit.serviceConfig.UMask == "0007"
|
||||
&& lib.hasInfix "--unix-socket ${sock}" unit.postStart;
|
||||
}
|
||||
{
|
||||
# On the bridge by DHCP, listening on a socket (protocol `socket` ignores the
|
||||
# upstream-default `http_port`, which stays in the settings): the
|
||||
|
|
|
|||
Loading…
Reference in a new issue