diff --git a/.changes/rig-v2.2.1.md b/.changes/rig-v2.2.1.md new file mode 100644 index 00000000..738f5cb7 --- /dev/null +++ b/.changes/rig-v2.2.1.md @@ -0,0 +1,12 @@ +**rig is taken from upstream again.** + +`go.mod` carried `replace github.com/k0sproject/rig/v2 => +github.com/james-nesbitt/rig/v2`, pinned to a September pre-release of a +fork. The fork existed to carry one fix — bounding WinRM `command.Wait()` +and `remotefs` upload against a dead session, which had hung +`smoke-windows` for 40+ minutes — that upstream had not yet merged. + +Upstream merged it (k0sproject/rig#473) and released it. The replace is +removed and launchpad builds against `github.com/k0sproject/rig/v2 v2.2.1`, +which carries that fix plus roughly fifty commits of SSH, remotefs and +WinRM fixes made since the fork point. diff --git a/go.mod b/go.mod index 62e2494f..fce8af0c 100644 --- a/go.mod +++ b/go.mod @@ -200,5 +200,3 @@ require ( sigs.k8s.io/structured-merge-diff/v6 v6.4.2 // indirect sigs.k8s.io/yaml v1.6.0 // indirect ) - -replace github.com/k0sproject/rig/v2 => github.com/james-nesbitt/rig/v2 v2.0.0-alpha.2.0.20260916132849-b534cbe07c9f diff --git a/go.sum b/go.sum index 571db5ac..51d23e0a 100644 --- a/go.sum +++ b/go.sum @@ -267,8 +267,6 @@ github.com/huandu/xstrings v1.6.3 h1:7997PcI0mYC9uPNBJ7udg/KrdJh1GhJid8f2tzKFHYQ github.com/huandu/xstrings v1.6.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/james-nesbitt/rig/v2 v2.0.0-alpha.2.0.20260916132849-b534cbe07c9f h1:OvlctYe5aCrzx5bLRhyvyvPEOl1md/tQ3Bf7jNqxhh4= -github.com/james-nesbitt/rig/v2 v2.0.0-alpha.2.0.20260916132849-b534cbe07c9f/go.mod h1:MT/AK5aXluuTE+soUNQ2yLlINWjrMLzY+FKltqpVJcc= github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8= github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo= @@ -289,6 +287,8 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/k0sproject/dig v0.4.0 h1:yBxFUUxNXAMGBg6b7c6ypxdx/o3RmhoI5v5ABOw5tn0= github.com/k0sproject/dig v0.4.0/go.mod h1:rlZ7N7ZEcB4Fi96TPXkZ4dqyAiDWOGLapyL9YpZ7Qz4= +github.com/k0sproject/rig/v2 v2.2.1 h1:RG/WdtN9qe6XFWTr4FO8uYK6URvTnT3o8lnjMqRCRsQ= +github.com/k0sproject/rig/v2 v2.2.1/go.mod h1:mioiuQgsFdOz22nx09XWJGs6YDHf+6XM2vSTZfcrk3U= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= github.com/klauspost/compress v1.20.4 h1:dD0v/bvxtjCBqQu6sx1TNWkalEY5lNTIe+HY9w8TeNI= diff --git a/pkg/product/common/phase/connect.go b/pkg/product/common/phase/connect.go index 502560dd..aa08303d 100644 --- a/pkg/product/common/phase/connect.go +++ b/pkg/product/common/phase/connect.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "reflect" - "strings" "sync" "time" @@ -109,56 +108,22 @@ func (p *Connect) connectHost(host connectable) error { // shouldRetryConnect reports whether a failed connect attempt is worth another // try. Everything is retried except states no amount of waiting will change. -func shouldRetryConnect(err error) bool { - if isTransientAuthError(err) { - return true - } - - return !errors.Is(err, rig.ErrNonRetryable) -} - -// isTransientAuthError reports whether err is a WinRM HTTP 401/403. -// -// This phase exists to wait for hosts to become reachable, and on Windows an -// auth rejection is an expected part of that wait: the WinRM HTTPS listener -// starts answering before provisioning has finished configuring authentication, -// so a freshly booted host returns 401 for a while with entirely correct -// credentials. // -// rig v2 wraps 401/403 as protocol.ErrNonRetryable, which is reasonable for a -// general purpose library but wrong here -- it aborts the wait on its first -// attempt. rig v0 did not classify these, so launchpad retried them and the -// condition healed itself; smoke-fips regressed on exactly this. Treat them as -// retryable again, while still honouring ErrNonRetryable for everything else -// (bad certificates, host key mismatches, misconfigured bastions), which no -// amount of waiting will fix. +// A credential rejection is retried, and rig decides that rather than this +// phase. Protocol implementations tag it with protocol.ErrAuthFailed -- an +// HTTP 401/403 on WinRM, an exhausted handshake on SSH -- and rig deliberately +// does not wrap that in ErrNonRetryable, because a rejection is routinely +// transient while a host is still being provisioned: the WinRM listener +// answers before authentication is configured, and sshd accepts connections +// before authorized_keys is written. // -// The cost is that genuinely wrong credentials now take the full retry budget -// to report instead of failing immediately. That is the right trade for a -// provisioning tool: a cluster that would have come up must not fail, and the -// budget is bounded at a few minutes. -// -// Matching is by substring because the underlying WinRM library returns untyped -// formatted errors and rig exports no sentinel for them. rig's own isAuthError -// does the same thing, and both message shapes it covers are matched here. See -// PRODENG-3594. -func isTransientAuthError(err error) bool { - if err == nil { - return false - } - msg := err.Error() - for _, probe := range []string{ - "http error 401", - "http error 403", - "http response error: 401", - "http response error: 403", - } { - if strings.Contains(msg, probe) { - return true - } - } - - return false +// Launchpad used to match "http error 401" and friends by substring here, +// because rig v2.1 classified 401/403 as ErrNonRetryable and aborted this wait +// on its first attempt (smoke-fips regressed on exactly that). rig v2.2 +// carries that fix, so the substring matching is gone. See PRODENG-3594 and +// k0sproject/rig#421. +func shouldRetryConnect(err error) bool { + return !errors.Is(err, rig.ErrNonRetryable) } func (p *Connect) testConnection(h connectable) error { diff --git a/pkg/product/common/phase/connect_test.go b/pkg/product/common/phase/connect_test.go index 85c691d0..b283d428 100644 --- a/pkg/product/common/phase/connect_test.go +++ b/pkg/product/common/phase/connect_test.go @@ -6,20 +6,25 @@ import ( "testing" rig "github.com/k0sproject/rig/v2" + "github.com/k0sproject/rig/v2/protocol" "github.com/stretchr/testify/require" ) // TestConnectRetriesTransientAuthErrors is the regression test for the WinRM // half of PRODENG-3594. // -// rig v2 wraps WinRM 401/403 as ErrNonRetryable, so the connect phase abandoned -// a host on its first attempt. A Windows host answers WinRM before its -// provisioning has configured authentication, so that aborted clusters which -// would have come up moments later. rig v0 retried these. +// rig v2.1 wrapped WinRM 401/403 in ErrNonRetryable, so the connect phase +// abandoned a host on its first attempt. A Windows host answers WinRM before +// its provisioning has configured authentication, so that aborted clusters +// which would have come up moments later. +// +// rig v2.2 tags a credential rejection with protocol.ErrAuthFailed and +// deliberately does not wrap it in ErrNonRetryable, so the retry happens +// without launchpad classifying anything itself. These cases use the shapes +// rig produces now; the substring matching they used to need is gone. func TestConnectRetriesTransientAuthErrors(t *testing.T) { - // Both message shapes the WinRM library produces, as seen in CI. ciError := fmt.Errorf("connect: connect: client connect: retry: abort condition reached after 1 attempts: %w", - fmt.Errorf("%w: create shell: http response error: 401 - invalid content type", rig.ErrNonRetryable)) + fmt.Errorf("%w: create shell: http response error: 401 - invalid content type", protocol.ErrAuthFailed)) for _, tc := range []struct { name string @@ -33,12 +38,12 @@ func TestConnectRetriesTransientAuthErrors(t *testing.T) { }, { name: "401 in the library's alternate format", - err: fmt.Errorf("%w: create shell: http error 401: unauthorized", rig.ErrNonRetryable), + err: fmt.Errorf("%w: create shell: http error 401: unauthorized", protocol.ErrAuthFailed), retry: true, }, { name: "403 is also a provisioning race, not a permanent state", - err: fmt.Errorf("%w: create shell: http error 403: forbidden", rig.ErrNonRetryable), + err: fmt.Errorf("%w: create shell: http error 403: forbidden", protocol.ErrAuthFailed), retry: true, }, { diff --git a/pkg/product/mke/config/host.go b/pkg/product/mke/config/host.go index 35c469e7..a08d451a 100644 --- a/pkg/product/mke/config/host.go +++ b/pkg/product/mke/config/host.go @@ -46,23 +46,25 @@ var rigLogger = slog.New(sloglogrus.Option{ Logger: log.StandardLogger(), }.NewLogrusHandler()) -// osReleaseRegistry resolves a host's OS release. It deliberately mirrors rig's -// os.DefaultRegistry minus ResolveLinuxCompat. +// osReleaseRegistry mirrors rig's os.DefaultRegistry minus ResolveLinuxCompat. // -// rig's registry reorders itself: on a successful match the winning resolver is -// swapped to the front so later hosts hit it first. That optimisation is unsafe -// when one resolver matches a superset of another. ResolveLinuxCompat is exactly -// that -- a fallback for hosts with no /etc/os-release, which reports ID "linux" -// for any Linux host. Resolving a Windows host swaps ResolveWindows to index 0, -// which pushes ResolveLinuxCompat ahead of ResolveLinux, and every Linux host -// resolved afterwards is misreported as "linux" and fails configurer lookup. -// Mixed Linux/Windows clusters therefore broke while Linux-only ones passed. +// It originally had two jobs. The first is gone: rig's registry used to promote +// the winning resolver to the front, which let ResolveLinuxCompat -- a resolver +// matching every Linux host -- overtake ResolveLinux once a Windows host had +// been resolved, misreporting every subsequent Linux host as "linux". rig +// v2.2's ResolveLinuxCompat stands down when os-release identifies the host, so +// order no longer decides the outcome. TestOSRegistryOrderingIsStable now +// asserts that against rig's own DefaultRegistry. // -// Dropping the fallback also restores rig v0's behaviour: a host whose -// os-release cannot be read now fails with os.ErrNotRecognized naming the real -// cause, instead of being silently misclassified. Every OS launchpad supports -// ships an os-release file, so the fallback could never yield a usable -// configurer anyway. See PRODENG-3594. +// The second job remains. Compat synthesizes a release from the host's package +// manager: a host with no readable os-release but with apt-get resolves to +// ID "linux", IDLike ["debian"]. Every matcher registered with +// configurer.RegisterOSModule compares r.ID against an exact distribution name +// and none consults IDLike, so such a host matches no configurer and fails +// later, further from the cause. Excluding compat keeps the failure at +// resolution, as os.ErrNotRecognized naming the real problem. Every OS +// launchpad supports ships an os-release file, so the fallback could not yield +// a usable configurer in the first place. See PRODENG-3594. var osReleaseRegistry = sync.OnceValue(func() *rigos.Registry { r := rigos.NewRegistry() r.Register(rigos.ResolveLinux) diff --git a/pkg/product/mke/config/osregistry_test.go b/pkg/product/mke/config/osregistry_test.go index 71e0442e..105be3d7 100644 --- a/pkg/product/mke/config/osregistry_test.go +++ b/pkg/product/mke/config/osregistry_test.go @@ -81,7 +81,7 @@ func linuxRunner() *fakeRunner { // // Detecting a Windows host must not change how the next Linux host is detected. func TestOSRegistryOrderingIsStable(t *testing.T) { - registry := osReleaseRegistry() + registry := rigos.DefaultRegistry() // Baseline: a Linux host on its own is identified correctly. before, err := registry.Get(linuxRunner())