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

Save application default credentials (ADC) #383

Closed
mering opened this issue Jan 17, 2024 · 4 comments
Closed

Save application default credentials (ADC) #383

mering opened this issue Jan 17, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@mering
Copy link

mering commented Jan 17, 2024

TL;DR

Save ADC at ${HOME}/.config/gcloud/application_default_credentials.json instead of workspace.

Detailed design

Instead of saving the credentials file in the workspace which is prone to be overwritten for example by the checkout action, save it to the well-known location at ${HOME}/.config/gcloud/application_default_credentials.json.

We currently use the following step (which also deals with multi-line secrets correctly):

- name: Create service account credentials files
  env:
    ROBOT_JSON_KEY: ${{ secrets.ROBOT_JSON_KEY }}
  run: |
    mkdir -p "${HOME}/.config/gcloud"
    echo "${ROBOT_JSON_KEY}" > "${HOME}/.config/gcloud/application_default_credentials.json"
    gcloud auth activate-service-account --key-file "${HOME}/.config/gcloud/application_default_credentials.json"

We use it mainly with Bazel RBE via bazel --google_default_credentials=true.

It would be nice if we could replace this step by using google-github-actions/auth action instead.

Additional information

No response

@mering mering added the enhancement New feature or request label Jan 17, 2024
Copy link

Hi there @mering 👋!

Thank you for opening an issue. Our team will triage this as soon as we can. Please take a moment to review the troubleshooting steps which lists common error messages and their resolution steps.

@sethvargo
Copy link
Member

Hi @mering - thank you for opening an issue.

The auth action exports the GOOGLE_APPLICATION_CREDENTIALS environment variable, which all well-behaved Google Cloud client libraries respect.

As for why the credentials are stored in the workspace, it's the workspace is one of the only places that is reliably shared with Docker-based actions. We've explored environment variables and alternative file paths, but they all come with trade-offs, particularly around self-hosted runner threat models. Last time we tried to "fix" this, we accidentally broke all Docker-based actions.

For Service Account Key JSON, you could theoretically not use this entire action and just write the JSON file to disk and set $GOOGLE_APPLICATION_CREDENTIALS.

It would be nice if we could replace this step by using google-github-actions/auth action instead.

Have you tried? It looks like --google-default-credentials should "just work".

See also: #109, #123, #134, #212, #264, #315, #316, #333

@mering
Copy link
Author

mering commented Jan 17, 2024

Hi @sethvargo, thanks for your explanation.

As we do sometimes overwrite our workspace or publish packages via wildcards, extra care would need to be taken in our setup when the key is stored within the workspace.

While do currently do use only the SA JSON key, we plan to migrate towards WIF in the future so it might be a good intermediate step.

Maybe I will try to set credentials_file_path to some location outside of the workspace and see if this just works.

@sethvargo
Copy link
Member

Hi @mering - credentials_file_path is an output, not an input.

You could move the file somewhere else, but you'd need to update all the associated environment variables to the new path.

As we do sometimes overwrite our workspace or publish packages via wildcards, extra care would need to be taken in our setup when the key is stored within the workspace.

There are instructions in the TROUBLESHOOTING guide for excluding the credentials from a git push or docker build, for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants