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

fix: composite action input pollution #2348

Merged
merged 6 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions pkg/runner/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ func runPostStep(step actionStep) common.Executor {
case model.ActionRunsUsingNode12, model.ActionRunsUsingNode16, model.ActionRunsUsingNode20:

populateEnvsFromSavedState(step.getEnv(), step, rc)
populateEnvsFromInput(ctx, step.getEnv(), step.getActionModel(), rc)
Copy link
Contributor Author

@ChristopherHX ChristopherHX Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleaning up env caused missing default values in post steps


containerArgs := []string{"node", path.Join(containerActionDir, action.Runs.Post)}
logger.Debugf("executing remote job container: %s", containerArgs)
Expand Down
2 changes: 2 additions & 0 deletions pkg/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ func TestRunEvent(t *testing.T) {
// Uses
{workdir, "uses-composite", "push", "", platforms, secrets},
{workdir, "uses-composite-with-error", "push", "Job 'failing-composite-action' failed", platforms, secrets},
{workdir, "uses-composite-check-for-input-collision", "push", "", platforms, secrets},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test only passes via changes made here

{workdir, "uses-composite-check-for-input-shadowing", "push", "", platforms, secrets},
{workdir, "uses-nested-composite", "push", "", platforms, secrets},
{workdir, "remote-action-composite-js-pre-with-defaults", "push", "", platforms, secrets},
{workdir, "remote-action-composite-action-ref", "push", "", platforms, secrets},
Expand Down
10 changes: 10 additions & 0 deletions pkg/runner/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ func mergeEnv(ctx context.Context, step step) {
}

rc.withGithubEnv(ctx, step.getGithubContext(ctx), *env)

if step.getStepModel().Uses != "" {
// prevent uses action input pollution of unset parameters, skip this for run steps
// due to design flaw
for key := range *env {
if strings.Contains(key, "INPUT_") {
delete(*env, key)
}
}
}
}

func isStepEnabled(ctx context.Context, expr string, step step, stage stepStage) (bool, error) {
Expand Down
1 change: 1 addition & 0 deletions pkg/runner/step_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func TestSetupEnv(t *testing.T) {
JobContainer: cm,
}
step := &model.Step{
Uses: "./",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See if step.getStepModel().Uses != "" { check above, empty with doesn't mean it's a run step

With: map[string]string{
"STEP_WITH": "with-value",
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Action with pre and post"
description: "Action with pre and post"

inputs:
step:
description: "step"
required: true
cache:
required: false
default: false

runs:
using: "node16"
pre: pre.js
main: main.js
post: post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { appendFileSync } = require('fs');
const step = process.env['INPUT_STEP'];
appendFileSync(process.env['GITHUB_ENV'], `TEST=${step}`, { encoding:'utf-8' })

var cache = process.env['INPUT_CACHE']
try {
var cache = JSON.parse(cache)
} catch {

}
if(typeof cache !== 'boolean') {
console.log("Input Polluted boolean true/false expected, got " + cache)
process.exit(1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { appendFileSync } = require('fs');
const step = process.env['INPUT_STEP'];
appendFileSync(process.env['GITHUB_ENV'], `TEST=${step}-post`, { encoding:'utf-8' })

var cache = process.env['INPUT_CACHE']
try {
var cache = JSON.parse(cache)
} catch {

}
if(typeof cache !== 'boolean') {
console.log("Input Polluted boolean true/false expected, got " + cache)
process.exit(1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
console.log('pre');

var cache = process.env['INPUT_CACHE']
try {
var cache = JSON.parse(cache)
} catch {

}
if(typeof cache !== 'boolean') {
console.log("Input Polluted boolean true/false expected, got " + cache)
process.exit(1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Test Composite Action"
description: "Test action uses composite"

inputs:
cache:
default: none

runs:
using: "composite"
steps:
- uses: ./uses-composite-check-for-input-collision/action-with-pre-and-post
with:
step: step1
- uses: ./uses-composite-check-for-input-collision/action-with-pre-and-post
with:
step: step2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: uses-composite-with-pre-and-post-steps
on: push

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo -n "STEP_OUTPUT_TEST=empty" >> $GITHUB_ENV
- uses: ./uses-composite-check-for-input-collision/composite_action
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Action with pre and post"
description: "Action with pre and post"

inputs:
step:
description: "step"
required: true
cache:
required: false
default: false

runs:
using: "node16"
pre: pre.js
main: main.js
post: post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { appendFileSync } = require('fs');
const step = process.env['INPUT_STEP'];
appendFileSync(process.env['GITHUB_ENV'], `TEST=${step}`, { encoding:'utf-8' })

var cache = process.env['INPUT_CACHE']
try {
var cache = JSON.parse(cache)
} catch {

}
if(typeof cache !== 'boolean') {
console.log("Input Polluted boolean true/false expected, got " + cache)
process.exit(1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { appendFileSync } = require('fs');
const step = process.env['INPUT_STEP'];
appendFileSync(process.env['GITHUB_ENV'], `TEST=${step}-post`, { encoding:'utf-8' })

var cache = process.env['INPUT_CACHE']
try {
var cache = JSON.parse(cache)
} catch {

}
if(typeof cache !== 'boolean') {
console.log("Input Polluted boolean true/false expected, got " + cache)
process.exit(1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
console.log('pre');

var cache = process.env['INPUT_CACHE']
try {
var cache = JSON.parse(cache)
} catch {

}
if(typeof cache !== 'boolean') {
console.log("Input Polluted boolean true/false expected, got " + cache)
process.exit(1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Test Composite Action"
description: "Test action uses composite"

inputs:
cache:
default: true

runs:
using: "composite"
steps:
- uses: ./uses-composite-check-for-input-shadowing/action-with-pre-and-post
with:
step: step1
cache: ${{ inputs.cache || 'none' }}
- uses: ./uses-composite-check-for-input-shadowing/action-with-pre-and-post
with:
step: step2
cache: ${{ inputs.cache || 'none' }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: uses-composite-with-pre-and-post-steps
on: push

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo -n "STEP_OUTPUT_TEST=empty" >> $GITHUB_ENV
- uses: ./uses-composite-check-for-input-shadowing/composite_action
# with:
# cache: other
Loading