Skip to content

REG-22125 fix standalone-generated AES-256 EncryptionKey length#7

Open
echerry-rs wants to merge 1 commit into
mainfrom
REG-22125_standalone_aes_key_length
Open

REG-22125 fix standalone-generated AES-256 EncryptionKey length#7
echerry-rs wants to merge 1 commit into
mainfrom
REG-22125_standalone_aes_key_length

Conversation

@echerry-rs
Copy link
Copy Markdown
Contributor

@echerry-rs echerry-rs commented May 11, 2026

Summary

Fixes REG-22125: standalone setup produced a 64-byte EncryptionKey, which fails the AES-256 check in Atlas.Utilities/Helpers/Encryptor.cs (The encryption key must encode to exactly 32 bytes for AES-256. Got 64 bytes.).

  • New generate_key(length) uses secrets.choice over the base64url alphabet excluding = and + (A-Za-z0-9-_), satisfying the ticket's request for an env-var-safe, cross-platform-safe key format.
  • EncryptionKey is now 32 chars / 32 UTF-8 bytes (AES-256). JWTSecretKey is also 32 chars (>= 256 bits for HS256).
  • New _assert_aes_key_length validator runs before the key is written, so a regression fails setup rather than platform startup.
  • Drive-by: updated the startup-completion log-line match to the string the current platform actually emits.

Note on the underlying mismatch (see ticket comment)

The ticket asks for the value to be base64-encoded and decode to 32 bytes, but the runtime path that produces this error (Encryptor.cs) does not base64-decode -- it counts raw UTF-8 bytes. The newer SecureKeyService.ValidateAndParseKey does decode and validate correctly; aligning Encryptor.cs with that pattern is a worthwhile platform-side follow-up so on-prem and SaaS truly agree on key format.

Test plan

  • Local: 500 generated keys all 32 chars / 32 UTF-8 bytes, base64url-safe, no = or +.
  • Local: validator rejects a 64-byte key with the expected error message.
  • End-to-end: run standalone_regscale.py setup against a clean install dir; confirm atlas.env EncryptionKey= value is exactly 32 chars and that the resulting container starts without the AES-256 length error.

Generate the EncryptionKey and JWTSecretKey from a base64url-safe
alphabet (A-Za-z0-9-_, no '=' or '+') using the `secrets` module, and
size the EncryptionKey at exactly 32 UTF-8 bytes so Encryptor.cs's
AES-256 check (which compares raw UTF-8 byte length to 32) passes.

A pre-write validator asserts the EncryptionKey byte length so a
regression here fails the setup step rather than the platform startup.

Also: update the startup-detection string to match the log line the
current platform actually emits.
@echerry-rs echerry-rs marked this pull request as ready for review May 11, 2026 18:41
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