Skip to content

Commit 46ace0f

Browse files
committed
fix: prevent script injection in workflows
Move github.event references to env vars to prevent script injection vulnerabilities in run steps
1 parent 5a3689b commit 46ace0f

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

.github/workflows/post-release-version-bump.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ on:
1212
default: 'false'
1313

1414
env:
15+
VERSION: ${{ env.VERSION }}
16+
IS_PATCH: ${{ env.IS_PATCH }}
17+
18+
1519
AWS_DEFAULT_REGION: us-east-1
1620

1721
permissions:
@@ -100,13 +104,13 @@ jobs:
100104
101105
- name: Update version to next development version in main
102106
run: |
103-
DEV_VERSION="${{ github.event.inputs.version }}.dev0"
107+
DEV_VERSION="${{ env.VERSION }}.dev0"
104108
sed -i 's/__version__ = ".*"/__version__ = "'$DEV_VERSION'"/' aws-opentelemetry-distro/src/amazon/opentelemetry/distro/version.py
105-
VERSION="${{ github.event.inputs.version }}"
109+
VERSION="${{ env.VERSION }}"
106110
sed -i 's/python:v.*"/python:v'$VERSION'"/' .github/workflows/daily-scan.yml
107111
108112
# for patch releases, avoid merge conflict by manually resolving CHANGELOG with main
109-
if [[ "${{ github.event.inputs.is_patch }}" == "true" ]]; then
113+
if [[ "${{ env.IS_PATCH }}" == "true" ]]; then
110114
# Copy the patch release entries
111115
sed -n "/^## v${VERSION}/,/^## v[0-9]/p" CHANGELOG.md | sed '$d' > /tmp/patch_release_section.txt
112116
@@ -127,7 +131,7 @@ jobs:
127131
env:
128132
GITHUB_TOKEN: ${{ env.BOT_TOKEN_GITHUB_RW_PATOKEN }}
129133
run: |
130-
DEV_VERSION="${{ github.event.inputs.version }}.dev0"
134+
DEV_VERSION="${{ env.VERSION }}.dev0"
131135
gh pr create --title "Post release $VERSION: Update version to $DEV_VERSION" \
132136
--body "This PR prepares the main branch for the next development cycle by updating the version to $DEV_VERSION and updating the image version to be scanned to the latest released.
133137

.github/workflows/pre-release-prepare.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ on:
1212
default: 'false'
1313

1414
env:
15+
VERSION: ${{ env.VERSION }}
16+
IS_PATCH: ${{ env.IS_PATCH }}
17+
18+
1519
AWS_DEFAULT_REGION: us-east-1
1620

1721
permissions:
@@ -56,7 +60,7 @@ jobs:
5660
5761
- name: Create branches
5862
run: |
59-
IS_PATCH=${{ github.event.inputs.is_patch }}
63+
IS_PATCH=${{ env.IS_PATCH }}
6064
if [[ "$IS_PATCH" != "true" && "$IS_PATCH" != "false" ]]; then
6165
echo "Invalid input for IS_PATCH. Must be 'true' or 'false'."
6266
exit 1
@@ -109,5 +113,5 @@ jobs:
109113
--body "This PR updates the version to ${VERSION}.
110114
111115
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice." \
112-
--head v${{ github.event.inputs.version }}_release \
116+
--head v${{ env.VERSION }}_release \
113117
--base release/v${MAJOR_MINOR}.x

.github/workflows/release-build.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ env:
1818
RELEASE_PRIVATE_REPOSITORY: 020628701572.dkr.ecr.us-west-2.amazonaws.com/adot-autoinstrumentation-python
1919
RELEASE_PRIVATE_REGISTRY: 020628701572.dkr.ecr.us-west-2.amazonaws.com
2020
PACKAGE_NAME: aws-opentelemetry-distro
21-
WHEEL_ARTIFACT_NAME: aws_opentelemetry_distro-${{ github.event.inputs.version }}-py3-none-any.whl
22-
SOURCE_ARTIFACT_NAME: aws_opentelemetry_distro-${{ github.event.inputs.version }}.tar.gz
21+
WHEEL_ARTIFACT_NAME: aws_opentelemetry_distro-${{ env.VERSION }}-py3-none-any.whl
22+
SOURCE_ARTIFACT_NAME: aws_opentelemetry_distro-${{ env.VERSION }}.tar.gz
2323
# Legacy list of commercial regions to deploy to. New regions should NOT be added here, and instead should be added to the `aws_region` default input to the workflow.
2424
LEGACY_COMMERCIAL_REGIONS: us-east-1, us-east-2, us-west-1, us-west-2, ap-south-1, ap-northeast-3, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-northeast-1, ca-central-1, eu-central-1, eu-west-1, eu-west-2, eu-west-3, eu-north-1, sa-east-1
2525
LAYER_NAME: AWSOpenTelemetryDistroPython
2626
LAYER_ARTIFACT_NAME: aws-opentelemetry-python-layer.zip
27-
VERSION: ${{ github.event.inputs.version }}
27+
VERSION: ${{ env.VERSION }}
2828

2929
permissions:
3030
id-token: write
@@ -91,7 +91,7 @@ jobs:
9191
- name: Set up regions matrix
9292
id: set-matrix
9393
env:
94-
AWS_REGIONS: ${{ github.event.inputs.aws_region }}
94+
AWS_REGIONS: ${{ env.AWS_REGIONS }}
9595
run: |
9696
IFS=',' read -ra REGIONS <<< "$AWS_REGIONS"
9797
MATRIX="["
@@ -190,7 +190,7 @@ jobs:
190190
file: ./Dockerfile
191191
platforms: linux/amd64,linux/arm64
192192
tags: |
193-
${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}
193+
${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION }}
194194
195195
# Publish to private ECR
196196
- name: Build and push private ECR image
@@ -201,7 +201,7 @@ jobs:
201201
file: ./Dockerfile
202202
platforms: linux/amd64,linux/arm64
203203
tags: |
204-
${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}
204+
${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION }}
205205
206206
publish-layer-prod:
207207
runs-on: ubuntu-latest
@@ -443,7 +443,7 @@ jobs:
443443
id: create_release
444444
env:
445445
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
446-
VERSION: ${{ github.event.inputs.version }}
446+
VERSION: ${{ env.VERSION }}
447447
run: |
448448
# Extract all dependencies from pyproject.toml
449449
DEPS=$(python3 -c "

0 commit comments

Comments
 (0)