Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions e2e-next/clusters/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ var (
)
)

var (
//go:embed vcluster-rootless.yaml
RootlessVClusterYAMLTemplate string
RootlessVClusterName = "rootless-test-vcluster"
RootlessVClusterYAML, RootlessVClusterYAMLCleanup = template.MustRender(
RootlessVClusterYAMLTemplate,
DefaultVClusterVars,
)
RootlessVCluster = vcluster.Define(
vcluster.WithName(RootlessVClusterName),
vcluster.WithVClusterYAML(RootlessVClusterYAML),
vcluster.WithOptions(
DefaultVClusterOptions...,
),
vcluster.WithDependencies(HostCluster),
)
)

var (
//go:embed vcluster-servicesync.yaml
ServiceSyncVClusterYAMLTemplate string
Expand Down
19 changes: 19 additions & 0 deletions e2e-next/clusters/vcluster-rootless.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
controlPlane:
statefulSet:
image:
registry: ""
repository: {{ .Repository }}
tag: {{ .Tag }}
security:
podSecurityContext:
fsGroup: 12345
containerSecurityContext:
runAsUser: 12345
runAsNonRoot: true
backingStore:
etcd:
deploy:
statefulSet:
security:
podSecurityContext:
fsGroup: 12345
3 changes: 3 additions & 0 deletions e2e-next/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
_ "github.com/loft-sh/vcluster/e2e-next/test_core/sync"
_ "github.com/loft-sh/vcluster/e2e-next/test_core/sync/fromhost"
_ "github.com/loft-sh/vcluster/e2e-next/test_deploy"
_ "github.com/loft-sh/vcluster/e2e-next/test_security/rootless"
)

var (
Expand Down Expand Up @@ -89,6 +90,7 @@ var _ = SynchronizedBeforeSuite(
DeferCleanup(clusters.InitManifestsVClusterYAMLCleanup)
DeferCleanup(clusters.ServiceSyncVClusterYAMLCleanup)
DeferCleanup(clusters.FromHostConfigMapsVClusterYAMLCleanup)
DeferCleanup(clusters.RootlessVClusterYAMLCleanup)

ctx, err = setup.All(
clusters.HostCluster.Setup,
Expand All @@ -110,6 +112,7 @@ var _ = SynchronizedBeforeSuite(
clusters.InitManifestsVCluster.Setup,
clusters.ServiceSyncVCluster.Setup,
clusters.FromHostConfigMapsVCluster.Setup,
clusters.RootlessVCluster.Setup,
)(ctx)
Expect(err).NotTo(HaveOccurred())
})
Expand Down
64 changes: 64 additions & 0 deletions e2e-next/test_security/rootless/rootless.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package rootless

import (
"context"
"strings"

"github.com/loft-sh/e2e-framework/pkg/setup/cluster"
"github.com/loft-sh/vcluster/e2e-next/clusters"
"github.com/loft-sh/vcluster/e2e-next/constants"
"github.com/loft-sh/vcluster/e2e-next/labels"
"github.com/loft-sh/vcluster/pkg/util/podhelper"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)

var _ = Describe("Rootless mode",
labels.Security,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add PR label so rootless spec runs in default CI

This spec is tagged only with labels.Security, so it is skipped by the default PR e2e-next run: e2e-ginkgo.yaml defaults the label filter to pr and run-ginkgo-e2e/action.yml applies --label-filter=${LABEL_FILTER} || pr, which runs only pr-labeled tests unless a custom filter is provided. Because this commit also removes the legacy rootless-specific import from test/e2e_rootless/e2e_rootless_mode_suite_test.go, the UID 12345 assertion is no longer part of the standard CI path and rootless regressions can slip through unnoticed.

Useful? React with 👍 / 👎.

cluster.Use(clusters.RootlessVCluster),
cluster.Use(clusters.HostCluster),
func() {
var (
hostClient kubernetes.Interface
hostRestConfig *rest.Config
vClusterNamespace = "vcluster-" + clusters.RootlessVClusterName
)

BeforeEach(func(ctx context.Context) {
hostClient = cluster.KubeClientFrom(ctx, constants.GetHostClusterName())
Expect(hostClient).NotTo(BeNil())
hostRestConfig = cluster.From(ctx, constants.GetHostClusterName()).KubernetesRestConfig()
Expect(hostRestConfig).NotTo(BeNil())
})

It("verifies the syncer container runs as non-root user", func(ctx context.Context) {
By("Listing vcluster pods in the rootless vcluster namespace", func() {
pods, err := hostClient.CoreV1().Pods(vClusterNamespace).List(ctx, metav1.ListOptions{
LabelSelector: "app=vcluster",
})
Expect(err).NotTo(HaveOccurred())
Expect(pods.Items).NotTo(BeEmpty(), "expected at least one vcluster pod")

By("Executing id -u in the syncer container", func() {
vclusterPod := pods.Items[0].Name
cmd := []string{"/bin/sh", "-c", "id -u"}
stdout, stderr, err := podhelper.ExecBuffered(
ctx,
hostRestConfig,
vClusterNamespace,
vclusterPod,
"syncer",
cmd,
nil,
)
Expect(err).NotTo(HaveOccurred())
Expect(stderr).To(BeEmpty(), "expected no stderr output")
Expect(strings.TrimSpace(string(stdout))).To(Equal("12345"), "expected syncer to run as UID 12345")
})
})
})
},
)
1 change: 0 additions & 1 deletion test/e2e_rootless/e2e_rootless_mode_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
_ "github.com/loft-sh/vcluster/test/e2e/syncer/pvc"
_ "github.com/loft-sh/vcluster/test/e2e/syncer/services"
_ "github.com/loft-sh/vcluster/test/e2e/webhook"
_ "github.com/loft-sh/vcluster/test/e2e_rootless/rootless"
)

// TestRunE2ERootLessModeTests checks configuration parameters (specified through flags) and then runs
Expand Down
38 changes: 0 additions & 38 deletions test/e2e_rootless/rootless/rootlessmode.go

This file was deleted.

Loading