Repository navigation
fix(k8s): give moca-provisioner a read-only Redis ACL user - #869
Conversation
The provisioner's orphan sweep only GETs workload records, but it read Redis with the deployment's shared read-write REDIS_URL, which can write sh:sandbox:records (the executor for every turn) -- from a process whose seed port model code can reach. With SH_WORKLOAD_SANDBOXES=1, setup.sh now generates a password for a Redis user of the provisioner's own, keeps it in a new Secret, moca-redis-provisioner (REDIS_PASSWORD, REDIS_URL), and appends the user to moca-redis's redis.conf as `user moca-provisioner reset on #<sha256> ~sh:wl:* resetchannels +get`: GET on workload records, nothing else. The provisioner Deployment takes REDIS_URL from the new Secret. Redis reads redis.conf only at start, so the generated overlay stamps the sha256 of the user's line on Redis's pod template: adding the user, changing its password or turning the feature off rolls redis-0. Off, nothing renders differently. Tests: sweep.test.ts holds a real Valkey to setup.sh's own REDIS_PROVISIONER_ACL (connect, sweep, every write refused); the k8s manifest tests pin the Secret reference and the roll annotation; setup.test.sh pins the Secret, the redis.conf line, stickiness and the off path. Docs: k8s README, configuration, Redis backup, security model, workload sandboxes spec §3.1, §6.2, §9. Closes rossoctl#626 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Review at 219f9da
With SH_WORKLOAD_SANDBOXES=1, moca-provisioner now reads Redis as its own ACL user (~sh:wl:* resetchannels +get) from a separate Secret, moca-redis-provisioner. Redis rolls when the user line changes, through moca.dev/redis-acl-hash.
What I checked at the head:
- The provisioner only calls
records.getonsh:wl:keys (workloadRecordKey), so+get ~sh:wl:*is enough. - With the feature off,
redis.confand the overlay render are unchanged from main. - The Redis pod template has no existing annotations, so the
op: addis safe. - The other callers keep
moca-redis. - No secret reaches argv.
I found no correctness defects. Two doc-wording nits are inline.
Author: webchang (MEMBER — maintainer)
Areas reviewed: Shell, K8s/Kustomize YAML, TypeScript (provisioner, tests), Docs/spec
Agent/IDE config (.claude/.vscode): none
Commits: 1, all signed off: yes
CI status: all checks passing at submit time
- nit: the commit subject
k8s: give moca-provisioner …has no conventional type;fix(k8s): …would match the PR title.
Drafted by an AI reviewer and approved by a human before posting.
| | `moca-supervisor-tls` | `moca` (OCP) | `tls.crt`, `tls.key` | ghostunnel sidecar | | ||
|
|
||
| - The tokens and the Redis passwords are `openssl rand -hex 32`. | ||
| - `REDIS_URL` and `redis.conf` are re-derived from `REDIS_PASSWORD` on every run, so the three never |
There was a problem hiding this comment.
nit: This bullet is now stale. With workload sandboxes on, redis.conf is also re-derived from moca-redis-provisioner's REDIS_PASSWORD, which supplies the user line's #<sha256>. So it is no longer only "REDIS_PASSWORD... the three". Consider: "...are re-derived from the Redis passwords on every run, so they never disagree."
| ## Secrets to back up separately | ||
|
|
||
| `setup.sh` creates the first four rows once and never rotates them; the per-user Secrets in `moca-credentials` are | ||
| `setup.sh` creates every row's Secrets but `moca-credentials` once and never rotates them; the per-user Secrets in `moca-credentials` are |
There was a problem hiding this comment.
nit: "creates every row's Secrets but moca-credentials once" is hard to parse. Also, moca-redis-provisioner is created only with workload sandboxes on. Maybe: "setup.sh creates every Secret in the table except the moca-credentials ones (moca-redis-provisioner only with workload sandboxes), once, and never rotates them; ..."
…Secrets setup.sh creates Review follow-up. With workload sandboxes on, redis.conf's provisioner user line comes from moca-redis-provisioner's password too, so the README no longer says "the three". The backup guide's sentence on which Secrets setup.sh creates is reworded, and notes moca-redis-provisioner exists only with workload sandboxes on. Refs rossoctl#626 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
Brings 25 upstream merges since 1aa8dd6, among them the sbx OIDC identity provider (rossoctl#851), the Redis schema-version key and config bundle format marker (rossoctl#868), the provisioner Redis ACL user (rossoctl#869), the relay keepalive env (rossoctl#866), the per-source OIDC pending bound with the forwarded-headers Route pin (rossoctl#874), the egress refusal hints and control-plane index (rossoctl#864), the empty-workspace sweep (rossoctl#872) and the orphan-sweep log split (rossoctl#849). No conflicts. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Closes #626
What changed and why
moca-provisionerreads Redis as an ACL user of its own (Kubernetes,SH_WORKLOAD_SANDBOXES=1). Its orphan sweep onlyGETs workload records, but it used the deployment's shared read-writeREDIS_URL. That credential can writesh:sandbox:records, which picks the executor for every turn, and the provisioner's seed port is reachable from model code. The new user isreset on #<sha256> ~sh:wl:* resetchannels +get:GETonsh:wl:*only, with no write, no other key and no Pub/Sub. This is the issue's proposal,+get ~sh:wl:*.deploy/k8s/setup.sh:ensure_redis_secretgenerates the user's password once (openssl rand -hex 32, kept on every re-run like every other Secret value) into a new Secret,moca-redis-provisioner(REDIS_PASSWORD,REDIS_URL=redis://moca-provisioner:<pw>@redis.<ns>.svc:6379).moca-redis'sredis.conf. The line holds only the SHA-256 of the password (#<hex>), not the password.REDIS_PROVISIONER_ACL.redis.confhas no user line, and the Secret, if an earlier run made it, is left unreferenced, asmoca-provisioneralready is.redis.confonly at start, sowrite_overlaystampsmoca.dev/redis-acl-hash(the sha256 of the user's line) on Redis's pod template when the feature is on. Adding the user, changing its password or turning the feature off (the annotation goes away) rollsredis-0. Without this, an upgraded stack would keep the old config and the provisioner's login would fail. The stack without workload sandboxes renders as before: no annotation.base/workload-sandboxes/provisioner.yaml:REDIS_URLnow comes frommoca-redis-provisioner, notmoca-redis.deploy/k8s/README.md: the Secrets table, the new user, and rotation.docs/reference/configuration.md: the provisioner'sREDIS_URL.docs/operations/redis-backup-recovery.md: the generated config, who reaches 6379, and the Secrets to back up.docs/reference/security-model.md: the Redis 6379 row.redis.yaml, the component'skustomization.yamlandpackages/provisioner/src/main.ts.requirepass).deploy/sbx, compose and the VM path run no provisioner, so they are unchanged.Tests
All run locally. Before = this branch's tests with the source changes (
setup.sh,provisioner.yaml) reverted to main.packages/provisioner/test/sweep.test.ts, new block "the orphan sweep as setup.sh's provisioner Redis user (Give moca-provisioner a read-only Redis ACL user #626)". It readsREDIS_PROVISIONER_ACLfromdeploy/k8s/setup.shitself and creates that user (throwaway name and password) on the CI Valkey. Then:redisRecordsconnects as it (node-redis 6's RESP3HELLO ... AUTHhandshake).sweepOrphanspass reads the records and sweeps only the orphan.SET/DELon a workload record,HSET/GETonsh:sandbox:records,KEYSandPUBLISHare all refused withNOPERM.no REDIS_PROVISIONER_ACL='...' line in .../deploy/k8s/setup.sh). After, 41/41 passed, and the whole provisioner suite passes (114 tests,tsc --noEmitclean).packages/supervisor/test/k8s(realkubectl kustomize, setup.sh's ownwrite_overlay):base-provisioner.test.ts: the provisioner'sREDIS_URLismoca-redis-provisioner's, and its pod spec never referencesmoca-redis. Redis's StatefulSet carriesmoca.dev/redis-acl-hashon kind and ocp.generated-overlay.test.ts: without workload sandboxes, Redis's pod template stays unannotated.#626cases inbase-provisioner.test.ts). After, 107/107 passed across the 13 files.deploy/k8s/tests/setup.test.sh, workload sandboxes section:moca-redis-provisionerand nouserline inredis.conf.moca-redis's. ItsREDIS_URLnamesmoca-provisionerand that password, and the Secret has only those two keys.redis.confis exactlyrequirepass, AOF,dirand theuser moca-provisioner reset on #<sha256(pw)> ~sh:wl:* resetchannels +getline, never the password in clear. The applied overlay carries the hash annotation, and no secret reaches any argv.FAIL: no moca-redis-provisioner Secret with the feature on(bash 5 and 3.2; the "off" checks pass on main). After, the whole suite passes under bash 5 and macOS/bin/bash3.2.ensure_redis_secret(setup.sh sourced, with the Kubernetes calls stubbed) wrote aredis.conf. Valkey booted from it. The provisioner'sredisRecords, using the generatedREDIS_URL, became ready and read a record.SET,HSET sh:sandbox:records,GET sh:sandbox:recordsandFLUSHALLas that user were refused withNOPERM, and the default user was unaffected. A client whose user did not exist yet loggedWRONGPASSand retried, then became ready once the user appeared. So on an upgrade, a provisioner that restarts beforeredis-0has rolled recovers by itself.shellcheck -S warningonsetup.sh,setup.test.shand the overlay fixture is clean, andpython3 scripts/check-doc-links.pyfinds 0 broken links.Out of scope
moca-provisionerautomatically when only its Redis password is rotated. As for every other Secret, the README says to restart it (Redis itself rolls automatically).Every commit is signed off (DCO).
Assisted-By: Claude Code