0

So currently I've faced some issues restoring databases with Symmetrical keys, Master keys, SSISDB and etc and I got curious.

We didn't have the password for anything. All that was done in the past, stayed there, BUT I could normally restore the DBs by regenerating password for keys, moving DBs, restoring DBs,opening the keys on source server and latest ALTER MASTER KEY ADD ENCRYPTION BY SERVICE MASTER KEY.

So, if you are a sysadmin, (obviously it's a good practice) but if you lose keys, it's no trouble , since we can regenerate, right?

2
  • Now, imagine that you don't have access to the source server, your DR plan assumes you have a brand new server and only the information that you have explicitly made sure is in your DR space; like backups, notes about special configurations and .... encryption keys. Commented Aug 29 at 12:44
  • oh man didn't think about this Scenario. makes total sense.
    – Racer SQL
    Commented Sep 3 at 12:45

1 Answer 1

0

if you lose keys, it's no trouble , since we can regenerate, right?

Here is the scenario: you are new DBA and master key is opened by service master key.

SELECT * FROM sys.openkeys;

You do not know the password this master key was generated but it's ok, you can always add another password to open it.

ALTER MASTER KEY ADD ENCRYPTION BY PASSWORD = 'another strong password';

Verify this password works by

OPEN MASTER KEY DECRYPTION BY PASSWORD = 'another strong password'; 

Feel free to backup/restore this database master key to another database on another server and open symmetric keys using this restored master key.

You can check number of passwords in

SELECT * FROM sys.key_encryptions;

Can you drop the password? Sure.

ALTER MASTER KEY DROP ENCRYPTION BY PASSWORD = 'another strong password';

Can you drop initial password or change password without knowing it?

Nope, in this case you should regenerate master key removing all password except the one you created.

ALTER MASTER KEY REGENERATE WITH ENCRYPTION BY PASSWORD = 'new password';

Regenerate is resource-intensive operation it will decrypt everything with old key, generate new keys and encrypt everything with new keys. So if you have a lot of data encrypted with symmetric keys it could take a while.

Also, you can remove auto-open feature by removing ENCRYPTION BY service master key just to simulate behavior of freshly restored database.

ALTER MASTER KEY DROP ENCRYPTION BY service master key;

Now if you close your master key

CLOSE MASTER KEY; 

you have to provide the password to open it

OPEN MASTER KEY DECRYPTION BY PASSWORD = 'new password'; 

Now you can turn on 'auto-open'

ALTER MASTER KEY ADD ENCRYPTION BY service master key;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.