External NATS hands every task container the broker's full token #1866

Closed
opened 2026-11-12 09:35:03 +00:00 by sam · 2 comments
Owner

Problem

On the embedded broker a task container logs in as task-<id> with its run credential and is limited to its own task's subjects. On an external broker, NATSEndpoint.ContainerToken returns the broker's own token because Scoped is false whenever [nats] mode is external (archied bootstrap). Both task paths pass it in: containerEnv on the default path and kitrun.WorkerEnv on the Kit path. Any process in any task container can then publish and subscribe to every subject, including other tasks' work. archied reports this as a health issue but runs anyway.

Multi-host workers (#1864) need an external broker, so this blocks that work.

Wanted

Use NATS auth callout so an external broker hands each login to archie, and apply the same check the embedded broker uses (the authenticator in eventbus/nats/auth.go): instance token gets full permissions, task-<id> gets only its task's subjects, inbox and one reply. Then delete ContainerToken and the unscoped fallback.

Done when

  • On an external broker, a task container connects with its run credential only, and a publish outside its task's subjects is refused.
  • No code path puts the broker token in a container's environment.
  • Test: the callout grants the same permissions the embedded authenticator does, table-driven, no live broker.
## Problem On the embedded broker a task container logs in as `task-<id>` with its run credential and is limited to its own task's subjects. On an external broker, `NATSEndpoint.ContainerToken` returns the broker's own token because `Scoped` is false whenever `[nats] mode` is external (archied bootstrap). Both task paths pass it in: `containerEnv` on the default path and `kitrun.WorkerEnv` on the Kit path. Any process in any task container can then publish and subscribe to every subject, including other tasks' work. archied reports this as a health issue but runs anyway. Multi-host workers (#1864) need an external broker, so this blocks that work. ## Wanted Use NATS auth callout so an external broker hands each login to archie, and apply the same check the embedded broker uses (the `authenticator` in `eventbus/nats/auth.go`): instance token gets full permissions, `task-<id>` gets only its task's subjects, inbox and one reply. Then delete `ContainerToken` and the unscoped fallback. ## Done when - On an external broker, a task container connects with its run credential only, and a publish outside its task's subjects is refused. - No code path puts the broker token in a container's environment. - Test: the callout grants the same permissions the embedded authenticator does, table-driven, no live broker.
sam added a new dependency 2026-11-12 09:35:22 +00:00
sam added the highbug labels 2026-11-12 15:51:30 +00:00
Author
Owner

Landed on main; task check passed on the merged tree. Not yet proven live.

Landed on main; task check passed on the merged tree. Not yet proven live.
Author
Owner

Already fixed by 3a965e2a4: external-broker logins go through the embedded authenticator via the callout (internal/infrastructure/eventbus/nats/callout.go:59), TestBrokerScopesTaskCredentials (internal/infrastructure/eventbus/nats/auth_test.go:29) checks both brokers, and no ContainerToken remains in internal or cmd.

Already fixed by 3a965e2a4: external-broker logins go through the embedded authenticator via the callout (internal/infrastructure/eventbus/nats/callout.go:59), TestBrokerScopesTaskCredentials (internal/infrastructure/eventbus/nats/auth_test.go:29) checks both brokers, and no ContainerToken remains in internal or cmd.
sam closed this issue 2026-11-14 04:31:16 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: sam/archie#1866