diff --git a/cmd/crossplane/common/gitflags.go b/cmd/crossplane/common/gitflags.go new file mode 100644 index 000000000..d5dc11274 --- /dev/null +++ b/cmd/crossplane/common/gitflags.go @@ -0,0 +1,50 @@ +/* +Copyright 2026 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package common + +import ( + "github.com/crossplane/cli/v2/internal/dependency" + "github.com/crossplane/cli/v2/internal/git" +) + +// GitFlags configures authentication and connectivity for git-based +// dependencies. It is embedded in every command that resolves project +// dependencies, so users can pass the same settings across the CLI. +type GitFlags struct { + GitUsername string `default:"x-access-token" env:"CROSSPLANE_GIT_USERNAME" help:"Username for git HTTPS authentication."` + GitToken string `env:"CROSSPLANE_GIT_TOKEN" help:"Token for git HTTPS authentication."` + GitProxy string `env:"CROSSPLANE_GIT_PROXY" help:"Proxy URL to tunnel git operations through, for example http://proxy:8080. Supports HTTP CONNECT for SSH tunneling."` + GitInsecureHostKey bool `env:"CROSSPLANE_GIT_INSECURE_HOST_KEY" help:"Skip SSH host key verification for git operations. Only use if you understand the MITM risks."` +} + +// ManagerOptions returns the dependency manager options the flags configure. +func (f GitFlags) ManagerOptions() []dependency.ManagerOption { + var opts []dependency.ManagerOption + if f.GitToken != "" { + opts = append(opts, dependency.WithGitAuthProvider(&git.HTTPSAuthProvider{ + Username: f.GitUsername, + Password: f.GitToken, + })) + } + if f.GitProxy != "" { + opts = append(opts, dependency.WithGitProxyURL(f.GitProxy)) + } + if f.GitInsecureHostKey { + opts = append(opts, dependency.WithGitInsecureHostKey(true)) + } + return opts +} diff --git a/cmd/crossplane/dependency/add.go b/cmd/crossplane/dependency/add.go index 4b1d9fcbc..e9a7d170d 100644 --- a/cmd/crossplane/dependency/add.go +++ b/cmd/crossplane/dependency/add.go @@ -29,9 +29,9 @@ import ( "github.com/crossplane/crossplane-runtime/v2/pkg/logging" "github.com/crossplane/cli/v2/apis/dev/v1alpha1" + "github.com/crossplane/cli/v2/cmd/crossplane/common" "github.com/crossplane/cli/v2/internal/config" "github.com/crossplane/cli/v2/internal/dependency" - "github.com/crossplane/cli/v2/internal/git" "github.com/crossplane/cli/v2/internal/project/projectfile" "github.com/crossplane/cli/v2/internal/schemas/generator" "github.com/crossplane/cli/v2/internal/terminal" @@ -45,11 +45,11 @@ var addHelp string // addCmd adds a dependency to the current project. type addCmd struct { + common.GitFlags + Package string `arg:"" help:"Package to add (xpkg OCI reference, k8s:, git repository URL, or HTTP(S) URL)."` ProjectFile string `default:"${project_file}" help:"Path to project definition file." short:"f"` CacheDir string `env:"CROSSPLANE_XPKG_CACHE" help:"Directory for cached xpkg package contents." name:"cache-dir"` - GitToken string `env:"CROSSPLANE_GIT_TOKEN" help:"Token for git HTTPS authentication."` - GitUsername string `default:"x-access-token" env:"CROSSPLANE_GIT_USERNAME" help:"Username for git HTTPS authentication."` // Flags for specific dependency types. APIOnly bool `help:"Mark an xpkg dependency as API-only (not a runtime dependency)." name:"api-only"` @@ -82,7 +82,9 @@ func (c *addCmd) Run(logger logging.Logger, sp terminal.SpinnerPrinter, cfg *con return errors.Wrap(err, "cannot create xpkg client") } - opts := []dependency.ManagerOption{ + gitOpts := c.ManagerOptions() + opts := make([]dependency.ManagerOption, 0, 3+len(gitOpts)) + opts = append(opts, dependency.WithProjectFile(c.ProjectFile), dependency.WithSchemaGenerators(generator.Filter( generator.AllLanguages( @@ -92,14 +94,8 @@ func (c *addCmd) Run(logger logging.Logger, sp terminal.SpinnerPrinter, cfg *con proj.Spec.Schemas.GetLanguages(), )), dependency.WithXpkgClient(client), - } - - if c.GitToken != "" { - opts = append(opts, dependency.WithGitAuthProvider(&git.HTTPSAuthProvider{ - Username: c.GitUsername, - Password: c.GitToken, - })) - } + ) + opts = append(opts, gitOpts...) m := dependency.NewManager(proj, projFS, opts...) diff --git a/cmd/crossplane/dependency/cache.go b/cmd/crossplane/dependency/cache.go index 3cee514b3..ee9962a87 100644 --- a/cmd/crossplane/dependency/cache.go +++ b/cmd/crossplane/dependency/cache.go @@ -28,10 +28,10 @@ import ( "github.com/crossplane/crossplane-runtime/v2/pkg/errors" "github.com/crossplane/crossplane-runtime/v2/pkg/logging" + "github.com/crossplane/cli/v2/cmd/crossplane/common" "github.com/crossplane/cli/v2/internal/async" "github.com/crossplane/cli/v2/internal/config" "github.com/crossplane/cli/v2/internal/dependency" - "github.com/crossplane/cli/v2/internal/git" "github.com/crossplane/cli/v2/internal/project/projectfile" "github.com/crossplane/cli/v2/internal/schemas/generator" "github.com/crossplane/cli/v2/internal/schemas/manager" @@ -47,10 +47,10 @@ var updateHelp string // updateCacheCmd updates the dependency cache by regenerating all schemas. type updateCacheCmd struct { + common.GitFlags + ProjectFile string `default:"${project_file}" help:"Path to project definition file." short:"f"` CacheDir string `env:"CROSSPLANE_XPKG_CACHE" help:"Directory for cached xpkg package contents." name:"cache-dir"` - GitToken string `env:"CROSSPLANE_GIT_TOKEN" help:"Token for git HTTPS authentication."` - GitUsername string `default:"x-access-token" env:"CROSSPLANE_GIT_USERNAME" help:"Username for git HTTPS authentication."` } func (c *updateCacheCmd) Help() string { @@ -86,18 +86,14 @@ func (c *updateCacheCmd) Run(logger logging.Logger, sp terminal.SpinnerPrinter, proj.Spec.Schemas.GetLanguages(), ) - opts := []dependency.ManagerOption{ + gitOpts := c.ManagerOptions() + opts := make([]dependency.ManagerOption, 0, 3+len(gitOpts)) + opts = append(opts, dependency.WithProjectFile(c.ProjectFile), dependency.WithSchemaGenerators(generators), dependency.WithXpkgClient(client), - } - - if c.GitToken != "" { - opts = append(opts, dependency.WithGitAuthProvider(&git.HTTPSAuthProvider{ - Username: c.GitUsername, - Password: c.GitToken, - })) - } + ) + opts = append(opts, gitOpts...) m := dependency.NewManager(proj, projFS, opts...) diff --git a/cmd/crossplane/dependency/dependency_test.go b/cmd/crossplane/dependency/dependency_test.go index ee254ac68..3ffa6c524 100644 --- a/cmd/crossplane/dependency/dependency_test.go +++ b/cmd/crossplane/dependency/dependency_test.go @@ -31,20 +31,21 @@ import ( "github.com/crossplane/crossplane-runtime/v2/pkg/logging" + "github.com/crossplane/cli/v2/cmd/crossplane/common" "github.com/crossplane/cli/v2/internal/config" "github.com/crossplane/cli/v2/internal/terminal" ) func TestAddGitAuth(t *testing.T) { testDependencyGitAuth(t, func(serverURL, projectFile, cacheDir, token string) error { - c := &addCmd{Package: serverURL + "/repo.git", GitRef: "main", ProjectFile: projectFile, CacheDir: cacheDir, GitToken: token, GitUsername: "test-user"} + c := &addCmd{Package: serverURL + "/repo.git", GitRef: "main", ProjectFile: projectFile, CacheDir: cacheDir, GitFlags: common.GitFlags{GitToken: token, GitUsername: "test-user"}} return c.Run(logging.NewNopLogger(), terminal.NewSpinnerPrinter(io.Discard, false), &config.Config{}) }) } func TestUpdateCacheGitAuth(t *testing.T) { testDependencyGitAuth(t, func(_, projectFile, cacheDir, token string) error { - c := &updateCacheCmd{ProjectFile: projectFile, CacheDir: cacheDir, GitToken: token, GitUsername: "test-user"} + c := &updateCacheCmd{ProjectFile: projectFile, CacheDir: cacheDir, GitFlags: common.GitFlags{GitToken: token, GitUsername: "test-user"}} return c.Run(logging.NewNopLogger(), terminal.NewSpinnerPrinter(io.Discard, false), &config.Config{}) }) } diff --git a/cmd/crossplane/project/build.go b/cmd/crossplane/project/build.go index 81fc73fc4..12b75d85c 100644 --- a/cmd/crossplane/project/build.go +++ b/cmd/crossplane/project/build.go @@ -31,10 +31,10 @@ import ( "github.com/crossplane/crossplane-runtime/v2/pkg/logging" devv1alpha1 "github.com/crossplane/cli/v2/apis/dev/v1alpha1" + "github.com/crossplane/cli/v2/cmd/crossplane/common" "github.com/crossplane/cli/v2/internal/async" "github.com/crossplane/cli/v2/internal/config" "github.com/crossplane/cli/v2/internal/dependency" - "github.com/crossplane/cli/v2/internal/git" "github.com/crossplane/cli/v2/internal/project" "github.com/crossplane/cli/v2/internal/project/functions" "github.com/crossplane/cli/v2/internal/project/projectfile" @@ -52,13 +52,13 @@ var buildHelp string // BuildCmd builds a project into Crossplane packages. type BuildCmd struct { + common.GitFlags + ProjectFile string `default:"${project_file}" help:"Path to project definition." short:"f"` Repository string `help:"Override the repository in the project file." optional:""` OutputDir string `default:"_output" help:"Output directory for packages." short:"o"` MaxConcurrency uint `default:"8" help:"Max concurrent function builds."` CacheDir string `env:"CROSSPLANE_XPKG_CACHE" help:"Directory for cached xpkg package contents." name:"cache-dir"` - GitToken string `env:"CROSSPLANE_GIT_TOKEN" help:"Token for git HTTPS authentication."` - GitUsername string `default:"x-access-token" env:"CROSSPLANE_GIT_USERNAME" help:"Username for git HTTPS authentication."` proj *devv1alpha1.Project projFS afero.Fs @@ -115,20 +115,16 @@ func (c *BuildCmd) Run(logger logging.Logger, sp terminal.SpinnerPrinter, cfg *c return errors.Wrap(err, "cannot create xpkg client") } - opts := []dependency.ManagerOption{ + gitOpts := c.ManagerOptions() + opts := make([]dependency.ManagerOption, 0, 5+len(gitOpts)) + opts = append(opts, dependency.WithProjectFile(c.ProjectFile), dependency.WithSchemaFS(schemasFS), dependency.WithSchemaGenerators(generators), dependency.WithSchemaRunner(schemaRunner), dependency.WithXpkgClient(client), - } - - if c.GitToken != "" { - opts = append(opts, dependency.WithGitAuthProvider(&git.HTTPSAuthProvider{ - Username: c.GitUsername, - Password: c.GitToken, - })) - } + ) + opts = append(opts, gitOpts...) depMgr := dependency.NewManager(c.proj, c.projFS, opts...) diff --git a/cmd/crossplane/project/build_test.go b/cmd/crossplane/project/build_test.go index a8fe86fb4..66f63268e 100644 --- a/cmd/crossplane/project/build_test.go +++ b/cmd/crossplane/project/build_test.go @@ -31,6 +31,7 @@ import ( "github.com/crossplane/crossplane-runtime/v2/pkg/logging" + "github.com/crossplane/cli/v2/cmd/crossplane/common" "github.com/crossplane/cli/v2/internal/config" "github.com/crossplane/cli/v2/internal/terminal" ) @@ -74,7 +75,7 @@ spec: sp := terminal.NewSpinnerPrinter(io.Discard, false) cfg := &config.Config{} - c := &BuildCmd{ProjectFile: projectFile, CacheDir: filepath.Join(dir, "cache"), GitToken: token, GitUsername: "test-user", MaxConcurrency: 1} + c := &BuildCmd{ProjectFile: projectFile, CacheDir: filepath.Join(dir, "cache"), GitFlags: common.GitFlags{GitToken: token, GitUsername: "test-user"}, MaxConcurrency: 1} if err := c.AfterApply(); err != nil { t.Fatal(err) } diff --git a/go.mod b/go.mod index 811cf5442..ed37a9c3b 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,9 @@ require ( github.com/shirou/gopsutil/v4 v4.26.10 github.com/spf13/afero v1.15.0 github.com/willabides/kongplete v0.4.0 + golang.org/x/crypto v0.59.0 golang.org/x/mod v0.42.0 + golang.org/x/net v0.62.0 golang.org/x/sync v0.25.0 golang.org/x/sys v0.50.0 golang.org/x/text v0.44.0 @@ -60,6 +62,7 @@ require ( google.golang.org/grpc v1.85.0 google.golang.org/protobuf v1.36.12 gopkg.in/yaml.v3 v3.0.1 + gotest.tools/v3 v3.5.2 helm.sh/helm/v3 v3.22.1 k8s.io/api v0.37.1 k8s.io/apiextensions-apiserver v0.37.1 @@ -317,10 +320,8 @@ require ( go.yaml.in/yaml/v2 v2.4.4 // indirect go.yaml.in/yaml/v3 v3.0.5 // indirect go.yaml.in/yaml/v4 v4.0.0-rc.6 // indirect - golang.org/x/crypto v0.59.0 // indirect golang.org/x/crypto/openpgp v0.1.0-deprecated // indirect golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa // indirect - golang.org/x/net v0.62.0 // indirect golang.org/x/oauth2 v0.36.0 // indirect golang.org/x/term v0.48.0 // indirect golang.org/x/time v0.15.0 // indirect diff --git a/internal/dependency/manager.go b/internal/dependency/manager.go index 98764ce69..0940483e3 100644 --- a/internal/dependency/manager.go +++ b/internal/dependency/manager.go @@ -54,8 +54,9 @@ type Manager struct { projFile string schemas *smanager.Manager - gitCloner git.Cloner - gitAuthProvider git.AuthProvider + gitCloner git.Cloner + gitAuthProvider git.AuthProvider + gitInsecureHostKey bool client clixpkg.Client @@ -71,12 +72,14 @@ type Manager struct { type ManagerOption func(*managerOptions) type managerOptions struct { - projFile string - schemaFS afero.Fs - schemaGenerators []generator.Interface - schemaRunner runner.SchemaRunner - gitAuthProvider git.AuthProvider - client clixpkg.Client + projFile string + schemaFS afero.Fs + schemaGenerators []generator.Interface + schemaRunner runner.SchemaRunner + gitAuthProvider git.AuthProvider + gitProxyURL string + gitInsecureHostKey bool + client clixpkg.Client } // WithProjectFile sets the path to the project file. @@ -114,6 +117,24 @@ func WithGitAuthProvider(p git.AuthProvider) ManagerOption { } } +// WithGitProxyURL tunnels git-based dependency clones via an HTTP CONNECT +// proxy. +func WithGitProxyURL(u string) ManagerOption { + return func(opts *managerOptions) { + opts.gitProxyURL = u + } +} + +// WithGitInsecureHostKey disables SSH host key verification for git-based +// dependencies over SSH. This makes connections vulnerable to +// man-in-the-middle attacks and should only be enabled when the user +// explicitly opts in. +func WithGitInsecureHostKey(insecure bool) ManagerOption { + return func(opts *managerOptions) { + opts.gitInsecureHostKey = insecure + } +} + // WithXpkgClient sets the xpkg client used to resolve version constraints and // to fetch and parse xpkg dependencies. func WithXpkgClient(c clixpkg.Client) ManagerOption { @@ -134,7 +155,6 @@ func NewManager(proj *v1alpha1.Project, projFS afero.Fs, opts ...ManagerOption) schemaRunner: runner.NewRealSchemaRunner( runner.WithImageConfig(proj.Spec.ImageConfigs), ), - gitAuthProvider: &git.HTTPSAuthProvider{}, } for _, opt := range opts { @@ -148,14 +168,15 @@ func NewManager(proj *v1alpha1.Project, projFS afero.Fs, opts ...ManagerOption) ) return &Manager{ - proj: proj, - projFS: projFS, - projFile: options.projFile, - schemas: schemas, - gitCloner: &git.DefaultCloner{}, - gitAuthProvider: options.gitAuthProvider, - client: options.client, - visited: make(map[string]struct{}), + proj: proj, + projFS: projFS, + projFile: options.projFile, + schemas: schemas, + gitCloner: &git.DefaultCloner{ProxyURL: options.gitProxyURL}, + gitAuthProvider: options.gitAuthProvider, + gitInsecureHostKey: options.gitInsecureHostKey, + client: options.client, + visited: make(map[string]struct{}), } } @@ -365,7 +386,7 @@ func (m *Manager) addDependencyNoWrite(ctx context.Context, dep *v1alpha1.Depend return m.addPackage(ctx, xpkgRef(dep.Xpkg.Package, dep.Xpkg.Version), refresh) case dep.Git != nil: - return nil, m.schemas.Add(ctx, smanager.NewGitSource(*dep, m.gitCloner, m.gitAuthProvider)) + return nil, m.schemas.Add(ctx, smanager.NewGitSource(*dep, m.gitCloner, m.gitProviderFor(dep.Git.Repository))) case dep.HTTP != nil: return nil, m.schemas.Add(ctx, smanager.NewHTTPSource(*dep)) case dep.K8s != nil: @@ -375,6 +396,22 @@ func (m *Manager) addDependencyNoWrite(ctx context.Context, dep *v1alpha1.Depend } } +// gitProviderFor returns the auth provider for a git dependency. When the +// caller hasn't supplied one, pick the right default for the transport: SSH +// agent for SSH URLs, anonymous HTTPS otherwise. +func (m *Manager) gitProviderFor(repo string) git.AuthProvider { + if m.gitAuthProvider != nil { + return m.gitAuthProvider + } + if git.IsSSHURL(repo) { + return &git.SSHAgentAuthProvider{ + Username: git.ExtractSSHUsername(repo), + InsecureIgnoreHostKey: m.gitInsecureHostKey, + } + } + return &git.HTTPSAuthProvider{} +} + // Clean removes all generated schemas. func (m *Manager) Clean() error { return m.projFS.RemoveAll(m.proj.Spec.Paths.Schemas) diff --git a/internal/git/git.go b/internal/git/git.go index eb89800bd..f83c0ff51 100644 --- a/internal/git/git.go +++ b/internal/git/git.go @@ -18,6 +18,7 @@ limitations under the License. package git import ( + "net/url" "strings" "github.com/go-git/go-billy/v5" @@ -28,6 +29,7 @@ import ( "github.com/go-git/go-git/v5/plumbing/transport/http" "github.com/go-git/go-git/v5/plumbing/transport/ssh" "github.com/go-git/go-git/v5/storage" + cryptossh "golang.org/x/crypto/ssh" "github.com/crossplane/crossplane-runtime/v2/pkg/errors" ) @@ -38,6 +40,11 @@ type CloneOptions struct { RefName string Directory string Path string // Optional path for sparse checkout + + // ProxyURL, when set, tunnels the clone via an HTTP CONNECT proxy (e.g. + // http://proxy:8080). For SSH URLs the connection is tunneled through + // the proxy via CONNECT; see proxy.go. + ProxyURL string } // AuthProvider wraps a specific auth method. @@ -85,6 +92,10 @@ func (a *SSHAuthProvider) GetAuthMethod() (transport.AuthMethod, error) { // SSHAgentAuthProvider provides authentication using the SSH agent. type SSHAgentAuthProvider struct { Username string + // InsecureIgnoreHostKey disables SSH host key verification when true. + // This makes connections vulnerable to man-in-the-middle attacks and + // should only be enabled when the user explicitly opts in. + InsecureIgnoreHostKey bool } // GetAuthMethod returns the SSH agent auth method. @@ -93,7 +104,54 @@ func (a *SSHAgentAuthProvider) GetAuthMethod() (transport.AuthMethod, error) { if username == "" { username = "git" } - return ssh.NewSSHAgentAuth(username) + + auth, err := ssh.NewSSHAgentAuth(username) + if err != nil { + return nil, errors.Wrapf(err, "failed to authenticate to the git repository as user %q via the SSH agent; check that an SSH agent is running and reachable (SSH_AUTH_SOCK)", username) + } + + if a.InsecureIgnoreHostKey { + auth.HostKeyCallback = cryptossh.InsecureIgnoreHostKey() //nolint:gosec // G106: opt-in via an explicit flag. + } + + return auth, nil +} + +// IsSSHURL returns true if the given repository URL uses the SSH protocol. +// It recognizes both SCP-style URLs (user@host:path) and ssh:// scheme URLs. +// URLs with any other explicit scheme (http://, https://, git://, etc.) are +// not considered SSH, regardless of case. +func IsSSHURL(repo string) bool { + // If the URL has an explicit scheme (contains "://"), only ssh counts. + if before, _, ok := strings.Cut(repo, "://"); ok { + return strings.EqualFold(before, "ssh") + } + // SCP-style URLs have a user@host:path shape. + before, _, ok := strings.Cut(repo, ":") + return ok && strings.Contains(before, "@") +} + +// ExtractSSHUsername extracts the SSH username from a repository URL. +// For SCP-style URLs (user@host:path), it returns the part before "@". +// For ssh:// URLs (ssh://user@host/path), it returns the user component. +// Returns an empty string if no username is found or the URL is not SSH. +func ExtractSSHUsername(repo string) string { + if before, _, ok := strings.Cut(repo, "://"); ok { + if !strings.EqualFold(before, "ssh") { + return "" + } + // Parse as a URL so percent-encoded userinfo is decoded, the same + // way go-git's endpoint parsing would. + u, err := url.Parse(repo) + if err != nil || u.User == nil { + return "" + } + return u.User.Username() + } + if before, _, ok := strings.Cut(repo, "@"); ok { + return before + } + return "" } // CompositeAuthProvider tries multiple auth providers in order until one succeeds. @@ -122,8 +180,12 @@ type Cloner interface { CloneRepository(store storage.Storer, fs billy.Filesystem, auth AuthProvider, opts CloneOptions) (*plumbing.Reference, error) } -// DefaultCloner is the default implementation of Cloner. -type DefaultCloner struct{} +// DefaultCloner is the default implementation of Cloner. ProxyURL, when +// set, tunnels clones and fetches via an HTTP CONNECT proxy; it applies when +// the CloneOptions don't set their own proxy. +type DefaultCloner struct { + ProxyURL string +} // CheckSHA1Hash checks if a string is a valid git SHA hash (40 hex characters). func CheckSHA1Hash(ref string) bool { @@ -150,13 +212,20 @@ func extractBranchName(ref string) string { return "main" } -func handleSHACheckout(repoObj *git.Repository, authMethod transport.AuthMethod, sha string, sparsePath string) error { - err := repoObj.Fetch(&git.FetchOptions{ +func handleSHACheckout(repoObj *git.Repository, authMethod transport.AuthMethod, sha string, sparsePath string, proxyURL string) error { + fetchOpts := &git.FetchOptions{ Auth: authMethod, RefSpecs: []config.RefSpec{ config.RefSpec("+refs/heads/*:refs/remotes/origin/*"), }, - }) + } + // The fetch opens a new session that does not inherit the clone's proxy. + if proxyURL != "" { + fetchOpts.ProxyOptions = transport.ProxyOptions{ + URL: proxyURL, + } + } + err := repoObj.Fetch(fetchOpts) if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) { return errors.Wrap(err, "failed to fetch refs") } @@ -185,6 +254,15 @@ func handleSHACheckout(repoObj *git.Repository, authMethod transport.AuthMethod, // CloneRepository clones a git repository using the provided CloneOptions and AuthProvider. func (dc *DefaultCloner) CloneRepository(store storage.Storer, fs billy.Filesystem, auth AuthProvider, opts CloneOptions) (*plumbing.Reference, error) { + if opts.ProxyURL == "" { + opts.ProxyURL = dc.ProxyURL + } + if opts.ProxyURL != "" { + // SSH URLs tunnel through the proxy via a dialer that must be + // registered with golang.org/x/net/proxy before dialing. + registerProxyOnce() + } + authMethod, err := auth.GetAuthMethod() if err != nil { return nil, errors.Wrap(err, "failed to get authentication method") @@ -203,6 +281,14 @@ func (dc *DefaultCloner) CloneRepository(store storage.Storer, fs billy.Filesyst Tags: git.NoTags, } + // For SSH URLs the proxy is used via HTTP CONNECT tunneling; the dialer + // registered in proxy.go handles this. + if opts.ProxyURL != "" { + cloneOptions.ProxyOptions = transport.ProxyOptions{ + URL: opts.ProxyURL, + } + } + if !isSHA { cloneOptions.ReferenceName = plumbing.ReferenceName(opts.RefName) cloneOptions.SingleBranch = !isTag @@ -214,7 +300,7 @@ func (dc *DefaultCloner) CloneRepository(store storage.Storer, fs billy.Filesyst } if isSHA { - if err := handleSHACheckout(repoObj, authMethod, refToCheck, opts.Path); err != nil { + if err := handleSHACheckout(repoObj, authMethod, refToCheck, opts.Path, opts.ProxyURL); err != nil { return nil, err } } diff --git a/internal/git/git_test.go b/internal/git/git_test.go index ad7bdaadf..73caa10a9 100644 --- a/internal/git/git_test.go +++ b/internal/git/git_test.go @@ -566,3 +566,76 @@ func (m *MockCloner) CloneRepository(storage storage.Storer, fs billy.Filesystem } return nil, nil } + +func TestIsSSHURL(t *testing.T) { + t.Parallel() + + cases := map[string]struct { + reason string + repo string + want bool + }{ + "SCPStyle": { + reason: "An SCP-style URL is SSH.", + repo: "git@github.com:org/repo.git", + want: true, + }, + "SSHScheme": { + reason: "An ssh:// URL is SSH.", + repo: "ssh://git@github.com/org/repo.git", + want: true, + }, + "HTTPS": { + reason: "An https:// URL is not SSH.", + repo: "https://github.com/org/repo.git", + want: false, + }, + } + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + t.Parallel() + if diff := cmp.Diff(tc.want, IsSSHURL(tc.repo)); diff != "" { + t.Errorf("\n%s\nIsSSHURL(%q): -want, +got:\n%s", tc.reason, tc.repo, diff) + } + }) + } +} + +func TestExtractSSHUsername(t *testing.T) { + t.Parallel() + + cases := map[string]struct { + reason string + repo string + want string + }{ + "SCPStyle": { + reason: "The user before @ in an SCP-style URL is returned.", + repo: "git@github.com:org/repo.git", + want: "git", + }, + "SSHScheme": { + reason: "The userinfo of an ssh:// URL is returned.", + repo: "ssh://alice@git.example.com/repo.git", + want: "alice", + }, + "SSHSchemePercentEncoded": { + reason: "Percent-encoded userinfo is decoded, matching go-git's endpoint parsing.", + repo: "ssh://alice%40example.com@git.example.com/repo.git", + want: "alice@example.com", + }, + "HTTPS": { + reason: "A non-SSH URL has no SSH username.", + repo: "https://github.com/org/repo.git", + want: "", + }, + } + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + t.Parallel() + if diff := cmp.Diff(tc.want, ExtractSSHUsername(tc.repo)); diff != "" { + t.Errorf("\n%s\nExtractSSHUsername(%q): -want, +got:\n%s", tc.reason, tc.repo, diff) + } + }) + } +} diff --git a/internal/git/proxy.go b/internal/git/proxy.go new file mode 100644 index 000000000..e21e34f33 --- /dev/null +++ b/internal/git/proxy.go @@ -0,0 +1,205 @@ +/* +Copyright 2026 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package git + +import ( + "bufio" + "context" + "crypto/tls" + "encoding/base64" + "io" + "net" + "net/http" + "net/url" + "sync" + + "golang.org/x/net/proxy" + + "github.com/crossplane/crossplane-runtime/v2/pkg/errors" +) + +// bufferedConn wraps a net.Conn with a buffered reader so that any data read +// during the CONNECT handshake (which may include bytes past the response +// headers) is not lost. Its Close is idempotent and also stops the +// context-cancellation watchdog started in DialContext. +type bufferedConn struct { + net.Conn + + r io.Reader + + closeOnce sync.Once + closeFn func() error +} + +func (b *bufferedConn) Read(p []byte) (int, error) { + return b.r.Read(p) +} + +func (b *bufferedConn) Close() error { + var err error + b.closeOnce.Do(func() { + err = b.closeFn() + }) + return err +} + +// httpConnectDialer implements proxy.ContextDialer for HTTP CONNECT proxies. +// This allows SSH connections to be tunneled through HTTP proxies, +// similar to using ssh -o ProxyCommand='nc -X connect -x proxy:port %h %p'. +type httpConnectDialer struct { + proxyURL *url.URL + forward proxy.Dialer +} + +// Dial establishes a connection to the target address through the HTTP CONNECT proxy. +func (d *httpConnectDialer) Dial(network, addr string) (net.Conn, error) { + return d.DialContext(context.Background(), network, addr) +} + +// DialContext establishes a connection to the target address through the HTTP CONNECT proxy +// with context support for cancellation and timeouts. +func (d *httpConnectDialer) DialContext(ctx context.Context, _, addr string) (net.Conn, error) { + // Try to use DialContext if forward dialer supports it + var conn net.Conn + var err error + + proxyAddr := proxyAddress(d.proxyURL) + if ctxDialer, ok := d.forward.(proxy.ContextDialer); ok { + conn, err = ctxDialer.DialContext(ctx, "tcp", proxyAddr) + } else { + conn, err = d.forward.Dial("tcp", proxyAddr) + } + if err != nil { + return nil, errors.Wrapf(err, "failed to connect to the git proxy at %s; check the --git-proxy URL and that the proxy is reachable", proxyAddr) + } + + // Wrap with TLS if proxy uses HTTPS + if d.proxyURL.Scheme == "https" { + conn = tls.Client(conn, &tls.Config{ + ServerName: d.proxyURL.Hostname(), + MinVersion: tls.VersionTLS12, + }) + } + + // closeOnce guards conn.Close() against races between the handshake's + // error paths, the context-cancellation watchdog, and the caller's Close + // on the returned bufferedConn. + var closeOnce sync.Once + closeConn := func() error { + var err error + closeOnce.Do(func() { err = conn.Close() }) + return err + } + + // The watchdog closes the connection if ctx fires while the CONNECT + // handshake is in flight. It is disarmed when DialContext returns: the + // dialing context must not govern the returned connection's lifetime + // (go-git cancels it right after a successful dial). + done := make(chan struct{}) + watchdogDone := make(chan struct{}) + go func() { + defer close(watchdogDone) + select { + case <-ctx.Done(): + _ = closeConn() + case <-done: + } + }() + defer func() { + close(done) + // Wait for the watchdog to exit so a context cancellation racing + // with a successful handshake cannot close the connection after we + // have handed it to the caller. + <-watchdogDone + }() + + // Build CONNECT request + connectReq := &http.Request{ + Method: http.MethodConnect, + URL: &url.URL{Opaque: addr}, + Host: addr, + Header: make(http.Header), + } + + // Add proxy authentication if credentials are present in URL + if d.proxyURL.User != nil { + password, _ := d.proxyURL.User.Password() + auth := d.proxyURL.User.Username() + ":" + password + connectReq.Header.Set("Proxy-Authorization", + "Basic "+base64.StdEncoding.EncodeToString([]byte(auth))) + } + + // Send CONNECT request + if err := connectReq.Write(conn); err != nil { + _ = closeConn() + return nil, errors.Wrapf(err, "failed to connect to %s through the git proxy at %s; check the --git-proxy URL and proxy access", addr, proxyAddr) + } + + // Read response. Create the buffered reader once so that any bytes + // buffered beyond the HTTP response headers are not lost. + br := bufio.NewReader(conn) + resp, err := http.ReadResponse(br, connectReq) + if err != nil { + _ = closeConn() + return nil, errors.Wrapf(err, "failed to connect to %s through the git proxy at %s: error reading the proxy response", addr, proxyAddr) + } + resp.Body.Close() //nolint:errcheck // Body is typically empty for CONNECT responses. + + if resp.StatusCode != http.StatusOK { + _ = closeConn() + return nil, errors.Errorf("the git proxy at %s refused the connection to %s with status %q; check proxy access", proxyAddr, addr, resp.Status) + } + + return &bufferedConn{ + r: br, + Conn: conn, + closeFn: closeConn, + }, nil +} + +// proxyAddress returns the host-and-port address to dial for the proxy URL, +// defaulting the port by scheme (80 for http, 443 for https) when the URL +// omits it. TCP dialing requires an explicit port. +func proxyAddress(u *url.URL) string { + if u.Port() != "" { + return u.Host + } + port := "80" + if u.Scheme == "https" { + port = "443" + } + return net.JoinHostPort(u.Hostname(), port) +} + +// registerHTTPConnectProxy registers HTTP and HTTPS CONNECT proxy support +// with the golang.org/x/net/proxy package. It is called from init() so that +// importing this package is sufficient to enable HTTP CONNECT proxies for +// go-git's ProxyOptions (e.g. "http://proxy:8080" or "https://proxy:8443"). +func registerHTTPConnectProxy() { + newDialer := func(u *url.URL, forward proxy.Dialer) (proxy.Dialer, error) { + return &httpConnectDialer{proxyURL: u, forward: forward}, nil + } + proxy.RegisterDialerType("http", newDialer) + proxy.RegisterDialerType("https", newDialer) +} + +// init automatically registers HTTP CONNECT proxy support when this package is imported. +// registerProxyOnce performs the dialer registration once; it is invoked +// from every code path that may dial through a proxy. +// +//nolint:gochecknoglobals // The x/net/proxy dialer registry is process-global; registration must happen exactly once. +var registerProxyOnce = sync.OnceFunc(registerHTTPConnectProxy) diff --git a/internal/git/proxy_test.go b/internal/git/proxy_test.go new file mode 100644 index 000000000..074a6015d --- /dev/null +++ b/internal/git/proxy_test.go @@ -0,0 +1,500 @@ +/* +Copyright 2026 The Crossplane Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package git + +import ( + "bufio" + "context" + "fmt" + "net" + "net/http" + "net/url" + "strings" + "testing" + "time" + + "github.com/google/go-cmp/cmp" + "golang.org/x/net/proxy" +) + +func TestHTTPConnectDialer(t *testing.T) { + t.Parallel() + + // Start a mock HTTP CONNECT proxy server + listener, err := (&net.ListenConfig{}).Listen(t.Context(), "tcp", "127.0.0.1:0") + if err != nil { + t.Fatalf("Listen(...): %v", err) + } + defer listener.Close() + + proxyAddr := listener.Addr().String() + targetAddr := "example.com:443" + + // Track if CONNECT was received + connectReceived := make(chan string, 1) + + go func() { + conn, err := listener.Accept() + if err != nil { + return + } + defer conn.Close() + + // Read the CONNECT request + reader := bufio.NewReader(conn) + req, err := http.ReadRequest(reader) + if err != nil { + return + } + + // Signal that we received the CONNECT request + connectReceived <- req.URL.String() + + // Send 200 OK response + resp := &http.Response{ + StatusCode: http.StatusOK, + Status: "200 Connection established", + Proto: "HTTP/1.1", + ProtoMajor: 1, + ProtoMinor: 1, + } + resp.Write(conn) + + // Keep connection open briefly + time.Sleep(100 * time.Millisecond) + }() + + // Create dialer using our implementation + proxyURL, err := url.Parse("http://" + proxyAddr) + if err != nil { + t.Fatalf("url.Parse(...): %v", err) + } + + dialer := &httpConnectDialer{ + proxyURL: proxyURL, + forward: proxy.Direct, + } + + // Dial through proxy; the fixture answers 200, so this must succeed. + conn, err := dialer.Dial("tcp", targetAddr) + if err != nil { + t.Fatalf("Dial(...): %v", err) + } + if conn == nil { + t.Fatal("Dial(...): got nil conn") + } + conn.Close() + + // Verify CONNECT request was sent + select { + case received := <-connectReceived: + if !strings.Contains(received, "example.com:443") { + t.Errorf("expected CONNECT to example.com:443, got: %s", received) + } + case <-time.After(2 * time.Second): + t.Fatal("Timeout waiting for CONNECT request") + } +} + +func TestHTTPConnectDialerWithAuth(t *testing.T) { + t.Parallel() + + // Start a mock HTTP CONNECT proxy server that requires auth + listener, err := (&net.ListenConfig{}).Listen(t.Context(), "tcp", "127.0.0.1:0") + if err != nil { + t.Fatalf("Listen(...): %v", err) + } + defer listener.Close() + + proxyAddr := listener.Addr().String() + targetAddr := "example.com:22" + + // Track auth header + authReceived := make(chan string, 1) + + go func() { + conn, err := listener.Accept() + if err != nil { + return + } + defer conn.Close() + + // Read the CONNECT request + reader := bufio.NewReader(conn) + req, err := http.ReadRequest(reader) + if err != nil { + return + } + + // Extract auth header + authReceived <- req.Header.Get("Proxy-Authorization") + + // Send 200 OK response + resp := &http.Response{ + StatusCode: http.StatusOK, + Status: "200 Connection established", + Proto: "HTTP/1.1", + ProtoMajor: 1, + ProtoMinor: 1, + } + resp.Write(conn) + + time.Sleep(100 * time.Millisecond) + }() + + // Create dialer with authentication + proxyURL, err := url.Parse(fmt.Sprintf("http://testuser:testpass@%s", proxyAddr)) + if err != nil { + t.Fatalf("url.Parse(...): %v", err) + } + + dialer := &httpConnectDialer{ + proxyURL: proxyURL, + forward: proxy.Direct, + } + + // Dial through proxy; the fixture answers 200, so this must succeed. + conn, err := dialer.Dial("tcp", targetAddr) + if err != nil { + t.Fatalf("Dial(...): %v", err) + } + conn.Close() + + // Verify auth header was sent + select { + case auth := <-authReceived: + // Basic dGVzdHVzZXI6dGVzdHBhc3M= is base64 of "testuser:testpass". + if diff := cmp.Diff("Basic dGVzdHVzZXI6dGVzdHBhc3M=", auth); diff != "" { + t.Errorf("Proxy-Authorization header: -want, +got:\n%s", diff) + } + case <-time.After(2 * time.Second): + t.Fatal("Timeout waiting for auth header") + } +} + +func TestHTTPConnectDialerNon200(t *testing.T) { + t.Parallel() + + // Start a mock HTTP CONNECT proxy server that returns 403 Forbidden + listener, err := (&net.ListenConfig{}).Listen(t.Context(), "tcp", "127.0.0.1:0") + if err != nil { + t.Fatalf("Listen(...): %v", err) + } + defer listener.Close() + + proxyAddr := listener.Addr().String() + targetAddr := "example.com:22" + + go func() { + conn, err := listener.Accept() + if err != nil { + return + } + defer conn.Close() + + // Read the CONNECT request + reader := bufio.NewReader(conn) + _, err = http.ReadRequest(reader) + if err != nil { + return + } + + // Send 403 Forbidden response + resp := &http.Response{ + StatusCode: http.StatusForbidden, + Status: "403 Forbidden", + Proto: "HTTP/1.1", + ProtoMajor: 1, + ProtoMinor: 1, + } + resp.Write(conn) + }() + + proxyURL, err := url.Parse("http://" + proxyAddr) + if err != nil { + t.Fatalf("url.Parse(...): %v", err) + } + + dialer := &httpConnectDialer{ + proxyURL: proxyURL, + forward: proxy.Direct, + } + + conn, err := dialer.Dial("tcp", targetAddr) + if err == nil { + t.Fatal("expected error for non-200 proxy response, got nil") + } + if conn != nil { + t.Error("expected nil connection for non-200 proxy response") + } + if !strings.Contains(err.Error(), "403") { + t.Errorf("expected error to mention 403 status, got: %s", err.Error()) + } +} + +func TestHTTPConnectDialerHTTPS(t *testing.T) { + t.Parallel() + + // Start a plain TCP listener. The dialer should attempt a TLS + // handshake because the proxy URL uses the https scheme. Since the + // listener is plain TCP, the TLS handshake will not complete and the + // context deadline will fire, proving TLS was attempted. + listener, err := (&net.ListenConfig{}).Listen(t.Context(), "tcp", "127.0.0.1:0") + if err != nil { + t.Fatalf("Listen(...): %v", err) + } + defer listener.Close() + + // Read the first byte before closing: a TLS ClientHello starts with the + // handshake record type 0x16, proving the dialer attempted TLS rather + // than sending a plaintext CONNECT. + firstByte := make(chan byte, 1) + go func() { + conn, err := listener.Accept() + if err != nil { + return + } + defer conn.Close() + buf := make([]byte, 1) + if _, err := conn.Read(buf); err == nil { + firstByte <- buf[0] + } + }() + + proxyAddr := listener.Addr().String() + targetAddr := "example.com:22" + + proxyURL, err := url.Parse("https://" + proxyAddr) + if err != nil { + t.Fatalf("url.Parse(...): %v", err) + } + + dialer := &httpConnectDialer{ + proxyURL: proxyURL, + forward: proxy.Direct, + } + + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + + conn, err := dialer.DialContext(ctx, "tcp", targetAddr) + if conn != nil { + conn.Close() + } + // We expect an error because the plain TCP listener cannot complete a TLS handshake. + if err == nil { + t.Error("expected error when TLS handshake fails against plain TCP proxy, got nil") + } + + select { + case b := <-firstByte: + if b != 0x16 { + t.Errorf("expected a TLS handshake record (0x16) as the first byte, got 0x%02x", b) + } + case <-time.After(2 * time.Second): + t.Fatal("timeout waiting for the proxy to receive any bytes") + } +} + +// TestHTTPConnectDialerCancellation verifies that DialContext returns promptly +// when the context is cancelled while the proxy accepts a socket but never +// responds (exercising the watchdog goroutine). +func TestHTTPConnectDialerCancellation(t *testing.T) { + t.Parallel() + + // Start a listener that accepts connections but never writes a response. + listener, err := (&net.ListenConfig{}).Listen(t.Context(), "tcp", "127.0.0.1:0") + if err != nil { + t.Fatalf("Listen(...): %v", err) + } + defer listener.Close() + + go func() { + conn, err := listener.Accept() + if err != nil { + return + } + // Hold the connection open; never respond. + defer conn.Close() + <-t.Context().Done() + }() + + proxyURL, _ := url.Parse("http://" + listener.Addr().String()) + dialer := &httpConnectDialer{proxyURL: proxyURL, forward: proxy.Direct} + + ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond) + defer cancel() + + conn, err := dialer.DialContext(ctx, "tcp", "example.com:443") + if err == nil { + t.Fatal("expected error on cancelled context, got nil") + } + if conn != nil { + t.Error("expected nil conn on cancelled context") + } +} + +// TestRegisterHTTPConnectProxy verifies that the init()-driven dialer +// registration works. It must NOT use t.Parallel() because it validates +// package-global proxy dialer registration and must not run in parallel +// with other proxy tests that rely on that global state. +func TestRegisterHTTPConnectProxy(t *testing.T) { + registerProxyOnce() + // Verify that HTTP and HTTPS schemes are registered + // by checking if we can create dialers for these schemes + httpURL, _ := url.Parse("http://proxy.example.com:8080") + httpsURL, _ := url.Parse("https://proxy.example.com:8443") + + // These should not panic after registerHTTPConnectProxy is called (via init) + httpDialer, err := proxy.FromURL(httpURL, proxy.Direct) + if err != nil { + t.Fatalf("proxy.FromURL(http): %v", err) + } + if httpDialer == nil { + t.Error("expected a dialer for the http scheme, got nil") + } + + httpsDialer, err := proxy.FromURL(httpsURL, proxy.Direct) + if err != nil { + t.Fatalf("proxy.FromURL(https): %v", err) + } + if httpsDialer == nil { + t.Error("expected a dialer for the https scheme, got nil") + } +} + +// TestHTTPConnectDialerSurvivesDialContextCancel verifies the dialing +// context does not govern the returned connection's lifetime: go-git cancels +// the dial context right after a successful dial, and the tunnel must keep +// working. +func TestHTTPConnectDialerSurvivesDialContextCancel(t *testing.T) { + t.Parallel() + + listener, err := (&net.ListenConfig{}).Listen(t.Context(), "tcp", "127.0.0.1:0") + if err != nil { + t.Fatalf("Listen(...): %v", err) + } + defer listener.Close() + + echoed := make(chan string, 1) + go func() { + conn, err := listener.Accept() + if err != nil { + return + } + defer conn.Close() + + reader := bufio.NewReader(conn) + if _, err := http.ReadRequest(reader); err != nil { + return + } + resp := &http.Response{ + StatusCode: http.StatusOK, + Status: "200 Connection established", + Proto: "HTTP/1.1", + ProtoMajor: 1, + ProtoMinor: 1, + } + resp.Write(conn) + + // Echo one line of tunneled data back. + line, err := reader.ReadString('\n') + if err != nil { + return + } + echoed <- line + fmt.Fprint(conn, line) + }() + + proxyURL, err := url.Parse("http://" + listener.Addr().String()) + if err != nil { + t.Fatalf("url.Parse(...): %v", err) + } + dialer := &httpConnectDialer{proxyURL: proxyURL, forward: proxy.Direct} + + ctx, cancel := context.WithCancel(context.Background()) + conn, err := dialer.DialContext(ctx, "tcp", "example.com:22") + if err != nil { + t.Fatalf("DialContext(...): %v", err) + } + defer conn.Close() + + // Cancel the dialing context, as go-git does after a successful dial, + // then exchange data through the tunnel. + cancel() + + if _, err := fmt.Fprint(conn, "hello\n"); err != nil { + t.Fatalf("writing through the tunnel after cancel: %v", err) + } + reply, err := bufio.NewReader(conn).ReadString('\n') + if err != nil { + t.Fatalf("reading through the tunnel after cancel: %v", err) + } + if diff := cmp.Diff("hello\n", reply); diff != "" { + t.Errorf("tunneled echo: -want, +got:\n%s", diff) + } + select { + case <-echoed: + case <-time.After(2 * time.Second): + t.Fatal("timeout waiting for the proxy to receive tunneled data") + } +} + +// TestProxyAddress verifies default ports are applied when the proxy URL +// omits one. +func TestProxyAddress(t *testing.T) { + t.Parallel() + + cases := map[string]struct { + reason string + in string + want string + }{ + "HTTPDefaultPort": { + reason: "An http proxy URL without a port dials port 80.", + in: "http://proxy.example.com", + want: "proxy.example.com:80", + }, + "HTTPSDefaultPort": { + reason: "An https proxy URL without a port dials port 443.", + in: "https://proxy.example.com", + want: "proxy.example.com:443", + }, + "ExplicitPort": { + reason: "An explicit port is preserved.", + in: "http://proxy.example.com:8080", + want: "proxy.example.com:8080", + }, + "IPv6DefaultPort": { + reason: "An IPv6 host is bracketed with the default port.", + in: "http://[::1]", + want: "[::1]:80", + }, + } + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + t.Parallel() + u, err := url.Parse(tc.in) + if err != nil { + t.Fatalf("url.Parse(%q): %v", tc.in, err) + } + if diff := cmp.Diff(tc.want, proxyAddress(u)); diff != "" { + t.Errorf("\n%s\nproxyAddress(%q): -want, +got:\n%s", tc.reason, tc.in, diff) + } + }) + } +} diff --git a/nix/vendor-hashes.nix b/nix/vendor-hashes.nix index f605ebce9..4d111a891 100644 --- a/nix/vendor-hashes.nix +++ b/nix/vendor-hashes.nix @@ -12,5 +12,5 @@ # hand.) { # Root module: github.com/crossplane/cli/v2 - root = "sha256-XCOw0URyzJoaavJZ17u9NopRHpV8XCHwt8K0JFnxBa8="; + root = "sha256-ZVlGfgCHlfAJumwybqvCilM2iyVRMUMEg5j1V8v3P3g="; }