@@ -84,75 +84,25 @@ runs:
8484 lookup-only : ${{ inputs.lookup-only }}
8585
8686 # Cache with S3 (private/internal repos)
87- - name : Authenticate to AWS
87+ - name : Configure cache credential profile
8888 if : steps.cache-backend.outputs.cache-backend == 's3'
89- id : aws-auth
9089 shell : bash
9190 env :
9291 POOL_ID : ${{ inputs.environment == 'prod' && 'eu-central-1:511fe374-ae4f-46d0-adb7-9246e570c7f4' || 'eu-central-1:3221c6ea-3f67-4fd8-a7ff-7426f96add89' }}
9392 AWS_ACCOUNT_ID : ${{ inputs.environment == 'prod' && '275878209202' || '460386131003' }}
9493 IDENTITY_PROVIDER_NAME : token.actions.githubusercontent.com
9594 AUDIENCE : cognito-identity.amazonaws.com
9695 AWS_REGION : eu-central-1
97- GITHUB_RUN_ID : ${{ github.run_id }}
9896 run : |
99- # Get GitHub Actions ID token using script
100- ACCESS_TOKEN=$("$GITHUB_ACTION_PATH/scripts/get-github-token.sh")
101- echo "::add-mask::$ACCESS_TOKEN"
102-
103- # Get Identity ID
104- identityId=$(aws cognito-identity get-id \
105- --identity-pool-id "$POOL_ID" \
106- --account-id "$AWS_ACCOUNT_ID" \
107- --logins '{"'"$IDENTITY_PROVIDER_NAME"'":"'"$ACCESS_TOKEN"'"}' \
108- --query 'IdentityId' --output text)
109-
110- # Validate Identity ID was obtained
111- if [[ "$identityId" == "null" || -z "$identityId" ]]; then
112- echo "::error::Failed to obtain Identity ID from Cognito Identity Pool"
113- echo "::error::Check identity pool configuration and IAM roles"
114- exit 1
115- fi
116-
117- # Get and validate AWS credentials
118- awsCredentials=$(aws cognito-identity get-credentials-for-identity \
119- --identity-id "$identityId" \
120- --logins '{"'"$IDENTITY_PROVIDER_NAME"'":"'"$ACCESS_TOKEN"'"}')
121-
122- AWS_ACCESS_KEY_ID=$(echo "$awsCredentials" | jq -r ".Credentials.AccessKeyId")
123- AWS_SECRET_ACCESS_KEY=$(echo "$awsCredentials" | jq -r ".Credentials.SecretKey")
124- AWS_SESSION_TOKEN=$(echo "$awsCredentials" | jq -r ".Credentials.SessionToken")
125- if [[ "$AWS_ACCESS_KEY_ID" == "null" || -z "$AWS_ACCESS_KEY_ID" ]]; then
126- echo "::error::Failed to obtain AWS Access Key ID"
127- exit 1
128- fi
129- if [[ "$AWS_SECRET_ACCESS_KEY" == "null" || -z "$AWS_SECRET_ACCESS_KEY" ]]; then
130- echo "::error::Failed to obtain AWS Secret Access Key"
131- exit 1
132- fi
133- if [[ "$AWS_SESSION_TOKEN" == "null" || -z "$AWS_SESSION_TOKEN" ]]; then
134- echo "::error::Failed to obtain AWS Session Token"
135- exit 1
136- fi
137- echo "::add-mask::$AWS_ACCESS_KEY_ID"
138- echo "::add-mask::$AWS_SECRET_ACCESS_KEY"
139- echo "::add-mask::$AWS_SESSION_TOKEN"
140-
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-
97+ PROFILE_NAME="gh-action-cache"
14698 mkdir -p ~/.aws
14799 chmod 700 ~/.aws
148100
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"
101+ cat <<CONFIG >> ~/.aws/config
102+ [profile ${PROFILE_NAME}]
103+ region = ${AWS_REGION}
104+ credential_process = ${GITHUB_ACTION_PATH}/scripts/cache-credential-process.sh
105+ CONFIG
156106
157107 - name : Prepare cache keys
158108 if : steps.cache-backend.outputs.cache-backend == 's3'
@@ -174,10 +124,13 @@ runs:
174124 RUNS_ON_S3_BUCKET_CACHE : sonarsource-s3-cache-${{ inputs.environment }}-bucket
175125 AWS_DEFAULT_REGION : eu-central-1
176126 AWS_REGION : eu-central-1
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 }}
127+ AWS_SDK_LOAD_CONFIG : 1
128+ AWS_PROFILE : gh-action-cache
129+ AWS_DEFAULT_PROFILE : gh-action-cache
130+ POOL_ID : ${{ inputs.environment == 'prod' && 'eu-central-1:511fe374-ae4f-46d0-adb7-9246e570c7f4' || 'eu-central-1:3221c6ea-3f67-4fd8-a7ff-7426f96add89' }}
131+ AWS_ACCOUNT_ID : ${{ inputs.environment == 'prod' && '275878209202' || '460386131003' }}
132+ IDENTITY_PROVIDER_NAME : token.actions.githubusercontent.com
133+ AUDIENCE : cognito-identity.amazonaws.com
181134 with :
182135 path : ${{ inputs.path }}
183136 key : ${{ steps.prepare-keys.outputs.branch-key }}
0 commit comments