Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

weave-npc does not support kubernetes 1.7 NetworkPolicy semantics #3105

Closed
deitch opened this issue Aug 29, 2017 · 9 comments
Closed

weave-npc does not support kubernetes 1.7 NetworkPolicy semantics #3105

deitch opened this issue Aug 29, 2017 · 9 comments
Assignees
Milestone

Comments

@deitch
Copy link
Contributor

deitch commented Aug 29, 2017

Opening per request for @bboreham in #3083

In Kubernetes pre-1.7, the network policy semantics were as follows:

  • In a namespace, by default, allow all connections into all pods, whether or not a policy is defined
  • If a namespace has the DefaultDeny annotation, block all traffic to all pods, except for those that have a NetworkPolicy allowing access to the specific pods (by label, etc.)

In Kubernetes 1.7+, the semantics are as follows:

  • In a namespace, by default, allow all connections into all pods, if no policy is defined
  • If a pod has a NetworkPolicy attached to it, then deny all connections into that pod, except for those explicitly allowed by the policy
  • If a namespace has the DefaultDeny annotation, block all traffic to all pods, except for those that have a NetworkPolicy allowing access to the specific pods (by label, etc.) (unchanged)

The changes are in the middle one: If no annotation is set but a network policy applies to a pod, then block all connections to that pod except for those explicitly allowed by the policy.

As pointed out by @bboreham, weave-npc currently implements the pre-1.7 semantics, rather than the 1.7+. weave-npc should implement the 1.7+ semantics (or possibly check the kubernetes version and implement the appropriate semantics).

@bboreham
Copy link
Contributor

bboreham commented Aug 29, 2017

Since it's disappeared from the Kubernetes documentation, I'll note here that the workaround is to say:

kubectl annotate ns <my-namespace> "net.beta.kubernetes.io/network-policy={\"ingress\": {\"isolation\": \"DefaultDeny\"}}"

@stevesloka
Copy link

stevesloka commented Aug 29, 2017

The extra single quotes has an issue, this works for me:

kubectl annotate ns <my-namespace> "net.beta.kubernetes.io/network-policy={\"ingress\": {\"isolation\": \"DefaultDeny\"}}"

@bboreham
Copy link
Contributor

Sorry about that; I'll edit my comment.

@ceridwen
Copy link

I have weave running on minikube, which is running Kubernetes 1.7. I have a namespace with the DefaultDeny annotation, but connections are allowed to pods in that namespace whether there's a NetworkPolicy set or not. No combination of annotation or NetworkPolicy, expecting 1.6 or 1.7 semantics, seems to get weave to deny connections on my minikube setup. As in the original bug, the weave-npc logs indicate that weave sees the namespace. Is this the same bug, or should I file a separate issue?

@bboreham
Copy link
Contributor

@ceridwen please open a new issue and include the logs.

@bboreham
Copy link
Contributor

Some thoughts about implementation:
Currently we have an ipset for every pod in a namespace, and if the namespace is DefaultAllow then we add a rule accepting that ipset.
There are three cases:

  • DefaultDeny: just have rules for policies.
  • DefaultAllow 1.6 semantics: add rule accepting ipset containing every pod in namespace.
  • DefaultAllow 1.7 semantics: add rule accepting ipset containing every pod in namespace not touched by a policy.

We need to take care when policies are added and removed, since that will change the set.

@brb
Copy link
Contributor

brb commented Oct 26, 2017

FYI you can find PR at #3151.

bboreham added a commit that referenced this issue Nov 7, 2017
Implement Kubernetes 1.7 NetworkPolicy semantics
@SharpEdgeMarshall
Copy link

Just a clarification, actually are you saying that with weave 2.0.5 and k8s 1.7 or 1.8 if i need to isolate a pod i must isolate the entire namespace before?
So if i need to isolate the kubernetes-dashboard in the kube-system namespace from external pods i must DefaultDeny the entire namespace and then apply NetworkPolicy to enable each service in kube-system just to protect the dashboard?

@bboreham
Copy link
Contributor

@SharpEdgeMarshall yes, that was how network policies worked in Kubernetes when the current implementation was written.

@bboreham bboreham added this to the 2.1 milestone Nov 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants