Skip to content

Commit 01303d4

Browse files
committed
Add warnings for deleting kms led pki workers
1 parent 0be93a0 commit 01303d4

File tree

6 files changed

+27
-6
lines changed

6 files changed

+27
-6
lines changed

internal/gen/controller/api/warning.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/server/repository_worker.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/hashicorp/boundary/internal/kms"
1515
"github.com/hashicorp/boundary/internal/server/store"
1616
"github.com/hashicorp/boundary/internal/types/scope"
17+
"github.com/hashicorp/boundary/internal/warning"
1718
"github.com/hashicorp/go-dbw"
1819
"github.com/hashicorp/nodeenrollment"
1920
"github.com/hashicorp/nodeenrollment/registration"
@@ -31,11 +32,28 @@ func (r *Repository) DeleteWorker(ctx context.Context, publicId string, _ ...Opt
3132
if publicId == "" {
3233
return db.NoRowsAffected, errors.New(ctx, errors.InvalidParameter, op, "missing public id")
3334
}
35+
36+
// If it's a KMS-PKI worker we should warn the user that deleting the
37+
// worker may not persist as the worker can be auto recreated. If the
38+
// public ID is predictably generated in the KMS fashion, it's a KMS-PKI
39+
// worker.
40+
wAgg := &workerAggregate{PublicId: publicId}
41+
if err := r.reader.LookupById(ctx, wAgg); err != nil {
42+
return db.NoRowsAffected, errors.Wrap(ctx, err, op)
43+
}
44+
workerId, err := NewWorkerIdFromScopeAndName(ctx, wAgg.ScopeId, wAgg.Name)
45+
if err != nil {
46+
return db.NoRowsAffected, errors.Wrap(ctx, err, op, errors.WithMsg("error generating worker id in kms-pki name check case"))
47+
}
48+
if workerId == publicId {
49+
warning.Warn(ctx, warning.DeletingKmsLedWorkersMayNotBePermanent)
50+
}
51+
3452
worker := allocWorker()
3553
worker.Worker.PublicId = publicId
3654

3755
var rowsDeleted int
38-
_, err := r.writer.DoTx(
56+
_, err = r.writer.DoTx(
3957
ctx,
4058
db.StdRetryCnt,
4159
db.ExpBackoff{},

internal/target/repository.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/hashicorp/boundary/internal/types/action"
1919
"github.com/hashicorp/boundary/internal/types/resource"
2020
"github.com/hashicorp/boundary/internal/types/scope"
21+
"github.com/hashicorp/boundary/internal/warning"
2122
"github.com/hashicorp/go-dbw"
2223
)
2324

@@ -566,6 +567,8 @@ func (r *Repository) UpdateTarget(ctx context.Context, target Target, version ui
566567
switch {
567568
case strings.EqualFold("Address", f):
568569
updateAddress = true
570+
case strings.EqualFold("WorkerFilter", f):
571+
warning.Warn(ctx, warning.FieldDeprecatedTargetWorkerFilters)
569572
default:
570573
filteredDbMask = append(filteredDbMask, f)
571574
}

internal/warning/enumerated.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) HashiCorp, Inc.
2-
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-License-Identifier: BUSL-1.1
33

44
package warning
55

internal/warning/warning.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) HashiCorp, Inc.
2-
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-License-Identifier: BUSL-1.1
33

44
package warning
55

@@ -8,13 +8,13 @@ import (
88
"sync"
99

1010
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
11-
"github.com/hashicorp/boundary/internal/observability/event"
1211
"google.golang.org/grpc"
1312
"google.golang.org/grpc/metadata"
1413
"google.golang.org/protobuf/encoding/protojson"
1514
"google.golang.org/protobuf/proto"
1615

1716
"github.com/hashicorp/boundary/internal/errors"
17+
"github.com/hashicorp/boundary/internal/event"
1818
pbwarnings "github.com/hashicorp/boundary/internal/gen/controller/api"
1919
)
2020

internal/warning/warning_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) HashiCorp, Inc.
2-
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-License-Identifier: BUSL-1.1
33

44
package warning
55

0 commit comments

Comments
 (0)