Skip to content

fix(k8s): give moca-provisioner a read-only Redis ACL user - #869

Merged
webchang merged 2 commits into
rossoctl:mainfrom
webchang:pr/i626-provisioner-redis-acl
Nov 17, 2026
Merged

webchang merged 2 commits into
rossoctl:mainfrom
webchang:pr/i626-provisioner-redis-acl

Conversation

@webchang

Copy link
Copy Markdown
Member

Closes #626

What changed and why

  • moca-provisioner reads Redis as an ACL user of its own (Kubernetes, SH_WORKLOAD_SANDBOXES=1). Its orphan sweep only GETs workload records, but it used the deployment's shared read-write REDIS_URL. That credential can write sh:sandbox:records, which picks the executor for every turn, and the provisioner's seed port is reachable from model code. The new user is reset on #<sha256> ~sh:wl:* resetchannels +get: GET on sh: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_secret generates 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).
    • It appends the user's line to moca-redis's redis.conf. The line holds only the SHA-256 of the password (#<hex>), not the password.
    • The rules live in one place, REDIS_PROVISIONER_ACL.
    • With the feature off, redis.conf has no user line, and the Secret, if an earlier run made it, is left unreferenced, as moca-provisioner already is.
  • Redis rolls when the user changes. Redis reads redis.conf only at start, so write_overlay stamps moca.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) rolls redis-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_URL now comes from moca-redis-provisioner, not moca-redis.
  • Docs:
    • deploy/k8s/README.md: the Secrets table, the new user, and rotation.
    • docs/reference/configuration.md: the provisioner's REDIS_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.
    • Workload sandboxes spec §3.1, §6.2 and §9: these said "no ACL users" and named the provisioner's read-write credential as a widening.
    • Comments in redis.yaml, the component's kustomization.yaml and packages/provisioner/src/main.ts.
  • Nothing changes for the supervisor, relay or control plane. They keep the default user (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 reads REDIS_PROVISIONER_ACL from deploy/k8s/setup.sh itself and creates that user (throwaway name and password) on the CI Valkey. Then:
    • redisRecords connects as it (node-redis 6's RESP3 HELLO ... AUTH handshake).
    • A real sweepOrphans pass reads the records and sweeps only the orphan.
    • As that user, SET/DEL on a workload record, HSET/GET on sh:sandbox:records, KEYS and PUBLISH are all refused with NOPERM.
    • Results: before, 3 failed (no REDIS_PROVISIONER_ACL='...' line in .../deploy/k8s/setup.sh). After, 41/41 passed, and the whole provisioner suite passes (114 tests, tsc --noEmit clean).
  • packages/supervisor/test/k8s (real kubectl kustomize, setup.sh's own write_overlay):
    • base-provisioner.test.ts: the provisioner's REDIS_URL is moca-redis-provisioner's, and its pod spec never references moca-redis. Redis's StatefulSet carries moca.dev/redis-acl-hash on kind and ocp.
    • generated-overlay.test.ts: without workload sandboxes, Redis's pod template stays unannotated.
    • Results: before, 2 failed (the two #626 cases in base-provisioner.test.ts). After, 107/107 passed across the 13 files.
  • deploy/k8s/tests/setup.test.sh, workload sandboxes section:
    • Off by default: no moca-redis-provisioner and no user line in redis.conf.
    • On: the provisioner's password is its own 64-hex value, different from moca-redis's. Its REDIS_URL names moca-provisioner and that password, and the Secret has only those two keys. redis.conf is exactly requirepass, AOF, dir and the user moca-provisioner reset on #<sha256(pw)> ~sh:wl:* resetchannels +get line, never the password in clear. The applied overlay carries the hash annotation, and no secret reaches any argv.
    • A re-run rotates nothing.
    • Off again: the user line and the annotation are gone, and the Secret is kept.
    • Results: before, 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/bash 3.2.
  • End-to-end against Valkey 9: ensure_redis_secret (setup.sh sourced, with the Kubernetes calls stubbed) wrote a redis.conf. Valkey booted from it. The provisioner's redisRecords, using the generated REDIS_URL, became ready and read a record. SET, HSET sh:sandbox:records, GET sh:sandbox:records and FLUSHALL as that user were refused with NOPERM, and the default user was unaffected. A client whose user did not exist yet logged WRONGPASS and retried, then became ready once the user appeared. So on an upgrade, a provisioner that restarts before redis-0 has rolled recovers by itself.
  • shellcheck -S warning on setup.sh, setup.test.sh and the overlay fixture is clean, and python3 scripts/check-doc-links.py finds 0 broken links.

Out of scope

  • Separate ACL users for the supervisor, relay and control plane. They still share the default user. The issue is about the provisioner, and scoping the others needs their key sets and commands worked out one by one.
  • Rolling moca-provisioner automatically 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

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]>
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 17, 2026

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.get on sh:wl: keys (workloadRecordKey), so +get ~sh:wl:* is enough.
  • With the feature off, redis.conf and the overlay render are unchanged from main.
  • The Redis pod template has no existing annotations, so the op: add is 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.

Comment thread deploy/k8s/README.md Outdated
| `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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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."

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 55925d9, with your wording.

## 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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; ..."

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 55925d9, with your wording.

…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]>
@webchang
webchang merged commit 6ca3111 into rossoctl:main Nov 17, 2026
17 checks passed
webchang added a commit to webchang/moca that referenced this pull request Nov 18, 2026
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]>
@pdettori pdettori added this to the v0.11.0 milestone Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Give moca-provisioner a read-only Redis ACL user

3 participants