Skip to content

Commit ac0932d

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 8fbad82 commit ac0932d

4 files changed

Lines changed: 23 additions & 13 deletions

File tree

.github/workflows/post_release_version_bump.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
required: true
99

1010
env:
11+
VERSION: ${{ github.event.inputs.version }}
12+
1113
AWS_DEFAULT_REGION: us-east-1
1214

1315
permissions:
@@ -96,9 +98,9 @@ jobs:
9698
9799
- name: Update version to next development version in main
98100
run: |
99-
DEV_VERSION="${{ github.event.inputs.version }}.dev0"
101+
DEV_VERSION="${{ env.VERSION }}.dev0"
100102
sed -i 's/__version__ = ".*"/__version__ = "'$DEV_VERSION'"/' aws-opentelemetry-distro/src/amazon/opentelemetry/distro/version.py
101-
VERSION="${{ github.event.inputs.version }}"
103+
VERSION="${{ env.VERSION }}"
102104
sed -i 's/python:v.*"/python:v'$VERSION'"/' .github/workflows/daily_scan.yml
103105
git add aws-opentelemetry-distro/src/amazon/opentelemetry/distro/version.py
104106
git add .github/workflows/daily_scan.yml
@@ -109,7 +111,7 @@ jobs:
109111
env:
110112
GITHUB_TOKEN: ${{ env.BOT_TOKEN_GITHUB_RW_PATOKEN }}
111113
run: |
112-
DEV_VERSION="${{ github.event.inputs.version }}.dev0"
114+
DEV_VERSION="${{ env.VERSION }}.dev0"
113115
gh pr create --title "Post release $VERSION: Update version to $DEV_VERSION" \
114116
--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.
115117

.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
@@ -102,5 +105,5 @@ jobs:
102105
--body "This PR updates the version to ${VERSION}.
103106
104107
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice." \
105-
--head v${{ github.event.inputs.version }}_release \
108+
--head v${{ env.VERSION }}_release \
106109
--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
@@ -7,6 +7,8 @@ on:
77
required: true
88

99
env:
10+
VERSION: ${{ env.VERSION }}
11+
1012
AWS_DEFAULT_REGION: us-east-1
1113
AWS_PUBLIC_ECR_REGION: us-east-1
1214
AWS_PRIVATE_ECR_REGION: us-west-2
@@ -88,15 +90,15 @@ jobs:
8890
TWINE_USERNAME: '__token__'
8991
TWINE_PASSWORD: ${{ env.TEST_PYPI_TOKEN_API_TOKEN }}
9092
run: |
91-
twine upload --repository testpypi --skip-existing --verbose dist/aws_opentelemetry_distro-${{ github.event.inputs.version }}-py3-none-any.whl
93+
twine upload --repository testpypi --skip-existing --verbose dist/aws_opentelemetry_distro-${{ env.VERSION }}-py3-none-any.whl
9294
9395
# Publish to prod PyPI
9496
- name: Publish to PyPI
9597
env:
9698
TWINE_USERNAME: '__token__'
9799
TWINE_PASSWORD: ${{ env.PROD_PYPI_TOKEN_API_TOKEN }}
98100
run: |
99-
twine upload --skip-existing --verbose dist/aws_opentelemetry_distro-${{ github.event.inputs.version }}-py3-none-any.whl
101+
twine upload --skip-existing --verbose dist/aws_opentelemetry_distro-${{ env.VERSION }}-py3-none-any.whl
100102
101103
# Publish to public ECR
102104
- name: Build and push public ECR image
@@ -107,7 +109,7 @@ jobs:
107109
file: ./Dockerfile
108110
platforms: linux/amd64,linux/arm64
109111
tags: |
110-
${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}
112+
${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION }}
111113
112114
# Publish to private ECR
113115
- name: Build and push private ECR image
@@ -118,7 +120,7 @@ jobs:
118120
file: ./Dockerfile
119121
platforms: linux/amd64,linux/arm64
120122
tags: |
121-
${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}
123+
${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION }}
122124
123125
# Publish to GitHub releases
124126
- name: Create GH release
@@ -127,7 +129,7 @@ jobs:
127129
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
128130
run: |
129131
gh release create --target "$GITHUB_REF_NAME" \
130-
--title "Release v${{ github.event.inputs.version }}" \
132+
--title "Release v${{ env.VERSION }}" \
131133
--draft \
132-
"v${{ github.event.inputs.version }}" \
133-
dist/aws_opentelemetry_distro-${{ github.event.inputs.version }}-py3-none-any.whl
134+
"v${{ env.VERSION }}" \
135+
dist/aws_opentelemetry_distro-${{ env.VERSION }}-py3-none-any.whl

.github/workflows/release_lambda.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
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'
1010

1111
env:
12+
VERSION: ${{ env.VERSION }}
13+
AWS_REGIONS: ${{ env.AWS_REGIONS }}
14+
1215
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
1316
LAYER_NAME: AWSOpenTelemetryDistroPython
1417

@@ -25,7 +28,7 @@ jobs:
2528
- name: Set up regions matrix
2629
id: set-matrix
2730
run: |
28-
IFS=',' read -ra REGIONS <<< "${{ github.event.inputs.aws_region }}"
31+
IFS=',' read -ra REGIONS <<< "${{ env.AWS_REGIONS }}"
2932
MATRIX="["
3033
for region in "${REGIONS[@]}"; do
3134
trimmed_region=$(echo "$region" | xargs)

0 commit comments

Comments
 (0)