Skip to content

Commit 7ec459f

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 7ec459f

3 files changed

Lines changed: 20 additions & 13 deletions

File tree

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

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

1414
env:
15+
VERSION: ${{ github.event.inputs.version }}
16+
1517
AWS_DEFAULT_REGION: us-east-1
1618

1719
permissions:
@@ -100,13 +102,13 @@ jobs:
100102
101103
- name: Update version to next development version in main
102104
run: |
103-
DEV_VERSION="${{ github.event.inputs.version }}.dev0"
105+
DEV_VERSION="${{ env.VERSION }}.dev0"
104106
sed -i 's/__version__ = ".*"/__version__ = "'$DEV_VERSION'"/' aws-opentelemetry-distro/src/amazon/opentelemetry/distro/version.py
105-
VERSION="${{ github.event.inputs.version }}"
107+
VERSION="${{ env.VERSION }}"
106108
sed -i 's/python:v.*"/python:v'$VERSION'"/' .github/workflows/daily-scan.yml
107109
108110
# for patch releases, avoid merge conflict by manually resolving CHANGELOG with main
109-
if [[ "${{ github.event.inputs.is_patch }}" == "true" ]]; then
111+
if [[ "${{ env.IS_PATCH }}" == "true" ]]; then
110112
# Copy the patch release entries
111113
sed -n "/^## v${VERSION}/,/^## v[0-9]/p" CHANGELOG.md | sed '$d' > /tmp/patch_release_section.txt
112114
@@ -127,7 +129,7 @@ jobs:
127129
env:
128130
GITHUB_TOKEN: ${{ env.BOT_TOKEN_GITHUB_RW_PATOKEN }}
129131
run: |
130-
DEV_VERSION="${{ github.event.inputs.version }}.dev0"
132+
DEV_VERSION="${{ env.VERSION }}.dev0"
131133
gh pr create --title "Post release $VERSION: Update version to $DEV_VERSION" \
132134
--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.
133135

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

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

1414
env:
15+
VERSION: ${{ github.event.inputs.version }}
16+
IS_PATCH: ${{ github.event.inputs.is_patch }}
17+
1518
AWS_DEFAULT_REGION: us-east-1
1619

1720
permissions:
@@ -56,7 +59,7 @@ jobs:
5659
5760
- name: Create branches
5861
run: |
59-
IS_PATCH=${{ github.event.inputs.is_patch }}
62+
IS_PATCH=${{ env.IS_PATCH }}
6063
if [[ "$IS_PATCH" != "true" && "$IS_PATCH" != "false" ]]; then
6164
echo "Invalid input for IS_PATCH. Must be 'true' or 'false'."
6265
exit 1
@@ -109,5 +112,5 @@ jobs:
109112
--body "This PR updates the version to ${VERSION}.
110113
111114
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 \
115+
--head v${{ env.VERSION }}_release \
113116
--base release/v${MAJOR_MINOR}.x

.github/workflows/release-build.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@ on:
1111
default: '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, af-south-1, ap-east-1, ap-south-2, ap-southeast-3, ap-southeast-4, eu-central-2, eu-south-1, eu-south-2, il-central-1, me-central-1, me-south-1, ap-southeast-5, ap-southeast-7, mx-central-1, ca-west-1, cn-north-1, cn-northwest-1'
1212

1313
env:
14+
VERSION: ${{ env.VERSION }}
15+
1416
AWS_DEFAULT_REGION: us-east-1
1517
AWS_PUBLIC_ECR_REGION: us-east-1
1618
AWS_PRIVATE_ECR_REGION: us-west-2
1719
RELEASE_PUBLIC_REPOSITORY: public.ecr.aws/aws-observability/adot-autoinstrumentation-python
1820
RELEASE_PRIVATE_REPOSITORY: 020628701572.dkr.ecr.us-west-2.amazonaws.com/adot-autoinstrumentation-python
1921
RELEASE_PRIVATE_REGISTRY: 020628701572.dkr.ecr.us-west-2.amazonaws.com
2022
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
23+
WHEEL_ARTIFACT_NAME: aws_opentelemetry_distro-${{ env.VERSION }}-py3-none-any.whl
24+
SOURCE_ARTIFACT_NAME: aws_opentelemetry_distro-${{ env.VERSION }}.tar.gz
2325
# 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.
2426
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
2527
LAYER_NAME: AWSOpenTelemetryDistroPython
2628
LAYER_ARTIFACT_NAME: aws-opentelemetry-python-layer.zip
27-
VERSION: ${{ github.event.inputs.version }}
29+
VERSION: ${{ env.VERSION }}
2830

2931
permissions:
3032
id-token: write
@@ -91,7 +93,7 @@ jobs:
9193
- name: Set up regions matrix
9294
id: set-matrix
9395
env:
94-
AWS_REGIONS: ${{ github.event.inputs.aws_region }}
96+
AWS_REGIONS: ${{ env.AWS_REGIONS }}
9597
run: |
9698
IFS=',' read -ra REGIONS <<< "$AWS_REGIONS"
9799
MATRIX="["
@@ -190,7 +192,7 @@ jobs:
190192
file: ./Dockerfile
191193
platforms: linux/amd64,linux/arm64
192194
tags: |
193-
${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}
195+
${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION }}
194196
195197
# Publish to private ECR
196198
- name: Build and push private ECR image
@@ -201,7 +203,7 @@ jobs:
201203
file: ./Dockerfile
202204
platforms: linux/amd64,linux/arm64
203205
tags: |
204-
${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}
206+
${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION }}
205207
206208
publish-layer-prod:
207209
runs-on: ubuntu-latest
@@ -443,7 +445,7 @@ jobs:
443445
id: create_release
444446
env:
445447
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
446-
VERSION: ${{ github.event.inputs.version }}
448+
VERSION: ${{ env.VERSION }}
447449
run: |
448450
# Extract all dependencies from pyproject.toml
449451
DEPS=$(python3 -c "

0 commit comments

Comments
 (0)