Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support private Aws Ecr helm repositories for chart dependencies #200

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

orenlevi111
Copy link

No description provided.

Comment on lines +122 to +128
s := os.Getenv("ECR_LOGIN_ENABLED")
ecr_login_enabled, err := strconv.ParseBool(s)
if err != nil {
log.Fatal()
}

if ecr_login_enabled {
Copy link
Collaborator

@djeebus djeebus Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you modify the args to include something like cfg config.ServerConfig, then you can clean up some of this:

Suggested change
s := os.Getenv("ECR_LOGIN_ENABLED")
ecr_login_enabled, err := strconv.ParseBool(s)
if err != nil {
log.Fatal()
}
if ecr_login_enabled {
if cfg.EcrLoginEnabled {

You can pass it into the call to GetManifestsLocal in worker.go, roughly like 110, by passing w.ctr.Config

|`KUBECHECKS_ARGOCD_API_SERVER_ADDR`|ArgoCD API Server Address.|`argocd-server`|
|`KUBECHECKS_ARGOCD_API_TOKEN`|ArgoCD API token.||
|`KUBECHECKS_AWS_ECR_HOST`|The Aws ecr host. i.e: <account-id>.dkr.ecr.<region>.amazonaws.com.||
|`KUBECHECKS_ECR_LOGIN_ENABLED`|Enable Aws Ecr login and helm dependency build for chart dependencies that are hosted on Aws private Ecr repositories.|`false`|
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this, or is it enough to have KUBECHECKS_AWS_ECR_HOST be set to a non-empty string?

)

// Retrieve token for authentication against ECR registries.
func getToken(aws_ecr_host string) (string, error) {
os.Setenv("AWS_SDK_LOAD_CONFIG", "1")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to set this here, we'd rather allow the user to set this when running the application

// Retrieve token for authentication against ECR registries.
func getToken(aws_ecr_host string) (string, error) {
os.Setenv("AWS_SDK_LOAD_CONFIG", "1")
var region = strings.SplitN(string(aws_ecr_host), ".", 6)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var region = strings.SplitN(string(aws_ecr_host), ".", 6)
var region = strings.SplitN(aws_ecr_host, ".", 6)

)

// Retrieve token for authentication against ECR registries.
func getToken(aws_ecr_host string) (string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more nitpicking:

Suggested change
func getToken(aws_ecr_host string) (string, error) {
func getToken(awsECRHost string) (string, error) {

var aws_ecr_host = os.Getenv("AWS_ECR_HOST")
var currToken = ""
if token, err := getToken(aws_ecr_host); err != nil {
fmt.Println(err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll want to return this error, as we won't want to login to the registry if we can't get a token

return parts[1], nil
}

func helmLogin(tempRepoDir string, changedAppFilePath string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nitpicky:

Suggested change
func helmLogin(tempRepoDir string, changedAppFilePath string) error {
func helmLogin(tempRepoDir, changedAppFilePath string) error {

@KyriosGN0
Copy link
Contributor

can this be applicable to also Google artifact Registry/GCR repos?

@orenlevi111
Copy link
Author

can this be applicable to also Google artifact Registry/GCR repos?

u will need to re implement the get token function using google gcp library:
// Retrieve token for authentication against ECR registries.
func getToken(aws_ecr_host string) (string, error) {
os.Setenv("AWS_SDK_LOAD_CONFIG", "1")
var region = strings.SplitN(string(aws_ecr_host), ".", 6)
cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(region[3]))
if err != nil {
return "", err
}

svc := ecr.NewFromConfig(cfg)
token, err := svc.GetAuthorizationToken(context.TODO(), &ecr.GetAuthorizationTokenInput{})
if err != nil {
	return "", err
}

authData := token.AuthorizationData[0].AuthorizationToken
data, err := base64.StdEncoding.DecodeString(*authData)
if err != nil {
	return "", err
}

parts := strings.SplitN(string(data), ":", 2)

return parts[1], nil

}

and u will need to change the hardcoded username: "AWS" from the helmLogin function, that's all.
i dont have any gcp cloud so i cannt assist here. sorry

@shlomitubul
Copy link
Contributor

i take diffrent approach for gcp gar: #308

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants