GoogleCloudPlatform / gke-policy-library

Google Kubernetes Engine Policy Library
https://cloud.google.com/anthos-config-management/docs/concepts/policy-controller
Apache License 2.0
53 stars 49 forks source link

Add a "require sidecar proxy injection label on namespace" `Constraint` in the ASM bundle? #29

Closed mathieu-benoit closed 1 year ago

mathieu-benoit commented 2 years ago

Is it planned to add a "require sidecar injection label on namespace" Constraint in the ASM bundle?

Today there is the 1.1.2_asm-sidecar-injection Constraint allowing to avoid anyone by passing the sidecar proxy label, but there is no Constraint forcing the namespaces in the Mesh to actually have the label.

Here could be an option to achieve that in the ASM bundle?

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sRequiredLabels
metadata:
  name: namespace-sidecar-injection-label
spec:
  enforcementAction: deny
  match:
    kinds:
    - apiGroups:
      - ""
      kinds:
      - Namespace
    excludedNamespaces:
    - config-management-monitoring
    - config-management-system
    - default
    - gatekeeper-system
    - gke-connect
    - istio-system
    - kube-node-lease
    - kube-public
    - kube-system
    - resource-group-system
  parameters:
    labels:
    - allowedRegex: enabled
      key: istio-injection
    - allowedRegex: (asm-managed|asm-managed-rapid|asm-managed-stable)
      key: "istio.io/rev"

Note: this is not working as-is as we need to find a way to have a OR and not a AND with the 2 labels illustrated above.

apeabody commented 2 years ago

Hi @liwenhao0810 - Could you please take a look at this request?

liwenhao0810 commented 1 year ago

FWIK it might not always be true that all user namespaces are part of mesh, so the namespace level injection enforcement might not be always true. However bypassing sidecar injection would be as non-mesh namespaces' workloads shouldn't have this annotation either.

mathieu-benoit commented 1 year ago

Here are my thoughts on this, here is the CUJ I think we should help our customers with:

As a customer, I'm using the ASM bundle to have Google telling me what I should do to have a proper, successful and secure setup for my Mesh in my GKE cluster.

First thing first, if I don't have properly set up my Namespaces to be included in my Mesh, could you tell me please? And also how I should accomplish this? --> That's what the associated Constraint/ConstraintTemplate of this request is for.

That's what we illustrate in this tutorial at the very first step of setting the Constraints.

Now comes the tricky parts with some thoughts about their resolution:

Do you see other use-cases?

That's maybe the opportunity to have a custom K8sRequiredLabels just for ASM which could have all the intelligence in its ConstraintTemplate?

Let me know if that makes sense and what do you think about that. And let me know if you want we chat about that in 1:1 internally, more than happy to learn from you on this too.

mathieu-benoit commented 1 year ago

Following up on this @liwenhao0810, any thoughts or feedback? Thanks!

liwenhao0810 commented 1 year ago

Sorry lost tracking of this, thanks for reminding! I would agree with you this is a good idea to have this constraint to guide user.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days