← Back to Pull requests

Add integration test for OCI registry mTLS #8569

Merged
DeeBi9 merged 1 files (282 lines) on Nov 13, 2026 22:08 UTC
View on GitHub
DeeBi9 DeeBi9 commented on Oct 21, 2026 08:59 UTC
Author

Description


Follow-up to PR #6888, where integration test coverage for the new mTLS support when pulling Helm charts from OCI registries was discussed.

No production code or documentation changes are included; this is test-only coverage.

Closes #8562
<!--
Summarize your changes. Give context, mention alternatives considered, and what is
deliberately left out. It must not contradict the commit messages. When you rewrite
commits after a review round, re-read this description and update it, too.

Use "Fixes #N" only if this pull request resolves an issue. Otherwise, use "See #N".
-->

Type of change

  • Non-breaking change

  • Breaking change (must respect the version skew policy)
  • How has this been tested?

  • Manual test

  • Automated test added
  • <!-- Describe what was verified, and how. Provide instructions so we can reproduce. -->

    Verified locally with:
    go test ./inttest/addons -run '^TestAddonsSuite$' -count=1 -v

    Checklist

  • This pull request follows the contributing guidelines

  • I have performed a self-review of my changes

  • I have made corresponding changes to the documentation
  • Diff: 282 lines (+263 / -19) across 1 files Reviewer: twz123 Review duration: 33909m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.60) × (1 − Review Confidence (0.92)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.60 · 282 lines diff across 1 files
    0.60
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.92 · 5 substantive comment(s)
    0.92
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    91%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.338
    Sensitive Paths sensitive_paths
    0.060
    Real PR Conversation Timeline
    17 items
    DeeBi9 DeeBi9 commented on Oct 21, 2026 09:05 UTC
    Author

    Apologies for the delay in this PR, I was away and occupied with other commitments, which took me longer than expected to get back to this. I'll make an effort to stay more engaged with the project and contribute more consistently going forward.

    twz123 twz123 commented on code on Oct 22, 2026 15:43 UTC
    Code Review
    inttest/addons/addons_test.go:1
    @@ -344,6 +420,182 @@ func (as *AddonsSuite) testSecretBasedAuth(kc *k8s.Clientset) {
     	}))
     }
     
    +func (as *AddonsSuite) testMTLSAuth() {
    +	ctx := as.TContext()
    +
    +	if out, err := exec.Command("docker", "rm", "-f", mtlsRegistryNodeName).CombinedOutput(); err != nil && !strings.Contains(string(out), "No such container") {
    +		as.Require().NoErrorf(err, "failed to remove stale mTLS registry container: %s", out)
    +	}
    +
    +	certsDir := filepath.Join(as.T().TempDir(), "mtls-registry")
    +	as.Require().NoError(os.MkdirAll(certsDir, 0755))
    +
    +	caPEM, clientCertPEM, clientKeyPEM := issueMTLSRegistryCerts(as.T(), certsDir, mtlsRegistryNodeName)
    +
    +	caFile := filepath.Join(certsDir, "ca.crt")
    +	clientCertFile := filepath.Join(certsDir, "client.crt")
    +	clientKeyFile := filepath.Join(certsDir, "client.key")
    +	as.Require().NoError(os.WriteFile(caFile, caPEM, 0644))
    +	as.Require().NoError(os.WriteFile(clientCertFile, clientCertPEM, 0644))
    +	as.Require().NoError(os.WriteFile(clientKeyFile, clientKeyPEM, 0600))
    +
    +	out, err := exec.Command(
    +		"docker", "run", "-d", "--name", mtlsRegistryNodeName,
    +		"--network", as.Networks[0],
    +		"-p", fmt.Sprintf("0:%d", mtlsRegistryContainerPort),
    +		"-v", certsDir+":/tls",
    +		"-e", fmt.Sprintf("REGISTRY_HTTP_ADDR=0.0.0.0:%d", mtlsRegistryContainerPort),
    +		"-e", "REGISTRY_HTTP_TLS_CERTIFICATE=/tls/tls.crt",
    +		"-e", "REGISTRY_HTTP_TLS_KEY=/tls/tls.key",
    +		"-e", `REGISTRY_HTTP_TLS_CLIENTCAS=["/tls/client-ca.crt"]`,
    +		"docker.io/library/registry:3.1.2@sha256:ddf754342cfc8acc51a56d5d0ab6af06826461864460636d8bd5c546dab2a7b8",
    +	).CombinedOutput()
    +	as.Require().NoErrorf(err, "failed to start mTLS registry: %s", out)
    +
    +	inspectOut, err := exec.Command("docker", "inspect", "--format", "{{.Id}}", mtlsRegistryNodeName).CombinedOutput()
    +	as.Require().NoErrorf(err, "failed to inspect mTLS registry container: %s", inspectOut)
    +	containerID := strings.TrimSpace(string(inspectOut))
    +	as.Require().NotEmpty(containerID, "docker inspect returned an empty container ID")
    +	as.T().Cleanup(func() {
    +		if out, err := exec.Command("docker", "rm", "-f", containerID).CombinedOutput(); err != nil {
    +			as.T().Logf("failed to remove mTLS registry container %s: %v: %s", containerID, err, out)
    +		}
    +	})
    +
    +	portOut, err := exec.Command("docker", "port", containerID, strconv.Itoa(mtlsRegistryContainerPort)).CombinedOutput()
    +	as.Require().NoErrorf(err, "failed to determine mTLS registry port: %s", portOut)
    +	fields := strings.Fields(string(portOut))
    +	as.Require().NotEmpty(fields, "no port mapping for mTLS registry: %s", portOut)
    +	_, port, err := net.SplitHostPort(fields[0])
    +	as.Require().NoErrorf(err, "unexpected docker port output: %s", portOut)
    +	hostPort, err := strconv.Atoi(port)
    +	as.Require().NoError(err)
    +
    +	clientCert, err := tls.X509KeyPair(clientCertPEM, clientKeyPEM)
    +	as.Require().NoError(err)
    +	pool := x509.NewCertPool()
    +	as.Require().True(pool.AppendCertsFromPEM(caPEM))
    +	httpClient := &http.Client{Transport: &http.Transport{
    +		TLSClientConfig: &tls.Config{RootCAs: pool, Certificates: []tls.Certificate{clientCert}},
    +	}}
    +	defer httpClient.CloseIdleConnections()
    +
    +	as.T().Log("Waiting for mTLS registry to come up")
    +	as.Require().NoErrorf(wait.PollUntilContextCancel(ctx, time.Second, true, func(context.Context) (bool, error) {
    +		resp, err := httpClient.Get(fmt.Sprintf("https://localhost:%d/v2/", hostPort))
    +		if err != nil {
    +			as.T().Logf("mTLS registry not ready yet: %v", err)
    +			return false, nil
    +		}
    +		defer resp.Body.Close()
    +		if resp.StatusCode != http.StatusOK {
    +			as.T().Logf("mTLS registry not ready yet: HTTP %d", resp.StatusCode)
    +			return false, nil
    +		}
    +		return true, nil
    +	}), "timed out waiting for mTLS registry at localhost:%d", hostPort)
    +
    +	unauthenticatedClient := &http.Client{Transport: &http.Transport{
    +		TLSClientConfig: &tls.Config{RootCAs: pool},
    +	}}
    +	defer unauthenticatedClient.CloseIdleConnections()
    +
    +	unauthResp, unauthErr := unauthenticatedClient.Get(fmt.Sprintf("https://localhost:%d/v2/", hostPort))
    +	if unauthResp != nil {
    +		unauthResp.Body.Close()
    +	}
    +	var remoteErr *net.OpError
    +	as.Require().ErrorAs(unauthErr, &remoteErr, "registry should reject a request without a client certificate")
    +	as.Require().Equal("remote error", remoteErr.Op, "registry should reject the TLS handshake")
    +
    +	as.pushChartToMTLSRegistry(hostPort, clientCertFile, clientKeyFile, caFile)
    +
    +	as.PutFile(as.ControllerNode(0), mtlsRegistryCAPath, string(caPEM))
    +	as.PutFile(as.ControllerNode(0), mtlsClientCertPath, string(clientCertPEM))
    +	as.PutFile(as.ControllerNode(0), mtlsClientKeyPath, string(clientKeyPEM))
    +
    +	as.T().Cleanup(func() {
    +		cleanupCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
    +		defer cancel()
    +
    +		ssh, err := as.SSH(cleanupCtx, as.ControllerNode(0))
    +		if err != nil {
    +			as.T().Logf("failed to connect to controller to remove mTLS credentials: %v", err)
    +			return
    +		}
    +		defer ssh.Disconnect()
    +
    +		rm := "rm -f " + strings.Join([]string{mtlsRegistryCAPath, mtlsClientCertPath, mtlsClientKeyPath}, " ")
    +		if _, err := ssh.ExecWithOutput(cleanupCtx, rm); err != nil {
    +			as.T().Logf("failed to remove mTLS credentials from controller: %v", err)
    +		}
    +	})
    +
    +	restConfig, err := as.GetKubeConfig(as.ControllerNode(0))
    +	as.Require().NoError(err)
    +	chartClient, err := client.New(restConfig, client.Options{Scheme: k0sscheme.Scheme})
    +	as.Require().NoError(err)
    +
    +	releaseName := "mtls-oci-addon"
    +	chartName := "k0s-addon-chart-" + releaseName
    +	chart := &helmv1beta1.Chart{
    +		ObjectMeta: metav1.ObjectMeta{
    +			Name:      chartName,
    +			Namespace: metav1.NamespaceSystem,
    +			Finalizers: []string{
    +				"helm.k0sproject.io/uninstall-helm-release",
    +			},
    +		},
    +		Spec: helmv1beta1.ChartSpec{
    +			ChartName:   fmt.Sprintf("oci://%s/charts/echo-server", net.JoinHostPort(mtlsRegistryNodeName, strconv.Itoa(mtlsRegistryContainerPort))),
    +			ReleaseName: releaseName,
    +			Version:     "0.5.0",
    +			Namespace:   metav1.NamespaceDefault,
    +			Timeout:     "5m0s",
    +			Repository: &helmv1beta1.RepositorySpec{
    +				CAFile:   mtlsRegistryCAPath,
    +				CertFile: mtlsClientCertPath,
    +				KeyFile:  mtlsClientKeyPath,
    +			},
    +		},
    +	}
    +
    +	as.T().Logf("Creating mTLS Chart %s/%s", chart.Namespace, chart.Name)
    +	as.Require().NoError(chartClient.Create(ctx, chart))
    +
    +	deleteChart := func() {
    +		cleanupCtx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
    +		defer cancel()
    +
    +		if err := chartClient.Delete(cleanupCtx, chart); err != nil && !apierrors.IsNotFound(err) {
    +			as.T().Logf("failed to delete mTLS Chart %s/%s: %v", chart.Namespace, chart.Name, err)
    +			return
    +		}
    +
    +		err := wait.PollUntilContextCancel(cleanupCtx, time.Second, true, func(ctx context.Context) (bool, error) {
    +			var found helmv1beta1.Chart
    +			err := chartClient.Get(ctx, client.ObjectKey{Namespace: chart.Namespace, Name: chart.Name}, &found)
    +			if apierrors.IsNotFound(err) {
    +				return true, nil
    +			}
    +			if err != nil {
    +				as.T().Logf("failed to get mTLS Chart %s/%s: %v", chart.Namespace, chart.Name, err)
    +			}
    +			return false, nil
    +		})
    +		if err != nil {
    +			as.T().Logf("timed out waiting for mTLS Chart %s/%s to be deleted: %v", chart.Namespace, chart.Name, err)
    +		}
    +	}
    +	as.T().Cleanup(deleteChart)
    +
    +	reconciledChart := as.waitForTestRelease(releaseName, "0.6.0", metav1.NamespaceDefault, 1)
    +	as.Require().Empty(reconciledChart.Status.Error, "Chart should not have error after mTLS reconciliation")
    +
    +	as.T().Logf("Cleaning up mTLS test - deleting Chart")
    +	deleteChart()

    This doesn't check if the happy-path deletion worked. deleteChart only logs on failure, so a problem in the uninstall finalizer wouldn't fail the test. testSecretBasedAuth uses Require() for both the delete and the wait for the Chart to disappear.

    What about doing the in-line delete and wait with Require, and keep the Cleanup registration as the best-effort fallback for failure paths?

    twz123 twz123 commented on code on Oct 22, 2026 15:43 UTC
    Code Review
    inttest/addons/addons_test.go:1
    @@ -344,6 +420,182 @@ func (as *AddonsSuite) testSecretBasedAuth(kc *k8s.Clientset) {
     	}))
     }
     
    +func (as *AddonsSuite) testMTLSAuth() {
    +	ctx := as.TContext()
    +
    +	if out, err := exec.Command("docker", "rm", "-f", mtlsRegistryNodeName).CombinedOutput(); err != nil && !strings.Contains(string(out), "No such container") {
    +		as.Require().NoErrorf(err, "failed to remove stale mTLS registry container: %s", out)
    +	}
    +
    +	certsDir := filepath.Join(as.T().TempDir(), "mtls-registry")
    +	as.Require().NoError(os.MkdirAll(certsDir, 0755))
    +
    +	caPEM, clientCertPEM, clientKeyPEM := issueMTLSRegistryCerts(as.T(), certsDir, mtlsRegistryNodeName)
    +
    +	caFile := filepath.Join(certsDir, "ca.crt")
    +	clientCertFile := filepath.Join(certsDir, "client.crt")
    +	clientKeyFile := filepath.Join(certsDir, "client.key")
    +	as.Require().NoError(os.WriteFile(caFile, caPEM, 0644))
    +	as.Require().NoError(os.WriteFile(clientCertFile, clientCertPEM, 0644))
    +	as.Require().NoError(os.WriteFile(clientKeyFile, clientKeyPEM, 0600))
    +
    +	out, err := exec.Command(
    +		"docker", "run", "-d", "--name", mtlsRegistryNodeName,
    +		"--network", as.Networks[0],
    +		"-p", fmt.Sprintf("0:%d", mtlsRegistryContainerPort),
    +		"-v", certsDir+":/tls",
    +		"-e", fmt.Sprintf("REGISTRY_HTTP_ADDR=0.0.0.0:%d", mtlsRegistryContainerPort),
    +		"-e", "REGISTRY_HTTP_TLS_CERTIFICATE=/tls/tls.crt",
    +		"-e", "REGISTRY_HTTP_TLS_KEY=/tls/tls.key",
    +		"-e", `REGISTRY_HTTP_TLS_CLIENTCAS=["/tls/client-ca.crt"]`,
    +		"docker.io/library/registry:3.1.2@sha256:ddf754342cfc8acc51a56d5d0ab6af06826461864460636d8bd5c546dab2a7b8",
    +	).CombinedOutput()
    +	as.Require().NoErrorf(err, "failed to start mTLS registry: %s", out)
    +
    +	inspectOut, err := exec.Command("docker", "inspect", "--format", "{{.Id}}", mtlsRegistryNodeName).CombinedOutput()
    +	as.Require().NoErrorf(err, "failed to inspect mTLS registry container: %s", inspectOut)
    +	containerID := strings.TrimSpace(string(inspectOut))
    +	as.Require().NotEmpty(containerID, "docker inspect returned an empty container ID")
    +	as.T().Cleanup(func() {
    +		if out, err := exec.Command("docker", "rm", "-f", containerID).CombinedOutput(); err != nil {
    +			as.T().Logf("failed to remove mTLS registry container %s: %v: %s", containerID, err, out)
    +		}
    +	})
    +
    +	portOut, err := exec.Command("docker", "port", containerID, strconv.Itoa(mtlsRegistryContainerPort)).CombinedOutput()
    +	as.Require().NoErrorf(err, "failed to determine mTLS registry port: %s", portOut)
    +	fields := strings.Fields(string(portOut))
    +	as.Require().NotEmpty(fields, "no port mapping for mTLS registry: %s", portOut)
    +	_, port, err := net.SplitHostPort(fields[0])
    +	as.Require().NoErrorf(err, "unexpected docker port output: %s", portOut)
    +	hostPort, err := strconv.Atoi(port)
    +	as.Require().NoError(err)
    +
    +	clientCert, err := tls.X509KeyPair(clientCertPEM, clientKeyPEM)
    +	as.Require().NoError(err)
    +	pool := x509.NewCertPool()
    +	as.Require().True(pool.AppendCertsFromPEM(caPEM))
    +	httpClient := &http.Client{Transport: &http.Transport{
    +		TLSClientConfig: &tls.Config{RootCAs: pool, Certificates: []tls.Certificate{clientCert}},
    +	}}
    +	defer httpClient.CloseIdleConnections()
    +
    +	as.T().Log("Waiting for mTLS registry to come up")
    +	as.Require().NoErrorf(wait.PollUntilContextCancel(ctx, time.Second, true, func(context.Context) (bool, error) {
    +		resp, err := httpClient.Get(fmt.Sprintf("https://localhost:%d/v2/", hostPort))
    +		if err != nil {
    +			as.T().Logf("mTLS registry not ready yet: %v", err)
    +			return false, nil
    +		}
    +		defer resp.Body.Close()
    +		if resp.StatusCode != http.StatusOK {
    +			as.T().Logf("mTLS registry not ready yet: HTTP %d", resp.StatusCode)
    +			return false, nil
    +		}
    +		return true, nil
    +	}), "timed out waiting for mTLS registry at localhost:%d", hostPort)
    +
    +	unauthenticatedClient := &http.Client{Transport: &http.Transport{
    +		TLSClientConfig: &tls.Config{RootCAs: pool},
    +	}}
    +	defer unauthenticatedClient.CloseIdleConnections()
    +
    +	unauthResp, unauthErr := unauthenticatedClient.Get(fmt.Sprintf("https://localhost:%d/v2/", hostPort))
    +	if unauthResp != nil {
    +		unauthResp.Body.Close()
    +	}
    +	var remoteErr *net.OpError
    +	as.Require().ErrorAs(unauthErr, &remoteErr, "registry should reject a request without a client certificate")
    +	as.Require().Equal("remote error", remoteErr.Op, "registry should reject the TLS handshake")
    +
    +	as.pushChartToMTLSRegistry(hostPort, clientCertFile, clientKeyFile, caFile)
    +
    +	as.PutFile(as.ControllerNode(0), mtlsRegistryCAPath, string(caPEM))
    +	as.PutFile(as.ControllerNode(0), mtlsClientCertPath, string(clientCertPEM))
    +	as.PutFile(as.ControllerNode(0), mtlsClientKeyPath, string(clientKeyPEM))
    +
    +	as.T().Cleanup(func() {
    +		cleanupCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
    +		defer cancel()
    +
    +		ssh, err := as.SSH(cleanupCtx, as.ControllerNode(0))
    +		if err != nil {
    +			as.T().Logf("failed to connect to controller to remove mTLS credentials: %v", err)
    +			return
    +		}
    +		defer ssh.Disconnect()
    +
    +		rm := "rm -f " + strings.Join([]string{mtlsRegistryCAPath, mtlsClientCertPath, mtlsClientKeyPath}, " ")
    +		if _, err := ssh.ExecWithOutput(cleanupCtx, rm); err != nil {
    +			as.T().Logf("failed to remove mTLS credentials from controller: %v", err)
    +		}
    +	})
    +
    +	restConfig, err := as.GetKubeConfig(as.ControllerNode(0))
    +	as.Require().NoError(err)
    +	chartClient, err := client.New(restConfig, client.Options{Scheme: k0sscheme.Scheme})
    +	as.Require().NoError(err)
    +
    +	releaseName := "mtls-oci-addon"
    +	chartName := "k0s-addon-chart-" + releaseName
    +	chart := &helmv1beta1.Chart{
    +		ObjectMeta: metav1.ObjectMeta{
    +			Name:      chartName,
    +			Namespace: metav1.NamespaceSystem,
    +			Finalizers: []string{
    +				"helm.k0sproject.io/uninstall-helm-release",
    +			},
    +		},
    +		Spec: helmv1beta1.ChartSpec{
    +			ChartName:   fmt.Sprintf("oci://%s/charts/echo-server", net.JoinHostPort(mtlsRegistryNodeName, strconv.Itoa(mtlsRegistryContainerPort))),
    +			ReleaseName: releaseName,
    +			Version:     "0.5.0",
    +			Namespace:   metav1.NamespaceDefault,
    +			Timeout:     "5m0s",
    +			Repository: &helmv1beta1.RepositorySpec{
    +				CAFile:   mtlsRegistryCAPath,
    +				CertFile: mtlsClientCertPath,
    +				KeyFile:  mtlsClientKeyPath,
    +			},
    +		},
    +	}
    +
    +	as.T().Logf("Creating mTLS Chart %s/%s", chart.Namespace, chart.Name)
    +	as.Require().NoError(chartClient.Create(ctx, chart))
    +
    +	deleteChart := func() {
    +		cleanupCtx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
    +		defer cancel()
    +
    +		if err := chartClient.Delete(cleanupCtx, chart); err != nil && !apierrors.IsNotFound(err) {
    +			as.T().Logf("failed to delete mTLS Chart %s/%s: %v", chart.Namespace, chart.Name, err)
    +			return
    +		}
    +
    +		err := wait.PollUntilContextCancel(cleanupCtx, time.Second, true, func(ctx context.Context) (bool, error) {
    +			var found helmv1beta1.Chart
    +			err := chartClient.Get(ctx, client.ObjectKey{Namespace: chart.Namespace, Name: chart.Name}, &found)
    +			if apierrors.IsNotFound(err) {
    +				return true, nil
    +			}
    +			if err != nil {
    +				as.T().Logf("failed to get mTLS Chart %s/%s: %v", chart.Namespace, chart.Name, err)
    +			}
    +			return false, nil
    +		})
    +		if err != nil {
    +			as.T().Logf("timed out waiting for mTLS Chart %s/%s to be deleted: %v", chart.Namespace, chart.Name, err)
    +		}
    +	}
    +	as.T().Cleanup(deleteChart)
    +
    +	reconciledChart := as.waitForTestRelease(releaseName, "0.6.0", metav1.NamespaceDefault, 1)

    waitForTestRelease treats a non-empty Status.Error as "not ready yet" and keeps waiting, so a broken mTLS path would result as a suite timeout with the real error buried somewhere in the logs. An mTLS pull has nothing to wait on, so a first-attempt error is already a genuine failure here. testChartOrdering has the strict watch variant that fails on the first Status.Error, which would give a faster and clearer failure here.

    twz123 twz123 commented on code on Oct 22, 2026 15:43 UTC
    Code Review
    inttest/addons/addons_test.go:1
    @@ -344,6 +420,182 @@ func (as *AddonsSuite) testSecretBasedAuth(kc *k8s.Clientset) {
     	}))
     }
     
    +func (as *AddonsSuite) testMTLSAuth() {
    +	ctx := as.TContext()
    +
    +	if out, err := exec.Command("docker", "rm", "-f", mtlsRegistryNodeName).CombinedOutput(); err != nil && !strings.Contains(string(out), "No such container") {
    +		as.Require().NoErrorf(err, "failed to remove stale mTLS registry container: %s", out)
    +	}
    +
    +	certsDir := filepath.Join(as.T().TempDir(), "mtls-registry")
    +	as.Require().NoError(os.MkdirAll(certsDir, 0755))
    +
    +	caPEM, clientCertPEM, clientKeyPEM := issueMTLSRegistryCerts(as.T(), certsDir, mtlsRegistryNodeName)
    +
    +	caFile := filepath.Join(certsDir, "ca.crt")
    +	clientCertFile := filepath.Join(certsDir, "client.crt")
    +	clientKeyFile := filepath.Join(certsDir, "client.key")
    +	as.Require().NoError(os.WriteFile(caFile, caPEM, 0644))
    +	as.Require().NoError(os.WriteFile(clientCertFile, clientCertPEM, 0644))
    +	as.Require().NoError(os.WriteFile(clientKeyFile, clientKeyPEM, 0600))
    +
    +	out, err := exec.Command(
    +		"docker", "run", "-d", "--name", mtlsRegistryNodeName,
    +		"--network", as.Networks[0],
    +		"-p", fmt.Sprintf("0:%d", mtlsRegistryContainerPort),
    +		"-v", certsDir+":/tls",
    +		"-e", fmt.Sprintf("REGISTRY_HTTP_ADDR=0.0.0.0:%d", mtlsRegistryContainerPort),
    +		"-e", "REGISTRY_HTTP_TLS_CERTIFICATE=/tls/tls.crt",
    +		"-e", "REGISTRY_HTTP_TLS_KEY=/tls/tls.key",
    +		"-e", `REGISTRY_HTTP_TLS_CLIENTCAS=["/tls/client-ca.crt"]`,
    +		"docker.io/library/registry:3.1.2@sha256:ddf754342cfc8acc51a56d5d0ab6af06826461864460636d8bd5c546dab2a7b8",
    +	).CombinedOutput()
    +	as.Require().NoErrorf(err, "failed to start mTLS registry: %s", out)
    +
    +	inspectOut, err := exec.Command("docker", "inspect", "--format", "{{.Id}}", mtlsRegistryNodeName).CombinedOutput()

    Getting the ID here is just done to pass it to docker rm and docker port later on, but the name is already unique. Moreover, if inspect fails, the container leaks because the Cleanup is registered after it. Registering the removal by name right after docker run and dropping the inspect would be simpler and slightly more robust.

    twz123 twz123 commented on code on Oct 22, 2026 15:43 UTC
    Code Review
    inttest/addons/addons_test.go:1
    @@ -344,6 +420,182 @@ func (as *AddonsSuite) testSecretBasedAuth(kc *k8s.Clientset) {
     	}))
     }
     
    +func (as *AddonsSuite) testMTLSAuth() {
    +	ctx := as.TContext()
    +
    +	if out, err := exec.Command("docker", "rm", "-f", mtlsRegistryNodeName).CombinedOutput(); err != nil && !strings.Contains(string(out), "No such container") {

    This works, but reads a bit awkward.

    What about removing the strings.Contains and changing the statement inside the if like so:

    as.Require().Containsf(out, "No such container", failed to remove stale mTLS registry container: %v", err)

    twz123 twz123 commented on code on Oct 22, 2026 15:43 UTC
    Code Review
    inttest/addons/addons_test.go:1
    @@ -124,6 +135,52 @@ func issueServerCertsWithSelfSignedCA(t *testing.T, certsDir, registryHost strin
     	return serverCert
     }
     
    +func issueMTLSRegistryCerts(t *testing.T, certsDir, registryHost string) (caPEM, clientCertPEM, clientKeyPEM []byte) {

    This looks like it repeats quite a bit from issueServerCertsWithSelfSignedCA. Might be worth refactoring them into a helper for CA + signer + server cert. The mTLS variant could add the client profile and the client cert on top.

    twz123 twz123 commented on code on Oct 22, 2026 15:43 UTC
    Code Review
    inttest/addons/addons_test.go:1
    @@ -143,6 +200,24 @@ func (as *AddonsSuite) pushChartToLocalRegistry() {
     	as.Require().NoError(err)
     }
     
    +func (as *AddonsSuite) pushChartToMTLSRegistry(hostPort int, certFile, keyFile, caFile string) {

    Isn't this pushChartToLocalRegistry with one push option swapped? What about having a single pushChart(hostPort int, opts ...action.PushOpt)?

    twz123 twz123 commented on code on Oct 22, 2026 15:43 UTC
    Code Review
    inttest/addons/addons_test.go:1
    @@ -344,6 +420,182 @@ func (as *AddonsSuite) testSecretBasedAuth(kc *k8s.Clientset) {
     	}))
     }
     
    +func (as *AddonsSuite) testMTLSAuth() {
    +	ctx := as.TContext()
    +
    +	if out, err := exec.Command("docker", "rm", "-f", mtlsRegistryNodeName).CombinedOutput(); err != nil && !strings.Contains(string(out), "No such container") {
    +		as.Require().NoErrorf(err, "failed to remove stale mTLS registry container: %s", out)
    +	}
    +
    +	certsDir := filepath.Join(as.T().TempDir(), "mtls-registry")
    +	as.Require().NoError(os.MkdirAll(certsDir, 0755))
    +
    +	caPEM, clientCertPEM, clientKeyPEM := issueMTLSRegistryCerts(as.T(), certsDir, mtlsRegistryNodeName)
    +
    +	caFile := filepath.Join(certsDir, "ca.crt")
    +	clientCertFile := filepath.Join(certsDir, "client.crt")
    +	clientKeyFile := filepath.Join(certsDir, "client.key")
    +	as.Require().NoError(os.WriteFile(caFile, caPEM, 0644))
    +	as.Require().NoError(os.WriteFile(clientCertFile, clientCertPEM, 0644))
    +	as.Require().NoError(os.WriteFile(clientKeyFile, clientKeyPEM, 0600))
    +
    +	out, err := exec.Command(
    +		"docker", "run", "-d", "--name", mtlsRegistryNodeName,
    +		"--network", as.Networks[0],
    +		"-p", fmt.Sprintf("0:%d", mtlsRegistryContainerPort),
    +		"-v", certsDir+":/tls",
    +		"-e", fmt.Sprintf("REGISTRY_HTTP_ADDR=0.0.0.0:%d", mtlsRegistryContainerPort),
    +		"-e", "REGISTRY_HTTP_TLS_CERTIFICATE=/tls/tls.crt",
    +		"-e", "REGISTRY_HTTP_TLS_KEY=/tls/tls.key",
    +		"-e", `REGISTRY_HTTP_TLS_CLIENTCAS=["/tls/client-ca.crt"]`,
    +		"docker.io/library/registry:3.1.2@sha256:ddf754342cfc8acc51a56d5d0ab6af06826461864460636d8bd5c546dab2a7b8",
    +	).CombinedOutput()
    +	as.Require().NoErrorf(err, "failed to start mTLS registry: %s", out)

    Assertion messages read best when they state the expectation, e.g. "mTLS registry should start" rather than the failure, and the log lines in the cleanups should be capitalized like the rest of the file ("Failed to remove ...").

    twz123 twz123 commented on Oct 22, 2026 16:02 UTC
    Reviewer

    Apologies for the delay in this PR, I was away and occupied with other commitments, which took me longer than expected to get back to this. I'll make an effort to stay more engaged with the project and contribute more consistently going forward.

    No worries at all! Thanks for picking this up, once again!

    DeeBi9 DeeBi9 commented on code on Oct 23, 2026 04:42 UTC
    Code Review
    inttest/addons/addons_test.go:1
    @@ -344,6 +420,182 @@ func (as *AddonsSuite) testSecretBasedAuth(kc *k8s.Clientset) {
     	}))
     }
     
    +func (as *AddonsSuite) testMTLSAuth() {
    +	ctx := as.TContext()
    +
    +	if out, err := exec.Command("docker", "rm", "-f", mtlsRegistryNodeName).CombinedOutput(); err != nil && !strings.Contains(string(out), "No such container") {
    +		as.Require().NoErrorf(err, "failed to remove stale mTLS registry container: %s", out)
    +	}
    +
    +	certsDir := filepath.Join(as.T().TempDir(), "mtls-registry")
    +	as.Require().NoError(os.MkdirAll(certsDir, 0755))
    +
    +	caPEM, clientCertPEM, clientKeyPEM := issueMTLSRegistryCerts(as.T(), certsDir, mtlsRegistryNodeName)
    +
    +	caFile := filepath.Join(certsDir, "ca.crt")
    +	clientCertFile := filepath.Join(certsDir, "client.crt")
    +	clientKeyFile := filepath.Join(certsDir, "client.key")
    +	as.Require().NoError(os.WriteFile(caFile, caPEM, 0644))
    +	as.Require().NoError(os.WriteFile(clientCertFile, clientCertPEM, 0644))
    +	as.Require().NoError(os.WriteFile(clientKeyFile, clientKeyPEM, 0600))
    +
    +	out, err := exec.Command(
    +		"docker", "run", "-d", "--name", mtlsRegistryNodeName,
    +		"--network", as.Networks[0],
    +		"-p", fmt.Sprintf("0:%d", mtlsRegistryContainerPort),
    +		"-v", certsDir+":/tls",
    +		"-e", fmt.Sprintf("REGISTRY_HTTP_ADDR=0.0.0.0:%d", mtlsRegistryContainerPort),
    +		"-e", "REGISTRY_HTTP_TLS_CERTIFICATE=/tls/tls.crt",
    +		"-e", "REGISTRY_HTTP_TLS_KEY=/tls/tls.key",
    +		"-e", `REGISTRY_HTTP_TLS_CLIENTCAS=["/tls/client-ca.crt"]`,
    +		"docker.io/library/registry:3.1.2@sha256:ddf754342cfc8acc51a56d5d0ab6af06826461864460636d8bd5c546dab2a7b8",
    +	).CombinedOutput()
    +	as.Require().NoErrorf(err, "failed to start mTLS registry: %s", out)
    +
    +	inspectOut, err := exec.Command("docker", "inspect", "--format", "{{.Id}}", mtlsRegistryNodeName).CombinedOutput()
    +	as.Require().NoErrorf(err, "failed to inspect mTLS registry container: %s", inspectOut)
    +	containerID := strings.TrimSpace(string(inspectOut))
    +	as.Require().NotEmpty(containerID, "docker inspect returned an empty container ID")
    +	as.T().Cleanup(func() {
    +		if out, err := exec.Command("docker", "rm", "-f", containerID).CombinedOutput(); err != nil {
    +			as.T().Logf("failed to remove mTLS registry container %s: %v: %s", containerID, err, out)
    +		}
    +	})
    +
    +	portOut, err := exec.Command("docker", "port", containerID, strconv.Itoa(mtlsRegistryContainerPort)).CombinedOutput()
    +	as.Require().NoErrorf(err, "failed to determine mTLS registry port: %s", portOut)
    +	fields := strings.Fields(string(portOut))
    +	as.Require().NotEmpty(fields, "no port mapping for mTLS registry: %s", portOut)
    +	_, port, err := net.SplitHostPort(fields[0])
    +	as.Require().NoErrorf(err, "unexpected docker port output: %s", portOut)
    +	hostPort, err := strconv.Atoi(port)
    +	as.Require().NoError(err)
    +
    +	clientCert, err := tls.X509KeyPair(clientCertPEM, clientKeyPEM)
    +	as.Require().NoError(err)
    +	pool := x509.NewCertPool()
    +	as.Require().True(pool.AppendCertsFromPEM(caPEM))
    +	httpClient := &http.Client{Transport: &http.Transport{
    +		TLSClientConfig: &tls.Config{RootCAs: pool, Certificates: []tls.Certificate{clientCert}},
    +	}}
    +	defer httpClient.CloseIdleConnections()
    +
    +	as.T().Log("Waiting for mTLS registry to come up")
    +	as.Require().NoErrorf(wait.PollUntilContextCancel(ctx, time.Second, true, func(context.Context) (bool, error) {
    +		resp, err := httpClient.Get(fmt.Sprintf("https://localhost:%d/v2/", hostPort))
    +		if err != nil {
    +			as.T().Logf("mTLS registry not ready yet: %v", err)
    +			return false, nil
    +		}
    +		defer resp.Body.Close()
    +		if resp.StatusCode != http.StatusOK {
    +			as.T().Logf("mTLS registry not ready yet: HTTP %d", resp.StatusCode)
    +			return false, nil
    +		}
    +		return true, nil
    +	}), "timed out waiting for mTLS registry at localhost:%d", hostPort)
    +
    +	unauthenticatedClient := &http.Client{Transport: &http.Transport{
    +		TLSClientConfig: &tls.Config{RootCAs: pool},
    +	}}
    +	defer unauthenticatedClient.CloseIdleConnections()
    +
    +	unauthResp, unauthErr := unauthenticatedClient.Get(fmt.Sprintf("https://localhost:%d/v2/", hostPort))
    +	if unauthResp != nil {
    +		unauthResp.Body.Close()
    +	}
    +	var remoteErr *net.OpError
    +	as.Require().ErrorAs(unauthErr, &remoteErr, "registry should reject a request without a client certificate")
    +	as.Require().Equal("remote error", remoteErr.Op, "registry should reject the TLS handshake")
    +
    +	as.pushChartToMTLSRegistry(hostPort, clientCertFile, clientKeyFile, caFile)
    +
    +	as.PutFile(as.ControllerNode(0), mtlsRegistryCAPath, string(caPEM))
    +	as.PutFile(as.ControllerNode(0), mtlsClientCertPath, string(clientCertPEM))
    +	as.PutFile(as.ControllerNode(0), mtlsClientKeyPath, string(clientKeyPEM))
    +
    +	as.T().Cleanup(func() {
    +		cleanupCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
    +		defer cancel()
    +
    +		ssh, err := as.SSH(cleanupCtx, as.ControllerNode(0))
    +		if err != nil {
    +			as.T().Logf("failed to connect to controller to remove mTLS credentials: %v", err)
    +			return
    +		}
    +		defer ssh.Disconnect()
    +
    +		rm := "rm -f " + strings.Join([]string{mtlsRegistryCAPath, mtlsClientCertPath, mtlsClientKeyPath}, " ")
    +		if _, err := ssh.ExecWithOutput(cleanupCtx, rm); err != nil {
    +			as.T().Logf("failed to remove mTLS credentials from controller: %v", err)
    +		}
    +	})
    +
    +	restConfig, err := as.GetKubeConfig(as.ControllerNode(0))
    +	as.Require().NoError(err)
    +	chartClient, err := client.New(restConfig, client.Options{Scheme: k0sscheme.Scheme})
    +	as.Require().NoError(err)
    +
    +	releaseName := "mtls-oci-addon"
    +	chartName := "k0s-addon-chart-" + releaseName
    +	chart := &helmv1beta1.Chart{
    +		ObjectMeta: metav1.ObjectMeta{
    +			Name:      chartName,
    +			Namespace: metav1.NamespaceSystem,
    +			Finalizers: []string{
    +				"helm.k0sproject.io/uninstall-helm-release",
    +			},
    +		},
    +		Spec: helmv1beta1.ChartSpec{
    +			ChartName:   fmt.Sprintf("oci://%s/charts/echo-server", net.JoinHostPort(mtlsRegistryNodeName, strconv.Itoa(mtlsRegistryContainerPort))),
    +			ReleaseName: releaseName,
    +			Version:     "0.5.0",
    +			Namespace:   metav1.NamespaceDefault,
    +			Timeout:     "5m0s",
    +			Repository: &helmv1beta1.RepositorySpec{
    +				CAFile:   mtlsRegistryCAPath,
    +				CertFile: mtlsClientCertPath,
    +				KeyFile:  mtlsClientKeyPath,
    +			},
    +		},
    +	}
    +
    +	as.T().Logf("Creating mTLS Chart %s/%s", chart.Namespace, chart.Name)
    +	as.Require().NoError(chartClient.Create(ctx, chart))
    +
    +	deleteChart := func() {
    +		cleanupCtx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
    +		defer cancel()
    +
    +		if err := chartClient.Delete(cleanupCtx, chart); err != nil && !apierrors.IsNotFound(err) {
    +			as.T().Logf("failed to delete mTLS Chart %s/%s: %v", chart.Namespace, chart.Name, err)
    +			return
    +		}
    +
    +		err := wait.PollUntilContextCancel(cleanupCtx, time.Second, true, func(ctx context.Context) (bool, error) {
    +			var found helmv1beta1.Chart
    +			err := chartClient.Get(ctx, client.ObjectKey{Namespace: chart.Namespace, Name: chart.Name}, &found)
    +			if apierrors.IsNotFound(err) {
    +				return true, nil
    +			}
    +			if err != nil {
    +				as.T().Logf("failed to get mTLS Chart %s/%s: %v", chart.Namespace, chart.Name, err)
    +			}
    +			return false, nil
    +		})
    +		if err != nil {
    +			as.T().Logf("timed out waiting for mTLS Chart %s/%s to be deleted: %v", chart.Namespace, chart.Name, err)
    +		}
    +	}
    +	as.T().Cleanup(deleteChart)
    +
    +	reconciledChart := as.waitForTestRelease(releaseName, "0.6.0", metav1.NamespaceDefault, 1)
    +	as.Require().Empty(reconciledChart.Status.Error, "Chart should not have error after mTLS reconciliation")
    +
    +	as.T().Logf("Cleaning up mTLS test - deleting Chart")
    +	deleteChart()

    Fair point.

    DeeBi9 DeeBi9 commented on code on Oct 23, 2026 04:47 UTC
    Code Review
    inttest/addons/addons_test.go:1
    @@ -124,6 +135,52 @@ func issueServerCertsWithSelfSignedCA(t *testing.T, certsDir, registryHost strin
     	return serverCert
     }
     
    +func issueMTLSRegistryCerts(t *testing.T, certsDir, registryHost string) (caPEM, clientCertPEM, clientKeyPEM []byte) {

    I kept them separate to avoid touching the self-signed path, but a shared helper makes sense.

    DeeBi9 DeeBi9 commented on code on Oct 23, 2026 04:48 UTC
    Code Review
    inttest/addons/addons_test.go:1
    @@ -143,6 +200,24 @@ func (as *AddonsSuite) pushChartToLocalRegistry() {
     	as.Require().NoError(err)
     }
     
    +func (as *AddonsSuite) pushChartToMTLSRegistry(hostPort int, certFile, keyFile, caFile string) {

    Yeah the two are almost identical. I'll collapse them into one pusChart.

    twz123 twz123 commented on code on Nov 11, 2026 12:33 UTC
    Code Review
    inttest/addons/addons_test.go:1
    @@ -344,6 +388,207 @@ func (as *AddonsSuite) testSecretBasedAuth(kc *k8s.Clientset) {
     	}))
     }
     
    +func (as *AddonsSuite) testMTLSAuth() {
    +	ctx := as.TContext()
    +
    +	if out, err := exec.Command("docker", "rm", "-f", mtlsRegistryNodeName).CombinedOutput(); err != nil {
    +		as.Require().Containsf(string(out), "No such container", "Failed to remove stale mTLS registry container: %v", err)
    +	}
    +
    +	certsDir := filepath.Join(as.T().TempDir(), "mtls-registry")
    +	as.Require().NoError(os.MkdirAll(certsDir, 0755))
    +
    +	caPEM, clientCertPEM, clientKeyPEM := issueMTLSRegistryCerts(as.T(), certsDir, mtlsRegistryNodeName)
    +
    +	caFile := filepath.Join(certsDir, "ca.crt")
    +	clientCertFile := filepath.Join(certsDir, "client.crt")
    +	clientKeyFile := filepath.Join(certsDir, "client.key")
    +	as.Require().NoError(os.WriteFile(caFile, caPEM, 0644))
    +	as.Require().NoError(os.WriteFile(clientCertFile, clientCertPEM, 0644))
    +	as.Require().NoError(os.WriteFile(clientKeyFile, clientKeyPEM, 0600))
    +
    +	out, err := exec.Command(
    +		"docker", "run", "-d", "--name", mtlsRegistryNodeName,
    +		"--network", as.Networks[0],
    +		"-p", fmt.Sprintf("0:%d", mtlsRegistryContainerPort),
    +		"-v", certsDir+":/tls",
    +		"-e", fmt.Sprintf("REGISTRY_HTTP_ADDR=0.0.0.0:%d", mtlsRegistryContainerPort),
    +		"-e", "REGISTRY_HTTP_TLS_CERTIFICATE=/tls/tls.crt",
    +		"-e", "REGISTRY_HTTP_TLS_KEY=/tls/tls.key",
    +		"-e", `REGISTRY_HTTP_TLS_CLIENTCAS=["/tls/client-ca.crt"]`,
    +		"docker.io/library/registry:3.1.2@sha256:ddf754342cfc8acc51a56d5d0ab6af06826461864460636d8bd5c546dab2a7b8",
    +	).CombinedOutput()
    +	as.T().Cleanup(func() {
    +		if out, err := exec.Command("docker", "rm", "-f", mtlsRegistryNodeName).CombinedOutput(); err != nil {
    +			as.T().Logf("Failed to remove mTLS registry container %s: %v: %s", mtlsRegistryNodeName, err, out)
    +		}
    +	})
    +	as.Require().NoErrorf(err, "mTLS registry should start: %s", out)
    +
    +	portOut, err := exec.Command("docker", "port", mtlsRegistryNodeName, strconv.Itoa(mtlsRegistryContainerPort)).CombinedOutput()
    +	as.Require().NoErrorf(err, "mTLS registry port should be determined: %s", portOut)
    +	fields := strings.Fields(string(portOut))
    +	as.Require().NotEmpty(fields, "mTLS registry should have a port mapping: %s", portOut)
    +	_, port, err := net.SplitHostPort(fields[0])
    +	as.Require().NoErrorf(err, "mTLS registry port mapping should be parseable: %s", portOut)
    +	hostPort, err := strconv.Atoi(port)
    +	as.Require().NoError(err)
    +
    +	clientCert, err := tls.X509KeyPair(clientCertPEM, clientKeyPEM)
    +	as.Require().NoError(err)
    +	pool := x509.NewCertPool()
    +	as.Require().True(pool.AppendCertsFromPEM(caPEM))
    +	httpClient := &http.Client{Transport: &http.Transport{
    +		TLSClientConfig: &tls.Config{RootCAs: pool, Certificates: []tls.Certificate{clientCert}},
    +	}}
    +	defer httpClient.CloseIdleConnections()
    +
    +	as.T().Log("Waiting for mTLS registry to come up")
    +	as.Require().NoErrorf(wait.PollUntilContextCancel(ctx, time.Second, true, func(context.Context) (bool, error) {
    +		resp, err := httpClient.Get(fmt.Sprintf("https://localhost:%d/v2/", hostPort))
    +		if err != nil {
    +			as.T().Logf("mTLS registry not ready yet: %v", err)
    +			return false, nil
    +		}
    +		defer resp.Body.Close()
    +		if resp.StatusCode != http.StatusOK {
    +			as.T().Logf("mTLS registry not ready yet: HTTP %d", resp.StatusCode)
    +			return false, nil
    +		}
    +		return true, nil
    +	}), "mTLS registry should become ready at localhost:%d", hostPort)
    +
    +	unauthenticatedClient := &http.Client{Transport: &http.Transport{
    +		TLSClientConfig: &tls.Config{RootCAs: pool},
    +	}}
    +	defer unauthenticatedClient.CloseIdleConnections()
    +
    +	unauthResp, unauthErr := unauthenticatedClient.Get(fmt.Sprintf("https://localhost:%d/v2/", hostPort))
    +	if unauthResp != nil {
    +		unauthResp.Body.Close()
    +	}
    +	var remoteErr *net.OpError
    +	as.Require().ErrorAs(unauthErr, &remoteErr, "registry should reject a request without a client certificate")
    +	as.Require().Equal("remote error", remoteErr.Op, "registry should reject the TLS handshake")
    +
    +	as.pushChart(hostPort, action.WithTLSClientConfig(clientCertFile, clientKeyFile, caFile))
    +
    +	as.PutFile(as.ControllerNode(0), mtlsRegistryCAPath, string(caPEM))
    +	as.PutFile(as.ControllerNode(0), mtlsClientCertPath, string(clientCertPEM))
    +	as.PutFile(as.ControllerNode(0), mtlsClientKeyPath, string(clientKeyPEM))
    +
    +	as.T().Cleanup(func() {
    +		cleanupCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
    +		defer cancel()
    +
    +		ssh, err := as.SSH(cleanupCtx, as.ControllerNode(0))
    +		if err != nil {
    +			as.T().Logf("Failed to connect to controller to remove mTLS credentials: %v", err)
    +			return
    +		}
    +		defer ssh.Disconnect()
    +
    +		rm := "rm -f " + strings.Join([]string{mtlsRegistryCAPath, mtlsClientCertPath, mtlsClientKeyPath}, " ")
    +		if _, err := ssh.ExecWithOutput(cleanupCtx, rm); err != nil {
    +			as.T().Logf("Failed to remove mTLS credentials from controller: %v", err)
    +		}
    +	})
    +
    +	restConfig, err := as.GetKubeConfig(as.ControllerNode(0))
    +	as.Require().NoError(err)
    +	chartClient, err := client.New(restConfig, client.Options{Scheme: k0sscheme.Scheme})
    +	as.Require().NoError(err)
    +
    +	releaseName := "mtls-oci-addon"
    +	chartName := "k0s-addon-chart-" + releaseName
    +	chart := &helmv1beta1.Chart{
    +		ObjectMeta: metav1.ObjectMeta{
    +			Name:      chartName,
    +			Namespace: metav1.NamespaceSystem,
    +			Finalizers: []string{
    +				"helm.k0sproject.io/uninstall-helm-release",
    +			},
    +		},
    +		Spec: helmv1beta1.ChartSpec{
    +			ChartName:   fmt.Sprintf("oci://%s/charts/echo-server", net.JoinHostPort(mtlsRegistryNodeName, strconv.Itoa(mtlsRegistryContainerPort))),
    +			ReleaseName: releaseName,
    +			Version:     "0.5.0",
    +			Namespace:   metav1.NamespaceDefault,
    +			Timeout:     "5m0s",
    +			Repository: &helmv1beta1.RepositorySpec{
    +				CAFile:   mtlsRegistryCAPath,
    +				CertFile: mtlsClientCertPath,
    +				KeyFile:  mtlsClientKeyPath,
    +			},
    +		},
    +	}
    +
    +	as.T().Logf("Creating mTLS Chart %s/%s", chart.Namespace, chart.Name)
    +	as.Require().NoError(chartClient.Create(ctx, chart))
    +
    +	deleteChart := func() {
    +		cleanupCtx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
    +		defer cancel()
    +
    +		if err := chartClient.Delete(cleanupCtx, chart); err != nil && !apierrors.IsNotFound(err) {
    +			as.T().Logf("Failed to delete mTLS Chart %s/%s: %v", chart.Namespace, chart.Name, err)
    +			return
    +		}
    +
    +		err := wait.PollUntilContextCancel(cleanupCtx, time.Second, true, func(ctx context.Context) (bool, error) {
    +			var found helmv1beta1.Chart
    +			err := chartClient.Get(ctx, client.ObjectKey{Namespace: chart.Namespace, Name: chart.Name}, &found)
    +			if apierrors.IsNotFound(err) {
    +				return true, nil
    +			}
    +			if err != nil {
    +				as.T().Logf("Failed to get mTLS Chart %s/%s: %v", chart.Namespace, chart.Name, err)
    +			}
    +			return false, nil
    +		})
    +		if err != nil {
    +			as.T().Logf("Timed out waiting for mTLS Chart %s/%s to be deleted: %v", chart.Namespace, chart.Name, err)
    +		}
    +	}
    +	as.T().Cleanup(deleteChart)
    +
    +	mtlsKC, err := as.AutopilotClient(as.ControllerNode(0))
    +	as.Require().NoError(err)
    +	var reconciledChart helmv1beta1.Chart
    +	as.Require().NoError(watch.Charts(mtlsKC.HelmV1beta1().Charts(metav1.NamespaceSystem)).
    +		WithObjectName(chartName).
    +		Until(ctx, func(item *helmv1beta1.Chart) (bool, error) {
    +			if item.Status.Error != "" {
    +				return false, fmt.Errorf("mTLS chart %s should install without errors: %s", chartName, item.Status.Error)
    +			}
    +			if item.Status.ReleaseName == "" || item.Generation != 1 || item.Status.Revision != 1 {
    +				as.T().Logf("mTLS Chart not ready yet (version %q): releaseName=%q generation=%d revision=%d",
    +					item.ResourceVersion, item.Status.ReleaseName, item.Generation, item.Status.Revision)
    +				return false, nil
    +			}
    +			reconciledChart = *item
    +			return true, nil
    +		}))
    +	as.Require().Equal(metav1.NamespaceDefault, reconciledChart.Status.Namespace)
    +	as.Require().Equal("0.6.0", reconciledChart.Status.AppVersion, "mTLS Chart should reconcile to app version 0.6.0")
    +
    +	as.T().Logf("Cleaning up mTLS test - deleting Chart")
    +	as.Require().NoError(chartClient.Delete(ctx, chart))
    +	as.Require().NoError(wait.PollUntilContextCancel(ctx, time.Second, true, func(ctx context.Context) (bool, error) {
    +		var found helmv1beta1.Chart
    +		err := chartClient.Get(ctx, client.ObjectKey{Namespace: chart.Namespace, Name: chart.Name}, &found)
    +		if apierrors.IsNotFound(err) {
    +			as.T().Log("Chart has been deleted")
    +			return true, nil
    +		}
    +		if err != nil {
    +			as.T().Logf("Failed to get mTLS Chart %s/%s: %v", chart.Namespace, chart.Name, err)
    +			return false, err

    Returning the error here aborts the poll on transient errors. You already have the log line above, so what about just returning nil here and retry?

    twz123 twz123 commented on Nov 11, 2026 12:37 UTC
    Reviewer

    You need to rebase, once again, to pick up the CI fix for the lint job 🙏

    DeeBi9 DeeBi9 commented on code on Nov 12, 2026 14:46 UTC
    Code Review
    inttest/addons/addons_test.go:1
    @@ -344,6 +388,207 @@ func (as *AddonsSuite) testSecretBasedAuth(kc *k8s.Clientset) {
     	}))
     }
     
    +func (as *AddonsSuite) testMTLSAuth() {
    +	ctx := as.TContext()
    +
    +	if out, err := exec.Command("docker", "rm", "-f", mtlsRegistryNodeName).CombinedOutput(); err != nil {
    +		as.Require().Containsf(string(out), "No such container", "Failed to remove stale mTLS registry container: %v", err)
    +	}
    +
    +	certsDir := filepath.Join(as.T().TempDir(), "mtls-registry")
    +	as.Require().NoError(os.MkdirAll(certsDir, 0755))
    +
    +	caPEM, clientCertPEM, clientKeyPEM := issueMTLSRegistryCerts(as.T(), certsDir, mtlsRegistryNodeName)
    +
    +	caFile := filepath.Join(certsDir, "ca.crt")
    +	clientCertFile := filepath.Join(certsDir, "client.crt")
    +	clientKeyFile := filepath.Join(certsDir, "client.key")
    +	as.Require().NoError(os.WriteFile(caFile, caPEM, 0644))
    +	as.Require().NoError(os.WriteFile(clientCertFile, clientCertPEM, 0644))
    +	as.Require().NoError(os.WriteFile(clientKeyFile, clientKeyPEM, 0600))
    +
    +	out, err := exec.Command(
    +		"docker", "run", "-d", "--name", mtlsRegistryNodeName,
    +		"--network", as.Networks[0],
    +		"-p", fmt.Sprintf("0:%d", mtlsRegistryContainerPort),
    +		"-v", certsDir+":/tls",
    +		"-e", fmt.Sprintf("REGISTRY_HTTP_ADDR=0.0.0.0:%d", mtlsRegistryContainerPort),
    +		"-e", "REGISTRY_HTTP_TLS_CERTIFICATE=/tls/tls.crt",
    +		"-e", "REGISTRY_HTTP_TLS_KEY=/tls/tls.key",
    +		"-e", `REGISTRY_HTTP_TLS_CLIENTCAS=["/tls/client-ca.crt"]`,
    +		"docker.io/library/registry:3.1.2@sha256:ddf754342cfc8acc51a56d5d0ab6af06826461864460636d8bd5c546dab2a7b8",
    +	).CombinedOutput()
    +	as.T().Cleanup(func() {
    +		if out, err := exec.Command("docker", "rm", "-f", mtlsRegistryNodeName).CombinedOutput(); err != nil {
    +			as.T().Logf("Failed to remove mTLS registry container %s: %v: %s", mtlsRegistryNodeName, err, out)
    +		}
    +	})
    +	as.Require().NoErrorf(err, "mTLS registry should start: %s", out)
    +
    +	portOut, err := exec.Command("docker", "port", mtlsRegistryNodeName, strconv.Itoa(mtlsRegistryContainerPort)).CombinedOutput()
    +	as.Require().NoErrorf(err, "mTLS registry port should be determined: %s", portOut)
    +	fields := strings.Fields(string(portOut))
    +	as.Require().NotEmpty(fields, "mTLS registry should have a port mapping: %s", portOut)
    +	_, port, err := net.SplitHostPort(fields[0])
    +	as.Require().NoErrorf(err, "mTLS registry port mapping should be parseable: %s", portOut)
    +	hostPort, err := strconv.Atoi(port)
    +	as.Require().NoError(err)
    +
    +	clientCert, err := tls.X509KeyPair(clientCertPEM, clientKeyPEM)
    +	as.Require().NoError(err)
    +	pool := x509.NewCertPool()
    +	as.Require().True(pool.AppendCertsFromPEM(caPEM))
    +	httpClient := &http.Client{Transport: &http.Transport{
    +		TLSClientConfig: &tls.Config{RootCAs: pool, Certificates: []tls.Certificate{clientCert}},
    +	}}
    +	defer httpClient.CloseIdleConnections()
    +
    +	as.T().Log("Waiting for mTLS registry to come up")
    +	as.Require().NoErrorf(wait.PollUntilContextCancel(ctx, time.Second, true, func(context.Context) (bool, error) {
    +		resp, err := httpClient.Get(fmt.Sprintf("https://localhost:%d/v2/", hostPort))
    +		if err != nil {
    +			as.T().Logf("mTLS registry not ready yet: %v", err)
    +			return false, nil
    +		}
    +		defer resp.Body.Close()
    +		if resp.StatusCode != http.StatusOK {
    +			as.T().Logf("mTLS registry not ready yet: HTTP %d", resp.StatusCode)
    +			return false, nil
    +		}
    +		return true, nil
    +	}), "mTLS registry should become ready at localhost:%d", hostPort)
    +
    +	unauthenticatedClient := &http.Client{Transport: &http.Transport{
    +		TLSClientConfig: &tls.Config{RootCAs: pool},
    +	}}
    +	defer unauthenticatedClient.CloseIdleConnections()
    +
    +	unauthResp, unauthErr := unauthenticatedClient.Get(fmt.Sprintf("https://localhost:%d/v2/", hostPort))
    +	if unauthResp != nil {
    +		unauthResp.Body.Close()
    +	}
    +	var remoteErr *net.OpError
    +	as.Require().ErrorAs(unauthErr, &remoteErr, "registry should reject a request without a client certificate")
    +	as.Require().Equal("remote error", remoteErr.Op, "registry should reject the TLS handshake")
    +
    +	as.pushChart(hostPort, action.WithTLSClientConfig(clientCertFile, clientKeyFile, caFile))
    +
    +	as.PutFile(as.ControllerNode(0), mtlsRegistryCAPath, string(caPEM))
    +	as.PutFile(as.ControllerNode(0), mtlsClientCertPath, string(clientCertPEM))
    +	as.PutFile(as.ControllerNode(0), mtlsClientKeyPath, string(clientKeyPEM))
    +
    +	as.T().Cleanup(func() {
    +		cleanupCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
    +		defer cancel()
    +
    +		ssh, err := as.SSH(cleanupCtx, as.ControllerNode(0))
    +		if err != nil {
    +			as.T().Logf("Failed to connect to controller to remove mTLS credentials: %v", err)
    +			return
    +		}
    +		defer ssh.Disconnect()
    +
    +		rm := "rm -f " + strings.Join([]string{mtlsRegistryCAPath, mtlsClientCertPath, mtlsClientKeyPath}, " ")
    +		if _, err := ssh.ExecWithOutput(cleanupCtx, rm); err != nil {
    +			as.T().Logf("Failed to remove mTLS credentials from controller: %v", err)
    +		}
    +	})
    +
    +	restConfig, err := as.GetKubeConfig(as.ControllerNode(0))
    +	as.Require().NoError(err)
    +	chartClient, err := client.New(restConfig, client.Options{Scheme: k0sscheme.Scheme})
    +	as.Require().NoError(err)
    +
    +	releaseName := "mtls-oci-addon"
    +	chartName := "k0s-addon-chart-" + releaseName
    +	chart := &helmv1beta1.Chart{
    +		ObjectMeta: metav1.ObjectMeta{
    +			Name:      chartName,
    +			Namespace: metav1.NamespaceSystem,
    +			Finalizers: []string{
    +				"helm.k0sproject.io/uninstall-helm-release",
    +			},
    +		},
    +		Spec: helmv1beta1.ChartSpec{
    +			ChartName:   fmt.Sprintf("oci://%s/charts/echo-server", net.JoinHostPort(mtlsRegistryNodeName, strconv.Itoa(mtlsRegistryContainerPort))),
    +			ReleaseName: releaseName,
    +			Version:     "0.5.0",
    +			Namespace:   metav1.NamespaceDefault,
    +			Timeout:     "5m0s",
    +			Repository: &helmv1beta1.RepositorySpec{
    +				CAFile:   mtlsRegistryCAPath,
    +				CertFile: mtlsClientCertPath,
    +				KeyFile:  mtlsClientKeyPath,
    +			},
    +		},
    +	}
    +
    +	as.T().Logf("Creating mTLS Chart %s/%s", chart.Namespace, chart.Name)
    +	as.Require().NoError(chartClient.Create(ctx, chart))
    +
    +	deleteChart := func() {
    +		cleanupCtx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
    +		defer cancel()
    +
    +		if err := chartClient.Delete(cleanupCtx, chart); err != nil && !apierrors.IsNotFound(err) {
    +			as.T().Logf("Failed to delete mTLS Chart %s/%s: %v", chart.Namespace, chart.Name, err)
    +			return
    +		}
    +
    +		err := wait.PollUntilContextCancel(cleanupCtx, time.Second, true, func(ctx context.Context) (bool, error) {
    +			var found helmv1beta1.Chart
    +			err := chartClient.Get(ctx, client.ObjectKey{Namespace: chart.Namespace, Name: chart.Name}, &found)
    +			if apierrors.IsNotFound(err) {
    +				return true, nil
    +			}
    +			if err != nil {
    +				as.T().Logf("Failed to get mTLS Chart %s/%s: %v", chart.Namespace, chart.Name, err)
    +			}
    +			return false, nil
    +		})
    +		if err != nil {
    +			as.T().Logf("Timed out waiting for mTLS Chart %s/%s to be deleted: %v", chart.Namespace, chart.Name, err)
    +		}
    +	}
    +	as.T().Cleanup(deleteChart)
    +
    +	mtlsKC, err := as.AutopilotClient(as.ControllerNode(0))
    +	as.Require().NoError(err)
    +	var reconciledChart helmv1beta1.Chart
    +	as.Require().NoError(watch.Charts(mtlsKC.HelmV1beta1().Charts(metav1.NamespaceSystem)).
    +		WithObjectName(chartName).
    +		Until(ctx, func(item *helmv1beta1.Chart) (bool, error) {
    +			if item.Status.Error != "" {
    +				return false, fmt.Errorf("mTLS chart %s should install without errors: %s", chartName, item.Status.Error)
    +			}
    +			if item.Status.ReleaseName == "" || item.Generation != 1 || item.Status.Revision != 1 {
    +				as.T().Logf("mTLS Chart not ready yet (version %q): releaseName=%q generation=%d revision=%d",
    +					item.ResourceVersion, item.Status.ReleaseName, item.Generation, item.Status.Revision)
    +				return false, nil
    +			}
    +			reconciledChart = *item
    +			return true, nil
    +		}))
    +	as.Require().Equal(metav1.NamespaceDefault, reconciledChart.Status.Namespace)
    +	as.Require().Equal("0.6.0", reconciledChart.Status.AppVersion, "mTLS Chart should reconcile to app version 0.6.0")
    +
    +	as.T().Logf("Cleaning up mTLS test - deleting Chart")
    +	as.Require().NoError(chartClient.Delete(ctx, chart))
    +	as.Require().NoError(wait.PollUntilContextCancel(ctx, time.Second, true, func(ctx context.Context) (bool, error) {
    +		var found helmv1beta1.Chart
    +		err := chartClient.Get(ctx, client.ObjectKey{Namespace: chart.Namespace, Name: chart.Name}, &found)
    +		if apierrors.IsNotFound(err) {
    +			as.T().Log("Chart has been deleted")
    +			return true, nil
    +		}
    +		if err != nil {
    +			as.T().Logf("Failed to get mTLS Chart %s/%s: %v", chart.Namespace, chart.Name, err)
    +			return false, err

    Fixed, thanks

    twz123 twz123 approved these changes on Nov 13, 2026 22:08 UTC
    Approved Reviewer

    Thank you!

    Reviewers
    Assignees
    DeeBi9 DeeBi9
    Labels
    risk: low confidence: 91.7% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 59.9% (MEDIUM) · Higher = larger blast radius
    59.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 91.7% · Lower = rushed or shallow review
    91.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 5.0% · Safe to merge
    5.0%
    Repository