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

Update NetworkPolicy code for v1 semantics #14498

Merged

Conversation

danwinship
Copy link
Contributor

With NetworkPolicy v1, there is no longer a "DefaultDeny" annotation, and instead, pods are isolated if and only if there is a NetworkPolicy selecting them. This updates for that.

First, when parsing NetworkPolicies, we note which pod IPs they select. Then when updating OVS, we output the "accept" flows for all the policies at priority=150, while also checking if any policy selects the entire Namespace. If there is not a policy that selects the entire Namespace, then that means there are potentially un-isolated pods that are default-accept rather than default-deny, so we also output a priority=100, actions=drop flow for each IP mentioned in any of the "accept" flows, and a priority=50 flow accepting all other traffic in the namespace. (If there is a policy that selects the entire Namespace, then any traffic not accepted by any NetworkPolicy is denied, so we don't need any other rules because the base priority=0, actions=drop rule will do the right thing.)

We may want to revisit this and optimize it further later. In particular, it's inefficient if you have a different NetworkPolicy for each pod in a Namespace (and no match-all policies, and no unmatched pods). We could fix that by having explicit "accept" rules for unmatched pods rather than explicit "deny" rules for matched pods. That would have required more rewriting though, and it only matters in the case where you don't have a "default deny" policy anyway.

(Note to self: needs release note)

@openshift/networking PTAL

@danwinship danwinship mentioned this pull request Jun 6, 2017
Copy link
Contributor

@knobunc knobunc left a comment

Choose a reason for hiding this comment

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

The change looks good to me. I'd just like to see a comment about why we are structuring the rules as we are put into the code (you already do a great job explaining it in the commit message)

@@ -206,14 +199,28 @@ func (np *networkPolicyPlugin) syncNamespace(npns *npNamespace) {
otx := np.node.oc.NewTransaction()
otx.DeleteFlows("table=80, reg1=%d", npns.vnid)
if inUse {
if npns.isolated {
defaultAllow := true
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get a comment on this block? Your commit message has great information about how this works, so just plop it in here too?

@danwinship danwinship force-pushed the networkpolicy-v1-semantics branch from ebf3774 to 38bd1e6 Compare June 9, 2017 14:14
@danwinship
Copy link
Contributor Author

pushed with comments

Copy link
Contributor

@knobunc knobunc left a comment

Choose a reason for hiding this comment

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

Looks great. Thanks Dan

@knobunc knobunc requested a review from dcbw June 9, 2017 19:42
@knobunc knobunc self-assigned this Jun 9, 2017
for _, ip := range npp.selectedIPs {
if !selectedIPs.Has(ip) {
selectedIPs.Insert(ip)
otx.AddFlow("table=80, priority=100, reg1=%d, ip, nw_dst=%s, actions=drop", ip)
Copy link
Contributor

Choose a reason for hiding this comment

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

The AddFlow()'s format string has one more format than the # of args given. Not sure what the intention here is, to keep the VNID or remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FWIW, this resulted in errors being logged while running the tests but didn't cause any of the tests to fail, which I guess means we need more test cases...

@danwinship danwinship force-pushed the networkpolicy-v1-semantics branch from 38bd1e6 to 9a7dbaa Compare June 9, 2017 21:08
@danwinship danwinship force-pushed the networkpolicy-v1-semantics branch from 9a7dbaa to 8be5204 Compare June 9, 2017 21:12
@danwinship
Copy link
Contributor Author

pretty awesome that we've failed tests 6 times on a PR that doesn't modify any code that is exercised by any test...

@openshift openshift deleted a comment from openshift-bot Jun 12, 2017
@openshift openshift deleted a comment from openshift-bot Jun 12, 2017
@openshift openshift deleted a comment from knobunc Jun 12, 2017
@openshift openshift deleted a comment from knobunc Jun 12, 2017
@danwinship
Copy link
Contributor Author

deleted all test comments. I had originally hoped we could get in a passing test run to pre-validate our eventual merge, but that's not going to happen...

@knobunc
Copy link
Contributor

knobunc commented Jun 12, 2017

[merge]

@knobunc
Copy link
Contributor

knobunc commented Jun 12, 2017

@danwinship Does this need a release note?

@danwinship
Copy link
Contributor Author

Yes, we need a general NetworkPolicy stuff release note. It's on my todo list.

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 8be5204

@openshift-bot
Copy link
Contributor

[Test]ing while waiting on the merge queue

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 8be5204

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test FAILURE (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_origin/2158/) (Base Commit: 5f29c22)

@openshift-bot
Copy link
Contributor

openshift-bot commented Jun 13, 2017

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_request_origin/977/) (Base Commit: c0c1b22) (Image: devenv-rhel7_6346)

@openshift-bot openshift-bot merged commit 1284263 into openshift:master Jun 13, 2017
@danwinship danwinship deleted the networkpolicy-v1-semantics branch June 17, 2017 16:03
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

Successfully merging this pull request may close these issues.

4 participants