From c8d5d8dbf2dd183cd1fe7522fc7ce7fbb987418a Mon Sep 17 00:00:00 2001 From: James Nesbitt Date: Thu, 12 Nov 2026 09:04:01 +0200 Subject: [PATCH 1/2] chore: drop the rig fork replace and build against rig v2.2.1 go.mod carried replace github.com/k0sproject/rig/v2 => github.com/james-nesbitt/rig/v2 v2.0.0-alpha.2.0.20260916132849-b534cbe07c9f introduced with the rig v2 migration (#651). The fork existed to carry one fix: bounding winrm.(*command).Wait() and remotefs.(*winFile) .command() against a silently dead WinRM session, seen as a 40+ minute smoke-windows hang after a Windows host reboot during remotefs.Upload. Upstream had not merged it, so the replace was the only way to get it. Upstream has merged it since -- k0sproject/rig#473, issue #472 closed -- and released it. Verified by content rather than by commit SHA, which is why this was missed before: upstream merged a rebased commit, so the fork's SHA is not an ancestor of upstream main and an ancestry check reports the fix as absent when it is present. In remotefs/winfile.go, commandTimeout and errRcpTimeout appear 0 times at v2.1.0 and 14 times at v2.2.1, and v2.2.1's command.Wait() carries the ctx race the fork added. #706 bumped the require line to v2.2.1 but the replace silently discarded it; removing the replace is what actually moves rig. Roughly fifty commits arrive with it. Beyond the WinRM hang fix, the ones touching paths launchpad uses: fix(ssh): honour StrictHostKeyChecking=yes instead of always accepting fix(cmd,sudo): impose a POSIX shell instead of trusting $SHELL fix(initsystem): don't let SysVinit match systemd hosts fix(os): stop ResolveLinuxCompat claiming hosts os-release identifies fix(remotefs): several ErrNotExist misclassifications in WinFS stat feat(remotefs): atomic downloads, opt-in resume, HTTPHead feat(winrm): export ErrAuthFailed, stop marking 401/403 non-retryable Two of those overlap workarounds the migration added: launchpad builds its own OS release registry via rig.WithOSReleaseProvider to drop the compat fallback, and handles the 401/403 retry classification itself. Both still compile and are left alone here -- whether they are now redundant is a separate question from whether the update is safe. Verified: go build ./... clean, make lint 0 issues, make unit-test 35 packages ok and 0 failures. Not covered by unit tests: this is the host connectivity layer, so the smoke suites are the real exercise. smoke-modern is labelled on the PR. Written by AI: claude-opus-5 Signed-off-by: James Nesbitt --- .changes/rig-v2.2.1.md | 12 ++++++++++++ go.mod | 2 -- go.sum | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 .changes/rig-v2.2.1.md 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= From 94d90fec487e75db9e8e8ac0a021395f8550e6d3 Mon Sep 17 00:00:00 2001 From: James Nesbitt Date: Thu, 12 Nov 2026 09:36:39 +0200 Subject: [PATCH 2/2] Drop the launchpad workarounds rig v2.2 makes redundant Two migration-era workarounds overlapped fixes that arrived with v2.2.1. One is now entirely upstream's; the other turned out to be only half overlap, and the half that still earns its place is kept. 401/403 retry classification -- removed in full. isTransientAuthError matched "http error 401" and three sibling shapes by substring, because rig v2.1 wrapped a WinRM credential rejection in ErrNonRetryable and this phase, whose whole job is waiting for hosts to become reachable, abandoned a host on its first attempt. smoke-fips regressed on exactly that. rig v2.2 tags a rejection with protocol.ErrAuthFailed and deliberately leaves it outside ErrNonRetryable, documenting the same reasoning: "WinRM starts answering before authentication has been configured, and sshd accepts connections before authorized_keys has been written". shouldRetryConnect is now one line and the substring table is gone. The test keeps its cases and moves them to the shapes rig produces now. OS release registry -- kept, with its rationale corrected. It was introduced for two reasons. The first is upstream's now: rig's registry promoted the winning resolver to the front, letting ResolveLinuxCompat -- which matches every Linux host -- overtake ResolveLinux after a Windows host resolved, so mixed clusters misreported Linux hosts as "linux". v2.2's ResolveLinuxCompat stands down when os-release identifies the host, so ordering no longer decides the outcome. TestOSRegistryOrderingIsStable now asserts that against rig's own DefaultRegistry and passes. The second reason stands, and dropping the registry regressed it -- caught by TestOSRegistryRejectsUnreadableOSRelease failing. Measured against rig's default registry, a host with no readable os-release but with apt-get resolves to ID "linux", IDLike ["debian"] rather than erroring. Every matcher registered through configurer.RegisterOSModule compares r.ID to an exact distribution name and none consults IDLike, so that host matches no configurer and fails later, further from the cause. The registry still excludes compat so the failure stays at resolution as os.ErrNotRecognized. Verified: go build ./... clean, make lint 0 issues, make unit-test 0 failures. Written by AI: claude-opus-5 Signed-off-by: James Nesbitt --- pkg/product/common/phase/connect.go | 63 +++++------------------ pkg/product/common/phase/connect_test.go | 21 +++++--- pkg/product/mke/config/host.go | 32 ++++++------ pkg/product/mke/config/osregistry_test.go | 2 +- 4 files changed, 45 insertions(+), 73 deletions(-) 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())