Skip to content

Commit

Permalink
Merge pull request #80171 from itsbilal/ear-bugfix-21.1
Browse files Browse the repository at this point in the history
[release-21.1] storageccl: Don't disable data key rotation after restart
  • Loading branch information
itsbilal committed Apr 19, 2022
2 parents 9a83455 + 8f1aa7e commit 0cb819a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/ccl/storageccl/engineccl/pebble_key_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ func (m *DataKeyManager) SetActiveStoreKeyInfo(
) error {
m.mu.Lock()
defer m.mu.Unlock()
// Enable data key rotation regardless of what case we go into.
m.mu.rotationEnabled = true
prevActiveStoreKey, found := m.mu.keyRegistry.StoreKeys[m.mu.keyRegistry.ActiveStoreKeyId]
if found && prevActiveStoreKey.KeyId == storeKeyInfo.KeyId && m.mu.activeKey != nil {
// The active store key has not changed and we already have an active data key,
Expand Down
5 changes: 4 additions & 1 deletion pkg/ccl/storageccl/engineccl/pebble_key_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ func setActiveStoreKeyInProto(dkr *enginepbccl.DataKeysRegistry, id string) {
func setActiveDataKeyInProto(dkr *enginepbccl.DataKeysRegistry, id string) {
dkr.DataKeys[id] = &enginepbccl.SecretKey{
Info: &enginepbccl.KeyInfo{
EncryptionType: enginepbccl.EncryptionType_AES192_CTR, KeyId: id},
EncryptionType: enginepbccl.EncryptionType_AES192_CTR,
KeyId: id,
CreationTime: kmTimeNow().Unix(),
},
Key: []byte("some key"),
}
dkr.ActiveDataKeyId = id
Expand Down
59 changes: 57 additions & 2 deletions pkg/ccl/storageccl/engineccl/testdata/data_key_manager
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ load

get-active-data-key
----
encryption_type:AES192_CTR
encryption_type:AES192_CTR creation_time:6

get-active-store-key
----
Expand Down Expand Up @@ -172,7 +172,7 @@ check-exposed val=false

get-active-data-key
----
encryption_type:AES192_CTR
encryption_type:AES192_CTR creation_time:16

set-active-store-key-plain id=bar
----
Expand All @@ -184,3 +184,58 @@ get-active-data-key
----
creation_time:16 source:"data key manager" was_exposed:true parent_key_id:"bar"


# Test that starts with one active data and store key. Checks that data key is
# not immediately rotated after the call to SetActiveStoreKeyInfo with the same
# store key, but after the rotation period elapses, it gets rotated.

init
dir2
5
active-store-key foo
active-data-key data1
----

load
----

get-active-data-key
----
encryption_type:AES192_CTR creation_time:16

get-active-store-key
----
foo

record-active-data-key
----

compare-active-data-key
----
same

get-active-data-key
----
encryption_type:AES192_CTR creation_time:16

record-active-data-key
----

set-active-store-key id=foo
----

compare-active-data-key
----
same

get-active-data-key
----
encryption_type:AES192_CTR creation_time:16

wait
10
----

compare-active-data-key
----
different

0 comments on commit 0cb819a

Please sign in to comment.