Skip to content

Commit 324ff12

Browse files
feat: Add directory input to Maven builder (#2538)
Adds another `input` for the Maven builder to allow the user to specify the project directory. The current problem this solves is to make slsa-framework/example-package#253 work. This was suggested by @laurentsimon in slsa-framework/example-package#253 (comment) --------- Signed-off-by: AdamKorcz <[email protected]> Signed-off-by: AdamKorcz <[email protected]> Signed-off-by: laurentsimon <[email protected]> Co-authored-by: laurentsimon <[email protected]>
1 parent 54473c2 commit 324ff12

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

.github/workflows/builder_maven_slsa3.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ on:
2727
required: false
2828
default: 17
2929
type: number
30+
directory:
31+
description: "Sub-directory to launch the build from. Must be under the workspace. Relative from the root of the file directory when invoking the builder."
32+
required: false
33+
type: string
34+
default: "."
3035

3136
outputs:
3237
provenance-name:

internal/builders/maven/action.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,41 @@ runs:
6868
shell: bash
6969
env:
7070
SLSA_OUTPUTS_ARTIFACTS_FILE: ${{ inputs.slsa-layout-file }}
71+
UNTRUSTED_PROJECT_ROOT: ${{ fromJson(inputs.slsa-workflow-inputs).directory }}
7172
run: |
73+
# Ensure no directory traversal.
74+
# NOTE: the actions/download-artifact Action only creates files
75+
# in the workspace directory, but this may change in the future.
76+
# TODO(#1893): Consolidate directory traversal checks
77+
validate_path() {
78+
untrusted_path=$1
79+
resolved_dir=$(readlink -m "$untrusted_path")
80+
wd=$(readlink -m "${GITHUB_WORKSPACE}")
81+
if [[ "${resolved_dir}" != "${wd}"/* ]] && [[ "${resolved_dir}" != "${wd}" ]]; then
82+
if [[ "${RUNNER_TEMP}" != "" ]] && [[ "${resolved_dir}" != "${RUNNER_TEMP}"/* ]] && [[ "${resolved_dir}" != "${RUNNER_TEMP}" ]]; then
83+
if [[ "${resolved_dir}" != /tmp/* ]] && [[ "${resolved_dir}" != "/tmp" ]]; then
84+
echo "Path is not in the workspace or temp directory: $untrusted_path"
85+
exit 1
86+
fi
87+
fi
88+
fi
89+
}
90+
91+
validate_path "${UNTRUSTED_PROJECT_ROOT}"
92+
93+
# remove trailing "/"'s with `realpath`
94+
project_root=$(realpath "${UNTRUSTED_PROJECT_ROOT}")
95+
7296
mv ./__BUILDER_CHECKOUT_DIR__ ../__BUILDER_CHECKOUT_DIR__ \
7397
&& cd ../__BUILDER_CHECKOUT_DIR__/actions/maven/publish/slsa-hashing-plugin \
7498
&& mvn clean install \
7599
&& cd - \
100+
&& cd "${project_root}" \
76101
&& mvn package -Drun.hash.jarfile=true
102+
# NOTE: SLSA_OUTPUTS_ARTIFACTS_FILE is a relative path and the project_root may
103+
# not be in GITHUB_WORKSPACE, so we need to move the file.
104+
mv $(dirname "${SLSA_OUTPUTS_ARTIFACTS_FILE}") "${GITHUB_WORKSPACE}/../"
105+
mv target "${GITHUB_WORKSPACE}/"
77106
- name: Upload target
78107
id: upload-target
79108
uses: slsa-framework/slsa-github-generator/.github/actions/secure-upload-folder@main

0 commit comments

Comments
 (0)