Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make ACL for shoot ingresses optional #49

Merged
merged 1 commit into from
May 6, 2024
Merged
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
26 changes: 15 additions & 11 deletions pkg/controller/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,19 +380,23 @@ func (a *actuator) createSeedResources(
return err
}

defaultLabels, err := a.findDefaultIstioLabels(ctx)
if err != nil {
return err
cfg := map[string]interface{}{
"shootName": cluster.Shoot.Status.TechnicalID,
"targetNamespace": istioNamespace,
"apiEnvoyFilterSpec": apiEnvoyFilterSpec,
}

ingressEnvoyFilterSpec := envoyfilters.BuildIngressEnvoyFilterSpecForHelmChart(
cluster, spec.Rule, alwaysAllowedCIDRs, defaultLabels)

cfg := map[string]interface{}{
"shootName": cluster.Shoot.Status.TechnicalID,
"targetNamespace": istioNamespace,
"apiEnvoyFilterSpec": apiEnvoyFilterSpec,
"ingressEnvoyFilterSpec": ingressEnvoyFilterSpec,
defaultLabels, err := a.findDefaultIstioLabels(ctx)
if client.IgnoreNotFound(err) != nil {
return err
} else if err == nil {
// The `nginx-ingress-controller` Gateway object only exists in g/g@v1.89, (introduced with
// https://github.com/gardener/gardener/pull/9038).
// If it doesn't exist yet, we can't apply ACLs to shoot ingresses.
ingressEnvoyFilterSpec := envoyfilters.BuildIngressEnvoyFilterSpecForHelmChart(
cluster, spec.Rule, alwaysAllowedCIDRs, defaultLabels)

cfg["ingressEnvoyFilterSpec"] = ingressEnvoyFilterSpec
}

cfg, err = chart.InjectImages(cfg, imagevector.ImageVector(), []string{ImageName})
Expand Down
62 changes: 62 additions & 0 deletions pkg/controller/actuator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
"github.com/gardener/gardener/pkg/apis/resources/v1alpha1"
. "github.com/gardener/gardener/pkg/utils/test/matchers"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
istionetworkingClientGo "istio.io/client-go/pkg/apis/networking/v1alpha3"
Expand Down Expand Up @@ -121,6 +122,67 @@ var _ = Describe("actuator test", func() {
Expect(extState.IstioNamespace).ToNot(BeNil())
Expect(*extState.IstioNamespace).To(Equal(istioNamespace1))
})

// gardener >= v1.89, including https://github.com/gardener/gardener/pull/9038
Context("ingress-nginx is exposed via istio", func() {
BeforeEach(func() {
gateway := createNewGateway("nginx-ingress-controller", "garden", map[string]string{
"app": "istio-ingressgateway",
"istio": "ingressgateway",
})

DeferCleanup(func() {
Expect(k8sClient.Delete(ctx, gateway)).To(Or(Succeed(), BeNotFoundError()))
})
})

It("should create managed resource including acl-ingress-shoot EnvoyFilter object", func() {
extSpec := extensionspec.ExtensionSpec{
Rule: &envoyfilters.ACLRule{
Cidrs: []string{"1.2.3.4/24"},
Action: "ALLOW",
Type: "remote_ip",
},
}
extSpecJSON, err := json.Marshal(extSpec)
Expect(err).To(BeNil())
ext := createNewExtension(shootNamespace1, extSpecJSON)
Expect(ext).To(Not(BeNil()))

Expect(a.Reconcile(ctx, logger, ext)).To(Succeed())

mr := &v1alpha1.ManagedResource{}
Expect(k8sClient.Get(ctx, types.NamespacedName{Name: ResourceNameSeed, Namespace: shootNamespace1}, mr)).To(Succeed())
secret := &corev1.Secret{}
Expect(k8sClient.Get(ctx, types.NamespacedName{Name: mr.Spec.SecretRefs[0].Name, Namespace: shootNamespace1}, secret)).To(Succeed())
Expect(secret.Data["seed"]).To(ContainSubstring("acl-ingress-" + shootNamespace1))
})
})

// gardener < v1.89
Context("ingress-nginx is not exposed via istio", func() {
It("should create managed resource not including acl-ingress-shoot EnvoyFilter object", func() {
extSpec := extensionspec.ExtensionSpec{
Rule: &envoyfilters.ACLRule{
Cidrs: []string{"1.2.3.4/24"},
Action: "ALLOW",
Type: "remote_ip",
},
}
extSpecJSON, err := json.Marshal(extSpec)
Expect(err).To(BeNil())
ext := createNewExtension(shootNamespace1, extSpecJSON)
Expect(ext).To(Not(BeNil()))

Expect(a.Reconcile(ctx, logger, ext)).To(Succeed())

mr := &v1alpha1.ManagedResource{}
Expect(k8sClient.Get(ctx, types.NamespacedName{Name: ResourceNameSeed, Namespace: shootNamespace1}, mr)).To(Succeed())
secret := &corev1.Secret{}
Expect(k8sClient.Get(ctx, types.NamespacedName{Name: mr.Spec.SecretRefs[0].Name, Namespace: shootNamespace1}, secret)).To(Succeed())
Expect(secret.Data["seed"]).NotTo(ContainSubstring("acl-ingress-" + shootNamespace1))
})
})
})

Describe("reconciliation of an extension object with other ACL extensions being present", func() {
Expand Down
12 changes: 5 additions & 7 deletions pkg/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ var _ = BeforeSuite(func() {
Expect(err).ToNot(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())
createGardenNamespace()
istioNamespaceSelector := map[string]string{
"app": "istio-ingressgateway",
"istio": "ingressgateway",
}
createNewGateway("nginx-ingress-controller", "garden", istioNamespaceSelector)
})

var _ = AfterSuite(func() {
Expand Down Expand Up @@ -150,7 +145,7 @@ func createNewIstioDeployment(namespace string, labels map[string]string) {
Expect(k8sClient.Create(ctx, deployment)).ShouldNot(HaveOccurred())
}

func createNewGateway(name, shootNamespace string, labels map[string]string) {
func createNewGateway(name, shootNamespace string, labels map[string]string) *istionetworkingv1beta1.Gateway {
gw := &istionetworkingv1beta1.Gateway{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand All @@ -161,6 +156,7 @@ func createNewGateway(name, shootNamespace string, labels map[string]string) {
},
}
Expect(k8sClient.Create(ctx, gw)).ShouldNot(HaveOccurred())
return gw
}

func createNewExtension(shootNamespace string, providerConfig []byte) *extensionsv1alpha1.Extension {
Expand Down Expand Up @@ -235,7 +231,9 @@ func createNewCluster(shootNamespace string) {
Pods: nil,
},
},
Status: gardencorev1beta1.ShootStatus{ // needed to wait until k8s server is up and running
Status: gardencorev1beta1.ShootStatus{
TechnicalID: shootNamespace,
// needed to wait until k8s server is up and running
AdvertisedAddresses: []gardencorev1beta1.ShootAdvertisedAddress{{
Name: "test",
URL: "https://test",
Expand Down
Loading