Skip to content

ci: pass the manual image tag through env, as the release workflow does - #1688

Open
Dhairya-007 wants to merge 1 commit into
apache:mainfrom
Dhairya-007:ci/manual-image-tag-via-env
Open

Dhairya-007 wants to merge 1 commit into
apache:mainfrom
Dhairya-007:ci/manual-image-tag-via-env

Conversation

@Dhairya-007

Copy link
Copy Markdown

What problem does this PR solve?

.github/workflows/build-image-for-manual.yml interpolates ${{ inputs.tag_name }} directly into its run: block, in two places:

    - name: Build and push
      run: |
        docker buildx build \
          ...
          --tag "apache/answer:${{ inputs.tag_name }}" \
          --label org.opencontainers.image.version="${{ inputs.tag_name }}" \

GitHub substitutes ${{ }} expressions textually, before bash parses the script, so the value becomes part of the command rather than an argument to it. The surrounding double quotes don't help, because they are already in the text by the time the value is pasted in. A tag_name containing shell metacharacters therefore executes in a job that holds the DockerHub credentials.

The fix is already in the repo. The sibling build-image-for-release.yml does the same build and gets this right:

    - name: Build and push
      env:
        IMAGE_TAG: ${{ github.ref_name }}
      run: |
        ...
          --tag "apache/answer:${IMAGE_TAG#v}" \
          --label org.opencontainers.image.version="${IMAGE_TAG#v}" \

So this PR just brings the manual workflow in line with the release one. Bound through env:, the value arrives as an environment variable and the existing quoting makes it inert.

On severity, to be straight about it: workflow_dispatch can only be triggered by someone who already has write access, so this is not a hole open to the public, and I would not call it urgent. It is hardening — but the correct pattern costs nothing and the repo already uses it two files over. build-image-for-manual.yml is the only workflow in the repo with this pattern; the other four image/binary workflows are already clean.

What I deliberately did not change

The release workflow strips a leading v (${IMAGE_TAG#v}) because its value is a git ref like v1.2.3. Here the value is a tag name the operator types into the dispatch form, so I kept it as ${IMAGE_TAG}. Adding #v would change which image tag gets published, which is a behaviour change rather than a hardening one.

I also left the docker login line alone. It interpolates ${{ secrets.* }}, which GitHub treats as trusted and zizmor does not flag, and piping the token via --password-stdin is already the right shape — so changing it would be churn on a line this PR has no reason to touch.

Verification

$ zizmor --min-severity high --persona regular .github/workflows/build-image-for-manual.yml
No findings to report. Good job! (2 ignored, 5 suppressed)

$ actionlint .github/workflows/build-image-for-manual.yml
  (clean)

Before the change, zizmor reported two error[template-injection] findings on lines 56 and 60 of this file, both at high confidence.

The built image tag is unchanged: apache/answer:<tag_name>, exactly as before.


Claude Code assisted in writing this patch; I checked the sibling workflows for the same pattern and confirmed the before/after with the tools above.

`build-image-for-manual.yml` interpolates `${{ inputs.tag_name }}` straight
into its `run:` block, twice. GitHub substitutes expressions textually before
bash sees the script, so the value is spliced into the command rather than
passed as an argument -- a tag containing shell metacharacters runs as code
in the job, which holds the DockerHub credentials.

The sibling `build-image-for-release.yml` already handles this correctly:

    - name: Build and push
      env:
        IMAGE_TAG: ${{ github.ref_name }}
      run: |
        ...
          --tag "apache/answer:${IMAGE_TAG#v}" \

So this only brings the manual workflow in line with the release one. Values
bound through `env:` reach the script as environment variables, where the
existing quoting makes them inert.

Deliberately not stripping a leading `v` the way the release workflow does:
there the value is a git ref (`v1.2.3`), here it is a tag name the operator
types, and changing that would alter which image gets published.

Triggering `workflow_dispatch` already requires write access, so this is
hardening rather than a hole open to the public -- but the pattern is free,
and zizmor reports the file clean afterwards.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant