Skip to content

Commit e47d491

Browse files
authored
Merge pull request #6948 from devtron-labs/feat/ecr-cross-account-assume-role
fix: streamline AWS session creation and improve error handling
2 parents 90889af + 6d7284c commit e47d491

4 files changed

Lines changed: 31 additions & 18 deletions

File tree

internal/util/EcrService.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/aws/aws-sdk-go/aws"
2222
"github.com/aws/aws-sdk-go/aws/awserr"
2323
"github.com/aws/aws-sdk-go/aws/credentials"
24-
"github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
2524
"github.com/aws/aws-sdk-go/aws/session"
2625
"github.com/aws/aws-sdk-go/service/ecr"
2726
"github.com/juju/errors"
@@ -33,26 +32,22 @@ func CreateEcrRepo(repoName string, reg string, accessKey string, secretKey stri
3332
region := reg
3433
//fmt.Printf("repoName %s, reg %s, accessKey %s, secretKey %s\n", repoName, reg, accessKey, secretKey)
3534

36-
var creds *credentials.Credentials
35+
var sess *session.Session
36+
var err error
3737

3838
if len(accessKey) == 0 || len(secretKey) == 0 {
39-
//fmt.Println("empty accessKey or secretKey")
40-
sess, err := session.NewSession(&aws.Config{
39+
// Case 1: IAM role — use default credential chain (IRSA, instance profile, task role, env vars)
40+
sess, err = session.NewSession(&aws.Config{
4141
Region: &region,
4242
})
43-
if err != nil {
44-
log.Println(err)
45-
return err
46-
}
47-
creds = ec2rolecreds.NewCredentials(sess)
4843
} else {
49-
creds = credentials.NewStaticCredentials(accessKey, secretKey, "")
44+
// Case 2: Static credentials
45+
creds := credentials.NewStaticCredentials(accessKey, secretKey, "")
46+
sess, err = session.NewSession(&aws.Config{
47+
Region: &region,
48+
Credentials: creds,
49+
})
5050
}
51-
52-
sess, err := session.NewSession(&aws.Config{
53-
Region: &region,
54-
Credentials: creds,
55-
})
5651
if err != nil {
5752
log.Println(err)
5853
return err

pkg/pipeline/DockerRegistryConfig.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ package pipeline
1919
import (
2020
"context"
2121
"fmt"
22+
"net/http"
23+
"strings"
24+
"time"
25+
2226
"github.com/devtron-labs/common-lib/securestore"
2327
bean2 "github.com/devtron-labs/devtron/api/helm-app/gRPC"
2428
client "github.com/devtron-labs/devtron/api/helm-app/service"
@@ -27,9 +31,6 @@ import (
2731
"github.com/devtron-labs/devtron/pkg/sql"
2832
"github.com/go-pg/pg"
2933
"k8s.io/utils/strings/slices"
30-
"net/http"
31-
"strings"
32-
"time"
3334

3435
"github.com/devtron-labs/devtron/internal/constants"
3536
"github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
@@ -906,6 +907,10 @@ func (impl DockerRegistryConfigImpl) ValidateRegistryCredentials(bean *types.Doc
906907
bean.RegistryType == repository.REGISTRYTYPE_OTHER {
907908
return nil
908909
}
910+
// Verify credentials only for chart OCI registry using helm registry login, as for container OCI registry
911+
if _, ok := bean.OCIRegistryConfig[repository.OCI_REGISRTY_REPO_TYPE_CHART]; !ok {
912+
return nil
913+
}
909914
request := &bean2.RegistryCredential{
910915
RegistryUrl: bean.RegistryURL,
911916
Username: bean.Username,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright (c) 2025. Devtron Inc.
3+
*/
4+
5+
ALTER TABLE public.docker_artifact_store
6+
DROP COLUMN IF EXISTS assume_role_arn;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright (c) 2025. Devtron Inc.
3+
*/
4+
5+
-- Add assume_role_arn column to docker_artifact_store for cross-account ECR access via STS AssumeRole
6+
ALTER TABLE public.docker_artifact_store
7+
ADD COLUMN IF NOT EXISTS assume_role_arn VARCHAR(300) DEFAULT '';

0 commit comments

Comments
 (0)