Watch
0
0
Fork
You've already forked hyperhive
0

swarm-otel: stamp sender from the authenticated client id, not a hive

This commit is contained in:
atlas 2026-11-22 23:45:42 +01:00 • committed by mara
commit 22c4d16a20
4 changed files with 243 additions and 233 deletions

View file

@ -490,8 +490,8 @@ let
&&
s.extensions."oidc/${name}".audience == baoWithCollector.services.hyperhive.swarm.bao.otel.clientId
&& lib.elem "oidc/${name}" s.service.extensions
&& lib.elem "otlp/${name}" s.service.pipelines."metrics/${otel.producerName}".receivers
&& lib.elem "otlp/${name}" s.service.pipelines."logs/${otel.producerName}".receivers;
&& lib.elem "otlp/${name}" s.service.pipelines."metrics/authenticated".receivers
&& lib.elem "otlp/${name}" s.service.pipelines."logs/authenticated".receivers;
}
{
# A client authelia has never heard of mints nothing, so the publisher

View file

@ -75,7 +75,7 @@ let
&& otel.serviceProducers.swarm-ci-metrics.clientId == clientId
&& s.receivers."otlp/swarm-ci-metrics".protocols.http.auth.authenticator == "oidc/swarm-ci-metrics"
&& s.extensions."oidc/swarm-ci-metrics".audience == clientId
&& lib.elem "otlp/swarm-ci-metrics" s.service.pipelines."metrics/${otel.producerName}".receivers
&& lib.elem "otlp/swarm-ci-metrics" s.service.pipelines."metrics/authenticated".receivers
&& h.services.nginx.virtualHosts.${otel.domain}.locations ? "/swarm-ci-metrics/";
}
{

View file

@ -826,7 +826,7 @@ let
&& s.receivers."otlp/swarm-nats".protocols.http.auth.authenticator == "oidc/swarm-nats"
&& s.extensions."oidc/swarm-nats".audience == h.services.hyperhive.swarm.nats.clientId
&& lib.elem "oidc/swarm-nats" s.service.extensions
&& lib.elem "otlp/swarm-nats" s.service.pipelines."logs/${otel.producerName}".receivers
&& lib.elem "otlp/swarm-nats" s.service.pipelines."logs/authenticated".receivers
&& h.services.nginx.virtualHosts.${otel.domain}.locations ? "/swarm-nats/"
# The store's forwarder keeps its own receiver beside it.
&& s.extensions."oidc/swarm-bao".audience == h.services.hyperhive.swarm.bao.otel.clientId;
@ -861,7 +861,7 @@ let
s.receivers."otlp/${svc.machine}".protocols.http.auth.authenticator == "oidc/${svc.machine}"
&& s.extensions."oidc/${svc.machine}".audience == clientOf svc
&& lib.elem "oidc/${svc.machine}" s.service.extensions
&& lib.elem "otlp/${svc.machine}" s.service.pipelines."logs/${otel.producerName}".receivers
&& lib.elem "otlp/${svc.machine}" s.service.pipelines."logs/authenticated".receivers
&& h.services.nginx.virtualHosts.${otel.domain}.locations ? "/${svc.machine}/"
) forwarderServices
# Their receivers and the queue's on the collector's host, none sharing a socket.
@ -904,7 +904,7 @@ let
s.receivers."otlp/${svc.machine}".protocols.http.auth.authenticator == "oidc/${svc.machine}"
&& s.extensions."oidc/${svc.machine}".audience == ownClientIdOf h svc
&& lib.elem "oidc/${svc.machine}" s.service.extensions
&& lib.elem "otlp/${svc.machine}" s.service.pipelines."logs/${otel.producerName}".receivers
&& lib.elem "otlp/${svc.machine}" s.service.pipelines."logs/authenticated".receivers
&& h.services.nginx.virtualHosts.${otel.domain}.locations ? "/${svc.machine}/"
) ownClientForwarders
&& lib.length (lib.unique socks) == lib.length socks;

View file

@ -698,14 +698,54 @@ let
# config however the mapping is written. The length clause is what
# makes the `all` mean anything — over an empty roster it holds
# vacuously.
name = "the swarm collector routes every hive's logs, not just one";
name = "every authenticated receiver, each hive's included, feeds the sender-stamping logs and metrics pipelines";
ok =
let
p = (otelSettings otelTwoHives).service.pipelines;
hives = lib.attrNames otelTwoHives.services.hyperhive.swarm.hives;
in
lib.length hives == 2
&& lib.all (h: (p ? "logs/${h}") && p."logs/${h}".receivers == [ "otlp/${h}" ]) hives;
&& lib.all (
h:
lib.elem "otlp/${h}" p."logs/authenticated".receivers
&& lib.elem "otlp/${h}" p."metrics/authenticated".receivers
) hives
&& !(lib.any (h: (p ? "logs/${h}") || (p ? "metrics/${h}")) hives);
}
{
# 🕳️ The stamp is the attribution boundary, so each half is pinned: the
# claim it reads, the order that makes a missing claim leave NO sender
# (`insert` skips an existing key), and that no `hive` is stamped. The
# unauthenticated pipelines are the control — they carry the swarm
# stamp and must not carry `sender`, since nothing authenticated them.
name = "the sender stamp reads the token's client id, deletes any sender-set value first, and stamps no hive";
ok =
let
s = otelSettings otelTwoHives;
attrs = s.processors."resource/sender".attributes;
actions = map (a: "${a.action} ${a.key}") attrs;
idx = x: lib.lists.findFirstIndex (a: a == x) null actions;
insert = lib.findFirst (a: a.action == "insert" && a.key == "sender") null attrs;
authed = lib.filterAttrs (_: p: lib.elem "resource/sender" p.processors) s.service.pipelines;
unauthed = lib.filterAttrs (_: p: !(lib.elem "resource/sender" p.processors)) s.service.pipelines;
anyOtlp = ps: lib.any (p: lib.any (r: lib.hasPrefix "otlp/" r) p.receivers) (lib.attrValues ps);
in
insert != null
&& insert.from_context == "auth.claims.client_id"
&& idx "delete sender" != null
&& idx "delete sender" < idx "insert sender"
&& idx "delete hive" != null
&& lib.all (
n: !(lib.any (a: a.key == "hive" && a.action != "delete") (s.processors.${n}.attributes or [ ]))
) (lib.attrNames s.processors)
&&
lib.attrNames authed == [
"logs/authenticated"
"metrics/authenticated"
]
&& lib.all (p: p.processors == [ "resource/sender" ]) (lib.attrValues authed)
&& !(anyOtlp unauthed)
&& unauthed != { };
}
{
# The same split as the metrics case above — defining an exporter and