Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/nomad-pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
nomad_pack_version:
required: false
type: string
default: "0.1.1"
default: "0.4.1"
description: Hashicorp Nomad Pack version to use
os:
description: "OS version to run the workflow on. If not provided, defaults to 'blacksmith-4vcpu-ubuntu-2204'"
Expand Down Expand Up @@ -192,7 +192,7 @@
--var='cluster=${{ inputs.cluster }}' \
--var='environment=${{ inputs.environment }}' \
--var='code_version=${{ inputs.code_version || steps.checkout.outputs.commit }}' \
--var-file=${{ inputs.variables_file_name }} \
--var-file=${{ inputs.variables_file_name }} --ignore-missing-vars \

Check warning

Code scanning / CodeQL

Code injection Medium

Potential code injection in
${ inputs.variables_file_name }
, which may be controlled by an external user.

Copilot Autofix

AI about 1 month ago

In general, the fix is to avoid using the GitHub expression ${{ inputs.variables_file_name }} directly inside the shell script body. Instead, assign the input to an environment variable in the env: section of the step, and then reference that variable using native shell syntax ($VAR) inside the run: block. This prevents a malicious value from being re-interpreted as part of the script, because GitHub’s expression engine substitutes only the env var value (without re-parsing), and the shell performs a simple variable expansion within a single argument.

For this specific workflow, we should update the "Validate Nomad Configurations" step. Add an environment variable, for example NOMAD_VAR_FILE, set to ${{ inputs.variables_file_name }} in the step’s env: block. Then, in the run: script, replace --var-file=${{ inputs.variables_file_name }} with --var-file="$NOMAD_VAR_FILE". This preserves the existing behavior (the same value is passed to nomad-pack), but removes the direct GitHub expression from the shell script, aligning with GitHub’s secure usage guidance. No new imports or external tools are needed; this is entirely a YAML and shell change within .github/workflows/nomad-pack.yml.

Suggested changeset 1
.github/workflows/nomad-pack.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/nomad-pack.yml b/.github/workflows/nomad-pack.yml
--- a/.github/workflows/nomad-pack.yml
+++ b/.github/workflows/nomad-pack.yml
@@ -185,6 +185,7 @@
           NOMAD_VAR_task_image: ${{ inputs.image_name }}
           NOMAD_VAR_cluster: ${{ inputs.cluster }}
           NOMAD_VAR_environment: ${{ inputs.environment }}
+          NOMAD_VAR_FILE: ${{ inputs.variables_file_name }}
         run: |
           nomad-pack render ${{ inputs.pack_name }} \
           --var='task_image=${{ inputs.image_name }}' \
@@ -192,7 +193,7 @@
           --var='cluster=${{ inputs.cluster }}' \
           --var='environment=${{ inputs.environment }}' \
           --var='code_version=${{ inputs.code_version || steps.checkout.outputs.commit }}' \
-          --var-file=${{ inputs.variables_file_name }} --ignore-missing-vars  \
+          --var-file="$NOMAD_VAR_FILE" --ignore-missing-vars  \
           --name=${{ inputs.name }} --registry=remerge-pack \
           | tail -n +2 | nomad job validate -
 
EOF
@@ -185,6 +185,7 @@
NOMAD_VAR_task_image: ${{ inputs.image_name }}
NOMAD_VAR_cluster: ${{ inputs.cluster }}
NOMAD_VAR_environment: ${{ inputs.environment }}
NOMAD_VAR_FILE: ${{ inputs.variables_file_name }}
run: |
nomad-pack render ${{ inputs.pack_name }} \
--var='task_image=${{ inputs.image_name }}' \
@@ -192,7 +193,7 @@
--var='cluster=${{ inputs.cluster }}' \
--var='environment=${{ inputs.environment }}' \
--var='code_version=${{ inputs.code_version || steps.checkout.outputs.commit }}' \
--var-file=${{ inputs.variables_file_name }} --ignore-missing-vars \
--var-file="$NOMAD_VAR_FILE" --ignore-missing-vars \
--name=${{ inputs.name }} --registry=remerge-pack \
| tail -n +2 | nomad job validate -

Copilot is powered by AI and may make mistakes. Always verify output.
--name=${{ inputs.name }} --registry=remerge-pack \
| tail -n +2 | nomad job validate -

Expand All @@ -211,7 +211,7 @@
--var='cluster=${{ inputs.cluster }}' \
--var='environment=${{ inputs.environment }}' \
--var='code_version=${{ inputs.code_version || steps.checkout.outputs.commit }}' \
--var-file=${{ inputs.variables_file_name }} \
--var-file=${{ inputs.variables_file_name }} --ignore-missing-vars \

Check warning

Code scanning / CodeQL

Code injection Medium

Potential code injection in
${ inputs.variables_file_name }
, which may be controlled by an external user.

Copilot Autofix

AI about 1 month ago

In general, to fix this type of problem, any user‑controlled values used in run: scripts should not be interpolated directly using GitHub expression syntax within the script body. Instead, assign them to environment variables at the step level using ${{ ... }} and then reference them inside the script using the shell’s native variable expansion (e.g., $VAR), which avoids the templating engine rewriting and allows safe quoting and escaping.

For this concrete issue, we should stop using ${{ inputs.variables_file_name }} inside the run: block and instead expose it via an environment variable such as VARIABLES_FILE_NAME. Then, update both the Validate Nomad Configurations and Run Nomad Pack Plan steps to use "${VARIABLES_FILE_NAME}" in the --var-file argument. To keep behavior unchanged, we will:

  • Add VARIABLES_FILE_NAME: ${{ inputs.variables_file_name }} to the env: section of both steps.
  • Replace --var-file=${{ inputs.variables_file_name }} with --var-file="$VARIABLES_FILE_NAME" in the run: scripts.

This preserves the same effective argument content while removing direct expression interpolation from the shell command and allowing proper shell quoting.


Suggested changeset 1
.github/workflows/nomad-pack.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/nomad-pack.yml b/.github/workflows/nomad-pack.yml
--- a/.github/workflows/nomad-pack.yml
+++ b/.github/workflows/nomad-pack.yml
@@ -185,6 +185,7 @@
           NOMAD_VAR_task_image: ${{ inputs.image_name }}
           NOMAD_VAR_cluster: ${{ inputs.cluster }}
           NOMAD_VAR_environment: ${{ inputs.environment }}
+          VARIABLES_FILE_NAME: ${{ inputs.variables_file_name }}
         run: |
           nomad-pack render ${{ inputs.pack_name }} \
           --var='task_image=${{ inputs.image_name }}' \
@@ -192,7 +193,7 @@
           --var='cluster=${{ inputs.cluster }}' \
           --var='environment=${{ inputs.environment }}' \
           --var='code_version=${{ inputs.code_version || steps.checkout.outputs.commit }}' \
-          --var-file=${{ inputs.variables_file_name }} --ignore-missing-vars  \
+          --var-file="$VARIABLES_FILE_NAME" --ignore-missing-vars  \
           --name=${{ inputs.name }} --registry=remerge-pack \
           | tail -n +2 | nomad job validate -
 
@@ -202,6 +203,7 @@
         env:
           NOMAD_TOKEN: ${{ env.NOMAD_TOKEN }}
           NOMAD_ADDR: ${{ inputs.api_url }}
+          VARIABLES_FILE_NAME: ${{ inputs.variables_file_name }}
         # continue on error; default is `bash -e {0}`
         shell: bash {0}
         run: |
@@ -211,7 +213,7 @@
           --var='cluster=${{ inputs.cluster }}' \
           --var='environment=${{ inputs.environment }}' \
           --var='code_version=${{ inputs.code_version || steps.checkout.outputs.commit }}' \
-          --var-file=${{ inputs.variables_file_name }} --ignore-missing-vars  \
+          --var-file="$VARIABLES_FILE_NAME" --ignore-missing-vars  \
           --name=${{ inputs.name }} --registry=remerge-pack  \
           --exit-code-makes-changes=0)
 
EOF
@@ -185,6 +185,7 @@
NOMAD_VAR_task_image: ${{ inputs.image_name }}
NOMAD_VAR_cluster: ${{ inputs.cluster }}
NOMAD_VAR_environment: ${{ inputs.environment }}
VARIABLES_FILE_NAME: ${{ inputs.variables_file_name }}
run: |
nomad-pack render ${{ inputs.pack_name }} \
--var='task_image=${{ inputs.image_name }}' \
@@ -192,7 +193,7 @@
--var='cluster=${{ inputs.cluster }}' \
--var='environment=${{ inputs.environment }}' \
--var='code_version=${{ inputs.code_version || steps.checkout.outputs.commit }}' \
--var-file=${{ inputs.variables_file_name }} --ignore-missing-vars \
--var-file="$VARIABLES_FILE_NAME" --ignore-missing-vars \
--name=${{ inputs.name }} --registry=remerge-pack \
| tail -n +2 | nomad job validate -

@@ -202,6 +203,7 @@
env:
NOMAD_TOKEN: ${{ env.NOMAD_TOKEN }}
NOMAD_ADDR: ${{ inputs.api_url }}
VARIABLES_FILE_NAME: ${{ inputs.variables_file_name }}
# continue on error; default is `bash -e {0}`
shell: bash {0}
run: |
@@ -211,7 +213,7 @@
--var='cluster=${{ inputs.cluster }}' \
--var='environment=${{ inputs.environment }}' \
--var='code_version=${{ inputs.code_version || steps.checkout.outputs.commit }}' \
--var-file=${{ inputs.variables_file_name }} --ignore-missing-vars \
--var-file="$VARIABLES_FILE_NAME" --ignore-missing-vars \
--name=${{ inputs.name }} --registry=remerge-pack \
--exit-code-makes-changes=0)

Copilot is powered by AI and may make mistakes. Always verify output.
--name=${{ inputs.name }} --registry=remerge-pack \
--exit-code-makes-changes=0)

Expand Down