Skip to content

Commit

Permalink
add helm auth validation
Browse files Browse the repository at this point in the history
  • Loading branch information
dbw7 committed Mar 12, 2024
1 parent d1e49a9 commit 95e7034
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/image/validation/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@ func validateRepo(repo *image.HelmRepository, seenHelmRepos map[string]bool) []F
})
}

if repo.Authentication.Username != "" && repo.Authentication.Password == "" {
failures = append(failures, FailedValidation{
UserMessage: fmt.Sprintf("Helm repository 'password' field not defined for %q.", repo.Name),
})
}

if repo.Authentication.Username == "" && repo.Authentication.Password != "" {
failures = append(failures, FailedValidation{
UserMessage: fmt.Sprintf("Helm repository 'username' field not defined for %q.", repo.Name),
})
}

return failures
}

Expand Down
52 changes: 52 additions & 0 deletions pkg/image/validation/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,58 @@ func TestValidateHelmCharts(t *testing.T) {
"Helm repository 'url' field for \"apache-repo\" must begin with either 'oci://', 'http://', or 'https://'.",
},
},
`helm repository username no password`: {
K8s: image.Kubernetes{
Helm: image.Helm{
Charts: []image.HelmChart{
{
Name: "apache",
RepositoryName: "apache-repo",
Version: "10.7.0",
},
},
Repositories: []image.HelmRepository{
{
Name: "apache-repo",
URL: "oci://registry-1.docker.io/bitnamicharts/apache",
Authentication: image.HelmAuthentication{
Username: "user",
Password: "",
},
},
},
},
},
ExpectedFailedMessages: []string{
"Helm repository 'password' field not defined for \"apache-repo\".",
},
},
`helm repository password no username`: {
K8s: image.Kubernetes{
Helm: image.Helm{
Charts: []image.HelmChart{
{
Name: "apache",
RepositoryName: "apache-repo",
Version: "10.7.0",
},
},
Repositories: []image.HelmRepository{
{
Name: "apache-repo",
URL: "oci://registry-1.docker.io/bitnamicharts/apache",
Authentication: image.HelmAuthentication{
Username: "",
Password: "pass",
},
},
},
},
},
ExpectedFailedMessages: []string{
"Helm repository 'username' field not defined for \"apache-repo\".",
},
},
}

for name, test := range tests {
Expand Down

0 comments on commit 95e7034

Please sign in to comment.