Fix broken secrets-file restore on failed credential rotation#4202
Open
tas50 wants to merge 1 commit into
Open
Fix broken secrets-file restore on failed credential rotation#4202tas50 wants to merge 1 commit into
tas50 wants to merge 1 commit into
Conversation
👷 Deploy Preview for chef-server processing.
|
restore_secrets_file copied the live secrets file onto the backup instead of copying the backup back onto the live secrets file. On a failed rotation the rollback therefore did nothing useful and also overwrote the only good backup with the (possibly broken) current secrets, leaving the server with unusable credentials and no way to recover them. Copy backup -> live secrets file so a failed rotation can actually roll back. Add a regression test; the existing tests stubbed this method out entirely, so the direction bug was never exercised. Signed-off-by: Tim Smith <tsmith84@proton.me>
bce8a71 to
fff371e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
restore_secrets_fileinsrc/chef-server-ctl/plugins/rotate_credentials.rbcopies in the wrong direction:This is the rollback path invoked by
rotate-credentials,rotate-all-credentials, androtate-shared-secretswhen credential rotation raises (see therescueblocks that callrestore_secrets_file(backup_file)).Because the copy goes live secrets file → backup (the same direction as
backup_secrets_file), a failed rotation:private-chef-secrets.json.The net effect is that a failed credential rotation can leave the Chef Server with unusable credentials and no automated way to recover, which is the opposite of what this rescue path is intended to guarantee.
Fix
Copy backup → live secrets file so the rollback actually restores the pre-rotation state:
Tests
The existing
rotate_credentials_spec.rbstubbedrestore_secrets_fileout entirely and only asserted that it was called, so the copy direction was never exercised — which is how the bug went unnoticed. Added a focused regression test that calls the real method withFileUtils.cpmocked and asserts the argument order (backup_file,secrets_file_path).Note: the chef-server-ctl gem bundle targets Ruby 3.1 and could not be installed in my local environment (Ruby 4.x), so I verified the changed files with
ruby -cand am relying on CI to run the rspec suite.