Skip to content

Commit

Permalink
Use latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
robmonte committed Feb 11, 2025
1 parent 74ac057 commit 389285f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 74 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ require (
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-gcp-common v0.9.1
github.com/hashicorp/go-hclog v1.6.3
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.9
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/vault/api v1.15.0
github.com/hashicorp/vault/sdk v0.14.2-0.20250129205522-e38052d1ecb6
github.com/hashicorp/vault/sdk v0.15.0
github.com/stretchr/testify v1.10.0
golang.org/x/oauth2 v0.24.0
google.golang.org/api v0.214.0
Expand Down Expand Up @@ -49,12 +49,12 @@ require (
github.com/hashicorp/go-hmac-drbg v0.0.0-20210916214228-a6e5a68489f6 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-kms-wrapping/entropy/v2 v2.0.1 // indirect
github.com/hashicorp/go-kms-wrapping/v2 v2.0.16 // indirect
github.com/hashicorp/go-kms-wrapping/v2 v2.0.18 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.6.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/cryptoutil v0.1.0 // indirect
github.com/hashicorp/go-secure-stdlib/cryptoutil v0.1.1 // indirect
github.com/hashicorp/go-secure-stdlib/mlock v0.1.3 // indirect
github.com/hashicorp/go-secure-stdlib/permitpool v1.0.0 // indirect
github.com/hashicorp/go-secure-stdlib/plugincontainer v0.4.1 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJ
github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-kms-wrapping/entropy/v2 v2.0.1 h1:KIge4FHZEDb2/xjaWgmBheCTgRL6HV4sgTfDsH876L8=
github.com/hashicorp/go-kms-wrapping/entropy/v2 v2.0.1/go.mod h1:aHO1EoFD0kBYLBedqxXgalfFT8lrWfP7kpuSoaqGjH0=
github.com/hashicorp/go-kms-wrapping/v2 v2.0.16 h1:WZeXfD26QMWYC35at25KgE021SF9L3u9UMHK8fJAdV0=
github.com/hashicorp/go-kms-wrapping/v2 v2.0.16/go.mod h1:ZiKZctjRTLEppuRwrttWkp71VYMbTTCkazK4xT7U/NQ=
github.com/hashicorp/go-kms-wrapping/v2 v2.0.18 h1:DLfC677GfKEpSAFpEWvl1vXsGpEcSHmbhBaPLrdDQHc=
github.com/hashicorp/go-kms-wrapping/v2 v2.0.18/go.mod h1:t/eaR/mi2mw3klfl1WEAuiLKrlZ/Q8cosmsT+RIPLu0=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-plugin v1.6.1 h1:P7MR2UP6gNKGPp+y7EZw2kOiq4IR9WiqLvp0XOsVdwI=
Expand All @@ -125,12 +125,12 @@ github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISH
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5Oi2viEzc=
github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8=
github.com/hashicorp/go-secure-stdlib/cryptoutil v0.1.0 h1:4B46+S65WqQUlp0rX2F7TX6/p0HmUZsDD+cVzFTwztw=
github.com/hashicorp/go-secure-stdlib/cryptoutil v0.1.0/go.mod h1:hH8rgXHh9fPSDPerG6WzABHsHF+9ZpLhRI1LPk4JZ8c=
github.com/hashicorp/go-secure-stdlib/cryptoutil v0.1.1 h1:VaLXp47MqD1Y2K6QVrA9RooQiPyCgAbnfeJg44wKuJk=
github.com/hashicorp/go-secure-stdlib/cryptoutil v0.1.1/go.mod h1:hH8rgXHh9fPSDPerG6WzABHsHF+9ZpLhRI1LPk4JZ8c=
github.com/hashicorp/go-secure-stdlib/mlock v0.1.3 h1:kH3Rhiht36xhAfhuHyWJDgdXXEx9IIZhDGRk24CDhzg=
github.com/hashicorp/go-secure-stdlib/mlock v0.1.3/go.mod h1:ov1Q0oEDjC3+A4BwsG2YdKltrmEw8sf9Pau4V9JQ4Vo=
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8 h1:iBt4Ew4XEGLfh6/bPk4rSYmuZJGizr6/x/AEizP0CQc=
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8/go.mod h1:aiJI+PIApBRQG7FZTEBx5GiiX+HbOHilUdNxUZi4eV0=
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.9 h1:FW0YttEnUNDJ2WL9XcrrfteS1xW8u+sh4ggM8pN5isQ=
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.9/go.mod h1:Ll013mhdmsVDuoIXVfBtvgGJsXDYkTw1kooNcoCXuE0=
github.com/hashicorp/go-secure-stdlib/permitpool v1.0.0 h1:U6y5MXGiDVOOtkWJ6o/tu1TxABnI0yKTQWJr7z6BpNk=
github.com/hashicorp/go-secure-stdlib/permitpool v1.0.0/go.mod h1:ecDb3o+8D4xtP0nTCufJaAVawHavy5M2eZ64Nq/8/LM=
github.com/hashicorp/go-secure-stdlib/plugincontainer v0.4.1 h1:JY+zGg8gOmslwif1fiCqT5Hu1SikLZQcHkmQhCoA9gY=
Expand All @@ -151,8 +151,8 @@ github.com/hashicorp/hcl v1.0.1-vault-5 h1:kI3hhbbyzr4dldA8UdTb7ZlVVlI2DACdCfz31
github.com/hashicorp/hcl v1.0.1-vault-5/go.mod h1:XYhtn6ijBSAj6n4YqAaf7RBPS4I06AItNorpy+MoQNM=
github.com/hashicorp/vault/api v1.15.0 h1:O24FYQCWwhwKnF7CuSqP30S51rTV7vz1iACXE/pj5DA=
github.com/hashicorp/vault/api v1.15.0/go.mod h1:+5YTO09JGn0u+b6ySD/LLVf8WkJCPLAL2Vkmrn2+CM8=
github.com/hashicorp/vault/sdk v0.14.2-0.20250129205522-e38052d1ecb6 h1:IzkNuMyI4vma5Q1bN/OGDnXnr1C3p1JMDFAqS+bMHRA=
github.com/hashicorp/vault/sdk v0.14.2-0.20250129205522-e38052d1ecb6/go.mod h1:fTkRhR/985pjZm9CpuJ0lnQNcrikXY2k0rPDLxUg8wM=
github.com/hashicorp/vault/sdk v0.15.0 h1:xNo1lL2shm0yE4coXNZkTV/6++2GfEh+/cCAfBjzEnA=
github.com/hashicorp/vault/sdk v0.15.0/go.mod h1:2Wj2tHIgfz0gNWgEPWBbCXFIiPrq96E8FTjPNV9J1Bc=
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
Expand Down
101 changes: 39 additions & 62 deletions plugin/path_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import (
)

const (
rootRotationJobName = "gcp-auth-root-creds"
keyAlgorithmRSA2k = "KEY_ALG_RSA_2048"
privateKeyTypeJson = "TYPE_GOOGLE_CREDENTIALS_FILE"
keyAlgorithmRSA2k = "KEY_ALG_RSA_2048"
privateKeyTypeJson = "TYPE_GOOGLE_CREDENTIALS_FILE"
)

var (
Expand Down Expand Up @@ -150,11 +149,6 @@ func (b *GcpAuthBackend) pathConfigWrite(ctx context.Context, req *logical.Reque
return nil, err
}

backupCfg, err := b.config(ctx, req.Storage)
if err != nil {
return nil, err
}

if err := cfg.Update(d); err != nil {
return nil, logical.CodedError(http.StatusBadRequest, err.Error())
}
Expand All @@ -172,6 +166,36 @@ func (b *GcpAuthBackend) pathConfigWrite(ctx context.Context, req *logical.Reque
}
}

var performedRotationManagerOpern string
if cfg.ShouldDeregisterRotationJob() {
performedRotationManagerOpern = "deregistration"
// Disable Automated Rotation and Deregister credentials if required
deregisterReq := &rotation.RotationJobDeregisterRequest{
MountPoint: req.MountPoint,
ReqPath: req.Path,
}

b.Logger().Debug("Deregistering rotation job", "mount", req.MountPoint+req.Path)
if err := b.System().DeregisterRotationJob(ctx, deregisterReq); err != nil {
return logical.ErrorResponse("error deregistering rotation job: %s", err), nil
}
} else if cfg.ShouldRegisterRotationJob() {
performedRotationManagerOpern = "registration"
// Register the rotation job if it's required.
cfgReq := &rotation.RotationJobConfigureRequest{
MountPoint: req.MountPoint,
ReqPath: req.Path,
RotationSchedule: cfg.RotationSchedule,
RotationWindow: cfg.RotationWindow,
RotationPeriod: cfg.RotationPeriod,
}

b.Logger().Debug("Registering rotation job", "mount", req.MountPoint+req.Path)
if _, err = b.System().RegisterRotationJob(ctx, cfgReq); err != nil {
return logical.ErrorResponse("error registering rotation job: %s", err), nil
}
}

// Create/update the storage entry
entry, err := logical.StorageEntryJSON("config", cfg)
if err != nil {
Expand All @@ -180,63 +204,16 @@ func (b *GcpAuthBackend) pathConfigWrite(ctx context.Context, req *logical.Reque

// Save the storage entry
if err := req.Storage.Put(ctx, entry); err != nil {
return nil, fmt.Errorf("failed to persist configuration to storage: %w", err)
}
wrappedError := err
if performedRotationManagerOpern != "" {
b.Logger().Error("write to storage failed but the rotation manager still succeeded.",
"operation", performedRotationManagerOpern, "mount", req.MountPoint, "path", req.Path)

// Disable Automated Rotation and Deregister credentials if required
if cfg.DisableAutomatedRotation {
deregisterReq := &rotation.RotationJobDeregisterRequest{
MountType: req.MountType,
ReqPath: req.Path,
wrappedError = fmt.Errorf("write to storage failed but the rotation manager still succeeded; "+
"operation=%s, mount=%s, path=%s, storageError=%s", performedRotationManagerOpern, req.MountPoint, req.Path, err)
}

b.Logger().Debug("Deregistering rotation job", "mount", req.MountPoint+req.Path)
err := b.System().DeregisterRotationJob(ctx, deregisterReq)
if err != nil {
resp := logical.ErrorResponse("error deregistering rotation job but config was successfully updated: %s", err)
resp.AddWarning("config was successfully updated despite failing to disable automated rotation")

// Attempt to back out the storage update
entry, err := logical.StorageEntryJSON("config", backupCfg)
if err != nil {
return resp, nil
}
if err := req.Storage.Put(ctx, entry); err != nil {
return resp, nil
}

return nil, nil
}
} else {
// Now that the root config is set up, register the rotation job if it's required.
if cfg.ShouldRegisterRotationJob() {
cfgReq := &rotation.RotationJobConfigureRequest{
Name: rootRotationJobName,
MountType: req.MountType,
ReqPath: req.Path,
RotationSchedule: cfg.RotationSchedule,
RotationWindow: cfg.RotationWindow,
RotationPeriod: cfg.RotationPeriod,
}

b.Logger().Debug("Registering rotation job", "mount", req.MountPoint+req.Path)
_, err = b.System().RegisterRotationJob(ctx, cfgReq)
if err != nil {
resp := logical.ErrorResponse("error registering rotation job but config was successfully updated: %s", err)
resp.AddWarning("config was successfully updated despite failing to enable automated rotation")

// Attempt to back out the storage update
entry, err := logical.StorageEntryJSON("config", backupCfg)
if err != nil {
return resp, nil
}
if err := req.Storage.Put(ctx, entry); err != nil {
return resp, nil
}

return nil, nil
}
}
return nil, wrappedError
}

// Invalidate existing client so it reads the new configuration
Expand Down

0 comments on commit 389285f

Please sign in to comment.