linkerd2 icon indicating copy to clipboard operation
linkerd2 copied to clipboard

Support service network policies

Open campbel opened this issue 7 years ago • 14 comments

Feature Request

What problem are you trying to solve?

One of the promised visions of Kubernetes is a single control plane to manage all of your workloads. Many applications rely on network isolation in their security model, so to realize this there needs to be a way to securely isolate workloads. Currently Kubernetes supports logical separation (namespaces), but it doesn't support secure isolation out of the box. If you want secure isolation you need a CNI that supports NetworkPolicies (or a similar custom resource) such as Calico or Cilium. A service mesh is also a natural place to enforce the secure isolation as all network traffic passes through the system. Istio supports traffic policies.

With v2.3 Linkerd introduced mTLS on by default. This should make it possible for the proxy to securely identify the source of incomming traffic if the source is meshed. This could allow the proxy to make decisions about whether to pass the request on to the application.

Beyond intra-mesh communication policies, egress rules could also be useful allowing administrators to deploy kubernetes in shared networks, but only granting access to resources explicitly (not sure if this is possible with Linkerd today as all egress traffic would have to be forced through the proxy).

How should the problem be solved?

All traffic goes through the sidecar proxy (ingress & egress) so it is a natural location to enforce policies. This is a proven design in Istio and Cilium. A CRD can be used to configure the policies that can then be loaded into the sidecar, jut like route rules today.

Any alternatives you've considered?

Yes there are a couple options:

  1. Use Istio. This isn't ideal. Linkerd is appealing because of its focus on simplicity and high value features. Istio is featureful but complex and many teams don't have the operational bandwidth to support it.

  2. Use Cilium/Calico. This is an option, however, neither have a Linkerd integration story in their documentation so it could be that the two services don't play nicely together. In the case of Cilium this means redundant features such as running two sidecars (linkerd-proxy and envoy-proxy) and duplicate encryption (mTLS and Transparent Encryption)

How would users interact with this feature?

The ServiceProfile is an ideal location for configuring the policies.

  • Space in the spec for additional configuration.
  • Policies are service specific which fits intuitively with the name ServiceProfile.
  • Reduced complexity for end user.

Here are some possible configurations (AWS Security Groups for inspiration):

apiVersion: linkerd.io/v1alpha1
kind: ServiceProfile
metadata:
  name: foo.default.svc.cluster.local
spec:
  routes:
  ...
  policy:
    egress:
    - protocol: http
      service: bar.default.svc.cluster.local        # Support linkerd meshed services first class
    ingress:
    - protocol: http
      service: bar.default.svc.cluster.local
    - protocol: http
      service: gateway.ingress.svc.cluster.local
---
apiVersion: linkerd.io/v1alpha1
kind: ServiceProfile
metadata:
  name: bar.default.svc.cluster.local
spec:
  routes:
  ...
  policy:
    egress:
    - protocol: https                               # Support non-meshed services on egress
      host: twitter.com
    - protocol: tcp
      port: 6379
      host: redis.default.svc.cluster.local         # Support TCP services 
    ingress:
    - protocol: http
      service: *.default.svc.cluster.local          # Suport wildcard (maybe regexp?)

campbel avatar Apr 24 '19 21:04 campbel

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 15 '19 22:09 stale[bot]

This is tied up in the authz work now that identity is a first class citizen.

grampelberg avatar Sep 30 '19 19:09 grampelberg

We would also like to see something like this as we run several environments and databases in a single cluster and assuring isolation would be great. We can currently use the VPC native configuration on GKE but wanted the ability to block or route specific traffic and monitor traffic that violates those policies. We would very much like this inside of the service mesh instead of a CNI like calico.

thornbrambles avatar Oct 28 '19 22:10 thornbrambles

We would as well very much like such a feature - i.e. support identity based network policies, maybe even across clusters ? As linkerd has the identities for mTLS it seems to be a natural place. Could someone from the linkerd team comment on the general concept and whether it will ever make it into linkerd ? Indeed the alternative would be to go for some calico/istio combination or use some non-open-source tools like aporeto (which we would like to avoid).

chrisbulgaria avatar Jan 02 '20 08:01 chrisbulgaria

We'll be working to support SMI.

FWIW, most folks use case are taken care of by simply using NetworkPolicy

grampelberg avatar Jan 02 '20 15:01 grampelberg

We also use a mixture of Network Policies and Linkerd. I'd really love to drop NetPol because as much as they solve this issue, in reality they're difficult to implement without downtime on rollout.

SMI here would be a massive win 👍

andrew-waters avatar Jan 17 '20 11:01 andrew-waters

@andrew-waters Can you expand on how the NetworkPolicy rollout leads to downtime. I haven't rolled any out personally yet so I'm unaware of how their deployment implementation works.

GarrettGeorge avatar Mar 30 '20 21:03 GarrettGeorge

@GarrettGeorge - sure, whilst it is rare (because our PCI environments aren't as actively developed as others), we occasionally see a lag between pods coming up and the policies being applied to those before the old ones are destroyed giving a short window where the default deny policies kick in.

andrew-waters avatar Apr 02 '20 08:04 andrew-waters

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 02 '20 07:07 stale[bot]

Should this be reopened and pinned?

rbtcollins avatar Aug 10 '20 11:08 rbtcollins

@rbtcollins this looks like a good candidate for an rfc. Are you interested in kicking that off?

cpretzer avatar Aug 10 '20 17:08 cpretzer

Maybe the direction should be implementing traffic-access from SMI? https://github.com/servicemeshinterface/smi-spec/blob/master/apis/traffic-access/v1alpha2/traffic-access.md

campbel avatar Aug 10 '20 19:08 campbel

I would also be interested in such a feature

markthebault avatar Mar 05 '21 10:03 markthebault

This will be a feature in the next stable—2.11. We're still working on the more general proposal, but issues will start opening up to break out this work. I'm going to keep this closed for now since a policy meta-issue will probably come out from this planning.

kleimkuhler avatar Apr 08 '21 13:04 kleimkuhler