Keep the values of a session's environment out of the Job's spec (a Secret for each session) #54

Merged
mikluko merged 4 commits from server-secret into main 2026-11-16 08:20:41 +00:00
Owner

Item 2 of specs-18's request, as the owner chose it ("A"): no value of gc's environment, nor ROOMCITY_TOKEN, is written into a Job's spec. Replaces #52, which had server-env as its base: #50 is in, this is the same commit rebased on main.

  • The server makes a Secret for each session, named like its Job, before the Job: every variable gc gave the agent (less what #50 leaves out) and the server's own ROOMCITY_*. The pod reads it with envFrom; the container's own env is PATH and the paths of mounted files (path_env, ROOMCITY_SECRET_*), which win over the Secret's. The Job owns the Secret (owner reference, set once the Job has its UID), so deleting the Job, as stop, a failed start and kill-object do, removes it; Delete and DeleteObject also delete it by name.
  • No fall back: a server whose Role lacks the right gets the server may not make Secrets in the namespace ... (its Role: create, get, update and delete on secrets) as the start's error, and no Job is made. A start that finds the session's Job already there neither overwrites nor removes its Secret.
  • Tests (fake cluster): no value of the environment, no token, nowhere in the marshalled Job; the Secret holds them all and the container reads it; PATH is the pod's; owner reference and removal with the Job; DeleteObject; Forbidden gives the error and no Job; a Job that cannot be made leaves no Secret.
  • The explicit hold-back of GC_DOLT_PASSWORD stays, my judgement: it is no longer in a spec, but bd in the pod reads its credentials from the file BEADS_CREDENTIALS_FILE names (the Secret of roomcity.toml), so a second copy in the session's Secret serves nothing.
  • README: "What a session's pod is given": what the Secret holds, and who can read it (whoever may read Secrets of the namespace, not whoever reads Jobs).

Lands with the image that needs it: saraksh/kube's Role (roomcity-5e) gets create, get, update, delete on secrets in the namespace, no list. Of those, this code uses create, update and delete; get is granted as the owner said and not used.

Assisted-By: Claude noreply@anthropic.com

Item 2 of specs-18's request, as the owner chose it ("A"): no value of gc's environment, nor `ROOMCITY_TOKEN`, is written into a Job's spec. Replaces #52, which had `server-env` as its base: #50 is in, this is the same commit rebased on `main`. - The server makes a Secret for each session, named like its Job, before the Job: every variable gc gave the agent (less what #50 leaves out) and the server's own `ROOMCITY_*`. The pod reads it with `envFrom`; the container's own `env` is `PATH` and the paths of mounted files (`path_env`, `ROOMCITY_SECRET_*`), which win over the Secret's. The Job owns the Secret (owner reference, set once the Job has its UID), so deleting the Job, as `stop`, a failed start and `kill-object` do, removes it; `Delete` and `DeleteObject` also delete it by name. - No fall back: a server whose Role lacks the right gets `the server may not make Secrets in the namespace ... (its Role: create, get, update and delete on secrets)` as the start's error, and no Job is made. A start that finds the session's Job already there neither overwrites nor removes its Secret. - Tests (fake cluster): no value of the environment, no token, nowhere in the marshalled Job; the Secret holds them all and the container reads it; PATH is the pod's; owner reference and removal with the Job; `DeleteObject`; Forbidden gives the error and no Job; a Job that cannot be made leaves no Secret. - The explicit hold-back of `GC_DOLT_PASSWORD` stays, my judgement: it is no longer in a spec, but bd in the pod reads its credentials from the file `BEADS_CREDENTIALS_FILE` names (the Secret of `roomcity.toml`), so a second copy in the session's Secret serves nothing. - README: "What a session's pod is given": what the Secret holds, and who can read it (whoever may read Secrets of the namespace, not whoever reads Jobs). **Lands with the image that needs it**: saraksh/kube's Role (roomcity-5e) gets `create`, `get`, `update`, `delete` on `secrets` in the namespace, no `list`. Of those, this code uses create, update and delete; `get` is granted as the owner said and not used. Assisted-By: Claude <noreply@anthropic.com>
Keep the values of a session's environment out of the Job's spec
All checks were successful
image / image (pull_request) Successful in 4s
test / changelog (pull_request) Successful in 6s
test / go (pull_request) Successful in 1m15s
36fbc8226c
The owner chose, of two ways, a Secret for each session: the server makes
it before the Job, with every variable gc gave the agent and the server's
own (ROOMCITY_TOKEN among them), the pod reads it with envFrom, and the
Job owns it, so that deleting the Job, as stop does, removes it. The spec,
which whoever may read Jobs can read, holds PATH and the paths of the
mounted files, nothing else. A server that lacks the right to make Secrets
fails the start and says which rights its Role needs; it does not fall
back to a plain environment.

A start that finds the session's Job there neither overwrites nor removes
its Secret. GC_DOLT_PASSWORD stays held back by name: bd in the pod reads
its credentials from the file BEADS_CREDENTIALS_FILE names, so a copy in a
second place has no use.

Assisted-By: Claude <noreply@anthropic.com>
Author
Owner

Read at 36fbc82: the suite is green here under -race, internal/kube ten times with GOMAXPROCS=1. The Job's spec holds no value, the pod reads the Secret, the Job owns it, and a server without the right fails the start with the reason.

Two changes before it merges.

  1. The Role does not need get. The code creates a session's Secret, updates it and deletes it, and never reads one (Secrets(...) is called three times in internal/kube/jobs.go: Create and Update in putEnvSecret, Update for the owner, Delete). With get the server's account could read every Secret of its namespace by name: Claude Code's token, Kimi's key, the proxy's. Without it the server writes sessions' Secrets and reads none. So create, update and delete, in the README, in the error's text and its test, and in saraksh/kube's Role when it comes.

  2. if job.UID == "" { return nil } in Create is there for the fake clientset: a real cluster never returns a Job without a UID, and with the branch a Secret that got no owner passes for a start that succeeded. Give the fake's Jobs a UID in newJobs, as TestTheJobOwnsTheSecretAndTheyGoTogether already does with a reactor, and drop the branch.

Two limits I do not ask you to change here; say them in the README's section or tell me they are wrong.

  • A server that dies between making the Secret and making the Job, or before the owner is set, leaves a Secret that nothing owns. The next start of that name takes it over; a name that never starts again leaves it, and the server cannot list Secrets to find it.
  • "A start that finds the session's Job there leaves its Secret alone" holds for the check at the top of Create. A Job that appears between that check and the Job's creation has had its Secret overwritten by then, and the AlreadyExists branch deletes it. operate's start deletes the name's Job and takes the name in the registry first, so only something outside the server could make that Job.

For the map, not for this pull request: update and delete cannot be narrowed to the sessions' Secrets by RBAC, so this Role lets the server overwrite or delete any Secret of its namespace.

Read at 36fbc82: the suite is green here under `-race`, `internal/kube` ten times with `GOMAXPROCS=1`. The Job's spec holds no value, the pod reads the Secret, the Job owns it, and a server without the right fails the start with the reason. Two changes before it merges. 1. The Role does not need `get`. The code creates a session's Secret, updates it and deletes it, and never reads one (`Secrets(...)` is called three times in internal/kube/jobs.go: Create and Update in `putEnvSecret`, Update for the owner, Delete). With `get` the server's account could read every Secret of its namespace by name: Claude Code's token, Kimi's key, the proxy's. Without it the server writes sessions' Secrets and reads none. So `create`, `update` and `delete`, in the README, in the error's text and its test, and in saraksh/kube's Role when it comes. 2. `if job.UID == "" { return nil }` in `Create` is there for the fake clientset: a real cluster never returns a Job without a UID, and with the branch a Secret that got no owner passes for a start that succeeded. Give the fake's Jobs a UID in `newJobs`, as `TestTheJobOwnsTheSecretAndTheyGoTogether` already does with a reactor, and drop the branch. Two limits I do not ask you to change here; say them in the README's section or tell me they are wrong. - A server that dies between making the Secret and making the Job, or before the owner is set, leaves a Secret that nothing owns. The next start of that name takes it over; a name that never starts again leaves it, and the server cannot list Secrets to find it. - "A start that finds the session's Job there leaves its Secret alone" holds for the check at the top of `Create`. A Job that appears between that check and the Job's creation has had its Secret overwritten by then, and the `AlreadyExists` branch deletes it. `operate`'s start deletes the name's Job and takes the name in the registry first, so only something outside the server could make that Job. For the map, not for this pull request: `update` and `delete` cannot be narrowed to the sessions' Secrets by RBAC, so this Role lets the server overwrite or delete any Secret of its namespace.
Ask the Role for create, update and delete on secrets, not get
Some checks failed
test / changelog (pull_request) Failing after 5s
image / image (pull_request) Successful in 17s
test / go (pull_request) Successful in 57s
b6160dd84e
The code creates, updates and deletes a session's Secret and never reads
one, and with get the server's account could read every Secret of its
namespace by name. The error's text, its test, the README and the
CHANGELOG say create, update and delete. The README also says the two
limits that come of the server's not being able to read or list Secrets: a
Secret that nothing owns when the server dies between it and the Job, and
a Job made by hand between the check and the creation.

The fake cluster gives each Job a UID, as the real one does, so that the
branch for a Job without one is gone.

Assisted-By: Claude <noreply@anthropic.com>
mikluko force-pushed server-secret from b6160dd84e
Some checks failed
test / changelog (pull_request) Failing after 5s
image / image (pull_request) Successful in 17s
test / go (pull_request) Successful in 57s
to 0155079628
All checks were successful
test / changelog (pull_request) Successful in 6s
image / image (pull_request) Successful in 21s
test / go (pull_request) Successful in 1m3s
2026-11-16 07:52:16 +00:00
Compare
Hold back BEADS_DOLT_PASSWORD as GC_DOLT_PASSWORD is
All checks were successful
test / changelog (pull_request) Successful in 10s
image / image (pull_request) Successful in 16s
test / go (pull_request) Successful in 46s
3f64da6f5a
gc sets the Dolt password under two names. With the values out of the
Job's spec the second one would be in the pod's environment beside the
credentials file bd reads, a second copy that serves nothing. It is held
back by its full name, not by a pattern; the start logs it by name among
what it left out.

Assisted-By: Claude <noreply@anthropic.com>
mikluko force-pushed server-secret from 3f64da6f5a
All checks were successful
test / changelog (pull_request) Successful in 10s
image / image (pull_request) Successful in 16s
test / go (pull_request) Successful in 46s
to 59cc6874ac
All checks were successful
test / changelog (pull_request) Successful in 5s
image / image (pull_request) Successful in 18s
test / go (pull_request) Successful in 1m13s
2026-11-16 08:18:36 +00:00
Compare
mikluko deleted branch server-secret 2026-11-16 08:20:41 +00:00
Commenting is not possible because the repository is archived.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
mikluko/roomcity!54
No description provided.