Skip to content

Commit b1e1b85

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 d9a55c2 commit b1e1b85

3 files changed

Lines changed: 17 additions & 10 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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ 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-
ARTIFACT_NAME: aws_opentelemetry_distro-${{ github.event.inputs.version }}-py3-none-any.whl
23+
ARTIFACT_NAME: aws_opentelemetry_distro-${{ env.VERSION }}-py3-none-any.whl
2224
# 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.
2325
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
2426
LAYER_NAME: AWSOpenTelemetryDistroPython
@@ -82,7 +84,7 @@ jobs:
8284
- name: Set up regions matrix
8385
id: set-matrix
8486
env:
85-
AWS_REGIONS: ${{ github.event.inputs.aws_region }}
87+
AWS_REGIONS: ${{ env.AWS_REGIONS }}
8688
run: |
8789
IFS=',' read -ra REGIONS <<< "$AWS_REGIONS"
8890
MATRIX="["
@@ -191,7 +193,7 @@ jobs:
191193
file: ./Dockerfile
192194
platforms: linux/amd64,linux/arm64
193195
tags: |
194-
${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}
196+
${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION }}
195197
196198
# Publish to private ECR
197199
- name: Build and push private ECR image
@@ -202,7 +204,7 @@ jobs:
202204
file: ./Dockerfile
203205
platforms: linux/amd64,linux/arm64
204206
tags: |
205-
${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}
207+
${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION }}
206208
207209
publish-layer-prod:
208210
runs-on: ubuntu-latest
@@ -380,7 +382,7 @@ jobs:
380382
id: create_release
381383
env:
382384
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
383-
VERSION: ${{ github.event.inputs.version }}
385+
VERSION: ${{ env.VERSION }}
384386
run: |
385387
# Extract all dependencies from pyproject.toml
386388
DEPS=$(python3 -c "

0 commit comments

Comments
 (0)