Skip to content

Commit 7d1489b

Browse files
committed
PA: Add field pan-security-profile-group to policy.
1 parent 72cfb69 commit 7d1489b

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

capirca/lib/paloaltofw.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ def ModifyOptions(self, terms, service_map):
194194
self.options["source"] = []
195195
self.options["destination"] = []
196196
self.options["application"] = []
197+
self.options["security_profile_group"] = []
197198
self.options["service"] = []
198199
self.options["logging"] = []
199200

@@ -256,6 +257,11 @@ def pan_ports(ports):
256257
for pan_app in term.pan_application:
257258
self.options["application"].append(pan_app)
258259

260+
if term.pan_security_profile_group:
261+
if len(term.pan_security_profile_group) > 1:
262+
raise PaloAltoFWOptionError("Only one security profile group allowed")
263+
self.options["security_profile_group"].append(term.pan_security_profile_group[0])
264+
259265
if term.source_port or term.destination_port:
260266
src_ports = pan_ports(term.source_port)
261267
if term.destination_port:
@@ -367,7 +373,8 @@ def _BuildTokens(self):
367373
"stateless_reply",
368374
"timeout",
369375
"pan_application",
370-
"translated",
376+
"pan_security_profile_group",
377+
"translated"
371378
}
372379

373380
supported_sub_tokens.update({
@@ -906,6 +913,14 @@ def __str__(self):
906913
member = etree.SubElement(app, "member")
907914
member.text = x
908915

916+
# SECURITY PROFILE GROUP
917+
if options["security_profile_group"]:
918+
profile_setting = etree.SubElement(entry, "profile-setting")
919+
profile_setting_group = etree.SubElement(profile_setting, "group")
920+
for x in options["security_profile_group"]:
921+
member = etree.SubElement(profile_setting_group, "member")
922+
member.text = x
923+
909924
if tag_name is not None:
910925
rules_tag = etree.SubElement(entry, "tag")
911926
member = etree.SubElement(rules_tag, "member")

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 """

tests/lib/paloaltofw_test.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,14 @@
267267
}
268268
"""
269269

270+
PAN_SECURITY_PROFILE_GROUP = """
271+
term pan-security-profile-term {
272+
protocol:: tcp
273+
action:: accept
274+
pan-security-profile-group:: url-filtering
275+
}
276+
"""
277+
270278
ACTION_ACCEPT_TERM = """
271279
term test-accept-action {
272280
comment:: "Testing accept action for tcp."
@@ -377,7 +385,8 @@
377385
'stateless_reply',
378386
'timeout',
379387
'pan_application',
380-
'translated',
388+
'pan_security_profile_group',
389+
'translated'
381390
})
382391

383392
SUPPORTED_SUB_TOKENS = {
@@ -628,6 +637,14 @@ def testAcceptAction(self):
628637
"/entry[@name='test-accept-action']/action")
629638
self.assertEqual(x, 'allow', output)
630639

640+
def testPanSecurityProfileGroup(self):
641+
pol = policy.ParsePolicy(GOOD_HEADER_1 + PAN_SECURITY_PROFILE_GROUP, self.naming)
642+
paloalto = paloaltofw.PaloAltoFW(pol, EXP_INFO)
643+
output = str(paloalto)
644+
x = paloalto.config.findtext(PATH_RULES +
645+
"/entry[@name='pan-security-profile-term']/profile-setting/group/member")
646+
self.assertIsNotNone(x, output)
647+
631648
def testDenyAction(self):
632649
pol = policy.ParsePolicy(GOOD_HEADER_1 + ACTION_DENY_TERM, self.naming)
633650
paloalto = paloaltofw.PaloAltoFW(pol, EXP_INFO)

0 commit comments

Comments
 (0)