Skip to content

fix(x): accept 24-byte encryption keys and reject 64-byte keys - #9901

Open
VfourTwenty wants to merge 1 commit into
dgraph-io:mainfrom
VfourTwenty:fix/9898-enc-key-length
Open

VfourTwenty wants to merge 1 commit into
dgraph-io:mainfrom
VfourTwenty:fix/9898-enc-key-length

Conversation

@VfourTwenty

@VfourTwenty VfourTwenty commented Nov 23, 2026 •

Copy link
Copy Markdown

Description

Fixes #9898.

x.GetEncAclKeys checked the --encryption / --vault key for a length of 16, 32 or 64 bytes. AES and Badger accept 16, 24 or 32, and the --encryption help text and the docs say the same. So a 24-byte (AES-192) key was refused at start, and a 64-byte key passed the check and the alpha then exited in Badger's OpenKeyRegistry.

The check now accepts 16, 24 or 32 bytes, and the error message lists those lengths. Both the key-file and the Vault paths go through this check.

Added TestGetEncAclKeysEncKeyLength in x/acl_enc_keys_test.go: it writes keys of 0, 15, 16, 24, 32, 33 and 64 bytes to a temp file and checks that only 16, 24 and 32 are accepted. On main the 24- and 64-byte cases fail, with the change all pass. Ran go test ./x/ -run TestGetEncAclKeys, go vet ./x/, gofmt and golangci-lint 2.15.0 with the trunk config in docker (golang:1.27.3): no issues in the changed lines (the 6 staticcheck findings it reports in x/ are already on main).

Checklist

  • The PR title follows the Conventional Commits syntax, leading with fix:, feat:, chore:, ci:, etc.
  • Code compiles correctly and linting (via trunk) passes locally
  • Tests added for new functionality, or regression tests for bug fixes added as applicable

Show it working
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Behavior Changes
    • Encryption keys must now be 16, 24, or 32 bytes long. Keys of other lengths, including 64 bytes, are rejected with an error that lists the supported sizes.
    • When no encryption key is set, the operation continues without an error and returns no encryption key.

Signed-off-by: VfourTwenty <132915930+VfourTwenty@users.noreply.github.com>
@VfourTwenty
VfourTwenty requested a review from a team as a code owner November 23, 2026 11:05
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

GetEncAclKeys now accepts non-nil encryption keys of 16, 24, or 32 bytes and rejects other lengths. Tests cover valid and invalid lengths and the unset-key case.

Changes: Encryption Key Length Validation

Layer / File(s) Summary
Key length validation and tests
x/acl_enc_keys.go, x/acl_enc_keys_test.go
GetEncAclKeys accepts 16-, 24-, and 32-byte keys and rejects other lengths with an error listing the accepted sizes. Tests check valid and invalid lengths, plus an unset key.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: go

Suggested reviewers: mangalaman93, matthewmcneely

Merge Risk: Minimal · up to 08979

The change makes encryption key validation accept 16, 24 or 32 byte keys and reject 64 byte keys, matching what the cipher supports. Anyone currently using a 64 byte key will see a startup error and need to supply a supported key length. No merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main behavior change: GetEncAclKeys now accepts 24-byte keys and rejects 64-byte keys. The raw summary says the function accepts 16, 24, or 32 bytes and rejects other lengths, incl…
Linked Issues check Passed Issue #9898 requires the encryption key length check in x.GetEncAclKeys to accept exactly 16, 24, or 32 bytes and to reject other lengths, with the error text listing those lengths. The whole-PR dif…
Out of Scope Changes check Passed The whole-PR changes consist of the one-line length check and its error message in x/acl_enc_keys.go, plus the added unit tests in x/acl_enc_keys_test.go. Both changes directly implement issue #98…
Full details: Title check

Explanation

The title names the main behavior change: GetEncAclKeys now accepts 24-byte keys and rejects 64-byte keys. The raw summary says the function accepts 16, 24, or 32 bytes and rejects other lengths, including 64. The title is fully related to the changeset, though it omits the 16- and 32-byte cases and the test additions.

Full details: Linked Issues check

Explanation

Issue #9898 requires the encryption key length check in x.GetEncAclKeys to accept exactly 16, 24, or 32 bytes and to reject other lengths, with the error text listing those lengths. The whole-PR diff against the merge base changes x/acl_enc_keys.go line 55 from l != 16 &amp;&amp; l != 32 &amp;&amp; l != 64 to l != 16 &amp;&amp; l != 24 &amp;&amp; l != 32. The error message now reads encryption key must have length of 16, 24, or 32 bytes. The --vault path uses the same check, as the issue states. The change in x/acl_enc_keys_test.go (TestGetEncAclKeysEncKeyLength, per the PR summary) covers 0, 15, 16, 24, 32, 33, and 64 byte keys. I did not read the test file hunk directly. The code change alone meets the coding requirement.

Full details: Out of Scope Changes check

Explanation

The whole-PR changes consist of the one-line length check and its error message in x/acl_enc_keys.go, plus the added unit tests in x/acl_enc_keys_test.go. Both changes directly implement issue #9898. The tests support the fix and fall within scope. The PR summary reports no other file changes. No unrelated changes were identified.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • 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: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a48f3ccf-7aea-497c-9e84-5e7d6e672207
Commits

Reviewing files that changed from the base of the PR and between e95fc26 and 08979b8.

Files selected for processing: 2

  • x/acl_enc_keys.go
  • x/acl_enc_keys_test.go

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Encryption key length check refuses 24-byte keys and accepts 64-byte keys

1 participant