9494 IDENTITY_PROVIDER_NAME : token.actions.githubusercontent.com
9595 AUDIENCE : cognito-identity.amazonaws.com
9696 AWS_REGION : eu-central-1
97+ GITHUB_RUN_ID : ${{ github.run_id }}
9798 run : |
9899 # Get GitHub Actions ID token using script
99100 ACCESS_TOKEN=$("$GITHUB_ACTION_PATH/scripts/get-github-token.sh")
@@ -137,11 +138,21 @@ runs:
137138 echo "::add-mask::$AWS_SECRET_ACCESS_KEY"
138139 echo "::add-mask::$AWS_SESSION_TOKEN"
139140
140- {
141- echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID"
142- echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY"
143- echo "AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN"
144- } >> "$GITHUB_OUTPUT"
141+ # Create a unique AWS profile to isolate credentials from user-configured AWS credentials
142+ # This prevents credential override when users call aws-actions/configure-aws-credentials
143+ # between the cache restore (main step) and cache save (post step)
144+ PROFILE_NAME="gh-action-cache-${GITHUB_RUN_ID}"
145+
146+ mkdir -p ~/.aws
147+ chmod 700 ~/.aws
148+
149+ # Write credentials to a dedicated profile using AWS CLI (handles file format and permissions correctly)
150+ aws configure set aws_access_key_id "$AWS_ACCESS_KEY_ID" --profile "$PROFILE_NAME"
151+ aws configure set aws_secret_access_key "$AWS_SECRET_ACCESS_KEY" --profile "$PROFILE_NAME"
152+ aws configure set aws_session_token "$AWS_SESSION_TOKEN" --profile "$PROFILE_NAME"
153+ aws configure set region eu-central-1 --profile "$PROFILE_NAME"
154+ echo "Created AWS profile: $PROFILE_NAME"
155+ echo "AWS_PROFILE=$PROFILE_NAME" >> "$GITHUB_OUTPUT"
145156
146157 - name : Prepare cache keys
147158 if : steps.cache-backend.outputs.cache-backend == 's3'
@@ -163,9 +174,10 @@ runs:
163174 RUNS_ON_S3_BUCKET_CACHE : sonarsource-s3-cache-${{ inputs.environment }}-bucket
164175 AWS_DEFAULT_REGION : eu-central-1
165176 AWS_REGION : eu-central-1
166- AWS_ACCESS_KEY_ID : ${{ steps.aws-auth.outputs.AWS_ACCESS_KEY_ID }}
167- AWS_SECRET_ACCESS_KEY : ${{ steps.aws-auth.outputs.AWS_SECRET_ACCESS_KEY }}
168- AWS_SESSION_TOKEN : ${{ steps.aws-auth.outputs.AWS_SESSION_TOKEN }}
177+ # Use AWS profile instead of direct credentials to prevent override issues
178+ # When users configure their own AWS credentials mid-job, the profile remains isolated
179+ AWS_PROFILE : ${{ steps.aws-auth.outputs.AWS_PROFILE }}
180+ AWS_DEFAULT_PROFILE : ${{ steps.aws-auth.outputs.AWS_PROFILE }}
169181 with :
170182 path : ${{ inputs.path }}
171183 key : ${{ steps.prepare-keys.outputs.branch-key }}
0 commit comments