@@ -120,3 +120,174 @@ jobs:
120120 run : go mod download
121121 - name : Build
122122 run : go build -o hello main.go
123+
124+ test-s3-cache-with-credential-interference :
125+ runs-on : github-ubuntu-latest-s
126+ permissions :
127+ id-token : write
128+ contents : read
129+ steps :
130+ - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
131+ - uses : jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac # v2.4.4
132+ with :
133+ version : 2025.7.12
134+
135+ # Step 1: Use our cache action (should restore and later save)
136+ - name : Cache with S3
137+ id : cache-test
138+ uses : ./
139+ with :
140+ path : ~/.cache/pip
141+ key : interference-test-${{ runner.os }}-${{ github.run_id }}
142+ restore-keys : interference-test-${{ runner.os }}-
143+ environment : dev
144+ backend : s3
145+
146+ # Step 2: Simulate user overwriting AWS credentials
147+ # This is the scenario that caused production failures
148+ - name : Overwrite AWS credentials (simulating user workflow)
149+ run : |
150+ echo "AWS_ACCESS_KEY_ID=FAKE_KEY_TO_OVERRIDE" >> "$GITHUB_ENV"
151+ echo "AWS_SECRET_ACCESS_KEY=FAKE_SECRET_TO_OVERRIDE" >> "$GITHUB_ENV"
152+ echo "AWS_SESSION_TOKEN=FAKE_TOKEN_TO_OVERRIDE" >> "$GITHUB_ENV"
153+ echo "Simulated credential override via GITHUB_ENV"
154+
155+ # Step 3: Create something to cache
156+ - name : Install dependencies
157+ run : |
158+ python -m pip install --upgrade pip
159+ pip install pytest requests
160+
161+ # Post-step: credential-guard restores real creds, then runs-on/cache saves
162+ # If this job succeeds, the credential guard is working correctly
163+
164+ # Reproduces: "Unable to parse config file C:\Users\runneradmin/.aws/config"
165+ # https://github.com/SonarSource/peachee-cfamily/actions/runs/21646222381/job/62398839588#step:26:263
166+ test-s3-cache-windows :
167+ runs-on : github-windows-latest-s
168+ permissions :
169+ id-token : write
170+ contents : read
171+ steps :
172+ - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
173+
174+ - name : Cache with S3 on Windows
175+ id : cache-test
176+ uses : ./
177+ with :
178+ path : ~\AppData\Local\pip\Cache
179+ key : windows-test-${{ runner.os }}-${{ github.run_id }}
180+ restore-keys : windows-test-${{ runner.os }}-
181+ environment : dev
182+ backend : s3
183+
184+ - name : Create something to cache
185+ run : |
186+ python -m pip install --upgrade pip
187+ pip install requests
188+
189+ # Reproduces: ~/.aws/config corruption from multiple credential_process entries
190+ test-s3-cache-multiple-invocations :
191+ runs-on : github-ubuntu-latest-s
192+ permissions :
193+ id-token : write
194+ contents : read
195+ steps :
196+ - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
197+ - uses : jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac # v2.4.4
198+ with :
199+ version : 2025.7.12
200+
201+ # First cache invocation
202+ - name : Cache pip dependencies
203+ id : cache-pip
204+ uses : ./
205+ with :
206+ path : ~/.cache/pip
207+ key : multi-pip-${{ runner.os }}-${{ github.run_id }}
208+ restore-keys : multi-pip-${{ runner.os }}-
209+ environment : dev
210+ backend : s3
211+
212+ # Second cache invocation in same job
213+ # Old approach would append duplicate profile to ~/.aws/config
214+ - name : Cache npm dependencies
215+ id : cache-npm
216+ uses : ./
217+ with :
218+ path : ~/.npm
219+ key : multi-npm-${{ runner.os }}-${{ github.run_id }}
220+ restore-keys : multi-npm-${{ runner.os }}-
221+ environment : dev
222+ backend : s3
223+
224+ - name : Create something to cache
225+ run : |
226+ python -m pip install --upgrade pip
227+ pip install pytest
228+ npm init -y
229+
230+ # Reproduces: pre-existing AWS config from configure-aws-credentials
231+ # https://github.com/SonarSource/sonarsource-iam/actions/runs/21951781857/job/63404298650#step:5:9
232+ test-s3-cache-with-preset-aws-config :
233+ runs-on : github-ubuntu-latest-s
234+ permissions :
235+ id-token : write
236+ contents : read
237+ steps :
238+ - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
239+ - uses : jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac # v2.4.4
240+ with :
241+ version : 2025.7.12
242+
243+ # Simulate pre-existing AWS config (as if configure-aws-credentials ran before)
244+ - name : Create pre-existing AWS config
245+ run : |
246+ mkdir -p ~/.aws
247+ cat <<'AWSCONFIG' > ~/.aws/config
248+ [default]
249+ region = us-east-1
250+ output = json
251+ [profile some-other-profile]
252+ region = us-west-2
253+ AWSCONFIG
254+ cat <<'AWSCREDS' > ~/.aws/credentials
255+ [default]
256+ aws_access_key_id = AKIAFAKEDEFAULT
257+ aws_secret_access_key = fakesecretdefault
258+ [some-other-profile]
259+ aws_access_key_id = AKIAFAKEOTHER
260+ aws_secret_access_key = fakesecretother
261+ AWSCREDS
262+ echo "Pre-existing AWS config created"
263+ cat ~/.aws/config
264+
265+ - name : Set conflicting AWS env vars
266+ run : |
267+ echo "AWS_ACCESS_KEY_ID=AKIAFAKEENV" >> "$GITHUB_ENV"
268+ echo "AWS_SECRET_ACCESS_KEY=fakesecretenv" >> "$GITHUB_ENV"
269+ echo "AWS_SESSION_TOKEN=faketokenenv" >> "$GITHUB_ENV"
270+ echo "AWS_PROFILE=some-other-profile" >> "$GITHUB_ENV"
271+ echo "AWS_DEFAULT_PROFILE=some-other-profile" >> "$GITHUB_ENV"
272+
273+ # Cache action should override the conflicting credentials
274+ - name : Cache with S3
275+ id : cache-test
276+ uses : ./
277+ with :
278+ path : ~/.cache/pip
279+ key : preset-aws-${{ runner.os }}-${{ github.run_id }}
280+ restore-keys : preset-aws-${{ runner.os }}-
281+ environment : dev
282+ backend : s3
283+
284+ - name : Re-override with fake credentials (simulating mid-job auth change)
285+ run : |
286+ echo "AWS_ACCESS_KEY_ID=AKIAFAKEOVERRIDE" >> "$GITHUB_ENV"
287+ echo "AWS_SECRET_ACCESS_KEY=fakesecretoverride" >> "$GITHUB_ENV"
288+ echo "AWS_SESSION_TOKEN=faketokenoverride" >> "$GITHUB_ENV"
289+
290+ - name : Create something to cache
291+ run : |
292+ python -m pip install --upgrade pip
293+ pip install pytest requests
0 commit comments