Skip to content

Instantly share code, notes, and snippets.

View nleiva's full-sized avatar
☠️
Working from somewhere

Nicolas Leiva nleiva

☠️
Working from somewhere
View GitHub Profile
result['message'] = acl
...
module.exit_json(**result)
acl = get_acl(module.params)
module = AnsibleModule(
argument_spec=module_args,
supports_check_mode=True
)
SSH = 22/tcp
DNS = 53/tcp # transfers
53/udp # queries
RFC1918 = 192.168.0.0/16
172.16.0.0/12
10.0.0.0/8
OFFICE = 192.0.2.0/24 # company IP block-1
198.51.100.0 # company IP block-2
INTERNAL = RFC1918
OFFICE
term allow-intra-office {
comment:: "Spoofs are already blocked at the borders"
source-address:: INTERNAL
destination-address:: INTERNAL
destination-port:: SSH
protocol:: tcp
action:: accept
}
term allow-remote {
---
- name: Generate SSH ACL Filter for a given OS.
hosts: localhost
gather_facts: no
tasks:
- name: Run Capirca Module
nleiva.capirca_acl.translate:
platform: 'ciscoxr'
filter_options: 'My-SSH-Filter'
@nleiva
nleiva / get_acl.py
Last active July 9, 2020 19:05
get_acl.py
from capirca.lib import cisco, juniper
def get_acl(inputs):
...
header = header_template.safe_substitute(inputs)
defs = naming.Naming(inputs['def_folder'])
terms = open(inputs['pol_file']).read()
pol = policy.ParsePolicy(header + '\n' + terms, defs, optimize=True)
...
module_args = dict(
platform = dict(type='str', required=True, choices=['juniper', 'cisco', 'ciscoasa', 'ciscoxr', 'brocade', \
'arista', 'aruba', 'ipset', 'iptables', 'nsxv', \
'packetfilter', 'pcap', 'speedway', 'srx', 'srxlo', \
'windows_advfirewall', 'nftables', 'gce', 'paloalto', 'cloudarmor' \
'fail me']),
filter_options = dict(type='list', required=False, default=['Default-ACL-Name']),
comment = dict(type='str', required=False, default="Default Comment"),
def_folder = dict(type='str', required=False, default="integration/targets/translate/files/def"),
pol_file = dict(type='str', required=False, default="integration/targets/translate/files/policies/terms.pol"),