Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using delegated IAM with Pod Workload Identity #425

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
19 changes: 17 additions & 2 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,25 @@ func (c *Client) Token(ctx context.Context, cfg *config.MountConfig) (*oauth2.To
return idBindToken, nil
}

gcpSAResp, err := c.IAMClient.GenerateAccessToken(ctx, &credentialspb.GenerateAccessTokenRequest{
req := &credentialspb.GenerateAccessTokenRequest{
Name: fmt.Sprintf("projects/-/serviceAccounts/%s", gcpSA),
Scope: secretmanager.DefaultAuthScopes(),
}, gax.WithGRPCOptions(grpc.PerRPCCredentials(oauth.TokenSource{TokenSource: oauth2.StaticTokenSource(idBindToken)})))
}

if gcpSADelegates, ok := saResp.Annotations["iam.gke.io/gcp-service-account-delegates"]; ok {
var delegates []string
if err := json.Unmarshal([]byte(gcpSADelegates), &delegates); err != nil {
return nil, fmt.Errorf("unable to parse delegates annotation on SA: %w", err)
}

klog.V(5).InfoS("matched service account delegates", "service_account_delegates", delegates)

for _, delegate := range delegates {
req.Delegates = append(req.Delegates, fmt.Sprintf("projects/-/serviceAccounts/%s", delegate))
}
}

gcpSAResp, err := c.IAMClient.GenerateAccessToken(ctx, req, gax.WithGRPCOptions(grpc.PerRPCCredentials(oauth.TokenSource{TokenSource: oauth2.StaticTokenSource(idBindToken)})))
if err != nil {
return nil, fmt.Errorf("unable to fetch gcp service account token: %w", err)
}
Expand Down
14 changes: 14 additions & 0 deletions docs/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ a Google authentication token using the Kubernetes Service Account [Workload
Identity](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity)
annotations.

The `iam.gke.io/gcp-service-account-delegates` annotation can be used to [impersonate a chain of service accounts](https://cloud.google.com/iam/docs/create-short-lived-credentials-delegated) to be able to authenitcate as the service account in `iam.gke.io/gcp-service-account`.

```yaml
apiVersion: v1
kind: ServiceAccount
metadata:
annotations:
iam.gke.io/gcp-service-account: [email protected]
iam.gke.io/gcp-service-account-delegates: '["[email protected]"]'
...
```

In this case, the pod must have the permissions to authenticate as `[email protected]` and that service account must have the `roles/iam.serviceAccountTokenCreator` role granted on `[email protected]`.

## `provider-adc` - GCP Provider Identity

In the `SecretProviderClass` you can set
Expand Down