Skip to content

fix: rename EDA_SECRET_KEY to EDA_DB_ROTATION_KEY in rotate command#1610

Open
B-Whitt wants to merge 1 commit into
ansible:mainfrom
B-Whitt:fix/rename-rotation-env-var
Open

fix: rename EDA_SECRET_KEY to EDA_DB_ROTATION_KEY in rotate command#1610
B-Whitt wants to merge 1 commit into
ansible:mainfrom
B-Whitt:fix/rename-rotation-env-var

Conversation

@B-Whitt

@B-Whitt B-Whitt commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Rename the env var used by rotate_db_encryption_key --use-custom-key from EDA_SECRET_KEY to EDA_DB_ROTATION_KEY
  • EDA_SECRET_KEY serves double duty via dynaconf: it sets settings.SECRET_KEY (the decryption key) AND is read by the command as the new encryption key — making old == new, which aborts rotation
  • This mirrors AWX's pattern of using TOWER_SECRET_KEY (not AWX_SECRET_KEY) to avoid the same dynaconf prefix collision
  • Update unit tests to use the new env var name

Problem

When running:

EDA_SECRET_KEY='new-key' aap-eda-manage rotate_db_encryption_key --use-custom-key

Dynaconf loads EDA_SECRET_KEY as settings.SECRET_KEY at process startup. The command then reads settings.SECRET_KEY as the old key and os.environ['EDA_SECRET_KEY'] as the new key — they're identical, so rotation aborts with "New encryption key is identical to the current SECRET_KEY."

Validated against a live AAP 2.7 instance.

Fix

Rename the env var to EDA_DB_ROTATION_KEY which does not collide with dynaconf's EDA_ prefix mapping to settings.SECRET_KEY.

Test plan

  • Existing unit tests updated and passing (renamed env var references)
  • Verified on live pod: EDA_DB_ROTATION_KEY does not override settings.SECRET_KEY
  • Verified on live pod: rotation with new env var would succeed (old key ≠ new key)

Related

Assisted by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Updated the database encryption key rotation command to use the correct environment variable when a custom key is required.
    • Improved the command’s error message and usage text to match the new key source.
  • Tests
    • Adjusted command tests to validate the updated environment variable behavior for custom-key rotation scenarios.

EDA_SECRET_KEY serves double duty via dynaconf: it sets
settings.SECRET_KEY (the decryption key) AND is read by
rotate_db_encryption_key as the new encryption key. Old == new
causes "rotation aborted". This mirrors AWX's pattern of using
TOWER_SECRET_KEY (not AWX_SECRET_KEY) to avoid the same collision.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@B-Whitt B-Whitt requested a review from a team as a code owner June 29, 2026 20:30
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 910fde76-0176-4fa7-a73b-4bd3b03900cc

📥 Commits

Reviewing files that changed from the base of the PR and between ae92f55 and 535543b.

📒 Files selected for processing (2)
  • src/aap_eda/core/management/commands/rotate_db_encryption_key.py
  • tests/unit/commands/test_rotate_db_encryption_key.py
 _______________________________________________________________________________________________________
< Make it easy to reuse. If it's easy to reuse, people will. Create an environment that supports reuse. >
 -------------------------------------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@B-Whitt

B-Whitt commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

/run-e2e

@github-actions github-actions Bot deployed to e2e-tests June 29, 2026 20:32 Active

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/aap_eda/core/management/commands/rotate_db_encryption_key.py`:
- Around line 111-115: The custom-key path in rotate_db_encryption_key currently
only reads EDA_DB_ROTATION_KEY, but downstream deployments still provide
EDA_SECRET_KEY, so the command will fail in those environments. Update the
affected deployment wiring to set EDA_DB_ROTATION_KEY alongside the existing
consumers, or add a temporary fallback in the command’s new_key lookup so it can
still use EDA_SECRET_KEY during the migration. Reference the
rotate_db_encryption_key command and the manifests that inject the env var to
keep the rename consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 910fde76-0176-4fa7-a73b-4bd3b03900cc

📥 Commits

Reviewing files that changed from the base of the PR and between ae92f55 and 535543b.

📒 Files selected for processing (2)
  • src/aap_eda/core/management/commands/rotate_db_encryption_key.py
  • tests/unit/commands/test_rotate_db_encryption_key.py

Comment on lines +111 to +115
self.new_key = os.environ.get("EDA_DB_ROTATION_KEY")
if not self.new_key:
raise CommandError(
"--use-custom-key was specified but "
"EDA_SECRET_KEY is not set in the environment."
"EDA_DB_ROTATION_KEY is not set in the environment."

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Update the env wiring with this rename.

--use-custom-key now hard-requires EDA_DB_ROTATION_KEY, but the supplied downstream consumers still inject only EDA_SECRET_KEY (tools/deploy/eda-api/deployment.yaml:33-40, tools/docker/docker-compose-dev.yaml:20-24). In those environments this command will now fail every time on the custom-key path. Please either update those manifests in the same PR or keep a temporary fallback to EDA_SECRET_KEY during the migration.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/aap_eda/core/management/commands/rotate_db_encryption_key.py` around
lines 111 - 115, The custom-key path in rotate_db_encryption_key currently only
reads EDA_DB_ROTATION_KEY, but downstream deployments still provide
EDA_SECRET_KEY, so the command will fail in those environments. Update the
affected deployment wiring to set EDA_DB_ROTATION_KEY alongside the existing
consumers, or add a temporary fallback in the command’s new_key lookup so it can
still use EDA_SECRET_KEY during the migration. Reference the
rotate_db_encryption_key command and the manifests that inject the env var to
keep the rename consistent.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.48%. Comparing base (ae92f55) to head (535543b).

@@           Coverage Diff           @@
##             main    #1610   +/-   ##
=======================================
  Coverage   92.48%   92.48%           
=======================================
  Files         244      244           
  Lines       11244    11244           
=======================================
  Hits        10399    10399           
  Misses        845      845           
Flag Coverage Δ
unit-int-tests-3.11 92.48% <100.00%> (ø)
unit-int-tests-3.12 92.48% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...re/management/commands/rotate_db_encryption_key.py 98.85% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

Copy link
Copy Markdown

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.

2 participants