You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/credentials/providers/instance_credentials_provider.go
Copy file name to clipboardExpand all lines: agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/credentials/providers/instance_credentials_provider_linux.go
Copy file name to clipboardExpand all lines: agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/credentials/providers/instance_credentials_provider_windows.go
// NewInstanceCredentialsCache returns a chain of instance credentials providers wrapped in a credentials cache.
36
+
// The instance credentials chain is the default credentials chain plus the "rotating shared credentials provider",
37
+
// so credentials will be checked in this order:
38
+
//
39
+
// 1. Env vars (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY).
40
+
//
41
+
// 2. Shared credentials file (https://docs.aws.amazon.com/ses/latest/DeveloperGuide/create-shared-credentials-file.html) (file at ~/.aws/credentials containing access key id and secret access key).
42
+
//
43
+
// 3. EC2 role credentials. This is an IAM role that the user specifies when they launch their EC2 container instance (ie ecsInstanceRole (https://docs.aws.amazon.com/AmazonECS/latest/developerguide/instance_IAM_role.html)).
44
+
//
45
+
// 4. Rotating shared credentials file located at /rotatingcreds/credentials
46
+
//
47
+
// The default credential chain provided by the SDK includes:
48
+
// * EnvProvider
49
+
// * SharedCredentialsProvider
50
+
// * RemoteCredProvider (EC2RoleProvider)
51
+
//
52
+
// In the case of ECS-A, there are a couple considerations:
53
+
//
54
+
// * The `SharedCredentialsProvider` takes
55
+
// precedence over the `RotatingSharedCredentialsProvider` and this results
56
+
// in the credentials not being refreshed. To mitigate this issue, we will
57
+
// reorder the credential chain and ensure that `RotatingSharedCredentialsProvider`
58
+
// takes precedence over the `SharedCredentialsProvider` for ECS-A.
59
+
//
60
+
// * On EC2, the `EC2RoleProvider` takes precedence over the `RotatingSharedCredentialsProvider`.
61
+
// Prioritizing `RotatingSharedCredentialsProvider` over the
62
+
// `EC2RoleProvider` ensures that SSM credentials will be used if they are available,
63
+
// and the EC2 credentials will only be used as a last-resort.
64
+
65
+
funcNewInstanceCredentialsCache(
66
+
isExternalbool,
67
+
rotatingSharedCreds aws.CredentialsProvider,
68
+
imdsClient ec2rolecreds.GetMetadataAPIClient,
69
+
)*aws.CredentialsCache {
70
+
varproviders []aws.CredentialsProvider
71
+
72
+
// If imdsClient is nil, the SDK will default to the EC2 IMDS client.
73
+
// Pass a non-nil imdsClient to stub it out in tests.