Skip to content

Commit

Permalink
Use execution creds ID in ECR auth cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrc committed Sep 19, 2024
1 parent e59f18c commit d82670e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
16 changes: 14 additions & 2 deletions agent/dockerclient/dockerauth/ecr.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
ecrapi "github.com/aws/amazon-ecs-agent/agent/ecr/model/ecr"
"github.com/aws/amazon-ecs-agent/ecs-agent/async"
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"
"github.com/aws/amazon-ecs-agent/ecs-agent/logger"
"github.com/aws/amazon-ecs-agent/ecs-agent/logger/field"
"github.com/aws/amazon-ecs-agent/ecs-agent/utils/retry"
"github.com/aws/aws-sdk-go/aws"
log "github.com/cihub/seelog"
Expand All @@ -35,6 +37,7 @@ type cacheKey struct {
roleARN string
registryID string
endpointOverride string
credentialsID string
}

type ecrAuthProvider struct {
Expand All @@ -52,7 +55,8 @@ const (

// String formats the cachKey as a string
func (key *cacheKey) String() string {
return fmt.Sprintf("%s-%s-%s-%s", key.roleARN, key.region, key.registryID, key.endpointOverride)
return fmt.Sprintf("%s%s-%s-%s-%s",
key.credentialsID, key.roleARN, key.region, key.registryID, key.endpointOverride)
}

// NewECRAuthProvider returns a DockerAuthProvider that can handle retrieve
Expand Down Expand Up @@ -91,6 +95,7 @@ func (authProvider *ecrAuthProvider) GetAuthconfig(image string,
// containers pull with the same role can be cached
if authData.GetPullCredentials() != (credentials.IAMRoleCredentials{}) {
key.roleARN = authData.GetPullCredentials().RoleArn
key.credentialsID = authData.GetPullCredentials().CredentialsID
}

// Try to get the auth config from cache
Expand Down Expand Up @@ -140,7 +145,14 @@ func (authProvider *ecrAuthProvider) getAuthConfigFromECR(image string, key cach
return types.AuthConfig{}, err
}

log.Debugf("Calling ECR.GetAuthorizationToken for %s", image)
logger.Debug("Calling ECR.GetAuthorizationToken", logger.Fields{
field.Image: image,
field.CredentialsID: key.credentialsID,
field.RegistryID: key.registryID,
field.RoleARN: key.roleARN,
"endpointOverride": key.endpointOverride,
"region": key.region,
})
ecrAuthData, err := client.GetAuthorizationToken(authData.RegistryID)
if err != nil {
return types.AuthConfig{}, err
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ecs-agent/logger/field/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ const (
Request = "request"
RoleType = "roleType"
RoleARN = "roleARN"
RegistryID = "registryID"
)

0 comments on commit d82670e

Please sign in to comment.