Skip to content

Commit bee50ee

Browse files
committed
fix: prevent script injection in workflows
Move github.event references to env vars to prevent script injection vulnerabilities in workflow run steps. This follows the same pattern as the main branch fix in commit 371c614.
1 parent f1de709 commit bee50ee

File tree

5 files changed

+54
-47
lines changed

5 files changed

+54
-47
lines changed

.github/workflows/post_release_version_bump.yml

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

1010
env:
11+
VERSION_INPUT: ${{ env.VERSION_INPUT }}
1112
AWS_DEFAULT_REGION: us-east-1
1213

1314
permissions:
@@ -27,8 +28,8 @@ jobs:
2728

2829
- name: Extract Major.Minor Version and setup Env variable
2930
run: |
30-
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
31-
echo "MAJOR_MINOR=$(echo ${{ github.event.inputs.version }} | sed -E 's/([0-9]+\.[0-9]+)\.[0-9]+/\1/')" >> $GITHUB_ENV
31+
echo "VERSION=${{ env.VERSION_INPUT }}" >> $GITHUB_ENV
32+
echo "MAJOR_MINOR=$(echo ${{ env.VERSION_INPUT }} | sed -E 's/([0-9]+\.[0-9]+)\.[0-9]+/\1/')" >> $GITHUB_ENV
3233
3334
- name: Get current major.minor version from main branch
3435
id: get_version
@@ -84,8 +85,8 @@ jobs:
8485
8586
- name: Extract Major.Minor Version and setup Env variable
8687
run: |
87-
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
88-
echo "MAJOR_MINOR=$(echo ${{ github.event.inputs.version }} | sed -E 's/([0-9]+\.[0-9]+)\.[0-9]+/\1/')" >> $GITHUB_ENV
88+
echo "VERSION=${{ env.VERSION_INPUT }}" >> $GITHUB_ENV
89+
echo "MAJOR_MINOR=$(echo ${{ env.VERSION_INPUT }} | sed -E 's/([0-9]+\.[0-9]+)\.[0-9]+/\1/')" >> $GITHUB_ENV
8990
9091
- name: Determine release branch and checkout
9192
run: |
@@ -96,10 +97,10 @@ jobs:
9697
- name: Update version to next development version in main
9798
# TODO update version in daily_scan.yml
9899
run: |
99-
DEV_VERSION="${{ github.event.inputs.version }}.dev0"
100+
DEV_VERSION="${{ env.VERSION_INPUT }}.dev0"
100101
sed -i "s/public static string version = \".*\";/public static string version = \"${DEV_VERSION}\";/" src/AWS.Distro.OpenTelemetry.AutoInstrumentation/Version.cs
101102
sed -i "s/private readonly string version = \".*\";/private readonly string version = \"${DEV_VERSION}\";/" build/Build.InstallationScripts.cs
102-
VERSION="${{ github.event.inputs.version }}"
103+
VERSION="${{ env.VERSION_INPUT }}"
103104
git add src/AWS.Distro.OpenTelemetry.AutoInstrumentation/Version.cs
104105
git add build/Build.InstallationScripts.cs
105106
git commit -m "Prepare main for next development cycle: Update version to $DEV_VERSION"
@@ -109,7 +110,7 @@ jobs:
109110
env:
110111
GITHUB_TOKEN: ${{ env.BOT_TOKEN_GITHUB_RW_PATOKEN }}
111112
run: |
112-
DEV_VERSION="${{ github.event.inputs.version }}.dev0"
113+
DEV_VERSION="${{ env.VERSION_INPUT }}.dev0"
113114
gh pr create --title "Post release $VERSION: Update version to $DEV_VERSION" \
114115
--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.
115116

.github/workflows/pre_release_prepare.yml

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

1515
env:
16+
VERSION_INPUT: ${{ env.VERSION_INPUT }}
17+
IS_PATCH_INPUT: ${{ env.IS_PATCH_INPUT }}
1618
AWS_DEFAULT_REGION: us-east-1
1719

1820
permissions:
@@ -52,12 +54,12 @@ jobs:
5254
5355
- name: Extract Major.Minor Version and setup Env variable
5456
run: |
55-
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
56-
echo "MAJOR_MINOR=$(echo ${{ github.event.inputs.version }} | sed -E 's/([0-9]+\.[0-9]+)\.[0-9]+/\1/')" >> $GITHUB_ENV
57+
echo "VERSION=${{ env.VERSION_INPUT }}" >> $GITHUB_ENV
58+
echo "MAJOR_MINOR=$(echo ${{ env.VERSION_INPUT }} | sed -E 's/([0-9]+\.[0-9]+)\.[0-9]+/\1/')" >> $GITHUB_ENV
5759
5860
- name: Create branches
5961
run: |
60-
IS_PATCH=${{ github.event.inputs.is_patch }}
62+
IS_PATCH=${{ env.IS_PATCH_INPUT }}
6163
if [[ "$IS_PATCH" != "true" && "$IS_PATCH" != "false" ]]; then
6264
echo "Invalid input for IS_PATCH. Must be 'true' or 'false'."
6365
exit 1
@@ -103,5 +105,5 @@ jobs:
103105
--body "This PR updates the version to ${VERSION}.
104106
105107
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice." \
106-
--head v${{ github.event.inputs.version }}_release \
108+
--head v${{ env.VERSION_INPUT }}_release \
107109
--base release/v${MAJOR_MINOR}.x

.github/workflows/release_build.yml

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
required: true
88

99
env:
10+
VERSION_INPUT: ${{ env.VERSION_INPUT }}
1011
AWS_DEFAULT_REGION: us-east-1
1112
AWS_PUBLIC_ECR_REGION: us-east-1
1213
AWS_PRIVATE_ECR_REGION: us-west-2
@@ -89,7 +90,7 @@ jobs:
8990

9091
- name: Upload to Private S3 Bucket
9192
run: |
92-
PREFIX="Release_v${{github.event.inputs.version}}"
93+
PREFIX="Release_v${{ env.VERSION_INPUT }}"
9394
9495
find ./artifacts/ -name "*.zip" | while read file; do
9596
base=$(basename "$file")
@@ -105,32 +106,32 @@ jobs:
105106
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
106107
run: |
107108
gh release create --target "$GITHUB_REF_NAME" \
108-
--title "Release v${{ github.event.inputs.version }}" \
109-
"v${{ github.event.inputs.version }}" \
110-
--notes "Release Verions v${{ github.event.inputs.version }}"
109+
--title "Release v${{ env.VERSION_INPUT }}" \
110+
"v${{ env.VERSION_INPUT }}" \
111+
--notes "Release Verions v${{ env.VERSION_INPUT }}"
111112
112113
- name: Upload artifacts and checksum to release
113114
env:
114115
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
115116
run: |
116-
PREFIX="Release_v${{github.event.inputs.version}}_"
117+
PREFIX="Release_v${{ env.VERSION_INPUT }}_"
117118
118119
find ./artifacts/ -name "*.zip" | while read file; do
119120
base=$(basename "$file")
120121
cp "$file" "$base"
121122
shasum -a 256 $base > $base.sha256
122-
gh release upload "v${{ github.event.inputs.version }}" \
123+
gh release upload "v${{ env.VERSION_INPUT }}" \
123124
$base \
124125
$base.sha256 \
125126
--clobber
126127
done
127128
shasum -a 256 ./installationScripts/aws-otel-dotnet-install.sh | sed "s|./installationScripts/||" > aws-otel-dotnet-install.sh.sha256
128129
shasum -a 256 ./installationScripts/AWS.Otel.DotNet.Auto.psm1 | sed "s|./installationScripts/||" > AWS.Otel.DotNet.Auto.psm1.sha256
129-
gh release upload "v${{ github.event.inputs.version }}" \
130+
gh release upload "v${{ env.VERSION_INPUT }}" \
130131
./installationScripts/aws-otel-dotnet-install.sh \
131132
aws-otel-dotnet-install.sh.sha256 \
132133
--clobber
133-
gh release upload "v${{ github.event.inputs.version }}" \
134+
gh release upload "v${{ env.VERSION_INPUT }}" \
134135
./installationScripts/AWS.Otel.DotNet.Auto.psm1 \
135136
AWS.Otel.DotNet.Auto.psm1.sha256 \
136137
--clobber
@@ -234,38 +235,38 @@ jobs:
234235
if: runner.os == 'Linux'
235236
run: |
236237
set -e
237-
docker build -t ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}-amd64 -f ./Dockerfile.linux .
238-
docker push ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}-amd64
239-
docker tag ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}-amd64 ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}-amd64
240-
docker push ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}-amd64
238+
docker build -t ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}-amd64 -f ./Dockerfile.linux .
239+
docker push ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}-amd64
240+
docker tag ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}-amd64 ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION_INPUT }}-amd64
241+
docker push ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION_INPUT }}-amd64
241242
242243
- name: Build Linux arm64 container
243244
if: runner.os == 'Linux'
244245
run: |
245246
set -e
246247
cp THIRD-PARTY-LICENSES ./arm64/THIRD-PARTY-LICENSES
247248
cd ./arm64
248-
docker build --platform linux/arm64 -t ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}-arm64 -f ../Dockerfile.linux .
249-
docker push ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}-arm64
250-
docker tag ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}-arm64 ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}-arm64
251-
docker push ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}-arm64
249+
docker build --platform linux/arm64 -t ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}-arm64 -f ../Dockerfile.linux .
250+
docker push ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}-arm64
251+
docker tag ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}-arm64 ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION_INPUT }}-arm64
252+
docker push ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION_INPUT }}-arm64
252253
253254
- name: Build Windows container
254255
if: runner.os == 'Windows'
255256
run: |
256257
$osInfo = systeminfo | Select-String "OS Version"
257258
if ($osInfo -match "10.0.17763") {
258259
Echo "Build image for Windows Server 2019"
259-
docker build -t ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}-windows2019 -f ./Dockerfile.windows2019 .
260-
docker push ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}-windows2019
261-
docker tag ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}-windows2019 ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}-windows2019
262-
docker push ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}-windows2019
260+
docker build -t ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}-windows2019 -f ./Dockerfile.windows2019 .
261+
docker push ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}-windows2019
262+
docker tag ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}-windows2019 ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION_INPUT }}-windows2019
263+
docker push ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION_INPUT }}-windows2019
263264
} elseif ($osInfo -match "10.0.20348") {
264265
Echo "Build image for Windows Server 2022"
265-
docker build -t ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}-windows2022 -f ./Dockerfile.windows2022 .
266-
docker push ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}-windows2022
267-
docker tag ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}-windows2022 ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}-windows2022
268-
docker push ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}-windows2022
266+
docker build -t ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}-windows2022 -f ./Dockerfile.windows2022 .
267+
docker push ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}-windows2022
268+
docker tag ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}-windows2022 ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION_INPUT }}-windows2022
269+
docker push ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION_INPUT }}-windows2022
269270
} else {
270271
Echo "Unknown Windows Server version: $osInfo"
271272
exit 1
@@ -300,15 +301,15 @@ jobs:
300301

301302
- name: Create multi-platform image and push to Amazon private ECR
302303
run: |
303-
docker manifest create ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }} ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}-amd64 ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}-arm64 ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}-windows2019 ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}-windows2022
304-
docker manifest inspect ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}
305-
docker manifest push ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ github.event.inputs.version }}
304+
docker manifest create ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }} ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}-amd64 ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}-arm64 ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}-windows2019 ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}-windows2022
305+
docker manifest inspect ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}
306+
docker manifest push ${{ env.RELEASE_PRIVATE_REPOSITORY }}:v${{ env.VERSION_INPUT }}
306307
307308
- name: Create multi-platform image and push to Amazon public ECR
308309
run: |
309-
docker manifest create ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }} ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}-amd64 ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}-arm64 ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}-windows2019 ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}-windows2022
310-
docker manifest inspect ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}
311-
docker manifest push ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ github.event.inputs.version }}
310+
docker manifest create ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION_INPUT }} ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION_INPUT }}-amd64 ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION_INPUT }}-arm64 ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION_INPUT }}-windows2019 ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION_INPUT }}-windows2022
311+
docker manifest inspect ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION_INPUT }}
312+
docker manifest push ${{ env.RELEASE_PUBLIC_REPOSITORY }}:v${{ env.VERSION_INPUT }}
312313
313314
build-release-nuget:
314315
runs-on: windows-latest
@@ -348,7 +349,7 @@ jobs:
348349
run: >
349350
dotnet pack
350351
.\src\AWS.Distro.OpenTelemetry.AutoInstrumentation
351-
/p:Version=${{github.event.inputs.version}}
352+
/p:Version=${{ env.VERSION_INPUT }}
352353
--no-build
353354
-c Release
354355
-o .\Deployment\nuget-packages

.github/workflows/release_lambda.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ on:
1212
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'
1313

1414
env:
15+
VERSION_INPUT: ${{ env.VERSION_INPUT }}
16+
AWS_REGION_INPUT: ${{ env.AWS_REGION_INPUT }}
1517
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
1618
LAYER_NAME: AWSOpenTelemetryDistroDotNet
1719

@@ -38,7 +40,7 @@ jobs:
3840
- name: Set up regions matrix
3941
id: set-matrix
4042
run: |
41-
IFS=',' read -ra REGIONS <<< "${{ github.event.inputs.aws_region }}"
43+
IFS=',' read -ra REGIONS <<< "${{ env.AWS_REGION_INPUT }}"
4244
MATRIX="["
4345
for region in "${REGIONS[@]}"; do
4446
trimmed_region=$(echo "$region" | xargs)
@@ -101,7 +103,7 @@ jobs:
101103
--compatible-runtimes dotnet6 dotnet8 \
102104
--compatible-architectures "x86_64" \
103105
--license-info "Apache-2.0" \
104-
--description "AWS Distro of OpenTelemetry Lambda Layer for .Net Runtime v${{ github.event.inputs.version }}" \
106+
--description "AWS Distro of OpenTelemetry Lambda Layer for .Net Runtime v${{ env.VERSION_INPUT }}" \
105107
--query 'LayerVersionArn' \
106108
--output text
107109
)
@@ -191,7 +193,7 @@ jobs:
191193
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
192194
run: |
193195
gh release create --target "$GITHUB_REF_NAME" \
194-
--title "Release lambda-v${{ github.event.inputs.version }}" \
196+
--title "Release lambda-v${{ env.VERSION_INPUT }}" \
195197
--draft \
196-
"lambda-v${{ github.event.inputs.version }}" \
198+
"lambda-v${{ env.VERSION_INPUT }}" \
197199
layer.tf

.github/workflows/unlist_nuget.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
required: true
88

99
env:
10+
VERSION_INPUT: ${{ env.VERSION_INPUT }}
1011
AWS_SIGNING_KEY_REGION: us-west-2
1112

1213
permissions:
@@ -35,6 +36,6 @@ jobs:
3536
--output text
3637
--query SecretString | ConvertFrom-Json
3738
38-
nuget delete AWS.Distro.OpenTelemetry.AutoInstrumentation ${{github.event.inputs.version}}
39+
nuget delete AWS.Distro.OpenTelemetry.AutoInstrumentation ${{ env.VERSION_INPUT }}
3940
-Source https://api.nuget.org/v3/index.json
4041
-ApiKey $nugetKey.Key

0 commit comments

Comments
 (0)