Watch
0
0
Fork
You've already forked hyperhive
0

swarm-otel: delete a sender-set sender and hive from datapoints and log records

This commit is contained in:
atlas 2026-11-23 00:51:31 +01:00 • committed by mara
commit 90a1e523fb
4 changed files with 75 additions and 18 deletions

View file

@ -146,12 +146,13 @@ harness metrics rather than from a metric label.
The swarm tier checks a token at **one receiver per audience**, because an OIDC The swarm tier checks a token at **one receiver per audience**, because an OIDC
authenticator accepts exactly one. Every receiver feeds the same pipelines, and authenticator accepts exactly one. Every receiver feeds the same pipelines, and
the first processor in them deletes any `sender` the payload carried, then sets the first processors in them delete any `sender` or `hive` the payload
`sender` from the token's `client_id` claim. The collector stamps no `hive`. A hive carried, on the resource and on each datapoint or log record, then set `sender`
from the token's `client_id` claim. The collector stamps no `hive`. A hive
collector therefore can't report metrics as another sender, and can't relabel collector therefore can't report metrics as another sender, and can't relabel
its own by editing what it sends — the label isn't taken from the payload at its own by editing what it sends — the label isn't taken from the payload at
all. A token without the claim leaves the record with no `sender`, never one the all. A token without the claim leaves the record with no `sender`, never one
sender chose. the sender chose.
**Nothing to set where the hive holds its store identity.** The hive's collector **Nothing to set where the hive holds its store identity.** The hive's collector
reads its secret from the swarm's secret store under the hive's own leaf reads its secret from the swarm's secret store under the hive's own leaf

View file

@ -244,17 +244,20 @@ restarts and starts about 18 seconds after it. Senders retry through that window
**What the collector stamps.** Every authenticated receiver feeds one metrics **What the collector stamps.** Every authenticated receiver feeds one metrics
pipeline and one logs pipeline. Their first processor, `resource/sender`, pipeline and one logs pipeline. Their first processor, `resource/sender`,
deletes any `sender` and `hive` attribute the payload carried, then sets deletes any `sender` and `hive` attribute the payload carried on the resource,
`sender` from the token's `client_id` claim and `swarm` to the swarm's display then sets `sender` from the token's `client_id` claim and `swarm` to the swarm's
name. `sender` is therefore the client that authenticated: `hive-<name>` for a display name. `sender` is therefore the client that authenticated: `hive-<name>`
hive's collector, the service's own client for a service forwarder. A token for a hive's collector, the service's own client for a service forwarder.
without the claim leaves the record with no `sender`. The collector stamps no A token without the claim leaves the record with no `sender`. The collector
`hive` label. A hive is a place an agent runs: dashboards and alerts select an stamps no `hive` label. A hive is a place an agent runs: dashboards and alerts
agent by `agent` and a machine by `host.name`, and the alert `no log records select an agent by `agent` and a machine by `host.name`, and the alert
from <hive>` selects on `sender`. Records that nothing authenticated (the `no log records from <hive>` selects on `sender`. Records that nothing
host's journal, the collector's own journal and the Prometheus scrapes) carry authenticated (the host's journal, the collector's own journal and the
`swarm` and no `sender`. A `batch` processor must never run before Prometheus scrapes) carry `swarm` and no `sender`. A `batch` processor must
`resource/sender`, because a batch drops the authentication context. never run before `resource/sender`, because a batch drops the authentication
context. A second processor, `attributes/sender`, deletes `sender` and `hive`
from every datapoint and log record, where a sender can set them too. Scope
attributes stay as sent.
The collector fetches authelia's discovery document through the gateway when The collector fetches authelia's discovery document through the gateway when
it starts and exits if that fails. systemd restarts it with no start limit and a it starts and exits if that fails. systemd restarts it with no start limit and a

View file

@ -318,6 +318,13 @@ let
# without joining them. # without joining them.
authPipeline = "authenticated"; authPipeline = "authenticated";
authReceivers = map (owner: "otlp/${owner}") (lib.attrNames receiverSockets); authReceivers = map (owner: "otlp/${owner}") (lib.attrNames receiverSockets);
# `resource/sender` stamps the resource; `attributes/sender` clears the
# same two keys from every datapoint and log record, where a sender can set
# them too and the stores keep them as labels and fields.
senderProcessors = [
"resource/sender"
"attributes/sender"
];
upstreamOf = sock: "http://unix:${sock}:/"; upstreamOf = sock: "http://unix:${sock}:/";
# Set by nginx on every response from a route, whatever its status, so the # Set by nginx on every response from a route, whatever its status, so the
@ -1437,7 +1444,7 @@ in
service.pipelines = { service.pipelines = {
"metrics/${authPipeline}" = { "metrics/${authPipeline}" = {
receivers = authReceivers; receivers = authReceivers;
processors = [ "resource/sender" ]; processors = senderProcessors;
exporters = exporterNames; exporters = exporterNames;
}; };
} }
@ -1463,7 +1470,7 @@ in
// lib.optionalAttrs collectLogs { // lib.optionalAttrs collectLogs {
"logs/${authPipeline}" = { "logs/${authPipeline}" = {
receivers = authReceivers; receivers = authReceivers;
processors = [ "resource/sender" ]; processors = senderProcessors;
exporters = logExporterNames; exporters = logExporterNames;
}; };
} }
@ -1657,6 +1664,21 @@ in
action = "upsert"; action = "upsert";
} }
]; ];
# The record level of the same boundary. `resource/sender`
# only touches resource attributes, so a `sender` or `hive`
# set on a datapoint or a log record would reach the store as
# a label or field beside the stamped one. Scope attributes
# are out of this processor's reach.
"attributes/sender".actions = [
{
key = "sender";
action = "delete";
}
{
key = "hive";
action = "delete";
}
];
} }
# The unauthenticated inputs' stamp: `swarm` and no `sender`, # The unauthenticated inputs' stamp: `swarm` and no `sender`,
# because nothing authenticated them. # because nothing authenticated them.

View file

@ -751,10 +751,41 @@ let
"logs/authenticated" "logs/authenticated"
"metrics/authenticated" "metrics/authenticated"
] ]
&& lib.all (p: p.processors == [ "resource/sender" ]) (lib.attrValues authed) && lib.all (p: lib.head p.processors == "resource/sender") (lib.attrValues authed)
&& !(anyOtlp unauthed) && !(anyOtlp unauthed)
&& unauthed != { }; && unauthed != { };
} }
{
# `resource/sender` only rewrites resource attributes. A `sender` or
# `hive` a sender sets on a datapoint or a log record reaches the store
# as a label beside the stamped one unless `attributes/sender` deletes
# it, so each authenticated pipeline must carry it. The unauthenticated
# pipelines are the control: they carry neither processor.
# 🔬 Invert-proof: drop `attributes/sender` from either pipeline, or
# either delete from the processor.
name = "every authenticated pipeline deletes a sender-set sender and hive from datapoints and log records";
ok =
let
s = otelSettings otelTwoHives;
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;
deleted = map (a: a.key) (
lib.filter (a: a.action == "delete") s.processors."attributes/sender".actions
);
in
lib.attrNames authed == [
"logs/authenticated"
"metrics/authenticated"
]
&& lib.all (p: lib.elem "attributes/sender" p.processors) (lib.attrValues authed)
&& !(lib.any (p: lib.elem "attributes/sender" p.processors) (lib.attrValues unauthed))
&&
lib.sort lib.lessThan deleted == [
"hive"
"sender"
]
&& lib.length s.processors."attributes/sender".actions == 2;
}
{ {
# The same split as the metrics case above — defining an exporter and # The same split as the metrics case above — defining an exporter and
# naming it are two lists — plus the half one shared list cannot have: # naming it are two lists — plus the half one shared list cannot have: