Skip to content

Commit 3a2a328

Browse files
committed
Add diagnostics logging for S3 cache AssumeRole operations
Add structured logging to track AssumeRole operation duration and role ARN when fetching credentials for S3 cache uploads. This helps diagnose issues with IAM role authentication on AWS EKS. See: https://gitlab.com/gitlab-com/request-for-help/-/work_items/4098
1 parent 9452f0f commit 3a2a328

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

cache/s3v2/s3.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,21 +174,37 @@ func (c *s3Client) FetchCredentialsForRole(ctx context.Context, roleARN, bucketN
174174
duration = timeout
175175
}
176176

177+
startTime := time.Now()
177178
roleCredentials, err := stsClient.AssumeRole(ctx, &sts.AssumeRoleInput{
178179
RoleArn: aws.String(roleARN),
179180
RoleSessionName: aws.String(sessionName),
180181
Policy: aws.String(sessionPolicy), // Limit the role's access
181182
DurationSeconds: aws.Int32(int32(duration.Seconds())),
182183
})
184+
elapsed := time.Since(startTime).Seconds()
185+
183186
if err != nil {
184-
return nil, fmt.Errorf("failed to assume role: %w", err)
187+
logrus.WithError(err).WithFields(logrus.Fields{
188+
"role_arn": roleARN,
189+
"duration_s": elapsed,
190+
}).Error("Failed to assume role for cache credentials")
191+
return nil, fmt.Errorf("failed to assume role (took %.2fs): %w", elapsed, err)
185192
}
186193
// AssumeRole should always return credentials if successful, but
187194
// just in case it doesn't let's check this.
188195
if roleCredentials.Credentials == nil {
189-
return nil, fmt.Errorf("failed to retrieve credentials: %w", err)
196+
logrus.WithFields(logrus.Fields{
197+
"role_arn": roleARN,
198+
"duration_s": elapsed,
199+
}).Error("AssumeRole succeeded but returned no credentials")
200+
return nil, fmt.Errorf("failed to retrieve credentials (took %.2fs): %w", elapsed, err)
190201
}
191202

203+
logrus.WithFields(logrus.Fields{
204+
"role_arn": roleARN,
205+
"duration_s": elapsed,
206+
}).Debug("Successfully assumed role for cache credentials")
207+
192208
return map[string]string{
193209
"AWS_ACCESS_KEY_ID": *roleCredentials.Credentials.AccessKeyId,
194210
"AWS_SECRET_ACCESS_KEY": *roleCredentials.Credentials.SecretAccessKey,

0 commit comments

Comments
 (0)