Skip to content

Commit d03fbe2

Browse files
authored
fix(login-to-gar): replace hardcoded opt dir with runner temp env var (#1001)
* Replace hardcoded /opt directory with RUNNER_TEMP Non-root users are not allowed to write in the /opt directory. Instead we leave it to github runners to create stuff in a temp directory that every user can access. Note that we are allowing zizmor to ignore a github env error. This is because the RUNNER_TEMP variable is controlled just by GITHUB_ACTIONS and is not accessible to anyone else * Reword * Remove second zizmor ref
1 parent 0e7ecbf commit d03fbe2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

actions/login-to-gar/action.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ runs:
6464
shell: bash
6565
env:
6666
DOCKER_CREDENTIAL_GCR_VERSION: "v2.1.28"
67-
run: |
67+
run: | # zizmor: ignore[github-env]
6868
set -ex
6969
7070
# Install docker-credential-gcr:
@@ -102,9 +102,11 @@ runs:
102102
103103
if [[ ! -z ${tag} ]]; then
104104
echo "Installing docker-credential-gcr @ ${tag} for ${os}/${arch}"
105-
mkdir -p /opt/docker-credential-gcr
106-
curl -fsL "https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/${tag}/docker-credential-gcr_${os}_${arch}-${tag:1}.tar.gz" | tar xzf - -C /opt/docker-credential-gcr docker-credential-gcr
107-
echo "/opt/docker-credential-gcr" >> $GITHUB_PATH
105+
mkdir -p "${RUNNER_TEMP}/docker-credential-gcr"
106+
curl -fsL "https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/${tag}/docker-credential-gcr_${os}_${arch}-${tag:1}.tar.gz" | tar xzf - -C "${RUNNER_TEMP}/docker-credential-gcr" docker-credential-gcr
107+
# Ignoring the github-env warning - docker-credential-gcr binary must be on the PATH for credHelpers in /.docker/config.json to work.
108+
# We are only adding a path to a binary that was just downloaded in RUNNER_TEMP (controlled by GitHub Actions).
109+
echo "${RUNNER_TEMP}/docker-credential-gcr" >> $GITHUB_PATH
108110
fi
109111
- name: "Configure GCP Artifact Registry"
110112
if: ${{ steps.auth_with_service_account.outputs.access_token == '' }}

0 commit comments

Comments
 (0)