Skip to content

refactor: group node auth and split-migration flags (M2, part 3) - #1439

Merged
bootjp merged 2 commits into
mainfrom
design/root-package-decomposition-m2c
Nov 12, 2026
Merged

bootjp merged 2 commits into
mainfrom
design/root-package-decomposition-m2c

Conversation

@bootjp

@bootjp bootjp commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Design: docs/design/2026_11_12_partial_root_package_decomposition.md

Stacked on #1438 (M2 part 2), which is stacked on #1437. Retarget each to main as the one below it merges.

What

Third part of M2 (typed flag config). The node auth flags become nodeAuthFlags (main_node_auth.go):

  • adminTokenFile / adminInsecureNoAuth
  • splitMigrationTokenFile / splitMigrationPeerAuthEnforced
  • grpcTLSCAFile / grpcTLSCertFile / grpcTLSKeyFile
  • s3BlobPeerTokenFile

These flags were read in many places, so some call paths change:

  • Split-migration readiness gate. splitMigrationLocalReadinessGate becomes a method on nodeAuthFlags. Its method value is handed to:

    • the distribution server (capability gate, split-job readiness)
    • startDistributionSplitJobRunner / startMigrationOwnershipRefresh
    • the raft gRPC servers, through a new adminGRPCInterceptors.migrationReady field. They apply it in the coverage interceptor (now newMigrationCoverageUnaryGate(ready)) and in migrationOwnershipRuntimeReady.

    The new migrationReadinessGate type fails closed when nil. Production always sets it; the nil branch keeps a future caller that forgets it from opening migration.

  • configureAdminService takes nodeAuthFlags instead of four positional token/insecure values, and no longer reads the enforcement global. setupAdminService takes it from serversInput.

  • Peer TLS and start-up validation. configureNodeGRPCTransport(nodeAuth) handles both. resolveNetworkRuntimeInputs takes nodeAuth.

  • Protected bootstrap. The check that the startup token differs from the Admin, migration and S3 peer tokens used to read the three globals deep inside loadProtectedBootstrapDomain. It now gets the token files through raftBootstrapConfig.serviceTokenFiles, which buildShardGroups already receives. The check still runs before any group is opened.

  • S3 blob cluster. The runner reads its token files from runtimeServerRunner.nodeAuth.

Still package globals after this PR:

  • listener addresses
  • Raft and shard topology
  • encryption and KEK
  • the bootstrap peer-config dir

Behavior change

None intended. Flag names, defaults and usage strings are unchanged: -help output is identical to the base. The readiness gate used to read the globals on each call. It now reads the parsed values bound at start-up, and nothing mutates these flags after parsing.

Tests

  • Tests that saved, overwrote and restored the auth globals now build nodeAuthFlags values. enableMigrationRuntimeFlags returns one.
  • The two helpers that toggled enforcement mid-test now toggle a local value (*nodeAuthFlags in assertMigrationRuntimeFlagsRequired).
  • newOwnershipRefreshRaftNode takes the gate explicitly. The refresh test keeps the default posture (gate closed), and the readiness tests pass their enabled one, matching what each saw through the globals before.
  • New: TestMigrationReadinessGateMissingFailsClosed, TestValidateBootstrapStartupTokenRejectsServiceTokenReuse (that path had no direct test), and TestNodeAuthServiceTokenFilesCoverEveryServiceToken. The flag-binding test now covers node auth too.

Verification

  • go build ./..., go vet ., golangci-lint (0 issues), importguard
  • go test -race -count=1 .: ok (224s)
  • One earlier targeted run (-run over the migration/admin/bootstrap tests) reported FAIL. I did not keep its output, so I cannot say which test failed or why. Two reruns of the same set and the full suite passed, so it may be an existing flaky e2e test, but that is not confirmed. Worth watching in CI.
  • Help output diffed against the base binary: identical
  • Jepsen not run: the design doc exempts M2

Self-review

  1. Data loss: no write, apply or migration data path changed; only where the auth/gate inputs come from.
  2. Concurrency / distributed failures: the gate's method value is bound once at start-up from immutable parsed flags. Tests no longer race on shared globals. Every production path that previously consulted the gate still does: capability, runners, coverage interceptor, ownership readiness and the split-job readiness option.
  3. Performance: start-up only; the gate does the same work per call.
  4. Data consistency: migration admission semantics are unchanged, including the insecure-mode rollout exception and opcode env checks. The startup-token separation still fails start-up before any group opens.
  5. Test coverage: existing gate/auth tests still run against local values. New tests cover the fail-closed nil gate and the bootstrap token separation.

Move the Admin gRPC token and insecure mode, the split-migration token
and peer-auth enforcement switch, peer gRPC TLS and the S3 blob peer
token into nodeAuthFlags, passed down from run().

The split-migration readiness gate becomes a method on nodeAuthFlags.
The distribution server, the split-job and ownership-refresh runners and
the raft gRPC servers (through adminGRPCInterceptors) receive its method
value; a missing gate fails closed. configureAdminService takes
nodeAuthFlags instead of four positional values. The protected-bootstrap
check that the startup token differs from the service tokens gets the
token files through raftBootstrapConfig, so it still runs before any
group opens.

Flag names, defaults and usage text are unchanged (identical -help
output). Tests build nodeAuthFlags values instead of overwriting
globals.

Signed-off-by: bootjp <contact@bootjp.me>
Signed-off-by: bootjp <contact@bootjp.me>
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T13:11:01.951310Z 2cc6939 PR opened
🔒 Security Review ✅ Completed 2026-11-12T13:12:39.540262Z 2cc6939 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Base automatically changed from design/root-package-decomposition-m2b to main November 12, 2026 14:18
@bootjp
bootjp merged commit 2d4bab3 into main Nov 12, 2026
13 checks passed
@bootjp
bootjp deleted the design/root-package-decomposition-m2c branch November 12, 2026 14:19
bootjp added a commit that referenced this pull request Nov 12, 2026
Design: docs/design/2026_11_12_partial_root_package_decomposition.md

M2 part 4, following #1437, #1438 and #1439 (all merged). It moves the
five encryption flags out of package globals into `encryptionFlags`,
which is registered on the FlagSet and passed down from `run()`.

## Changes
- `encryptionFlags` (`main_encryption_kek.go`) holds
`--encryptionSidecarPath`, `--encryption-enabled`,
`--encryption-rotate-on-startup`, `--kekFile` and `--kekUri`. The flag
comments moved onto the struct.
- These functions now take the flags as a parameter:
`loadKEKAfterPreNonceStartupGuards`, `loadKEKAndRunStartupGuards`,
`verifyKEKBeforeMutators`, `loadKEKWrapperFromFlags` (renamed from
`loadKEKWrapperFromFlag`) and `encryptionMutatorsEnabled`.
`startRaftServers` gets the flags through `serversInput` /
`runtimeServerRunner`.
- Protected bootstrap admission needs only two facts: whether encryption
is configured (enabled, or a sidecar path is set) and whether a startup
rotation was requested.
- Those two facts now travel as `bootstrapEncryptionRequest` in
`raftBootstrapConfig`.
- `loadProtectedBootstrapDomain` takes the whole `raftBootstrapConfig`.
- The bootstrap domain keeps the request, and WAL recovery uses it to
decide whether the encryption registration is "not configured".
- Tests:
- The bootstrap e2e fixtures and the KEK and metrics tests pass flag
values directly instead of overwriting process globals.
  - Two of those tests are now `t.Parallel`.
- `raftBootstrapPeerConfigDir` is still a global and is still set by the
e2e fixtures.

## Behavior change
None. Flag names, defaults and help text are unchanged: `-help` output
is identical to the base. The bootstrap "requested" and recovery "not
configured" conditions compute the same booleans as before.

## Risk
Low. The flags are read-only after parsing, so passing copies of their
values changes nothing at runtime. The one new data path is `run()`
setting `bootstrapCfg.encryption` right after
`resolveNetworkRuntimeInputs`, before
`buildShardGroupsWithEncryptionWiring` reads it.

## Test evidence
- `go test -race -count=1 .`: ok (225s).
- `go test ./internal/encryption/`: ok.
- `golangci-lint`: 0 issues.
- `scripts/check-production-imports.sh`: ok.
- `-help` output: identical to the base binary.
- Test list: identical apart from the new
`TestEncryptionFlagsBootstrapRequest`.
- Jepsen: not run. Nothing in replication, MVCC or OCC changed.

## Self-review
1. **Data loss**: no change to the apply, persist or sidecar write
paths.
2. **Concurrency**: the flag values are immutable after parsing, and the
bootstrap domain stores the request once at construction.
3. **Performance**: no hot path is involved.
4. **Consistency**: the KEK guards, mutator gate, bootstrap admission
and recovery registration all read the same values as before.
5. **Test coverage**: a new table test covers `bootstrapRequest()` /
`requested()`. The existing KEK, bootstrap-domain and rotation e2e tests
now pass these values explicitly.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **改善**
  * 暗号化とKEKの設定を起動処理や保護されたブートストラップで一貫して扱うようになりました。
  * 暗号化が構成されているかどうかに応じて、ブートストラップ時の復旧状態を適切に判定します。
  * テストで暗号化設定を個別に扱えるようになり、テスト間で設定が影響しにくくなりました。

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant