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

PAN: Support for rule-type in security rules #6291

Merged
merged 11 commits into from Oct 11, 2020
Merged

PAN: Support for rule-type in security rules #6291

merged 11 commits into from Oct 11, 2020

Conversation

ratulm
Copy link
Member

@ratulm ratulm commented Oct 8, 2020

No description provided.

@ratulm ratulm requested a review from sfraint October 8, 2020 21:14
@batfish-bot
Copy link

This change is Reviewable

@codecov
Copy link

codecov bot commented Oct 8, 2020

Codecov Report

Merging #6291 into master will increase coverage by 0.02%.
The diff coverage is 84.44%.

@@             Coverage Diff              @@
##             master    #6291      +/-   ##
============================================
+ Coverage     72.94%   72.96%   +0.02%     
+ Complexity    35081    35044      -37     
============================================
  Files          2832     2828       -4     
  Lines        142491   142200     -291     
  Branches      17106    17085      -21     
============================================
- Hits         103933   103753     -180     
+ Misses        30339    30233     -106     
+ Partials       8219     8214       -5     
Impacted Files Coverage Δ Complexity Δ
...rammar/palo_alto/PaloAltoConfigurationBuilder.java 88.48% <80.00%> (-0.07%) 452.00 <4.00> (+4.00) ⬇️
...epresentation/palo_alto/PaloAltoConfiguration.java 87.50% <82.14%> (-0.25%) 360.00 <14.00> (+10.00) ⬇️
...batfish/representation/palo_alto/SecurityRule.java 90.90% <100.00%> (+1.71%) 18.00 <2.00> (+2.00)
.../InterfaceSpecifierInterfaceLocationSpecifier.java 60.00% <0.00%> (-10.00%) 3.00% <0.00%> (-1.00%)
...ifier/NodeSpecifierInterfaceLocationSpecifier.java 66.66% <0.00%> (-8.34%) 4.00% <0.00%> (-1.00%)
...ain/java/org/batfish/specifier/NodeSpecifiers.java 0.00% <0.00%> (-6.67%) 0.00% <0.00%> (-1.00%)
...eachability/BidirectionalReachabilityAnswerer.java 38.15% <0.00%> (-3.68%) 11.00% <0.00%> (-11.00%)
...rc/main/java/org/batfish/datamodel/flow/Trace.java 80.64% <0.00%> (-3.23%) 13.00% <0.00%> (-1.00%)
...org/batfish/datamodel/flow/BidirectionalTrace.java 81.81% <0.00%> (-2.28%) 14.00% <0.00%> (-1.00%)
...a/org/batfish/question/ReachabilityParameters.java 95.31% <0.00%> (-2.01%) 14.00% <0.00%> (-11.00%)
... and 13 more

Copy link
Member

@dhalperi dhalperi left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 6 files at r1, 3 of 3 files at r2.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @ratulm and @sfraint)


projects/batfish/src/main/java/org/batfish/representation/palo_alto/PaloAltoConfiguration.java, line 647 at r2 (raw file):

            .isEmpty();
    boolean toZoneInRuleTo =
        !Sets.intersection(rule.getTo(), ImmutableSet.of(toZoneName, CATCHALL_ZONE_NAME)).isEmpty();

I think what you have written is probably correct, but I think it is confusing.

  1. If either condition is false, return false.

switch (firstNonNull(ruletype, UNIVERSAL)
case UNIVERSAL:
  return true;
case INTRAZONE:
  return fromZoneName.equals(toZoneName);
case INTERZONE:
  return !fromZoneName.equals(toZoneName);
default:
  throw missing statmeent or whatever.

Yes, PAN UI enforces that INTRAZONE => the from and to sets are equal, but I think we should not rely on that here. What if the text is human-generated?

If we want to rely on that here, we need to document it and enforce it sensibly (elsewhere? drop the rule in this case?)


projects/batfish/src/test/java/org/batfish/representation/palo_alto/PaloAltoConfigurationTest.java, line 651 at r2 (raw file):

    rule.setRuleType(RuleType.INTRAZONE);
    assertTrue(securityRuleApplies("A", "A", rule));

This condition should not pass: A is not a valid toZone


projects/batfish/src/test/resources/org/batfish/grammar/palo_alto/testconfigs/rulebase-rule-type, line 6 at r2 (raw file):

Quoted 5 lines of code…
set rulebase security rules RULE2 from z1
set rulebase security rules RULE2 to z2
set rulebase security rules RULE2 source any
set rulebase security rules RULE2 destination any
set rulebase security rules RULE2 rule-type intrazone

this seems to violate the constraints?


projects/batfish/src/test/resources/org/batfish/grammar/palo_alto/testconfigs/rulebase-rule-type, line 24 at r2 (raw file):

set rulebase security rules RULE3 destination any
set rulebase security rules RULE3 rule-type universal

add a "default" case where the value is null?

Copy link
Member

@dhalperi dhalperi left a comment

Choose a reason for hiding this comment

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

Reviewed 5 of 5 files at r3.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ratulm and @sfraint)


projects/batfish/src/main/java/org/batfish/grammar/palo_alto/PaloAltoConfigurationBuilder.java, line 2844 at r3 (raw file):

Quoted 4 lines of code…
    _mainConfiguration
        .getVirtualSystems()
        .values()
        .forEach(this::removeInvalidIntrazoneSecurityRules);

@sfraint - better place to do this? Extractor#getConfiguration seems like an odd choice vs, say, during conversion. Do we do similar things elsewhere?

Copy link
Member Author

@ratulm ratulm left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @sfraint)


projects/batfish/src/main/java/org/batfish/grammar/palo_alto/PaloAltoConfigurationBuilder.java, line 2844 at r3 (raw file):

Previously, dhalperi (Dan Halperin) wrote…
    _mainConfiguration
        .getVirtualSystems()
        .values()
        .forEach(this::removeInvalidIntrazoneSecurityRules);

@sfraint - better place to do this? Extractor#getConfiguration seems like an odd choice vs, say, during conversion. Do we do similar things elsewhere?

happy to defer to @sfraint's take. the rationale for doing it here: the parser itself produces a "clean" configuration and is in line with how we treat some other instances of the box rejecting config lines.

@dhalperi
Copy link
Member

dhalperi commented Oct 9, 2020


projects/batfish/src/main/java/org/batfish/grammar/palo_alto/PaloAltoConfigurationBuilder.java, line 2844 at r3 (raw file):

we treat some other instances of the box rejecting config lines.
Not sure what you mean? AFAIU, we reject a line in the parser only if it would have been rejected by the device when typed right there. That's not this -- the device would let you type these lines in, at least if the rule-type was after the from.
Can you point me at an example of what you're thinking of?

The other concern I have is that there's nothing in the API contract that links getConfiguration to "parsing is done". No guarantees about when or how many times it's called.

Copy link
Member

@dhalperi dhalperi left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r4.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @sfraint)

Copy link
Member Author

@ratulm ratulm left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @sfraint)


projects/batfish/src/main/java/org/batfish/grammar/palo_alto/PaloAltoConfigurationBuilder.java, line 2844 at r3 (raw file):

Previously, dhalperi (Dan Halperin) wrote…

we treat some other instances of the box rejecting config lines.
Not sure what you mean? AFAIU, we reject a line in the parser only if it would have been rejected by the device when typed right there. That's not this -- the device would let you type these lines in, at least if the rule-type was after the from.
Can you point me at an example of what you're thinking of?

The other concern I have is that there's nothing in the API contract that links getConfiguration to "parsing is done". No guarantees about when or how many times it's called.

Some context on rejection via Spencer:

https://intentionet.slack.com/archives/C01C58KHB7F/p1602199116034100?thread_ts=1602198664.031900&cid=C01C58KHB7F

(We should test if the device behavior is based on whats current when it sees the rule-type command. So, entering from z1 and then rule-type intrazone will fail unless to z1 has been entered before. If that is the behavior, the cleanup discussion is moot.)

Your other concern is valid. Another place I considered was here:

I couldn't find other examples of such post-parsing clean ups but doing it during conversion "felt wrong."

@dhalperi
Copy link
Member

dhalperi commented Oct 9, 2020


projects/batfish/src/main/java/org/batfish/grammar/palo_alto/PaloAltoConfigurationBuilder.java, line 2844 at r3 (raw file):

Previously, ratulm wrote…

Some context on rejection via Spencer:

https://intentionet.slack.com/archives/C01C58KHB7F/p1602199116034100?thread_ts=1602198664.031900&cid=C01C58KHB7F

(We should test if the device behavior is based on whats current when it sees the rule-type command. So, entering from z1 and then rule-type intrazone will fail unless to z1 has been entered before. If that is the behavior, the cleanup discussion is moot.)

Your other concern is valid. Another place I considered was here:

I couldn't find other examples of such post-parsing clean ups but doing it during conversion "felt wrong."

We have parsers that call processParseTree more than once, too. (Juniper).

--

I'm not quite sure why conversion is the wrong time to do this. It feels like "commit time" errors are best mapped to conversion -- at least, it's definitely not something that is part of walking the parse tree, it's something that comes from post-processing the extracted data from the parse tree.

Batfish-standard is to do this kind of thing during conversion; for example that's where we change undefined references into "match all" in Cisco. (That's also what Spencer suggested in the thread you linked.)

I could see a design with a middle phase between parsing and conversion -- parsing is literally just extracting the text into objects, then something where we "normalize" or "validate" (and/or "concretize"?) the parsed data, and then conversion where we blindly create VI objects from the VS ones.

That middle step would also be where we fill in every single null field with its defaults, for example. I could see why it's strange to propagate firstNonNull(field, it's default) all over conversion code.

Right now we don't really have that separation tho.

Copy link
Member

@dhalperi dhalperi left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @sfraint)


projects/batfish/src/main/java/org/batfish/grammar/palo_alto/PaloAltoConfigurationBuilder.java, line 2848 at r3 (raw file):

  }

  /** Remove intrazone rules that don't have identical From and To zones */

FYI you'll have to merge master. It looks like your prior PR(s) conflicted with this one.

Copy link
Member

@sfraint sfraint left a comment

Choose a reason for hiding this comment

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

Reviewable status: 4 of 6 files reviewed, 1 unresolved discussion (waiting on @dhalperi and @ratulm)


projects/batfish/src/main/java/org/batfish/grammar/palo_alto/PaloAltoConfigurationBuilder.java, line 2844 at r3 (raw file):

Previously, dhalperi (Dan Halperin) wrote…

We have parsers that call processParseTree more than once, too. (Juniper).

--

I'm not quite sure why conversion is the wrong time to do this. It feels like "commit time" errors are best mapped to conversion -- at least, it's definitely not something that is part of walking the parse tree, it's something that comes from post-processing the extracted data from the parse tree.

Batfish-standard is to do this kind of thing during conversion; for example that's where we change undefined references into "match all" in Cisco. (That's also what Spencer suggested in the thread you linked.)

I could see a design with a middle phase between parsing and conversion -- parsing is literally just extracting the text into objects, then something where we "normalize" or "validate" (and/or "concretize"?) the parsed data, and then conversion where we blindly create VI objects from the VS ones.

That middle step would also be where we fill in every single null field with its defaults, for example. I could see why it's strange to propagate firstNonNull(field, it's default) all over conversion code.

Right now we don't really have that separation tho.

I'd say we should either:
1a. add this check in PaloAltoConfigurationBuilder
1b. (better version of 1a) add this check in a new pre-conversion step like @dhalperi suggested
2. add this check during conversion

Generally, I'd say for things PAN cli won't let you enter 1 seems appropriate, and for things you can enter but might be rejected during commit process 2 seems appropriate.

Since PAN enforces validation for rule-type when you enter it on the cli (not at commit time), I'm leaning slightly toward doing this in 1. (also I believe @ratulm confirmed rule-type comes after to / from in config dumps)

@dhalperi
Copy link
Member


projects/batfish/src/main/java/org/batfish/grammar/palo_alto/PaloAltoConfigurationBuilder.java, line 2844 at r3 (raw file):

Previously, sfraint (Spencer Fraint) wrote…

I'd say we should either:
1a. add this check in PaloAltoConfigurationBuilder
1b. (better version of 1a) add this check in a new pre-conversion step like @dhalperi suggested
2. add this check during conversion

Generally, I'd say for things PAN cli won't let you enter 1 seems appropriate, and for things you can enter but might be rejected during commit process 2 seems appropriate.

Since PAN enforces validation for rule-type when you enter it on the cli (not at commit time), I'm leaning slightly toward doing this in 1. (also I believe @ratulm confirmed rule-type comes after to / from in config dumps)

For 1, as long as we can do it in an enter|exit_Rule -- the part that corresponds to CLI entry time -- then I'm down.

Copy link
Member

@dhalperi dhalperi left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r5.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ratulm and @sfraint)

Copy link
Member

@sfraint sfraint left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dhalperi and @ratulm)


projects/batfish/src/main/java/org/batfish/grammar/palo_alto/PaloAltoConfigurationBuilder.java, line 2844 at r3 (raw file):

Previously, dhalperi (Dan Halperin) wrote…

For 1, as long as we can do it in an enter|exit_Rule -- the part that corresponds to CLI entry time -- then I'm down.

👍 I was thinking in the rule-type exit rule

Copy link
Member Author

@ratulm ratulm left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dhalperi and @sfraint)


projects/batfish/src/main/java/org/batfish/grammar/palo_alto/PaloAltoConfigurationBuilder.java, line 2844 at r3 (raw file):

Previously, sfraint (Spencer Fraint) wrote…

👍 I was thinking in the rule-type exit rule

just so we are clear, we need checks here both 1) when rule-type is entered; and 2) after parsing is done. 2 is needed because the rule can be made invalid after the fact by changing its From/To zones.

i'll add 1 to parsing time and build on dan's other PR to 2.

@dhalperi
Copy link
Member


projects/batfish/src/main/java/org/batfish/grammar/palo_alto/PaloAltoConfigurationBuilder.java, line 2844 at r3 (raw file):

Previously, ratulm wrote…

just so we are clear, we need checks here both 1) when rule-type is entered; and 2) after parsing is done. 2 is needed because the rule can be made invalid after the fact by changing its From/To zones.

i'll add 1 to parsing time and build on dan's other PR to 2.

My other PR is a discussion piece.

Instead, you could prevent users from changing zones if rule type has been set to intrazone.

If you want to stick to post-processing, just do it in conversion for now so we can move forward. That's what we do everywhere else in Batfish.

Copy link
Member Author

@ratulm ratulm left a comment

Choose a reason for hiding this comment

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

Reviewable status: 2 of 6 files reviewed, 1 unresolved discussion (waiting on @dhalperi and @sfraint)


projects/batfish/src/main/java/org/batfish/grammar/palo_alto/PaloAltoConfigurationBuilder.java, line 2844 at r3 (raw file):

Previously, dhalperi (Dan Halperin) wrote…

My other PR is a discussion piece.

Instead, you could prevent users from changing zones if rule type has been set to intrazone.

If you want to stick to post-processing, just do it in conversion for now so we can move forward. That's what we do everywhere else in Batfish.

Did both during parsing and conversion, to get closer to device semantics (which checks during rule-type command and during commit, not during from/to commands).

If we prevented zone changes for intrazone rules, the following config will behave differently on device and batfish:

from = zone A
to = zone A
rule-type = intrazone
from = B
rule-type = interzone

on device: interzone rule from zone B -> A
on batfish: interzone rule from A -> A (because we rejected from = B)

Copy link
Member

@dhalperi dhalperi left a comment

Choose a reason for hiding this comment

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

Reviewed 5 of 5 files at r6.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ratulm)


projects/batfish/src/main/java/org/batfish/grammar/palo_alto/PaloAltoConfigurationBuilder.java, line 2485 at r6 (raw file):

Intrazone security

Maybe something that indicates we skipped this directive?

Error: cannot set rule-type intrazone for a security rule with different ...


projects/batfish/src/main/java/org/batfish/representation/palo_alto/PaloAltoConfiguration.java, line 706 at r6 (raw file):

Invalid

Skipping invalid... ?

Copy link
Member

@dhalperi dhalperi left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 4 files at r7.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@ratulm ratulm merged commit 275cbb3 into master Oct 11, 2020
@ratulm ratulm deleted the pan-rule-type branch October 11, 2020 21:37
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.

None yet

4 participants