Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions internal/util/EcrService.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ecr"
"github.com/juju/errors"
Expand All @@ -33,26 +32,22 @@ func CreateEcrRepo(repoName string, reg string, accessKey string, secretKey stri
region := reg
//fmt.Printf("repoName %s, reg %s, accessKey %s, secretKey %s\n", repoName, reg, accessKey, secretKey)

var creds *credentials.Credentials
var sess *session.Session
var err error

if len(accessKey) == 0 || len(secretKey) == 0 {
//fmt.Println("empty accessKey or secretKey")
sess, err := session.NewSession(&aws.Config{
// Case 1: IAM role — use default credential chain (IRSA, instance profile, task role, env vars)
sess, err = session.NewSession(&aws.Config{
Region: &region,
})
if err != nil {
log.Println(err)
return err
}
creds = ec2rolecreds.NewCredentials(sess)
} else {
creds = credentials.NewStaticCredentials(accessKey, secretKey, "")
// Case 2: Static credentials
creds := credentials.NewStaticCredentials(accessKey, secretKey, "")
sess, err = session.NewSession(&aws.Config{
Region: &region,
Credentials: creds,
})
}

sess, err := session.NewSession(&aws.Config{
Region: &region,
Credentials: creds,
})
if err != nil {
log.Println(err)
return err
Expand Down
11 changes: 8 additions & 3 deletions pkg/pipeline/DockerRegistryConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ package pipeline
import (
"context"
"fmt"
"net/http"
"strings"
"time"

"github.com/devtron-labs/common-lib/securestore"
bean2 "github.com/devtron-labs/devtron/api/helm-app/gRPC"
client "github.com/devtron-labs/devtron/api/helm-app/service"
Expand All @@ -27,9 +31,6 @@ import (
"github.com/devtron-labs/devtron/pkg/sql"
"github.com/go-pg/pg"
"k8s.io/utils/strings/slices"
"net/http"
"strings"
"time"

"github.com/devtron-labs/devtron/internal/constants"
"github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
Expand Down Expand Up @@ -906,6 +907,10 @@ func (impl DockerRegistryConfigImpl) ValidateRegistryCredentials(bean *types.Doc
bean.RegistryType == repository.REGISTRYTYPE_OTHER {
return nil
}
// Verify credentials only for chart OCI registry using helm registry login, as for container OCI registry
if _, ok := bean.OCIRegistryConfig[repository.OCI_REGISRTY_REPO_TYPE_CHART]; !ok {
return nil
}
request := &bean2.RegistryCredential{
RegistryUrl: bean.RegistryURL,
Username: bean.Username,
Expand Down
Loading