diff --git a/.github/actions/install-bot-engine/action.yml b/.github/actions/install-bot-engine/action.yml index d7e0020e..58941a2d 100644 --- a/.github/actions/install-bot-engine/action.yml +++ b/.github/actions/install-bot-engine/action.yml @@ -113,12 +113,13 @@ runs: if [ -s "$JFROG_NPMRC_FILE" ]; then NPM_ARGS=(--userconfig "$JFROG_NPMRC_FILE") fi + source "${{ github.action_path }}/redact-command-output.sh" # pip reads PIP_INDEX_URL from the env setup-jfrog exported. REF mode # resolves the published engine's deps unpinned + installs the SDK/CLI by # version (a consumer can't see the engine's hash-locked requirements). # SDK_VERSION/CLI_VERSION track the engine at ENGINE_REF. - python -m pip install --upgrade pip - pip install "databricks-bot-engine @ git+https://github.com/${ENGINE_REPO}@${ENGINE_REF}" - pip install "claude-agent-sdk==${SDK_VERSION}" - npm install "${NPM_ARGS[@]}" -g "@anthropic-ai/claude-code@${CLI_VERSION}" + run_with_redacted_url_queries python -m pip install --upgrade pip + run_with_redacted_url_queries pip install "databricks-bot-engine @ git+https://github.com/${ENGINE_REPO}@${ENGINE_REF}" + run_with_redacted_url_queries pip install "claude-agent-sdk==${SDK_VERSION}" + run_with_redacted_url_queries npm install "${NPM_ARGS[@]}" -g "@anthropic-ai/claude-code@${CLI_VERSION}" echo "$(npm prefix -g)/bin" >> "$GITHUB_PATH" diff --git a/.github/actions/install-bot-engine/redact-command-output.sh b/.github/actions/install-bot-engine/redact-command-output.sh new file mode 100644 index 00000000..9d6a85b0 --- /dev/null +++ b/.github/actions/install-bot-engine/redact-command-output.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +run_with_redacted_url_queries() { + local previous_shell_options="$-" + local command_status + + set +e + "$@" 2>&1 \ + | sed -E 's#([Hh][Tt][Tt][Pp][Ss]?://[^?[:space:]]+)\?[^[:space:]]+#\1?[REDACTED]#g' + command_status=${PIPESTATUS[0]} + if [[ "$previous_shell_options" == *e* ]]; then + set -e + fi + + return "$command_status" +} diff --git a/.github/actions/install-bot-engine/redact-command-output_test.sh b/.github/actions/install-bot-engine/redact-command-output_test.sh new file mode 100644 index 00000000..f02a10f3 --- /dev/null +++ b/.github/actions/install-bot-engine/redact-command-output_test.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +source "$SCRIPT_DIR/redact-command-output.sh" + +test_redacts_url_query_and_preserves_host_and_path() { + local output + + output=$(run_with_redacted_url_queries bash -c \ + 'printf "%s\n" "Downloading https://packages.example.test/artifacts/pkg.whl?X-Amz-Algorithm=DUMMY&X-Amz-Credential=DUMMY"') + + [[ "$output" == 'Downloading https://packages.example.test/artifacts/pkg.whl?[REDACTED]' ]] +} + +test_preserves_command_exit_code() { + local output + local status + + set +e + output=$(run_with_redacted_url_queries bash -c \ + 'printf "%s\n" "Failed https://packages.example.test/pkg.tgz?X-Amz-Signature=DUMMY" >&2; exit 37') + status=$? + set -e + + [[ "$status" -eq 37 ]] + [[ "$output" == 'Failed https://packages.example.test/pkg.tgz?[REDACTED]' ]] +} + +test_redacts_url_query_and_preserves_host_and_path +test_preserves_command_exit_code diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index c9e28d10..ffaa60bd 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -63,6 +63,9 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Test install-log URL redaction + run: bash .github/actions/install-bot-engine/redact-command-output_test.sh + - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0 with: toolchain: stable