refactor (kms): adopt the go-kms-wrapping/extras/kms package (#2027)

* feature (db): add Db.UnderlyingDB()

This is needed to allow for integration with bits that need a *dbw.DB

* feature (kms): add new go-kms-wrapping/extras/kms dependency

* refactor (kms): schema changes required to adopt extras/kms pkg

* refactor (kms/iam): rename to DeprecateCreateKeysTx(...)

* refactor (kms): remove deprecated test

* refactor (kms): refactor Kms type

This refactor includes renaming the existing type to DeprecatedKms
and then refactoring the Kms type to become a wrapper of
go-kms-wrapping/extras/kms

* refactor (kms): delete all the unneeded bits

All this stuff is not needed now that we're using
go-kms-wrapping/extras/kms

* refactor (db): fixup tests after kms refactor

* refactor (kms/tests): use testing.TB for test helpers

Our test helper packages were not possible to use
with benchmarks. This refactor switches to testing.TB
to allow both tests and benchmarks to use the helpers.

* tests (session benchmarks): refactor to use new Kms type

* refactor (schema): rm test which relies on deprecated Kms code

* refactor (kms): post rebase on main changes required

* chore (kms refactor): re-add unit test from main

* refactor (kms): uses migrations that don't include KMS schema changes
This commit is contained in:
Jim authored and GitHub committed 2022-05-13 13:53:22 -04:00
1 parent 8cef1017e9
commit 785241237e
97 files changed
+2580 -15154

No files matched your search

+21 -59
View File
@@ -24,6 +24,9 @@ const (
// KeyPurposeRecovery is used for recovery access
KeyPurposeRecovery
// KeyPurposeWorkerAuth is used for worker auth
KeyPurposeWorkerAuth
// KeyPurposeTokens is used for token encryption
KeyPurposeTokens
@@ -36,6 +39,9 @@ const (
// KeyPurposeAudit is used for audit operations
KeyPurposeAudit
// KeyPurposeRootKey is used as the root key
KeyPurposeRootKey
)
// String returns the key purpose cast as a string, just so it can be called as
@@ -48,6 +54,8 @@ func (k KeyPurpose) String() string {
return "oplog"
case KeyPurposeRecovery:
return "recovery"
case KeyPurposeWorkerAuth:
return "workerauth"
case KeyPurposeTokens:
return "tokens"
case KeyPurposeSessions:
@@ -56,67 +64,21 @@ func (k KeyPurpose) String() string {
return "oidc"
case KeyPurposeAudit:
return "audit"
default:
return "unknown"
}
}
// KeyType allows the kms repo to return a map[KeyType]Key which can be easily
// used without type casting.
type KeyType uint
const (
KeyTypeUnknown KeyType = iota
KeyTypeRootKey
KeyTypeRootKeyVersion
KeyTypeDatabaseKey
KeyTypeDatabaseKeyVersion
KeyTypeOplogKey
KeyTypeOplogKeyVersion
KeyTypeTokenKey
KeyTypeTokenKeyVersion
KeyTypeSessionKey
KeyTypeSessionKeyVersion
KeyTypeOidcKey
KeyTypeOidcKeyVersion
KeyTypeAuditKey
KeyTypeAuditKeyVersion
)
// String returns the key type cast as a string, just so it can be called as
// a function instead of direct casting elsewhere, yw
func (k KeyType) String() string {
switch k {
case KeyTypeRootKey:
case KeyPurposeRootKey:
return "rootKey"
case KeyTypeRootKeyVersion:
return "rootKeyVersion"
case KeyTypeDatabaseKey:
return "databaseKey"
case KeyTypeDatabaseKeyVersion:
return "databaseKeyVersion"
case KeyTypeOplogKey:
return "oplogKey"
case KeyTypeOplogKeyVersion:
return "oplogKeyVersion"
case KeyTypeTokenKey:
return "tokenKey"
case KeyTypeTokenKeyVersion:
return "tokenKeyVersion"
case KeyTypeSessionKey:
return "sessionKey"
case KeyTypeSessionKeyVersion:
return "sessionKeyVersion"
case KeyTypeOidcKey:
return "oidcKey"
case KeyTypeOidcKeyVersion:
return "oidcKeyVersion"
case KeyTypeAuditKey:
return "auditKey"
case KeyTypeAuditKeyVersion:
return "auditKeyVersion"
default:
return "unknown"
}
}
// ValidDekPurposes returns the current list of valid DEK key purposes
func ValidDekPurposes() []KeyPurpose {
return []KeyPurpose{
KeyPurposeDatabase,
KeyPurposeOplog,
KeyPurposeTokens,
KeyPurposeSessions,
KeyPurposeOidc,
KeyPurposeAudit,
}
}