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: sanitize repo creds in error messages (#12309) #12320

Merged
merged 4 commits into from
Feb 8, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/apis/application/v1alpha1/repository_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
"fmt"
"net/url"

"github.com/argoproj/argo-cd/v2/util/cert"
Expand Down Expand Up @@ -265,6 +266,14 @@ func (m *Repository) CopySettingsFrom(source *Repository) {
}
}

// StringForLogging gets a string representation of the Repository which is safe to log or return to the user.
func (m *Repository) StringForLogging() string {
if m == nil {
return ""
}
return fmt.Sprintf("&Repository{Repo: %q, Type: %q, Name: %q, Project: %q}", m.Repo, m.Type, m.Name, m.Project)
}
jannfis marked this conversation as resolved.
Show resolved Hide resolved

// Repositories defines a list of Repository configurations
type Repositories []*Repository

Expand Down
2 changes: 1 addition & 1 deletion util/argo/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func validateRepo(ctx context.Context,
return nil, err
}
if err := TestRepoWithKnownType(ctx, repoClient, repo, source.IsHelm(), source.IsHelmOci()); err != nil {
errMessage = fmt.Sprintf("repositories not accessible: %v", repo)
errMessage = fmt.Sprintf("repositories not accessible: %v: %v", repo.StringForLogging(), err)
}
repoAccessible := false

Expand Down