Skip to content

Commit b1bd341

Browse files
committed
PA: Add field pan-security-profile-group to policy.
1 parent eb5c9d4 commit b1bd341

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

capirca/lib/paloaltofw.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ def ModifyOptions(self, terms):
171171
self.options["source"] = []
172172
self.options["destination"] = []
173173
self.options["application"] = []
174+
self.options["security_profile_group"] = []
174175
self.options["service"] = []
175176
self.options["action"] = "allow"
176177

@@ -203,6 +204,11 @@ def ModifyOptions(self, terms):
203204
for pan_app in term.pan_application:
204205
self.options["application"].append(pan_app)
205206

207+
if term.pan_security_profile_group:
208+
if len(term.pan_security_profile_group) > 1:
209+
raise PaloAltoFWOptionError("Only one security profile group allowed")
210+
self.options["security_profile_group"].append(term.pan_security_profile_group[0])
211+
206212
if term.destination_port:
207213
ports = []
208214
for tup in term.destination_port:
@@ -250,7 +256,6 @@ def __init__(self, pol, exp_info):
250256
self.pafw_policies = []
251257
self.addressbook = collections.OrderedDict()
252258
self.applications = []
253-
self.pan_applications = []
254259
self.ports = []
255260
self.from_zone = ""
256261
self.to_zone = ""
@@ -283,6 +288,7 @@ def _BuildTokens(self):
283288
"stateless_reply",
284289
"timeout",
285290
"pan_application",
291+
"pan_security_profile_group",
286292
"translated"
287293
}
288294

@@ -603,6 +609,14 @@ def __str__(self):
603609
rules.append(self.INDENT * 10 + "<member>" + a + "</member>")
604610
rules.append(self.INDENT * 9 + "</application>")
605611

612+
if options["security_profile_group"]:
613+
rules.append(self.INDENT * 9 + "<profile-setting>")
614+
rules.append(self.INDENT * 10 + "<group>")
615+
for p in options["security_profile_group"]:
616+
rules.append(self.INDENT * 11 + "<member>" + p + "</member>")
617+
rules.append(self.INDENT * 10 + "</group>")
618+
rules.append(self.INDENT * 9 + "</profile-setting>")
619+
606620
rules.append(self.INDENT * 8 + "</entry>")
607621

608622
rules.append(self.INDENT * 7 + "</rules>")

capirca/lib/policy.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ class Term(object):
334334
next-ip: VarType.NEXT_IP
335335
qos: VarType.QOS
336336
pan-application: VarType.PAN_APPLICATION
337+
pan-security-profile-group: VarType.PAN_SECURITY_PROFILE_GROUP
337338
policer: VarType.POLICER
338339
priority: VarType.PRIORITY
339340
vpn: VarType.VPN
@@ -431,6 +432,7 @@ def __init__(self, obj):
431432
self.protocol_except = []
432433
self.qos = None
433434
self.pan_application = []
435+
self.pan_security_profile_group = []
434436
self.routing_instance = None
435437
self.source_address = []
436438
self.source_address_exclude = []
@@ -749,6 +751,8 @@ def __str__(self):
749751
ret_str.append(' qos: %s' % self.qos)
750752
if self.pan_application:
751753
ret_str.append(' pan_application: %s' % self.pan_application)
754+
if self.pan_security_profile_group:
755+
ret_str.append(' pan_security_profile_group: %s' % self.pan_security_profile_group)
752756
if self.logging:
753757
ret_str.append(' logging: %s' % self.logging)
754758
if self.log_limit:
@@ -838,6 +842,10 @@ def __eq__(self, other):
838842
if sorted(self.pan_application) != sorted(other.pan_application):
839843
return False
840844

845+
# pan-security-profile-group
846+
if sorted(self.pan_security_profile_group) != sorted(other.pan_security_profile_group):
847+
return False
848+
841849
# verbatim
842850
if self.verbatim != other.verbatim:
843851
return False
@@ -869,6 +877,8 @@ def __eq__(self, other):
869877
return False
870878
if sorted(self.pan_application) != sorted(other.pan_application):
871879
return False
880+
if sorted(self.pan_security_profile_group) != sorted(other.pan_security_profile_group):
881+
return False
872882
if self.packet_length != other.packet_length:
873883
return False
874884
if self.fragment_offset != other.fragment_offset:
@@ -1095,6 +1105,8 @@ def AddObject(self, obj):
10951105
self.forwarding_class_except.append(x.value)
10961106
elif x.var_type is VarType.PAN_APPLICATION:
10971107
self.pan_application.append(x.value)
1108+
elif x.var_type is VarType.PAN_SECURITY_PROFILE_GROUP:
1109+
self.pan_security_profile_group.append(x.value)
10981110
elif x.var_type is VarType.NEXT_IP:
10991111
self.next_ip = DEFINITIONS.GetNetAddr(x.value)
11001112
elif x.var_type is VarType.PLATFORM:
@@ -1139,6 +1151,8 @@ def AddObject(self, obj):
11391151
self.forwarding_class_except.append(obj.value)
11401152
elif obj.var_type is VarType.PAN_APPLICATION:
11411153
self.pan_application.append(obj.value)
1154+
elif obj.var_type is VarType.PAN_SECURITY_PROFILE_GROUP:
1155+
self.pan_security_profile_group.append(obj.value)
11421156
elif obj.var_type is VarType.NEXT_IP:
11431157
self.next_ip = DEFINITIONS.GetNetAddr(obj.value)
11441158
elif obj.var_type is VarType.VERBATIM:
@@ -1500,6 +1514,7 @@ class VarType(object):
15001514
TARGET_RESOURCES = 59
15011515
TARGET_SERVICE_ACCOUNTS = 60
15021516
ENCAPSULATE = 61
1517+
PAN_SECURITY_PROFILE_GROUP = 62
15031518

15041519
def __init__(self, var_type, value):
15051520
self.var_type = var_type
@@ -1710,6 +1725,7 @@ def __ne__(self, other):
17101725
'RPAREN',
17111726
'RSQUARE',
17121727
'PAN_APPLICATION',
1728+
'PAN_SECURITY_PROFILE_GROUP',
17131729
'ROUTING_INSTANCE',
17141730
'SADDR',
17151731
'SADDREXCLUDE',
@@ -1786,6 +1802,7 @@ def __ne__(self, other):
17861802
'protocol-except': 'PROTOCOL_EXCEPT',
17871803
'qos': 'QOS',
17881804
'pan-application': 'PAN_APPLICATION',
1805+
'pan-security-profile-group': 'PAN_SECURITY_PROFILE_GROUP',
17891806
'routing-instance': 'ROUTING_INSTANCE',
17901807
'source-address': 'SADDR',
17911808
'source-exclude': 'SADDREXCLUDE',
@@ -1963,6 +1980,7 @@ def p_term_spec(p):
19631980
| term_spec protocol_spec
19641981
| term_spec qos_spec
19651982
| term_spec pan_application_spec
1983+
| term_spec pan_security_profile_group_spec
19661984
| term_spec routinginstance_spec
19671985
| term_spec tag_list_spec
19681986
| term_spec target_resources_spec
@@ -2332,6 +2350,13 @@ def p_pan_application_spec(p):
23322350
p[0].append(VarType(VarType.PAN_APPLICATION, apps))
23332351

23342352

2353+
def p_pan_security_profile_group_spec(p):
2354+
""" pan_security_profile_group_spec : PAN_SECURITY_PROFILE_GROUP ':' ':' one_or_more_strings """
2355+
p[0] = []
2356+
for apps in p[4]:
2357+
p[0].append(VarType(VarType.PAN_SECURITY_PROFILE_GROUP, apps))
2358+
2359+
23352360
def p_interface_spec(p):
23362361
""" interface_spec : SINTERFACE ':' ':' STRING
23372362
| DINTERFACE ':' ':' STRING """

policies/pol/sample_paloalto.pol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ term allow-icmp{
4141

4242
term allow-only-pan-app{
4343
pan-application:: http
44+
pan-security-profile-group:: my-group
4445
action:: accept
4546
}
4647

tests/lib/paloaltofw_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
destination-address:: SOME_HOST
6464
protocol:: tcp
6565
pan-application:: ssl http
66+
pan-security-profile-group:: url-filtering
6667
action:: accept
6768
}
6869
"""
@@ -163,6 +164,7 @@
163164
'stateless_reply',
164165
'timeout',
165166
'pan_application',
167+
'pan_security_profile_group',
166168
'translated'
167169
}
168170

0 commit comments

Comments
 (0)