Skip to content

Commit

Permalink
ensure GCP CredsReq has a list of ServiceAccounts
Browse files Browse the repository at this point in the history
When setting up workload-identity on GCP, require that there is at least
one entry in .spec.serviceAccountNames so that we can properly restrict
which k8s ServiceAccounts can use the created GCP ServiceAccount.
  • Loading branch information
Joel Diaz committed Jan 4, 2022
1 parent 2e091dd commit 6ebbcf2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/cmd/provisioning/gcp/create_service_accounts.go
Expand Up @@ -105,6 +105,12 @@ func processCredentialsRequests(ctx context.Context, client gcp.Client, credReqs
}

func createServiceAccount(ctx context.Context, client gcp.Client, name string, credReq *credreqv1.CredentialsRequest, serviceAccountNum int, workloadIdentityPool, workloadIdentityProvider, project, targetDir string, generateOnly bool) (string, error) {
// The credReq must have a non zero-length list of ServiceAccountNames
// that can be used to restrict which k8s ServiceAccounts can use the GCP ServiceAccount.
if len(credReq.Spec.ServiceAccountNames) == 0 {
return "", fmt.Errorf("CredentialsRequest %s/%s must provide at least one ServiceAccount in .spec.ServiceAccountNames", credReq.Namespace, credReq.Name)
}

// The service account id has a max length of 30 chars
// split it into 12-11-5 where the resuling string becomes:
// <infraName chopped to 12 chars>-<crName chopped to 11 chars>-<random 5 chars>
Expand Down

0 comments on commit 6ebbcf2

Please sign in to comment.