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

fix(reposerver): fix OCI repository matching (#12436) #17955

Merged
merged 2 commits into from May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions USERS.md
Expand Up @@ -43,6 +43,7 @@ Currently, the following organizations are **officially** using Argo CD:
1. [BMW Group](https://www.bmwgroup.com/)
1. [Boozt](https://www.booztgroup.com/)
1. [Boticario](https://www.boticario.com.br/)
1. [Broker Consulting, a.s.](https://www.bcas.cz/en/)
1. [Bulder Bank](https://bulderbank.no)
1. [CAM](https://cam-inc.co.jp)
1. [Camptocamp](https://camptocamp.com)
Expand Down
4 changes: 3 additions & 1 deletion reposerver/repository/repository.go
Expand Up @@ -1000,7 +1000,9 @@ func getHelmRepos(appPath string, repositories []*v1alpha1.Repository, helmRepoC
// finally if repo is OCI and no credentials found, use the first OCI credential matching by hostname
// see https://github.com/argoproj/argo-cd/issues/14636
for _, cred := range repositories {
if depURL, err := url.Parse("oci://" + dep.Repo); err == nil && cred.EnableOCI && depURL.Host == cred.Repo {
// if the repo is OCI, don't match the repository URL exactly, but only as a dependent repository prefix just like in the getRepoCredential function
// see https://github.com/argoproj/argo-cd/issues/12436
if _, err := url.Parse("oci://" + dep.Repo); err == nil && cred.EnableOCI && strings.HasPrefix(dep.Repo, cred.Repo) {
repo.Username = cred.Username
repo.Password = cred.Password
break
Expand Down
17 changes: 15 additions & 2 deletions reposerver/repository/repository_test.go
Expand Up @@ -3036,9 +3036,9 @@ func Test_populateHelmAppDetails_values_symlinks(t *testing.T) {
})
}

func TestGetHelmRepos_OCIDependencies(t *testing.T) {
func TestGetHelmRepos_OCIDependenciesWithHelmRepo(t *testing.T) {
src := argoappv1.ApplicationSource{Path: "."}
q := apiclient.ManifestRequest{Repo: &argoappv1.Repository{}, ApplicationSource: &src, HelmRepoCreds: []*argoappv1.RepoCreds{
q := apiclient.ManifestRequest{Repos: []*argoappv1.Repository{}, ApplicationSource: &src, HelmRepoCreds: []*argoappv1.RepoCreds{
{URL: "example.com", Username: "test", Password: "test", EnableOCI: true},
}}

Expand All @@ -3051,6 +3051,19 @@ func TestGetHelmRepos_OCIDependencies(t *testing.T) {
assert.Equal(t, helmRepos[0].Repo, "example.com/myrepo")
}

func TestGetHelmRepos_OCIDependenciesWithRepo(t *testing.T) {
src := argoappv1.ApplicationSource{Path: "."}
q := apiclient.ManifestRequest{Repos: []*argoappv1.Repository{{Repo: "example.com", Username: "test", Password: "test", EnableOCI: true}}, ApplicationSource: &src, HelmRepoCreds: []*argoappv1.RepoCreds{}}

helmRepos, err := getHelmRepos("./testdata/oci-dependencies", q.Repos, q.HelmRepoCreds)
assert.Nil(t, err)

assert.Equal(t, len(helmRepos), 1)
assert.Equal(t, helmRepos[0].Username, "test")
assert.Equal(t, helmRepos[0].EnableOci, true)
assert.Equal(t, helmRepos[0].Repo, "example.com/myrepo")
}

func TestGetHelmRepo_NamedRepos(t *testing.T) {
src := argoappv1.ApplicationSource{Path: "."}
q := apiclient.ManifestRequest{Repo: &argoappv1.Repository{}, ApplicationSource: &src, Repos: []*argoappv1.Repository{{
Expand Down