Skip to content

Minor policy refactoring for CIDR+L4 work#3883

Merged
ianvernon merged 6 commits intocilium:masterfrom
joestringer:submit/cidr-refactor-policy
Apr 26, 2018
Merged

Minor policy refactoring for CIDR+L4 work#3883
ianvernon merged 6 commits intocilium:masterfrom
joestringer:submit/cidr-refactor-policy

Conversation

@joestringer
Copy link
Copy Markdown
Member

@joestringer joestringer commented Apr 25, 2018

[Split out from #3835 for easier review]

This PR includes the policy-only pieces of refactoring that are useful for #3835 . No functional changes should be observed.


This change is Reviewable

@joestringer joestringer added pending-review sig/policy Impacts whether traffic is allowed or denied based on user-defined policies. labels Apr 25, 2018
@joestringer joestringer requested a review from a team as a code owner April 25, 2018 06:30
@joestringer joestringer requested review from a team April 25, 2018 06:30
Comment thread pkg/policy/l4.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

comment on exported function CreateL4EgressFilter should be of the form "CreateL4EgressFilter ..."

Comment thread pkg/policy/l4.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

comment on exported function CreateL4EgressFilter should be of the form "CreateL4EgressFilter ..."

@joestringer joestringer force-pushed the submit/cidr-refactor-policy branch from 3671882 to 3f8e395 Compare April 25, 2018 06:31
@joestringer
Copy link
Copy Markdown
Member Author

test-me-please

Comment thread pkg/policy/api/cidr.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It might be worth noting that we expect perfect input in the function doc. We will, inevitably, call this with unsanitized addresses some day.

Comment thread pkg/policy/api/cidr.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we also want to call ip.CoalesceCIDRs ?
Was the rational to add this function and types here because we need the auto-generated serialisation functions? It seems like a useful extension to the other package.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The rationale here is that #3835 will add some additional helper functions for CIDR / labels conversion, which will need this function. I didn't attempt to change any logic.

#1658 tracks making use of ip.CoalesceCIDRs.

Comment thread pkg/policy/l4.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any chance you can make ingress bool a TrafficDirection type with two possible values? Calls to this function will then not have a mysterious boolean parament but we could also drop the ingress/egress wrappers.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point, I'll fix this up.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

hrm, we have a TrafficDirection type, but it's specific to the BPF datapath at the moment. Are you suggesting introducing another such type for this layer? /cc @ianvernon

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:/ I would prefer to reuse types if possible, but it's unlikely to be safe in this case. Perhaps it's out of scope since this is basically a bike-shed type thing on where such a thing should live and what it should be called.
Ultimately, my hope was to have a little less code. As it stands, it's readable since the Ingress/Egress is in the wrappers.

Copy link
Copy Markdown
Member Author

@joestringer joestringer Apr 25, 2018

Choose a reason for hiding this comment

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

I took a stab at it, it removed about 20LoC and seems about as clear. Please take a look.

EDIT: Turns out I forgot to include the new file I added. It adds an extra 20 LoC, but that's mostly copyright header.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

very keen! I might prefer the direction earlier in the parameter list but I'm not sure if a caller considers it the most important/global property of the filter (I do but I also asked you to expose the parameter directly so I am biased).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Putting TrafficDirection in the BPF datapath layer was a mistake on my part. IMO we can have it as its own little package? It'd make it much more portable and reusable.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This seems like a reasonable suggestion, but it's getting further and further from what I'm trying to achieve so I intend to just drop this for now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sure, that's fine.

@joestringer joestringer force-pushed the submit/cidr-refactor-policy branch from 3f8e395 to 97d5688 Compare April 25, 2018 17:21
@joestringer joestringer requested review from a team as code owners April 25, 2018 17:21
@joestringer joestringer force-pushed the submit/cidr-refactor-policy branch 2 times, most recently from 1922b02 to 5b1f2e0 Compare April 25, 2018 17:38
@joestringer
Copy link
Copy Markdown
Member Author

test-me-please

Comment thread pkg/policy/trafficdirection.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this deliberately distinct from policymap.TrafficDirection? Wouldn't it make more sense to put the type into its own package so it's more portable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I thought about that, but then you're basically saying that the details of one datapath implementation should define the behaviour all the way up the userspace layers. Worst case, we do this and someone ends up thinking they can just extend the field later on or change its meaning and it breaks the datapath.

I'll drop that patch, it doesn't make a big difference and I'd rather focus on other things. Thanks for looking it over.

@joestringer joestringer force-pushed the submit/cidr-refactor-policy branch from 5b1f2e0 to cd82457 Compare April 25, 2018 18:20
@joestringer
Copy link
Copy Markdown
Member Author

test-me-please

Copy link
Copy Markdown
Member

@jrajahalme jrajahalme left a comment

Choose a reason for hiding this comment

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

I may have spotted one functional change, please check it out.

Comment thread pkg/policy/l4.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like a functional change to me. Previously the incoming parameter was passed on. Now the possibly modified form is passed on.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I believe that this is the right behaviour. We should ensure that we are setting up the endpointselectors in the L4Filter, rather than relying on layers further down to treat the empty list of peerEndpoints as a wildcard selector.

/cc @ianvernon

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Filter endpoints is only modified if the filter selects all endpoints. If it does, then this is just an optimization, which I don't see a problem with at face value.

@joestringer
Copy link
Copy Markdown
Member Author

Saw what I believe to be a CI flake, filed #3901 to follow up. Will re-run tests.

Combine the ingress/egress cases into one core function to reduce code
duplication.

Signed-off-by: Joe Stringer <joe@covalent.io>
If the peerEndpoints selector selected all endpoints, the local
filterEndpoints variable would be set to the wildcard selector, but we
used to still use the peerEndpoints selector for creating the
L7RulesPerEp map. Be more consistent by using the version on the stack.

Signed-off-by: Joe Stringer <joe@covalent.io>
Describe in more detail what `L4Policy` and `L3L4Policy` are.

Signed-off-by: Joe Stringer <joe@covalent.io>
An upcoming commit will need to make use of this functionality from the
policy/api package, so shift it there.

Signed-off-by: Joe Stringer <joe@covalent.io>
These typed slices will allow for upcoming converters to translate these
rule objects into EndpointSelectors.

Signed-off-by: Joe Stringer <joe@covalent.io>
Signed-off-by: Joe Stringer <joe@covalent.io>
@joestringer joestringer force-pushed the submit/cidr-refactor-policy branch from cd82457 to 6359ad2 Compare April 25, 2018 22:45
@joestringer
Copy link
Copy Markdown
Member Author

test-me-please

@joestringer joestringer dismissed jrajahalme’s stale review April 26, 2018 16:38

Re-reviewed the relevant patch, I don't have any concern with it.

@joestringer joestringer requested review from a team April 26, 2018 16:39
@joestringer joestringer added ready-to-merge This PR has passed all tests and received consensus from code owners to merge. and removed pending-review labels Apr 26, 2018
@ianvernon ianvernon merged commit 4af204c into cilium:master Apr 26, 2018
@joestringer joestringer deleted the submit/cidr-refactor-policy branch April 26, 2018 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge This PR has passed all tests and received consensus from code owners to merge. sig/policy Impacts whether traffic is allowed or denied based on user-defined policies.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants