sigstore / root-signing-staging

Staging TUF repository for Sigstore trust root
https://tuf-repo-cdn.sigstage.dev/
Apache License 2.0
3 stars 5 forks source link

GCS publish: IAM_PERMISSION_DENIED during google-github-actions/auth #64

Closed jku closed 4 months ago

jku commented 4 months ago

This the cause of #63 which is a publish failure after the GCS publishing was first enabled: https://github.com/sigstore/root-signing-staging/actions/runs/8152961297/job/22283469446

Run google-github-actions/auth@a6e2e39c0a0331da29f7fd2c2a20a427e8d3ad1f
Created credentials file at "/home/runner/work/root-signing-staging/root-signing-staging/gha-creds-f5cc49c51c7cc2d8.json"
Error: google-github-actions/auth failed with: failed to generate Google Cloud OAuth 2.0 Access Token for tuf-gha@projectsigstore-staging.iam.gserviceaccount.com: {
  "error": {
    "code": 403,
    "message": "Permission 'iam.serviceAccounts.getAccessToken' denied on resource (or it may not exist).",
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "IAM_PERMISSION_DENIED",
        "domain": "iam.googleapis.com",
        "metadata": {
          "permission": "iam.serviceAccounts.getAccessToken"
        }
      }
    ]
  }
}
jku commented 4 months ago

Production variables look like this:

workload_identity_provider: 'projects/306323169285/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
service_account: 'github-actions@projectsigstore-staging.iam.gserviceaccount.com'

Here the values are in GitHub actions variables but otherwise used similarly:

 GCP_WORKLOAD_IDENTITY_PROVIDER: projects/306323169285/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider
 GCP_SERVICE_ACCOUNT: tuf-gha@projectsigstore-staging.iam.gserviceaccount.com

So the service account is different but it looks correct.

jku commented 4 months ago

Oh the workload identity principal is: principal://iam.googleapis.com/projects/306323169285/locations/global/workloadIdentityPools/github-actions-pool/subject/repo:sigstore/root-signing-staging:ref:refs/heads/main

I think the issue is that we're likely not running on "refs/heads/main" (although I don't know exactly where google-github-actions/auth gets that value -- I assume some field in the JWT)

Longer term we could try to change that in tuf-on-ci if that's an issue... The original idea behind this was

jku commented 4 months ago

So my assumption here is that the ref in the workload identity principal is the ref the workflow runs on: This should be "publish" at the moment (see https://github.com/theupdateframework/tuf-on-ci/blob/main/actions/online-sign/action.yml#L90) .

Options:

  1. We may be able to change the ref that the publish workflow runs on in tuf-on-ci without much actually changing: as mentioned above the real "ref-we-want-to-publish" is an input argument now anyway...
  2. We could add refs/heads/publish to approved refs in the GCP workload id principal: "publish" is a protected branch so should be just as safe as refs/heads/main

Based on discussion with @kommendorkapten I'm leaning towards option 2 if that's feasible.

haydentherapper commented 4 months ago

Option (2) is in https://github.com/sigstore/public-good-instance/pull/2118.

I would like to hear more about the design choice to publish from a different branch than main. Is the concern that main ends up with invalid metadata?

haydentherapper commented 4 months ago

Applied 2118. We can follow up later if we want to change the ref later.

jku commented 4 months ago

I would like to hear more about the design choice to publish from a different branch than main. Is the concern that main ends up with invalid metadata?

I tried to do that in a comment above:

jku commented 4 months ago

This one seems to work, debugging continues in #67