Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/chef-server-ctl/plugins/rotate_credentials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def backup_secrets_file(backup_file = nil)

def restore_secrets_file(backup_file)
log("Restoring #{backup_file} to #{secrets_file_path}...")
FileUtils.cp(secrets_file_path, backup_file)
FileUtils.cp(backup_file, secrets_file_path)
end

def secrets_file_path
Expand Down
19 changes: 19 additions & 0 deletions src/chef-server-ctl/spec/rotate_credentials_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,25 @@ def credentials
end
end

context "restore_secrets_file" do
it "copies the backup back over the live secrets file" do
allow(subject.ctl).to receive(:restore_secrets_file).and_call_original
allow(subject.ctl)
.to receive(:secrets_file_path)
.and_return("/etc/opscode/private-chef-secrets.json")

# The restore must copy backup -> live secrets file. Copying in the
# other direction would overwrite the only good backup with the
# (possibly broken) current secrets, making a failed rotation
# unrecoverable.
expect(FileUtils)
.to receive(:cp)
.with("/tmp/backup.json", "/etc/opscode/private-chef-secrets.json")

subject.ctl.send(:restore_secrets_file, "/tmp/backup.json")
end
end

context "require_credential_rotation_pre_hook" do
let(:credential_rotation_required_file) do
"/tmp/var/opt/opscode/credential_rotation_required"
Expand Down
Loading