Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Add SafeURL helper method to GitRemoteConfig
Browse files Browse the repository at this point in the history
During the development of the (secure) Git HTTPS credential feature,
I did not take the response of the `GitRepoConfig` API method into
account. As a direct result, the `fluxctl sync` command still exposes
the full Git URL in the logs.

This commit adds (and implements) a helper method `SafeURL` to
`GitRemoteConfig`, which makes it possible to print the URL without
leaking any sensitive data.
  • Loading branch information
hiddeco committed Oct 24, 2019
1 parent 874f1e9 commit 0060275
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/fluxctl/sync_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ func (opts *syncOpts) RunE(cmd *cobra.Command, args []string) error {
case git.RepoReady:
break
default:
return fmt.Errorf("git repository %s is not ready to sync (status: %s)", gitConfig.Remote.URL, string(gitConfig.Status))
return fmt.Errorf("git repository %s is not ready to sync (status: %s)", gitConfig.Remote.SafeURL(), string(gitConfig.Status))
}

fmt.Fprintf(cmd.OutOrStderr(), "Synchronizing with %s\n", gitConfig.Remote.URL)
fmt.Fprintf(cmd.OutOrStderr(), "Synchronizing with %s\n", gitConfig.Remote.SafeURL())

updateSpec := update.Spec{
Type: update.Sync,
Expand Down
15 changes: 15 additions & 0 deletions pkg/api/v6/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package v6

import (
"context"
"fmt"
"net/url"

giturls "github.com/whilp/git-urls"

"github.com/fluxcd/flux/pkg/cluster"
"github.com/fluxcd/flux/pkg/git"
Expand Down Expand Up @@ -54,6 +58,17 @@ type GitRemoteConfig struct {
Path string `json:"path"`
}

func (c GitRemoteConfig) SafeURL() string {
u, err := giturls.Parse(c.URL)
if err != nil {
return fmt.Sprintf("<unparseable: %s>", c.URL)
}
if u.User != nil {
u.User = url.User(u.User.Username())
}
return u.String()
}

type GitConfig struct {
Remote GitRemoteConfig `json:"remote"`
PublicSSHKey ssh.PublicKey `json:"publicSSHKey"`
Expand Down

0 comments on commit 0060275

Please sign in to comment.