Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions secrets/gcp/path_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,25 @@ func (b *backend) pathConfigRead(ctx context.Context, req *logical.Request, data
return nil, nil
}

configData := map[string]interface{}{
"ttl": int64(cfg.TTL / time.Second),
"max_ttl": int64(cfg.MaxTTL / time.Second),
"service_account_email": cfg.ServiceAccountEmail,
resp := &logical.Response{
Data: map[string]interface{}{
"ttl": int64(cfg.TTL / time.Second),
"max_ttl": int64(cfg.MaxTTL / time.Second),
"service_account_email": cfg.ServiceAccountEmail,
"private_key_id": "",
},
}

creds, err := gcputil.Credentials(cfg.CredentialsRaw)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning the Private Key ID will only work when the user passes the service account credentials in the credentials settings. From my experience it is much more common to use the default credentials passed to an application running in GCP as described in our docs.

I'd prefer it if this only returns an error if cfg.CredentialsRaw is not empty. Also I think this should try to parse the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the key specified in there if it is not empty.

resp.Warnings = []string{
fmt.Sprintf("Failed to parse key private key ID: %v", err),
Copy link

Copilot AI Jul 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message contains a grammatical error. It should be "Failed to parse private key ID" instead of "Failed to parse key private key ID".

Suggested change
fmt.Sprintf("Failed to parse key private key ID: %v", err),
fmt.Sprintf("Failed to parse private key ID: %v", err),

Copilot uses AI. Check for mistakes.
}
} else {
resp.Data["private_key_id"] = creds.PrivateKeyId
}

return &logical.Response{
Data: configData,
}, nil
return resp, nil
}

func (b *backend) pathConfigWrite(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
Expand Down
1 change: 1 addition & 0 deletions secrets/gcp/path_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestConfig(t *testing.T) {
"ttl": int64(0),
"max_ttl": int64(0),
"service_account_email": "",
"private_key_id": "privateKey123",
}

testConfigRead(t, b, reqStorage, expected)
Expand Down
9 changes: 8 additions & 1 deletion secrets/gcp/path_role_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package gcp
import (
"context"
"fmt"
"path"

"github.com/hashicorp/errwrap"
"github.com/openbao/openbao-plugins/secrets/gcp/util"
Expand Down Expand Up @@ -179,6 +180,7 @@ func (b *backend) pathRoleSetRead(ctx context.Context, req *logical.Request, d *

if rs.TokenGen != nil && rs.SecretType == SecretTypeAccessToken {
data["token_scopes"] = rs.TokenGen.Scopes
data["private_key_id"] = path.Base(rs.TokenGen.KeyName)
}

return &logical.Response{
Expand Down Expand Up @@ -419,7 +421,12 @@ func (b *backend) pathRoleSetRotateKey(ctx context.Context, req *logical.Request
if warn != "" {
return &logical.Response{Warnings: []string{warn}}, nil
}
return nil, nil

return &logical.Response{
Data: map[string]interface{}{
"private_key_id": path.Base(rs.TokenGen.KeyName),
},
}, nil
}

func getRoleSet(name string, ctx context.Context, s logical.Storage) (*RoleSet, error) {
Expand Down
2 changes: 2 additions & 0 deletions secrets/gcp/path_static_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"path"

"github.com/hashicorp/errwrap"
"github.com/openbao/openbao/sdk/v2/framework"
Expand Down Expand Up @@ -131,6 +132,7 @@ func (b *backend) pathStaticAccountRead(ctx context.Context, req *logical.Reques
}
if acct.TokenGen != nil && acct.SecretType == SecretTypeAccessToken {
data["token_scopes"] = acct.TokenGen.Scopes
data["private_key_id"] = path.Base(acct.TokenGen.KeyName)
}

return &logical.Response{
Expand Down
8 changes: 7 additions & 1 deletion secrets/gcp/path_static_account_rotate_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package gcp
import (
"context"
"fmt"
"path"

"github.com/openbao/openbao/sdk/v2/framework"
"github.com/openbao/openbao/sdk/v2/logical"
Expand Down Expand Up @@ -108,7 +109,12 @@ func (b *backend) pathStaticAccountRotateKey(ctx context.Context, req *logical.R
}
b.tryDeleteWALs(ctx, req.Storage, oldWalId)
}
return nil, nil

return &logical.Response{
Data: map[string]interface{}{
"private_key_id": path.Base(acct.TokenGen.KeyName),
},
}, nil
}

const pathStaticAccountRotateKeyHelpSyn = `Rotate the key used to generate access tokens for a static account`
Expand Down