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:
97 files changed
+2580
-15154
No files matched your search
@@ -31,7 +31,6 @@ func (r *Repository) CreateScope(ctx context.Context, s *Scope, userId string, o
|
||||
}
|
||||
|
||||
var parentOplogWrapper wrapping.Wrapper
|
||||
var externalWrappers *kms.ExternalWrappers
|
||||
var err error
|
||||
switch s.Type {
|
||||
case scope.Unknown.String():
|
||||
@@ -47,7 +46,6 @@ func (r *Repository) CreateScope(ctx context.Context, s *Scope, userId string, o
|
||||
default:
|
||||
parentOplogWrapper, err = r.kms.GetWrapper(ctx, s.ParentId, kms.KeyPurposeOplog)
|
||||
}
|
||||
externalWrappers = r.kms.GetExternalWrappers()
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "unable to get oplog wrapper")
|
||||
@@ -174,17 +172,17 @@ func (r *Repository) CreateScope(ctx context.Context, s *Scope, userId string, o
|
||||
|
||||
s := scopeRaw.(*Scope)
|
||||
|
||||
// Create the scope's keys
|
||||
_, err = kms.CreateKeysTx(ctx, dbr, w, externalWrappers.Root(), reader, s.PublicId)
|
||||
txnKms, err := kms.NewUsingReaderWriter(ctx, dbr, w)
|
||||
if err != nil {
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg("error creating transaction's kms"))
|
||||
}
|
||||
if err := txnKms.AddExternalWrappers(ctx, kms.WithRootWrapper(r.kms.GetExternalWrappers(ctx).Root())); err != nil {
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg("error adding external root wrapper to transaction's kms"))
|
||||
}
|
||||
if err := txnKms.CreateKeys(ctx, s.PublicId, kms.WithRandomReader(reader), kms.WithReaderWriter(dbr, w)); err != nil {
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg("error creating scope keys"))
|
||||
}
|
||||
|
||||
kmsRepo, err := kms.NewRepository(dbr, w)
|
||||
if err != nil {
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg("error creating new kms repo"))
|
||||
}
|
||||
childOplogWrapper, err := r.kms.GetWrapper(ctx, s.PublicId, kms.KeyPurposeOplog, kms.WithRepository(kmsRepo))
|
||||
childOplogWrapper, err := txnKms.GetWrapper(ctx, s.PublicId, kms.KeyPurposeOplog)
|
||||
if err != nil {
|
||||
return errors.New(ctx, errors.InvalidParameter, op, "unable to get oplog wrapper")
|
||||
}
|
||||
|
||||
@@ -160,8 +160,8 @@ func Test_Repository_delete(t *testing.T) {
|
||||
err = db.TestVerifyOplog(t, rw, s.PublicId, db.WithOperation(oplog.OpType_OP_TYPE_DELETE), db.WithCreateNotBefore(5*time.Second))
|
||||
require.NoError(err)
|
||||
})
|
||||
rk := kms.AllocRootKey()
|
||||
db.TestDeleteWhere(t, conn, &rk, "1=1")
|
||||
kms.TestKmsDeleteAllKeys(t, conn)
|
||||
|
||||
t.Run("nil-resource", func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestRepo(t testing.TB, conn *db.DB, rootWrapper wrapping.Wrapper, opt ...Op
|
||||
kmsCache := kms.TestKms(t, conn, rootWrapper)
|
||||
wrapper, err := kmsCache.GetWrapper(context.Background(), scope.Global.String(), kms.KeyPurposeOplog)
|
||||
if err != nil {
|
||||
_, err = kms.CreateKeysTx(context.Background(), rw, rw, rootWrapper, rand.Reader, scope.Global.String())
|
||||
err = kmsCache.CreateKeys(context.Background(), scope.Global.String(), kms.WithRandomReader(rand.Reader))
|
||||
require.NoError(err)
|
||||
wrapper, err = kmsCache.GetWrapper(context.Background(), scope.Global.String(), kms.KeyPurposeOplog)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user