Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3d9e89d
Added Fortigate modules and sample_fortigate.pol.
lweighall Oct 21, 2020
9b3cd85
First Round of Lint validation changes. PR Candidate.
lweighall Oct 21, 2020
8818190
Added a few missing items from policy.py, policy_simple.py, and aclge…
lweighall Oct 21, 2020
d1055ca
Minor bug fix to fortigate_test.py.
lweighall Oct 22, 2020
4ff7a7f
Removed two trailing whitespaces in fortigate_test.py
lweighall Oct 22, 2020
16f0b2d
Removed tailing whitespace in policy.py.
lweighall Oct 22, 2020
40631a2
Updates to multitarget support.
lweighall Oct 30, 2020
75c5832
Merge branch 'master' into ftnt_pr
lweighall Dec 10, 2020
e5dc16d
Make CloudArmor (CA) generator render rules that don't specify a sour…
a-googler Dec 11, 2020
fad05d4
Add attribute calculation to GCE generator.
a-googler Dec 12, 2020
eb5c9d4
Add generator patterns documentation
rdsharma Dec 12, 2020
f409a56
Changes for updated standards in Q4 2020.
lweighall Dec 28, 2020
c45c5dd
Changes for updated standards in Q4 2020.
lweighall Dec 28, 2020
dcf73b4
Editing git email user
ftntcorecse Dec 28, 2020
8b0b17d
Trying to kick over CLA....
ftntcorecse Dec 28, 2020
6214e68
Kicking over CLA take two.
Dec 28, 2020
fc5a0d8
Added Fortigate modules and sample_fortigate.pol.
lweighall Oct 21, 2020
fc9c3e5
First Round of Lint validation changes. PR Candidate.
lweighall Oct 21, 2020
4cf778f
Added a few missing items from policy.py, policy_simple.py, and aclge…
lweighall Oct 21, 2020
20ba26f
Minor bug fix to fortigate_test.py.
lweighall Oct 22, 2020
c17bfec
Removed two trailing whitespaces in fortigate_test.py
lweighall Oct 22, 2020
ac6fecb
Removed tailing whitespace in policy.py.
lweighall Oct 22, 2020
ff0a48f
Updates to multitarget support.
lweighall Oct 30, 2020
eed95e1
Changes for updated standards in Q4 2020.
lweighall Dec 28, 2020
7914fdc
Changes for updated standards in Q4 2020.
lweighall Dec 28, 2020
95ff671
Editing git email user
ftntcorecse Dec 28, 2020
3515a0c
Trying to kick over CLA....
ftntcorecse Dec 28, 2020
c7f508a
Kicking over CLA take two.
Dec 28, 2020
28f6584
Merge branch 'ftnt_pr' of https://github.com/fortinet/google-capirca …
Dec 28, 2020
b39a3a4
Kicking over CLA part four?
ftntcorecse Dec 28, 2020
97fb022
Changes for updated standards in Q4 2020.
ftntcorecse Jan 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion capirca/aclgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from capirca.lib import cloudarmor
from capirca.lib import gce
from capirca.lib import gcp_hf
from capirca.lib import fortigate
from capirca.lib import ipset
from capirca.lib import iptables
from capirca.lib import juniper
Expand Down Expand Up @@ -199,6 +200,7 @@ def RenderFile(base_directory, input_file, output_directory, definitions,
win_afw = False
xacl = False
paloalto = False
fcl = False

try:
with open(input_file) as f:
Expand Down Expand Up @@ -268,6 +270,8 @@ def RenderFile(base_directory, input_file, output_directory, definitions,
paloalto = copy.deepcopy(pol)
if 'cloudarmor' in platforms:
gca = copy.deepcopy(pol)
if 'fortigate' in platforms:
fcl = copy.deepcopy(pol)

if not output_directory.endswith('/'):
output_directory += '/'
Expand Down Expand Up @@ -366,11 +370,17 @@ def RenderFile(base_directory, input_file, output_directory, definitions,
acl_obj = cloudarmor.CloudArmor(gca, exp_info)
RenderACL(str(acl_obj), acl_obj.SUFFIX, output_directory,
input_file, write_files)

if fcl:
acl_obj = fortigate.Fortigate(fcl, exp_info)
RenderACL(str(acl_obj), acl_obj.SUFFIX, output_directory,
input_file, write_files)

# TODO(robankeny) add additional errors.
except (juniper.Error, junipermsmpc.Error, junipersrx.Error, cisco.Error,
ipset.Error, iptables.Error, speedway.Error, pcap.Error,
aclgenerator.Error, aruba.Error, nftables.Error, gce.Error,
cloudarmor.Error) as e:
cloudarmor.Error, fortigate.Error) as e:
raise ACLGeneratorError(
'Error generating target ACL for %s:\n%s' % (input_file, e))

Expand Down
40 changes: 22 additions & 18 deletions capirca/lib/cloudarmor.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,39 +105,43 @@ def ConvertToDict(self, priority_index):
'srcIpRanges': saddrs,
}
}

# If scrIpRanges within a single term exceed _MAX_IP_RANGES_PER_TERM,
# split into multiple terms
source_addr_chunks = [
saddrs[x:x+self._MAX_IP_RANGES_PER_TERM] for x in range(
0, len(saddrs), self._MAX_IP_RANGES_PER_TERM)]

split_rule_count = len(source_addr_chunks)

for i, chunk in enumerate(source_addr_chunks):
if not source_addr_chunks:
rule = copy.deepcopy(term_dict)
if split_rule_count > 1:
term_position_suffix = ' [%d/%d]' % (i+1, split_rule_count)
desc_limit = self._MAX_TERM_COMMENT_LENGTH - len(term_position_suffix)
rule['description'] = (rule.get('description', '')[:desc_limit]
+ term_position_suffix)

rule['priority'] = priority_index + i
rule['match'] = {
'versionedExpr': 'SRC_IPS_V1',
'config': {
'srcIpRanges': [str(saddr) for saddr in chunk],
}
}
rule['priority'] = priority_index
rule['match']['config']['srcIpRanges'] = ['*']
rules.append(rule)

else:
split_rule_count = len(source_addr_chunks)
for i, chunk in enumerate(source_addr_chunks):
rule = copy.deepcopy(term_dict)
if split_rule_count > 1:
term_position_suffix = ' [%d/%d]' % (i+1, split_rule_count)
desc_limit = self._MAX_TERM_COMMENT_LENGTH - len(term_position_suffix)
rule['description'] = (rule.get('description', '')[:desc_limit]
+ term_position_suffix)

rule['priority'] = priority_index + i
rule['match'] = {
'versionedExpr': 'SRC_IPS_V1',
'config': {
'srcIpRanges': [str(saddr) for saddr in chunk],
}
}
rules.append(rule)

# TODO(robankeny@): Review this log entry to make it cleaner/more useful.
# Right now, it prints the entire term which might be huge
if len(source_addr_chunks) > 1:
logging.debug('Current term [%s] was split into %d sub-terms since '
'_MAX_IP_RANGES_PER_TERM was exceeded',
str(term_dict), len(source_addr_chunks))

return rules


Expand Down
Loading