Skip to content

Commit

Permalink
feat: if project-scoped ECR auth fails, fallback to default (#2285)
Browse files Browse the repository at this point in the history
Signed-off-by: Remington Breeze <[email protected]>
Co-authored-by: Kent Rancourt <[email protected]>
  • Loading branch information
rbreeze and krancour authored Jul 11, 2024
1 parent 0da8b5d commit 34d1bfe
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions internal/credentials/kubernetes/ecr/pod_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package ecr
import (
"context"
"crypto/sha256"
"errors"
"fmt"
"net/http"
"os"
"strings"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
"github.com/aws/aws-sdk-go-v2/service/ecr"
Expand Down Expand Up @@ -163,8 +166,19 @@ func (p *podIdentityCredentialHelper) getAuthToken(
)
output, err := ecrSvc.GetAuthorizationToken(ctx, &ecr.GetAuthorizationTokenInput{})
if err != nil {
logger.Error(err, "error getting ECR authorization token")
return "", nil
var re *awshttp.ResponseError
if !errors.As(err, &re) || re.HTTPStatusCode() != http.StatusForbidden {
return "", err
}
logger.Debug(
"controller IAM role is not authorized to assume project-specific role. falling back to default config",
)
ecrSvc = ecr.NewFromConfig(cfg)
output, err = ecrSvc.GetAuthorizationToken(ctx, &ecr.GetAuthorizationTokenInput{})
if err != nil {
logger.Error(err, "error getting ECR authorization token")
return "", err
}
}
logger.Debug("got ECR authorization token")
return *output.AuthorizationData[0].AuthorizationToken, nil
Expand Down

0 comments on commit 34d1bfe

Please sign in to comment.