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

feat: Add directory input to Maven builder #2538

Merged
merged 13 commits into from
Aug 15, 2023
5 changes: 5 additions & 0 deletions .github/workflows/builder_maven_slsa3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ on:
required: false
default: 17
type: number
directory:
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."
required: false
type: string
default: "."

outputs:
provenance-name:
Expand Down
29 changes: 29 additions & 0 deletions internal/builders/maven/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,41 @@ runs:
shell: bash
env:
SLSA_OUTPUTS_ARTIFACTS_FILE: ${{ inputs.slsa-layout-file }}
UNTRUSTED_PROJECT_ROOT: ${{ fromJson(inputs.slsa-workflow-inputs).directory }}
run: |
# Ensure no directory traversal.
# NOTE: the actions/download-artifact Action only creates files
# in the workspace directory, but this may change in the future.
# TODO(#1893): Consolidate directory traversal checks
validate_path() {
untrusted_path=$1
resolved_dir=$(readlink -m "$untrusted_path")
wd=$(readlink -m "${GITHUB_WORKSPACE}")
if [[ "${resolved_dir}" != "${wd}"/* ]] && [[ "${resolved_dir}" != "${wd}" ]]; then
if [[ "${RUNNER_TEMP}" != "" ]] && [[ "${resolved_dir}" != "${RUNNER_TEMP}"/* ]] && [[ "${resolved_dir}" != "${RUNNER_TEMP}" ]]; then
if [[ "${resolved_dir}" != /tmp/* ]] && [[ "${resolved_dir}" != "/tmp" ]]; then
echo "Path is not in the workspace or temp directory: $untrusted_path"
exit 1
fi
fi
fi
}

validate_path "${UNTRUSTED_PROJECT_ROOT}"
project_root=$(realpath "${UNTRUSTED_PROJECT_ROOT}")
AdamKorcz marked this conversation as resolved.
Show resolved Hide resolved

# gh_root_dir is GITHUB_WORKSPACE and is trusted.
AdamKorcz marked this conversation as resolved.
Show resolved Hide resolved
# It does not require validation.
gh_root_dir=$(pwd)
AdamKorcz marked this conversation as resolved.
Show resolved Hide resolved
AdamKorcz marked this conversation as resolved.
Show resolved Hide resolved

mv ./__BUILDER_CHECKOUT_DIR__ ../__BUILDER_CHECKOUT_DIR__ \
&& cd ../__BUILDER_CHECKOUT_DIR__/actions/maven/publish/slsa-hashing-plugin \
&& mvn clean install \
&& cd - \
&& cd "${project_root}" \
&& mvn package -Drun.hash.jarfile=true
mv $(dirname "${SLSA_OUTPUTS_ARTIFACTS_FILE}") "${GITHUB_WORKSPACE}/../"
AdamKorcz marked this conversation as resolved.
Show resolved Hide resolved
laurentsimon marked this conversation as resolved.
Show resolved Hide resolved
mv target "${gh_root_dir}/"
- name: Upload target
id: upload-target
uses: slsa-framework/slsa-github-generator/.github/actions/secure-upload-folder@main
Expand Down
Loading