Skip to content

Commit

Permalink
Add warnings for deleting kms led pki workers
Browse files Browse the repository at this point in the history
  • Loading branch information
talanknight committed Oct 10, 2023
1 parent 0be93a0 commit 01303d4
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/gen/controller/api/warning.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion internal/server/repository_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/server/store"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/boundary/internal/warning"
"github.com/hashicorp/go-dbw"
"github.com/hashicorp/nodeenrollment"
"github.com/hashicorp/nodeenrollment/registration"
Expand All @@ -31,11 +32,28 @@ func (r *Repository) DeleteWorker(ctx context.Context, publicId string, _ ...Opt
if publicId == "" {
return db.NoRowsAffected, errors.New(ctx, errors.InvalidParameter, op, "missing public id")
}

// If it's a KMS-PKI worker we should warn the user that deleting the
// worker may not persist as the worker can be auto recreated. If the
// public ID is predictably generated in the KMS fashion, it's a KMS-PKI
// worker.
wAgg := &workerAggregate{PublicId: publicId}
if err := r.reader.LookupById(ctx, wAgg); err != nil {
return db.NoRowsAffected, errors.Wrap(ctx, err, op)
}
workerId, err := NewWorkerIdFromScopeAndName(ctx, wAgg.ScopeId, wAgg.Name)
if err != nil {
return db.NoRowsAffected, errors.Wrap(ctx, err, op, errors.WithMsg("error generating worker id in kms-pki name check case"))
}
if workerId == publicId {
warning.Warn(ctx, warning.DeletingKmsLedWorkersMayNotBePermanent)
}

worker := allocWorker()
worker.Worker.PublicId = publicId

var rowsDeleted int
_, err := r.writer.DoTx(
_, err = r.writer.DoTx(
ctx,
db.StdRetryCnt,
db.ExpBackoff{},
Expand Down
3 changes: 3 additions & 0 deletions internal/target/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/resource"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/boundary/internal/warning"
"github.com/hashicorp/go-dbw"
)

Expand Down Expand Up @@ -566,6 +567,8 @@ func (r *Repository) UpdateTarget(ctx context.Context, target Target, version ui
switch {
case strings.EqualFold("Address", f):
updateAddress = true
case strings.EqualFold("WorkerFilter", f):
warning.Warn(ctx, warning.FieldDeprecatedTargetWorkerFilters)
default:
filteredDbMask = append(filteredDbMask, f)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/warning/enumerated.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// SPDX-License-Identifier: BUSL-1.1

package warning

Expand Down
4 changes: 2 additions & 2 deletions internal/warning/warning.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// SPDX-License-Identifier: BUSL-1.1

package warning

Expand All @@ -8,13 +8,13 @@ import (
"sync"

"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/hashicorp/boundary/internal/observability/event"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"

"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/event"
pbwarnings "github.com/hashicorp/boundary/internal/gen/controller/api"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/warning/warning_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// SPDX-License-Identifier: BUSL-1.1

package warning

Expand Down

0 comments on commit 01303d4

Please sign in to comment.