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

Authenticate with Google Workload Identity Federation / OpenID Connect #146

Open
rich-j opened this issue Sep 25, 2022 · 4 comments
Open
Labels
enhancement New feature or request

Comments

@rich-j
Copy link

rich-j commented Sep 25, 2022

Please support authenticating with the Google recommended Workload Identity Federation instead of using a Cloud Service Account Key JSON secret text/file. Github supports it as OpenID Connect

Google has created a Github Action auth that establishes the authentication session with Google Cloud. We are now using this for our deployments to Google Cloud using the action setup-gcloud. It works great - no more secrets needed.

@StuClift
Copy link

This is already supported as the auth writes the credentials file by default:

- id: auth
  uses: google-github-actions/auth@v0
  with:
    workload_identity_provider: <provider>
    service_account: <service-account>
- uses: r0adkll/upload-google-play@v1
  with:
    serviceAccountJson: ${{ steps.auth.outputs.credentials_file_path }}

@boswelja
Copy link
Collaborator

I wonder if we can auto-detect when this is used? If not, there's probably no changes needed

@rich-j
Copy link
Author

rich-j commented Oct 18, 2022

To detect if Google auth is set up, check for and use the env var process.env.GOOGLE_GHA_CREDS_PATH.

More detail on the above check - auth documentation states that by default several environment variables are exported by default including GOOGLE_GHA_CREDS_PATH. Looking at Google's implementation of setup-gcloud their main typescript file includes the use of the above exported env var: if (serviceAccountKey || process.env.GOOGLE_GHA_CREDS_PATH) {.

At a minimum it would be nice to have the above snippet from @StuClift documented.

@boswelja boswelja added the enhancement New feature or request label Oct 24, 2022
@boswelja boswelja added this to the 1.0.20 milestone Oct 24, 2022
@boswelja boswelja removed this from the 1.0.20 milestone Feb 10, 2023
@kohtala
Copy link

kohtala commented May 17, 2023

The google-github-actions/auth seems to set three environment variables with the credential file path: CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE, GOOGLE_APPLICATION_CREDENTIALS and GOOGLE_GHA_CREDS_PATH.

r0adkll/upload-google-play seems to set GOOGLE_APPLICATION_CREDENTIALS. This environment variable is used by the @googleapis/androidpublisher via the google-auth-library as the default credential.

Reading on the documentation and source, I think instead of setting the GOOGLE_APPLICATION_CREDENTIALS environment variable, for serviceAccountJsonPlainText the runUpload could pass the JSON in credentials option to GoogleAuth. For serviceAccountJson it could pass keyFilename. If neither is defined, I think it would be ok to just not pass either and catch the Error from getClient() if it finds no default credentials.

That should support the google-github-actions/auth as well as any gcloud cli logins. Perhaps someone could run the GitHub runner on Google Cloud, so it might have also attached service accounts which would get supported.

boswelja pushed a commit that referenced this issue Jun 30, 2024
Fixes #224:
- Don't recommend giving "owner" to the service account, in fact no permissions are necessary.
- Show how to use workload identity instead of storing the JSON key in the project (credit to @StuClift in #146).
- Clean up formatting.
- Link relevant docs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants