Skip to content

refactor: group encryption and KEK flags (M2 part 4) - #1440

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

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

Conversation

@bootjp

@bootjp bootjp commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

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.

Summary by CodeRabbit

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

Move --encryptionSidecarPath, --encryption-enabled,
--encryption-rotate-on-startup, --kekFile and --kekUri into
encryptionFlags on serverFlags. The KEK load, start-up guards, KEK
preflight and EncryptionAdmin mutator gate take it as a parameter.

Protected bootstrap admission only needs whether encryption is
configured and whether a startup rotation was requested; those travel
as bootstrapEncryptionRequest in raftBootstrapConfig and stay on the
bootstrap domain for WAL recovery. Bootstrap e2e fixtures and the KEK
tests pass values instead of overwriting process globals.

No flag name, default or help text changes.

Signed-off-by: bootjp <contact@bootjp.me>
Signed-off-by: bootjp <contact@bootjp.me>
@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-12T14:28:37.243856Z dd58b15 PR opened
🔒 Security Review ✅ Completed 2026-11-12T14:30:33.352635Z dd58b15 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.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

暗号化とKEKの設定をencryptionFlagsに集約しました。ブートストラップ用の暗号化要求をraftBootstrapConfigで渡し、ドメイン生成と回復時の登録判定に使用します。

Changes: 暗号化設定とブートストラップ

Layer / File(s) Summary
暗号化フラグの集約と起動配線
main_flags.go, main_encryption_*.go, main.go, main_server_runner.go, main_raft_servers.go, internal/encryption/startup.go, main_encryption_*_test.go, main_encryption_write_wiring.go, docs/design/2026_11_12_partial_root_package_decomposition.md
暗号化とKEKのフラグをencryptionFlagsにまとめ、KEK読み込み、起動ガード、変更ゲート、サーバー起動に渡します。関連テストはパッケージグローバルの設定ではなく、ローカルの設定値を使います。
ブートストラップ要求の伝達
main.go, main_raft_peers.go, main_bootstrap_*.go, main_shard_groups.go
bootstrapEncryptionRequestをraftBootstrapConfigに保持し、保護付きドメインの生成と回復時の登録判定に使います。関連テストとE2E fixtureは、ブートストラップ設定または要求を明示して渡します。

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Merge Risk: Minimal · up to dd58b

This change moves encryption flag handling into a struct and passes the values explicitly through startup. It is described as not changing behavior, and no merge-blocking risk has been identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed タイトル「refactor: group encryption and KEK flags (M2 part 4)」は、変更の中心である暗号化およびKEKフラグのパッケージグローバルから encryptionFlags へのまとめ直しを具体的に示しています。PR の目的(五つのフラグの移行、encryptionFlags への集約、bootstrapEncryptionRequest の導入、動作…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

タイトル「refactor: group encryption and KEK flags (M2 part 4)」は、変更の中心である暗号化およびKEKフラグのパッケージグローバルから encryptionFlags へのまとめ直しを具体的に示しています。PR の目的(五つのフラグの移行、encryptionFlags への集約、bootstrapEncryptionRequest の導入、動作変更なし)とも一致します。「M2 part 4」は作業系列を示す接頭辞であり、変更内容を誤って伝えるものではありません。

  • 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 141f3cb6-beea-4742-ac12-28f59549bf91
Commits

Reviewing files that changed from the base of the PR and between 2d4bab3 and dd58b15.

Files selected for processing: 26

  • docs/design/2026_11_12_partial_root_package_decomposition.md
  • internal/encryption/startup.go
  • main.go
  • main_bootstrap_domain.go
  • main_bootstrap_enablement_e2e_test.go
  • main_bootstrap_enablement_multi_e2e_test.go
  • main_bootstrap_encryption_domain.go
  • main_bootstrap_encryption_domain_test.go
  • main_bootstrap_launch.go
  • main_bootstrap_offline_encryption_e2e_test.go
  • main_bootstrap_recovery_race_test.go
  • main_bootstrap_rotation_e2e_test.go
  • main_bootstrap_runtime.go
  • main_bootstrap_tso_enablement_e2e_test.go
  • main_bootstrap_tso_recovery_test.go
  • main_bootstrap_tso_test.go
  • main_encryption_admin.go
  • main_encryption_kek.go
  • main_encryption_kek_source_test.go
  • main_encryption_metrics_wiring_test.go
  • main_encryption_write_wiring.go
  • main_flags.go
  • main_raft_peers.go
  • main_raft_servers.go
  • main_server_runner.go
  • main_shard_groups.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@bootjp
bootjp merged commit 8a0568f into main Nov 12, 2026
18 checks passed
@bootjp
bootjp deleted the design/root-package-decomposition-m2d branch November 12, 2026 15:00
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 5, following #1440. It moves the client-facing listener flags
out of package globals into `listenerFlags`, which is registered on the
FlagSet and passed down from `run()`.

## Changes
- `listenerFlags` (`main_public_servers.go`) holds 15 flags:
  - Redis: `--redisAddress`, `--redisLuaMaxIdleStates`.
  - DynamoDB: `--dynamoAddress`.
- S3: `--s3Address`, `--s3Region`, `--s3CredentialsFile`,
`--s3PathStyleOnly`.
- SQS: `--sqsAddress`, `--sqsPublicEndpoint`, `--sqsRegion`,
`--sqsCredentialsFile`.
- Metrics and pprof: `--metricsAddress`, `--metricsToken`,
`--pprofAddress`, `--pprofToken`.
- `resolveNetworkRuntimeInputs` → `resolveValidatedRuntimeInputs` →
`resolveRuntimeInputs` pass it to `parseRuntimeConfig`.
- `serversInput` carries it. The `runtimeServerRunner` fields it already
had are now filled from it.
- `prepareRedisServer` takes the Lua pool size as a parameter.
- `prepareAdminFromFlags` takes the S3 credentials file (the admin
listener reuses it) as a parameter.
- `--address` stays a global for now. It is the node's Raft address and
belongs with the Raft topology flags in the next part.

## Behavior change
None. Flag names, defaults and help text are unchanged: `-help` output
is identical to the base.

## Risk
Low. The values are read-only after parsing, so passing them as copies
changes nothing.

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

## Self-review
1. **Data loss**: no write, apply or persistence path is touched.
2. **Concurrency**: the values are immutable after parsing, and nothing
new is shared.
3. **Performance**: start-up only. No hot path is involved.
4. **Consistency**: each listener, leader map and credentials loader
gets the same value it read from the global before.
5. **Test coverage**: a new test pins the defaults and the parsing of
the S3, SQS and pprof flags. Existing callers of the changed signatures
are updated.
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