Git Product home page Git Product logo

capirca's Introduction

capirca

BuildStatus

About

Capirca is designed to utilize common definitions of networks, services and high-level policy files to facilitate the development and manipulation of network access control lists (ACLs) for various platforms. It was developed by Google for internal use, and is now open source.

Capirca consist of capirca Python package and the capirca tool.

The typical usage workflow consists of the following steps:

  1. Create object definitions containing "network" and "service" definitions
  2. Create a access control policy defining the desired state of access control and referencing the object definitions together with desired firewall platforms
  3. Generate ACL configurations by running capirca command referencing the access control policy and the object definitions. The command triggers a generator for each of the firewall platforms.

The basics

At a high-level capirca rationalizes objects (networks, services) against a security definition (.pol file) to generate a specific device configuration file via a platform specific ACL generator. Before getting started some objects must exist, the below table summarizes where objects are stored:

path description
/def/NETWORK.net a list of network objects definitions
/def/SERVICES.svc a list of service objects definitions

Each network or service definition file has a very simple structure. A token is defined, e.g. GUEST_NET, followed by an equal sign, then followed by a definition, e.g. 10.10.10.0/24, and optional description field, e.g. # guest network range.

GUEST_NET = 10.10.10.0/24      # guest network range

The tool populates the access control policy from .pol files in a particular directory, e.g. policies/. The tool searches recursively for .pol files and add them to the policy, .e.g .pol files are located in policies/pol.

Additionally, the .pol files MAY reference other policy definition files located outside of the directory by using include directive. Please see Includes section for documentation.

Network Objects

The files with .net extension contain the definitions of network objects, e.g. IP networks and hosts. The following definition creates INTERNAL and RFC1918 network objects in the object definitions, whether INTERNAL references the IP ranges of RFC 1918 defined in the RFC1918.

RFC1918 = 10.0.0.0/8      # non-public
          172.16.0.0/12   # non-public
          192.168.0.0/16  # non-public

INTERNAL = RFC1918

Back to Top

Service Objects

The files with .svc extension contain the definitions of service objects, e.g. ports and protocols.

DNS = 53/tcp  # transfers
      53/udp  # queries

Back to Top

Object Nesting

The nesting of tokens is permitted only when both tokens are of the same type. The referencing of a "network" object by "service" object is not allowed, and vice versa.

The examples of nesting of the network and service object follow.

HTTP = 80/tcp               # common web
HTTPS = 443/tcp             # SSL web
HTTP_8080 = 8080/tcp        #  web on non-standard port
WEB_SERVICES = HTTP HTTP_8080 HTTPS  # all our web services
DB_SERVICES = 3306/tcp      # allow db access
              HTTPS         # and SSL access
NYC_NETWORK = 200.1.1.0/24  # New York office
ATL_NETWORK = 200.2.1.0/24  # Atlanta office
DEN_NETWORK = 200.5.1.0/24  # Denver office
REMOTE_OFFICES = NYC_NETWORK
                 ATL_NETWORK
                 DEN_NETWORK

The network objects may reference both IPv4 and IPv6 addresses at the same time.

LOOPBACK = 127.0.0.1/32          # loopback in IPv4
           ::1/128               # loopback in IPv6
LINKLOCAL = FE80::/10            # IPv6 link local address
NYC_NETWORK = 172.16.1.0/24      # NYC IPv4
              2620:0:10A1::/48   # NYC IPv6

Back to Top

Anatomy of a policy file

A policy file (/policies/pol/something.pol) has the security policy written using capirca specific meta-language and format. There are specific sections (e.g: header) that tell capirca how to generate the output configuration of the security policy.

Headers

The header section defines:

  • target firewall platforms (which ACL generator to use)
  • passes additional arguments to the generator responsible for that platform.

A single header may have many targets within a section. It will result in multiple outputs being generated for that policy.

Terms

The term sections defines the access control rules within an ACL, it contains keywords followed by an object (service or network) and policy decision ("action" keyword).

The term section specifies the network flow metadata for ACL matching.

  • Addresses
  • Ports
  • Protocols
  • Action (allow/deny)

Inside a term a mandatory keyword will be found followed by an object token for rule evaluation.

Tokens

Tokens are the names of services and networks loaded from the object definitions. Example:

token_name definition
"HTTPS" 443
"NYC_NETWORK" 192.168.0.0/24

Keywords

keyword description
required must be supported by all output policy generators
optional available in a subset of the generators and are intended to
: : provide additional flexibility when developing policies for that :
: : specific target platform :

Required

  • action
    • accept
    • deny
    • reject
    • next
    • reject-with-tcp-rst
  • comment
    • a text comment enclosed in double-quotes. Comments may span multiple lines if desired.
  • destination-address
    • one or more destination address tokens.
  • destination-exclude
    • exclude one or more address tokens from the specified destination-address.
  • destination-port
    • one or more service definition tokens.
  • icmp-type
    • specific icmp-type code to match (IPv4/IPv6 types vary).
      • IPv4:
      • echo-reply
      • unreachable
      • source-quench
      • redirect
      • alternate-address
      • echo-request
      • router-advertisement
      • router-solicitation
      • time-exceeded
      • parameter-problem
      • timestamp-request
      • timestamp-reply
      • information-request
      • information-reply
      • mask-request
      • mask-reply
      • conversion-error
      • mobile-redirect
      • IPv6:
      • destination-unreachable
      • packet-too-big
      • time-exceeded
      • parameter-problem
      • echo-request
      • echo-reply
      • multicast-listener-query
      • multicast-listener-report
      • multicast-listener-done
      • router-solicit
      • router-advertisement
      • neighbor-solicit
      • neighbor-advertisement
      • redirect-message
      • router-renumbering
      • icmp-node-information-query
      • icmp-node-information-response
      • inverse-neighbor-discovery-solicitation
      • inverse-neighbor-discovery-advertisement
      • version-2-multicast-listener-report
      • home-agent-address-discovery-request
      • home-agent-address-discovery-reply
      • mobile-prefix-solicitation
      • mobile-prefix-advertisement
      • certification-path-solicitation
      • certification-path-advertisement
      • multicast-router-advertisement
      • multicast-router-solicitation
      • multicast-router-termination
  • option
    • connection options.
      • established
        • only permit established connections; implements tcp-established flag if protocol is tcp only, otherwise adds 1024-65535 to required destination-ports.
      • tcp-established
        • only permit established tcp connections, usually checked based on TCP flag settings. If protocol UDP is included in term, only adds 1024-65535 to required destination-ports.
      • sample
        • not supported by all generators. Samples traffic for netflow.
      • intial
        • currently only supported by juniper generator. Appends tcp-initial to the term.
      • rst
        • currently only supported by juniper generator. Appends "tcp-flags rst" to the term.
      • first-fragment
        • currently only supported by juniper generator. Appends 'first-fragment' to the term.
  • protocol
    • network protocols this term will match, such as tcp, udp, icmp, or a numeric value.
  • protocol-except
    • network protocols that should be excluded from the protocol specification. This is rarely used.
  • source-address
    • one or more source address tokens.
  • source-exclude
    • exclude one or more address tokens from the specified source-address.
  • source-port
    • one or more service definition tokens.
  • verbatim
    • this specifies that the text enclosed within quotes should be rendered into the output without interpretation or modification. This is sometimes used as a temporary workaround while new required features are being added.

Optional

WARNING: These terms may or may not function properly on all generators. Always refer to the generator specific documentation and code base.

  • address
    • one or more network address tokens matches either source or destination.
  • counter
    • (Juniper only) enable filter-based generic routing encapsulation (GRE) tunneling using the specified tunnel template.
  • destination-prefix
    • (Juniper only) specify destination-prefix matching (e.g. source-prefix` configured-neighbors-only).
  • ether-type
    • (Juniper only) specify matching ether-type(e.g. ether-type` arp).
  • fragement-offset
    • (Juniper only) specify a fragment offset of a fragmented packet.
  • logging
    • (Juniper, speedway/iptables) specify that this packet should be logged via syslog.
  • loss-priority
    • (Juniper only) specify loss priority.
  • packet-length
    • (Juniper only) specify packet length.
  • policer
    • (Juniper only) specify which policer to apply to matching packets.
  • precedence
    • (Juniper only) specify precendence.
  • qos
    • (Juniper only) apply quality of service classification to matching packets (e.g. qos` af4).
  • routing-instance
    • (iptables, speedway only) specify specific interface a term should apply to (e.g. source-interface` eth3).
  • source-prefix
    • (Juniper only) specify source-prefix matching (e.g. source-prefix, configured-neighbors-only).
  • traffic-type
    • (Juniper only) specify traffic-type.

Includes

Policy files support the use of #include statements. An include may be used to avoid duplication of commonly used text, such as a group of terms that permit or block specific types of traffic.

An include directive will result in the contents of the included file being injected into the current policy file in the exact location of the #include directive. An example include:

#include 'includes/untrusted-networks-blocking.inc'

NOTE: Includes are only read from the subdirectories of your base_directory, all other directories will error out.

The .inc file extension and the includes/ folder is not required but it is recommended to be used as a best practice and for easier readability.

Example

WARNING: Not all generators have the same configuration options or feature set.

header {
  target:: paloalto from-zone internal to-zone external
}

term ping-gdns{
  source-address:: INTERNAL
  destination-address:: GOOGLE_DNS
  protocol:: icmp
  action:: accept
}

The above example tells capirca to use paloalto.py to generate a platform specific configuration for Palo Alto.

The security policy is written within the term section using the meta-language:

  • name/description: ping-gdns
  • source: any INTERNAL network (check /def/NETWORK.net definition of 'INTERNAL')
  • destination: service object named GOOGLE_DNS
  • protocol: icmp
  • action: accept

The above ACL controls traffic in one direction only (outbound towards the service) and there should be another header and term to control the traffic in the opposite direction. Unless the target generator features the ability to automatically create bi-directional configuration from a single ACL term. Always check the documentation of the generator or validate the output generated to validate final configuration and policy interpretation.

Term Keywords By Generator

The following list contains links to the documentation of the individual policy generators:

Back to Top

Term Examples

The following are examples of how to construct a term, and assumes that naming definition tokens used have been defined in the definitions files.

  • Block incoming bogons and spoofed traffic
term block-bogons {
  source-address:: BOGONS RFC1918
  source-address:: COMPANY_INTERNAL
  action:: deny
}
  • Permit Public to Web Servers
term permit-to-web-servers {
  destination-address:: WEB_SERVERS
  destination-port:: HTTP
  protocol:: tcp
  action:: accept
}
  • Permit Replies to DNS Servers From Primaries
term permit-dns-tcp-replies {
  source-address:: DNS_PRIMARIES
  destination-address:: DNS_SECONDARIES
  source-address:: DNS
  protocol:: tcp
  option:: tcp-established
  action:: accept
}
  • Permit All Corporate Networks, Except New York, to FTP Server

This will "subtract" the CORP_NYC_NETBLOCK from the CORP_NETBLOCKS token. For example, assume CORP_NETBLOCKS includes 200.0.0.0/20, and CORP_NYC_NETBLOCK is defined as 200.2.0.0/24. The source-exclude will remove the NYC netblock from the permitted source addresses. If the excluded address is not contained with the source address, nothing is changed.

term allow-inbound-ftp-from-corp {
  source-address:: CORP_NETBLOCKS
  source-exclude:: CORP_NYC_NETBLOCK
  destination-port:: FTP
  protocol:: tcp
  action:: accept
}

Back to Top

Example Policy File

Below is an example policy file for a Juniper target platform. It contains two filters, each with a handful of terms. This examples assumes that the network and service naming definition tokens have been defined.

header {
  comment:: "edge input filter for sample network."
  target:: juniper edge-inbound
}
term discard-spoofs {
  source-address:: RFC1918
  action:: deny
}
term permit-ipsec-access {
  source-address:: REMOTE_OFFICES
  destination-address:: VPN_HUB
  protocol:: 50
  action:: accept
}
term permit-ike-access {
  source-address:: REMOTE_OFFICES
  destination-address:: VPN_HUB
  protocol:: udp
  destination-port:: IKE
  action:: accept
}
term permit-public-web-access {
  destination-address:: WEB_SERVERS
  destination-port:: HTTP HTTPS HTTP_8080
  protocol:: tcp
  action:: accept
}
term permit-tcp-replies {
  option:: tcp-established
  action:: accept
}
term default-deny {
  action:: deny
}

header {
  comment:: "edge output filter for sample network."
  target:: juniper edge-outbound
}
term drop-internal-sourced-outbound {
  destination-address:: INTERNAL
  destination-address:: RESERVED
  action:: deny
}
term reject-internal {
  source-address:: INTERNAL
  action:: reject
}
term default-accept {
  action:: accept
}

Back to Top

Getting Started

Installation

From Source

If setuptools Python package is not installed on your system, install it: For example, the following commands installs the package with apt package manager.

sudo apt-get install python3-pip python3-setuptools

Next, to install capirca from source, clone the capirca repository and run its installer:

git clone https://github.com/google/capirca.git
cd capirca/
python3 setup.py install --user

Typically, when provided --user argument, the installer creates the following files, where 3.8 is Python version and 2.0.0 is the version of capirca:

  • ~/.local/bin/capirca
  • ~/.local/lib/python3.8/site-packages/capirca-2.0.0-py3.8.egg

If necessary, remove build files:

rm -rf build capirca.egg-info dist

Next, test capirca by generating sample output filters for Cisco, Juniper, iptables, and other firewall platforms.

~/.local/bin/capirca

The generation of sample output while in the capirca's source code directory does not require command line parameters, because capirca inherits default settings from the following configuration (see capirca/utils/config.py).

{
    'base_directory': './policies',
    'definitions_directory': './def',
    'policy_file': None,
    'output_directory': './filters',
    'optimize': False,
    'recursive': True,
    'debug': False,
    'verbose': False,
    'ignore_directories': ['DEPRECATED', 'def'],
    'max_renderers': 10,
    'shade_check': False,
    'exp_info': 2
}

Although the policy_file is None, the tool processes all policies located in base_directory, i.e. ./policies. The tool loads network and service definitions from definitions_directory. The tool output generated ACLs to the root of the source directory because output_directory is ./filters.

Back to Top

Package Manager

Currently, the PyPI is out of date. Nevertheless, a user can install an older version of capirca with pip:

pip install capirca --user

Back to Top

Basic Usage

There are a number of command-line arguments that can be used with capirca.

$ ~/.local/bin/capirca --helpfull

       USAGE: capirca [flags]
flags:

absl.app:
  -?,--[no]help: show this help
    (default: 'false')
  --[no]helpfull: show full help
    (default: 'false')
  --[no]helpshort: show this help
    (default: 'false')
  --[no]helpxml: like --helpfull, but generates XML output
    (default: 'false')
  --[no]only_check_args: Set to true to validate args and exit.
    (default: 'false')
  --[no]pdb: Alias for --pdb_post_mortem.
    (default: 'false')
  --[no]pdb_post_mortem: Set to true to handle uncaught exceptions with PDB post mortem.
    (default: 'false')
  --profile_file: Dump profile information to a file (for python -m pstats). Implies --run_with_profiling.
  --[no]run_with_pdb: Set to true for PDB debug mode
    (default: 'false')
  --[no]run_with_profiling: Set to true for profiling the script. Execution will be slower, and the output format might change over time.
    (default: 'false')
  --[no]use_cprofile_for_profiling: Use cProfile instead of the profile module for profiling. This has no effect unless --run_with_profiling
    is set.
    (default: 'true')

absl.logging:
  --[no]alsologtostderr: also log to stderr?
    (default: 'false')
  --log_dir: directory to write logfiles into
    (default: '')
  --logger_levels: Specify log level of loggers. The format is a CSV list of `name:level`. Where `name` is the logger name used with
    `logging.getLogger()`, and `level` is a level name  (INFO, DEBUG, etc). e.g. `myapp.foo:INFO,other.logger:DEBUG`
    (default: '')
  --[no]logtostderr: Should only log to stderr?
    (default: 'false')
  --[no]showprefixforinfo: If False, do not prepend prefix to info messages when it's logged to stderr, --verbosity is set to INFO level,
    and python logging is used.
    (default: 'true')
  --stderrthreshold: log messages at this level, or more severe, to stderr in addition to the logfile.  Possible values are 'debug', 'info',
    'warning', 'error', and 'fatal'.  Obsoletes --alsologtostderr. Using --alsologtostderr cancels the effect of this flag. Please also note
    that this flag is subject to --verbosity and requires logfile not be stderr.
    (default: 'fatal')
  -v,--verbosity: Logging verbosity level. Messages logged at this level or lower will be included. Set to 1 for debug logging. If the flag
    was not set or supplied, the value will be changed from the default of -1 (warning) to 0 (info) after flags are parsed.
    (default: '-1')
    (an integer)

capirca.capirca:
  --base_directory: The base directory to look for acls; typically where you'd find ./corp and ./prod
    (default: './policies')
  --config_file: A yaml file with the configuration options for capirca;
    repeat this option to specify a list of values
  --[no]debug: Debug messages
    (default: 'false')
  --definitions_directory: Directory where the definitions can be found.
    (default: './def')
  --exp_info: Print a info message when a term is set to expire in that many weeks.
    (default: '2')
    (an integer)
  --ignore_directories: Don't descend into directories that look like this string
    (default: 'DEPRECATED,def')
    (a comma separated list)
  --max_renderers: Max number of rendering processes to use.
    (default: '10')
    (an integer)
  -o,--[no]optimize: Turn on optimization.
    (default: 'False')
  --output_directory: Directory to output the rendered acls.
    (default: './filters')
  --policy_file: Individual policy file to generate.
  --[no]recursive: Descend recursively from the base directory rendering acls
    (default: 'true')
  --[no]shade_check: Raise an error when a term is completely shaded by a prior term.
    (default: 'false')
  --[no]verbose: Verbose messages
    (default: 'false')

absl.flags:
  --flagfile: Insert flag definitions from the given file into the command line.
    (default: '')
  --undefok: comma-separated list of flag names that it is okay to specify on the command line even if the program does not define a flag
    with that name.  IMPORTANT: flags in this list that have arguments MUST use the --flag=value format.
    (default: '')

Notably, the --config_file PATH argument allows passing one or more yaml configuration files. These files will be prioritized from left to right, i.e. any duplicate configurations will be overriden, not merged.

The command line arguments take precendence over any settings passed via the configuration files.

The default capirca configurations in a YAML format follows:

---
base_directory: ./policies
definitions_directory: ./def
output_directory: ./
optimize: false
recursive: true
debug: false
verbose: false
ignore_directories:
  - DEPRECATED
  - def
max_renderers: 10
shade_check: true
exp_info: 2

Back to Top

Python Package

The capirca tool uses capirca Python package.

Therefore, there is a way to access capirca programmatically.

  • policies/sample_paloalto.pol
  • def/SERVICES.svc
  • def/NETWORK.net

Provided you have the following files in your directory, the following code snippets create a naming definitions object, policy object, and render generator filter output.

NOTE: Paste the code snippets one line at a time.

First, start Python interpreter:

$ python3
Python 3.8.7 (default, Dec 22 2020, 10:37:26)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Next, import naming library and create naming object from definitions files in ./def directory.

from pprint import pprint
from capirca.lib import naming
defs = naming.Naming('./def')
pprint(defs)
<capirca.lib.naming.Naming object at 0x7f8421b57280>

The defs object follows:

<capirca.lib.naming.Naming object at 0x7f8421b57280>

The Naming object has various methods. The GetServiceNames method returns the service name tokens.

>>> dir(defs)
['GetIpParents', 'GetNet', 'GetNetAddr', 'GetNetChildren', 'GetServiceNames',
 <...intentionally omitted ..>
'unseen_networks', 'unseen_services']
>>>

>>> pprint(defs.GetServiceNames())
['WHOIS',
 'SSH',
 <...intentionally omitted ..>
 'TRACEROUTE']
>>>

Then, import policy library, read in the policy configuration data from ./policies/sample_paloalto.pol, and create a policy object.

from capirca.lib import policy
conf = open('./policies/sample_paloalto.pol').read()
pol = policy.ParsePolicy(conf, defs, optimize=True)

The policy object follows:

>>> pprint(pol)
Policy: {Target[paloalto], Comments [], Apply groups: [], except: []:[ name: ping-gdns
  source_address: [IPv4('10.0.0.0/8'), IPv4('172.16.0.0/12'), IPv4('192.168.0.0/16')]
  destination_address: [IPv4('8.8.4.4/32'), IPv4('8.8.8.8/32'), IPv6('2001:4860:4860::8844/128'), IPv6('2001:4860:4860::8888/128')]
  protocol: ['icmp']
  action: ['accept'],  name: dns-gdns
  source_address: [IPv4('10.0.0.0/8'), IPv4('172.16.0.0/12'), IPv4('192.168.0.0/16')]
  destination_address: [IPv4('8.8.4.4/32'), IPv4('8.8.8.8/32'), IPv6('2001:4860:4860::8844/128'), IPv6('2001:4860:4860::8888/128')]
  protocol: ['tcp']
  destination_port: [(53, 53)]
  action: ['accept'],  name: allow-web-outbound
  source_address: [IPv4('10.0.0.0/8'), IPv4('172.16.0.0/12'), IPv4('192.168.0.0/16')]
  protocol: ['tcp']
  destination_port: [(80, 80), (443, 443)]
  action: ['accept']], Target[paloalto], Comments [], Apply groups: [], except: []:[ name: allow-icmp
  protocol: ['icmp']
  action: ['accept'],  name: allow-only-pan-app
  action: ['accept']
  pan_application: ['http'],  name: allow-web-inbound
  destination_address: [IPv4('200.1.1.1/32'), IPv4('200.1.1.2/32')]
  protocol: ['tcp']
  destination_port: [(80, 80), (443, 443)]
  action: ['accept']
  pan_application: ['ssl', 'http']]}
>>>

Next, import a generator library (here paloaltofw for Palo Alto firewalls) and output a policy in the desired format.

from capirca.lib import paloaltofw
for header in pol.headers:
  if 'paloalto' in header.platforms:
    jcl = True
  if jcl:
    output = paloaltofw.PaloAltoFW(pol, 1)
    print(output)

The following code initiates Palo Alto firewall ACL model with the default expiration of 1 week.

paloaltofw.PaloAltoFW(pol, 1)

Back to Top

Running with Docker

If your use case is to just use the CLI and you don't want to go through the process of installing capirca, you can use the dockerized version of the tool.

When using docker, mount your working directory to the /data directory of the container and pass command-line arguments in the following way.

docker run -v "${PWD}:/data" docker.pkg.github.com/google/capirca/capirca:latest
docker run -v "${PWD}:/data" docker.pkg.github.com/google/capirca/capirca:latest --helpfull
docker run -v "${PWD}:/data" docker.pkg.github.com/google/capirca/capirca:latest --config_file /data/path/to/config

Back to Top

Miscellaneous

Security considerations

The Capirca threat model assumes some control and verification of policy definitions (in .pol files). This is either through human user verification, or that policies are generated by upstream systems that enforce correctness.

It is recommended that the ACL generated by Capirca is always tested for correctness before being applied to production. Not all generators support every feature, configuration option or term keywords. When something is unsupported, Capirca will error out. But due to the sensitive nature of network ACLs, it is always recommended to test any new generator being used, or new policies being generated.

Additional documentation

External links, resources and references:

Back to Top

capirca's People

Contributors

abhindes avatar alan-christopher avatar ankenyr avatar cryptaliagy avatar finfinack avatar g-nikoloff avatar gmonni avatar greenpau avatar ivucica avatar jgangel avatar jzohrab avatar kevinsteves avatar maddychan avatar micrictor avatar mirceaulinic avatar mpenning avatar nero85 avatar oribit avatar pw378 avatar rarcotvmw avatar rdsharma avatar ryantierney513 avatar sdatta09 avatar sneakywombat avatar sulrich avatar thechuchutrain avatar thelinuxguy avatar vklimovs avatar yilei avatar zombah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

capirca's Issues

Aclcheck.py thinks IP does not include TCP

What steps will reproduce the problem?
1. create term using "protocol:: ip:

term block-stuff {
  source-address:: MY_NETWORKS
  protocol:: ip
  logging:: true
  action:: deny
}

2.

Use ./aclcheck_cmdline.py to test the ACL with --proto ip. It works.
IP address 1.2.3.4 is in MY_NETWORKS.

./aclcheck_cmdline.py -p policies/toSERV03-WCM-IFZ.pol -s 1.2.3.4 -d 5.6.7.8 
--dport 80 --proto ip
  filter: toSERV03-WCM-IFZ
          term: block-stuff
                deny


3.

Use ./aclcheck_cmdline.py to test the ACL with --proto tcp. It *should* work 
just like the case above, since it is supposed to block all IP packets; but it 
does not. It rolls over the next term.

./aclcheck_cmdline.py -p policies/toSERV03-WCM-IFZ.pol -s 1.2.3.4 -d 5.6.7.8 
--dport 80 --proto tcp
  filter: toSERV03-WCM-IFZ
          term: default-deny
                deny


What version of the product are you using? On what operating system?

r145 with minor modifications on linux RHEL5.

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 23 Sep 2011 at 10:34

should #include be read as a comment or not?

What steps will reproduce the problem?
1. use i.e. #include policies/linux/monitoring in your policy 
(because you wanna add it later, not now)


What is the expected output? What do you see instead?
ignore the line and not try to parse the include file

What version of the product are you using? On what operating system?
svn version 

Please provide any additional information below.
this may not be an issue at all. I don't know the syntax well enough yet, 
opening the issue because i won't remember once I got used to working around it 
:)

Original issue reported on code.google.com by [email protected] on 6 Jun 2011 at 8:28

Add principals optional keyword

Purpose of code changes on this branch:
Add 'principals' optional keyword to policy.py. This is intended to allow a 
policy author to include this in a term when an ACL involves a list of named 
groups.

After the review, I'll merge this branch into:
/trunk


Original issue reported on code.google.com by [email protected] on 20 Dec 2012 at 5:08

Attachments:

SRX generator creates two terms when source and destination port is defined

What steps will reproduce the problem?

1. Create an SRX policy like this:
term accept-dhcp-access {
  source-port:: DHCP
  destination-port:: DHCP
  protocol:: udp
  action:: accept
}
2. Generate ACLs and check the application that has been generated.

What is the expected output?

    application accept-dhcp-access-app {
        term t1 protocol udp source-port 67-67 destination-port 67-67;
    }

What do you see instead?

    application accept-dhcp-access-app {
        term t1 protocol udp source-port 67-68;
        term t2 protocol udp destination-port 67-68;
    }

Original issue reported on code.google.com by [email protected] on 4 May 2012 at 1:47

Cisco generator uses ip as default protocol

What steps will reproduce the problem?
1. Create policy file:

# cat policies/test.pol 
header {
  target:: cisco testACL inet6
}

term permit-all {
  action:: accept
}


2. Compile filters:
./aclgen.py -d def/ -o filters/ --poldir=policies/

3. See filter in filters/test.acl

What is the expected output? What do you see instead?

Generated ACL looks like:

ipv6 access-list testACL
remark permit-all
 permit ip any any

but it should be like:
ipv6 access-list testACL
remark permit-all
 permit ipv6 any any


What version of the product are you using? On what operating system?

Latest SVN revision (r141).


Please provide any additional information below.

The problem lies in Term class of cisco.py. If there is no protocol specified 
in term, it is assumed to be ip:
    # protocol
    if not self.term.protocol:
      protocol = ['ip']

When af is 6 the fallback protocol should be ipv6.

Original issue reported on code.google.com by [email protected] on 7 Aug 2011 at 5:25

Packaging of Capirca libraries

Noticed this thread back from 2013 on the old capirca-dev google group.
https://groups.google.com/forum/#!topic/capirca-dev/mGls2XFH7ug

This is a good idea I believe.
Having a directory structure look something like the following
capirca/
capirca/generators/<cisco/juniper/...>
capirca/naming.py
capirca/policy.py

I understand there is work on new policy parsers. Those could live in a new directory called capirca/parsers.

Like it is said in the thread aclgen.py would be a script.

icmp-type for target:: cisco inet6 generates error

What steps will reproduce the problem?
1.include in policy file:

term icmp-filter-IRC-servers-I {
  destination-address:: IRC_SERVERS_SNT
  icmp-type:: echo-reply
  protocol:: icmp
  action:: accept
}

2. change 'target:: cisco' to inet6 or mixed

3. run aclgen.py

Traceback (most recent call last):
  File "./aclgen.py", line 172, in <module>
    main()
  File "./aclgen.py", line 152, in main
    count = load_and_render(FLAGS.policy_directory, defs)
  File "./aclgen.py", line 69, in load_and_render
    defs))
  File "./aclgen.py", line 114, in render_filters
    do_output_filter(str(fw), filter_name(source_file, fw._SUFFIX))
  File "/home/hoek/capirca-test/lib/cisco.py", line 634, in __str__
    target.append(str(term))
  File "/home/hoek/capirca-test/lib/cisco.py", line 394, in __str__
    self.term.name)
  File "/home/hoek/capirca-test/lib/aclgenerator.py", line 163, in NormalizeIcmpTypes
    self.term.name))
lib.aclgenerator.MismatchIcmpInetError: ICMP/ICMPv6 mismatch with address 
family IPv4/IPv6 in term icmp-filter-IRC-servers-I


What version of the product are you using? On what operating system?
capirca revision 155 (didn't work on rev 149 either) on ubuntu 11.10



Original issue reported on code.google.com by [email protected] on 20 Dec 2011 at 4:39

only the first target::cisco is processed (aclgen.py)

What steps will reproduce the problem?
1. runaclgen.py in a standard, unmodified install

What is the expected output? What do you see instead?
In filters/sample.acl only the inbound acl are generated (first
target::cisco). Work-a-round is to split /policies/sample.pol into two
files. One with the inbound policies and one with the outbound policies.


What version of the product are you using? On what operating system?
svn rev 98 (issue exists since rev_76 ?: cisco:mixed implementation)
OS: ubuntu 9.10

Please provide any additional information below.



Original issue reported on code.google.com by [email protected] on 4 Jun 2010 at 12:10

Missing support for logging in SRX generator

What steps will reproduce the problem?
1. Create a term in an SRX policy
2. Add "action:: log"

term permit-web-services {
  destination-address:: WEB_SERVERS
  protocol:: tcp
  destination-port:: WEB_SERVICES
  action:: accept log
}

3. Run aclgen

What is the expected output? What do you see instead?
Expected (but no output since it's not a supported action):
policy permit-web-services {
  match {
    source-address any;
    destination-address WEB_SERVERS;
    application WEB_SERVICES-app;
  }
  then {
    permit;
    log {
      session-init;
    }
  }
}

Imho, it's enough to support session-init logging but you might consider adding 
support for session-close as well...

Original issue reported on code.google.com by [email protected] on 21 Mar 2012 at 9:29

aclgen.py does not handle -p flag correctly

What steps will reproduce the problem?
1. Try to generate filters for only one policy with -p:
./aclgen.py -d def/ -o filters/ --poldir="" -p policies/sample_cisco_lab.pol

What is the expected output? What do you see instead?

aclgen crashes:

./aclgen.py -d def/ -o filters/ --poldir="" -p policies/sample_cisco_lab.pol 
Illegal character '/' on line 1
Traceback (most recent call last):
  File "./aclgen.py", line 165, in ?
    main()
  File "./aclgen.py", line 148, in main
    count = render_filters(policy.ParsePolicy(FLAGS.policy).read(), defs)
  File "/home/nms/devel/capirca/src/lib/policy.py", line 1480, in ParsePolicy
    return p.parse(preprocessed_data, lexer=lexer)
  File "/home/nms/devel/capirca/capirca/third_party/ply/yacc.py", line 265, in parse
  File "/home/nms/devel/capirca/capirca/third_party/ply/yacc.py", line 1047, in parseopt_notrack
  File "/home/nms/devel/capirca/src/lib/policy.py", line 1365, in p_error
    raise ParseError(' ERROR on "%s" (type %s, line %d, Next %s)'
lib.policy.ParseError:  ERROR on "policies" (type STRING, line 1, Next 
'sample_cisco_lab')

What version of the product are you using? On what operating system?
Latest SVN (r141)

Please provide any additional information below.

Arguments passed to render_filters function in aclgen.py from main() are not 
correct. Attached patch fixes this.


Original issue reported on code.google.com by [email protected] on 7 Aug 2011 at 5:52

Attachments:

SRX device supports only up to 8 terms per application

What steps will reproduce the problem?
1.
Policy:
term test-access {
  destination-port:: TEST
  action:: accept
}

SERVICES.svc:
TEST = 1/tcp
       2/tcp
       3/tcp
       4/tcp
       5/tcp
       6/tcp
       7/tcp
       8/tcp
       9/tcp
       10/tcp

2. Generate output. Application part:
    application test-access-app {
        term t1 protocol tcp destination-port 1;
        term t2 protocol tcp destination-port 2;
        term t3 protocol tcp destination-port 3;
        term t4 protocol tcp destination-port 4;
        term t5 protocol tcp destination-port 5;
        term t6 protocol tcp destination-port 6;
        term t7 protocol tcp destination-port 7;
        term t8 protocol tcp destination-port 8;
        term t9 protocol tcp destination-port 9;
        term t10 protocol tcp destination-port 10;
    }

3. Apply to an SRX:

root# commit check
[edit applications application test-access-app]
 'term'
  number of elements exceeds limit of 8
error: configuration check-out failed: (number of elements exceeds limit)



The SRX does not allow more than 8 terms per application definition (maybe 
different platforms have different limits?). There are two solutions in my 
opinion:
- Create one application per port (cleaner imho).
- Create each application with max N terms (where N is 8?) and create new 
applications as long as necessary...

Original issue reported on code.google.com by [email protected] on 25 Jun 2012 at 7:48

SRX security zone VPN not accepted

I'm testing your latest commits with my policies.

The policies containing for example:
"target:: srx from-zone corp to-zone vpn"
fail because of the vpn zone:

Traceback (most recent call last):
  File "aclgen.py", line 498, in <module>
    main(FLAGS(sys.argv))
  File "aclgen.py", line 461, in main
    FLAGS.exp_info, write_files)
  File "aclgen.py", line 193, in RenderFile
    input_file, sys.exc_info()[0], sys.exc_info()[1]))
__main__.ACLParserError: Error parsing policy file policies/pol/offices_srx_base_policies-global.pol:
<class 'lib.policy.ParseError'> ERROR on "vpn" (type VPN, line 262, Next '}')

If I rename vpn into something else it then works fine.

"option:: established" does the wrong thing on Cisco.

What steps will reproduce the problem?
1. compile the following ACL with target:: cisco

term test-term {
  source-address:: bas050-2
  destination-address:: HVAC_TEST_SERVERS
  protocol:: tcp
  destination-port:: SSH
  option:: established
  action:: accept
}

2. check the results:

 remark test-term
 permit tcp host 134.79.230.135 172.25.192.8 0.0.0.7 eq 22 established
 permit tcp host 134.79.230.135 172.25.192.8 0.0.0.7 range 1024 65535 established


What is the expected output? What do you see instead?

The second line should not be there, and the first line should read:

permit tcp host 134.79.230.135 range 1024 65535 172.25.192.8 0.0.0.7 eq 22 
established


What version of the product are you using? On what operating system?
SVN v110. Also tried on v103 with the same results.
Linux RHEL5.

Please provide any additional information below.

- it works correctly when specifying a source-port (as opposed to a 
destination-port).
- it fails in the same way on UDP.

Original issue reported on code.google.com by [email protected] on 8 Apr 2011 at 12:10

cisco mixed access-list naming

What steps will reproduce the problem?
1. Create policy with cisco mixed

header {
    comment:: "capirca test"
    target:: cisco capirca-test mixed
}

2. Run ./aclgen.py
3. Review filter output

What is the expected output? What do you see instead?

Expected:

no ip access-list extended capirca-test
ip access-list extended capirca-test
<SNIP>
no ipv6 access-list capirca-test-v6
ipv6 access-list capirca-test-v6
<SNIP>

Generated:

no ip access-list extended capirca-test
ip access-list extended capirca-test
<SNIP>
no ipv6 access-list capirca-test
ipv6 access-list capirca-test
<SNIP>

What version of the product are you using? On what operating system?

capirca-r245 on Xubuntu 14.04

Please provide any additional information below.

IOS 12.2(55)SE6 error:

Access-list type conflicts with prior definition
% A named extended IP access list with this name already exists

Changing the string on 711 and 712 of lib/cisco.py to %s-v6, making sure the 
name it generates for the IPv6 access-list differs from the extended 
access-list name.

Original issue reported on code.google.com by [email protected] on 2 Apr 2015 at 9:15

Outdated entries in BOGON list

What steps will reproduce the problem?
1. Look at def/NETWORK.net
2. Under BOGONS 1.0.0.0/8 is incorrectly listed as this netblock has been 
allocated by IANA:

http://www.iana.org/assignments/ipv4-address-space/ipv4-address-space.txt

Please check the BOGON list periodically for outdated entries.

Thanks,

Sebastian

Original issue reported on code.google.com by [email protected] on 22 Jul 2010 at 11:29

Missing support for ICMP policies in SRX generator

What steps will reproduce the problem?
1. Create a term in an SRX policy
2. Add icmp / icmp-type

term permit-web-services {
  destination-address:: WEB_SERVERS
  destination-port:: WEB_SERVICES
  protocol:: icmp
  icmp-type:: echo-request echo-reply
  action:: accept
}

3. Run aclgen

What is the expected output? What do you see instead?
Expected output:
policy permit-ping {
  match {
    source-address any;
    destination-address WEB_SERVERS;
    application [ icmp-echo-request icmp-echo-response ];
  }
  then {
    permit;
  }
}

application icmp-echo-request {
  term icmp-echo-request protocol icmp icmp-type 8 icmp-code 0 inactivity-timeout 60;
}
application icmp-echo-response {
  term icmp-echo-request protocol icmp icmp-type 0 icmp-code 0 inactivity-timeout 60;
}

Actual output for me without specifying "icmp-type" was this:

policy permit-ping {
  match {
    source-address any;
    destination-address WEB_SERVERS;
    application any;
  }
  then {
    permit;
  }
} 

Original issue reported on code.google.com by [email protected] on 21 Mar 2012 at 9:43

speedway does now accept inet6 token

What steps will reproduce the problem?
1. Generate a policy using token inet6:
header {
  target:: speedway INPUT DROP inet6
}
term deny-all-in {
  comment:: "Clean up rule for INPUT chain"
  logging:: syslog
  action:: deny
}

2. Generate policy using aclgen.py

What is the expected output? What do you see instead?
Expect to render a filter with IPv6 addresses to be used by ip6tables-restore.
 The above example is extremely simple so no special IPv6 filter is expected - just a policy to drop all IPv6 traffic. Instead get the following error:

Traceback (most recent call last):
  File "./aclgen.py", line 172, in <module>
    main()
  File "./aclgen.py", line 152, in main
    count = load_and_render(FLAGS.policy_directory, defs)
  File "./aclgen.py", line 69, in load_and_render
    defs))
  File "./aclgen.py", line 125, in render_filters
    fw = speedway.Speedway(spd)
  File "/home/jorge/Downloads/capirca/lib/aclgenerator.py", line 237, in __init__
    self._TranslatePolicy(pol)
  File "/home/jorge/Downloads/capirca/lib/iptables.py", line 618, in _TranslatePolicy
    filter_options))
lib.iptables.UnsupportedFilterError: 
May only specify one of ['inet', 'inet6'] in filter options: ['DROP', 'inet6']


What version of the product are you using? On what operating system?
Using capirca-r168. Tested on Ubuntu 11.10 and CentOS 6.2.

Please provide any additional information below.
n/a

Original issue reported on code.google.com by [email protected] on 19 Mar 2012 at 7:43

icmp-type usage for iptables has no effect

What steps will reproduce the problem?
1. Define an iptables policy and include the snippet below.

term allow-safe-icmp {
  protocol:: icmp
  icmp-type:: echo-request
  action:: accept
}

2. Run aclgen
3. Verify that icmp-type is seemingly ignored.  The generated rule allows
all inbound ICMP, which is incorrect.

-N allow-safe-icmp
-A allow-safe-icmp -p icmp -j ACCEPT
-A INPUT -j allow-safe-icmp

What is the expected output? What do you see instead?

I would expect to see the following as possible output instead.

-N allow-safe-icmp
-A allow-safe-icmp -p icmp --icmp-type echo-request -j ACCEPT
-A INPUT -j allow-safe-icmp

Please use labels and text to provide additional information.

bug, iptables, icmp, echo-request

Original issue reported on code.google.com by [email protected] on 26 Apr 2010 at 6:31

"established" option should allow "all" as a protocol parameter, at least for iptables definitions

What steps will reproduce the problem?
1. This is a valid command "iptables -A INPUT -p all -m state --state
ESTABLISHED,RELATED -j ACCEPT"

2. capirca will not allow us to generate this though.

term allow-established-all {
  option:: established
  protocol:: all
  action:: accept
}

3. $ ./aclgen.py
Traceback (most recent call last):
  File "./aclgen.py", line 139, in <module>
    main()
  File "./aclgen.py", line 135, in main
    parse_policies(policies_to_render, defs)
  File "./aclgen.py", line 100, in parse_policies
    p = policy.ParsePolicy(open(pol).read(), defs)
  File "/home/khermansen/projects/capirca-read-only.mt.2/lib/policy.py",
line 1240, in ParsePolicy
    return yacc.parse(data)
  File
"/home/khermansen/projects/capirca-read-only.mt.2/third_party/ply/yacc.py",
line 265, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File
"/home/khermansen/projects/capirca-read-only.mt.2/third_party/ply/yacc.py",
line 971, in parseopt_notrack
    p.callable(pslice)
  File "/home/khermansen/projects/capirca-read-only.mt.2/lib/policy.py",
line 987, in p_target
    p[0] = Policy(p[2], p[3])
  File "/home/khermansen/projects/capirca-read-only.mt.2/lib/policy.py",
line 123, in __init__
    self.AddFilter(header, terms)
  File "/home/khermansen/projects/capirca-read-only.mt.2/lib/policy.py",
line 128, in AddFilter
    self._TranslateTerms(terms)
  File "/home/khermansen/projects/capirca-read-only.mt.2/lib/policy.py",
line 155, in _TranslateTerms
    term.name))
lib.policy.TermPortProtocolError: no destination ports of the correct
protocol for term allow-established


What is the expected output? What do you see instead?

Expected output should be a correct .ipt file with the proper definitions
including a line such as "-A INPUT -p all -m state --state
ESTABLISHED,RELATED -j ACCEPT"

Please use labels and text to provide additional information.

At this time, capirca's current limitation allows protocols such as tcp/udp
to work with established connection, but not with protocols such as icmp. 
So, a simple scenario is that there is a default DROP policy on INPUT. 
However, when user attempts ICMP ECHO REQUEST from local machine, the ICMP
ECHO REPLY will be dropped.  capirca should allow all protocols with the
"established" option so that such issues like this are easily resolved.

Original issue reported on code.google.com by [email protected] on 26 Apr 2010 at 1:03

TypeError in warning for mismatched ports/protocols

In revision r133 in file lib/policy.py the warning for mismatched 
ports/protocols was broken. There was a comma lost between the last two 
parameters to the % operator in line 120:

https://code.google.com/p/capirca/source/diff?spec=svn141&r=133&format=side&path
=/trunk/lib/policy.py&old_path=/trunk/lib/policy.py&old=132

Right now this piece of code crashes with:

Traceback (most recent call last):
  File "./aclgen.py", line 140, in ?
    main()
  File "./aclgen.py", line 127, in main
    count = render_filters(FLAGS.policy, policy.ParsePolicy(open(FLAGS.policy).read(), defs))
  File "/home/nms/devel/capirca/src/lib/policy.py", line 1480, in ParsePolicy
    return p.parse(preprocessed_data, lexer=lexer)
  File "/home/nms/devel/capirca/capirca/third_party/ply/yacc.py", line 265, in parse
  File "/home/nms/devel/capirca/capirca/third_party/ply/yacc.py", line 971, in parseopt_notrack
  File "/home/nms/devel/capirca/src/lib/policy.py", line 1101, in p_target
    p[0] = Policy(p[2], p[3])
  File "/home/nms/devel/capirca/src/lib/policy.py", line 147, in __init__
    self.AddFilter(header, terms)
  File "/home/nms/devel/capirca/src/lib/policy.py", line 152, in AddFilter
    self._TranslateTerms(terms)
  File "/home/nms/devel/capirca/src/lib/policy.py", line 178, in _TranslateTerms
    term.protocol, term.name)
  File "/home/nms/devel/capirca/src/lib/policy.py", line 117, in TranslatePorts
    logging.warn('%s %s %s %s %s %s %s%s' % (
TypeError: not enough arguments for format string


Also, the string template should be changed to:
'%s %s %s %s %s %s%s %s'

to prevent an extra space before the comma.


Original issue reported on code.google.com by [email protected] on 7 Aug 2011 at 4:02

icmp application definitions are not ordered correctly

What steps will reproduce the problem?

Policy (snippet):

term accept-1 {
  comment:: "policy 1"
  source-address:: SRC_NET
  protocol:: icmp
  icmp-type:: echo-request echo-reply
  action:: accept
}

term accept-2 {
  comment:: "policy 2"
  source-address:: SRC_NET
  action:: accept
}

Generated (snippet):

            /*
            policy 1
            */
            policy accept-1 {
                match {
                    source-address [ SRC_NET ];
                    destination-address any;
                    application any;
                }
                then {
                    permit;
                }
            }
set applications application accept-1-app icmp-type 0
set applications application accept-1-app icmp-type 8
            /*
            policy 2
            */
            policy accept-2 {
                match {
                    source-address [ SRC_NET ];
                    destination-address any;
                    application any;
                }
                then {
                    permit;
                }
            }

What is the expected output? What do you see instead?

The ICMP applications are set right after the policy itself. Instead, they 
should be placed at the end of the output with the rest in the "applications" 
section.

Original issue reported on code.google.com by [email protected] on 10 Apr 2012 at 9:15

Cisco ASA generator

Here is a patch to add a 'ciscoasa' language generator. It is very basic
but works for us. Sorry to abuse the bug tracking system to submit a patch,
I could not find a better way.

Find attached the patch against SVN v91. 

   Antonio

Original issue reported on code.google.com by [email protected] on 8 May 2010 at 12:02

Attachments:

Add Cisco Nexus support

Cisco Nexus series is currently unsupported. With sed I can change most of the 
problematic ace's, but it would be great if it could be included natively.

Original issue reported on code.google.com by [email protected] on 27 May 2015 at 8:12

Tests failing after last couple of commits, need to work on export process

I am aware that a couple of tests are failing currently. I will fix these soon unless someone else gets to them first. These seem to have been introduced in part due to our process in exporting changes. I need to investigate what went wrong and how we can fix this so it does not happen again.

ERROR: testHopLimit (capirca.tests.juniper_test.JuniperTest)

Traceback (most recent call last):
File "/usr/local/google/home/robankeny/Desktop/capirca/tests/juniper_test.py", line 508, in testHopLimit
self.naming), EXP_INFO)
File "/usr/local/lib/python2.7/dist-packages/capirca-1.109-py2.7.egg/lib/policy.py", line 2158, in ParsePolicy
return p.parse(preprocessed_data, lexer=lexer)
File "/usr/lib/python2.7/dist-packages/ply/yacc.py", line 269, in parse
return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
File "/usr/lib/python2.7/dist-packages/ply/yacc.py", line 1051, in parseopt_notrack
tok = self.errorfunc(errtoken)
File "/usr/local/lib/python2.7/dist-packages/capirca-1.109-py2.7.egg/lib/policy.py", line 2035, in p_error
% (p.value, p.type, p.lineno, use_token))
ParseError: ERROR on "hop-limit" (type STRING, line 7, Next ':')

ERROR: testHopLimitRange (capirca.tests.policy_test.PolicyTest)

Traceback (most recent call last):
File "/usr/local/google/home/robankeny/Desktop/capirca/tests/policy_test.py", line 538, in testHopLimitRange
ret = policy.ParsePolicy(pol, self.naming)
File "/usr/local/lib/python2.7/dist-packages/capirca-1.109-py2.7.egg/lib/policy.py", line 2158, in ParsePolicy
return p.parse(preprocessed_data, lexer=lexer)
File "/usr/lib/python2.7/dist-packages/ply/yacc.py", line 269, in parse
return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
File "/usr/lib/python2.7/dist-packages/ply/yacc.py", line 1051, in parseopt_notrack
tok = self.errorfunc(errtoken)
File "/usr/local/lib/python2.7/dist-packages/capirca-1.109-py2.7.egg/lib/policy.py", line 2035, in p_error
% (p.value, p.type, p.lineno, use_token))
ParseError: ERROR on "hop-limit" (type STRING, line 9, Next ':')

ERROR: testHopLimitSingle (capirca.tests.policy_test.PolicyTest)

Traceback (most recent call last):
File "/usr/local/google/home/robankeny/Desktop/capirca/tests/policy_test.py", line 531, in testHopLimitSingle
ret = policy.ParsePolicy(pol, self.naming)
File "/usr/local/lib/python2.7/dist-packages/capirca-1.109-py2.7.egg/lib/policy.py", line 2158, in ParsePolicy
return p.parse(preprocessed_data, lexer=lexer)
File "/usr/lib/python2.7/dist-packages/ply/yacc.py", line 269, in parse
return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
File "/usr/lib/python2.7/dist-packages/ply/yacc.py", line 1051, in parseopt_notrack
tok = self.errorfunc(errtoken)
File "/usr/local/lib/python2.7/dist-packages/capirca-1.109-py2.7.egg/lib/policy.py", line 2035, in p_error
% (p.value, p.type, p.lineno, use_token))
ParseError: ERROR on "hop-limit" (type STRING, line 9, Next ':')

ERROR: testTermNameConflict (capirca.tests.packetfilter_test.PacketFilterTest)

Traceback (most recent call last):
File "/usr/local/google/home/robankeny/Desktop/capirca/tests/packetfilter_test.py", line 701, in testTermNameConflict
packetfilter.DuplicateTermError,
AttributeError: 'module' object has no attribute 'DuplicateTermError'


Ran 436 tests in 29.282s

generator outputs default "-P FORWARD DROP" policy for iptables even if not specified

What steps will reproduce the problem?
1. Create basic policy with a header for INPUT, OUTPUT, and FORWARD.
2. Do not specify the default DROP/ACCEPT in the header.
3. Run generator.
4. Notice that the output .ipt file has this in it.

-P FORWARD DROP

What is the expected output? What do you see instead?

Expected Output:
No "-P FORWARD" entry at all in the file

Witnessed Output:
-P FORWARD DROP

Please use labels and text to provide additional information.

drop, forward, policy, default, iptables. ipt, generator

Original issue reported on code.google.com by [email protected] on 26 Apr 2010 at 9:36

migrate away from mox towards mock

We should be moving away from using mox as a unit test framework and instead rewrite them to use mock (https://docs.python.org/3/library/unittest.mock.html). The unit tests based on mock are easier to read and write and gets rid of the "record functionality / replay" weirdness.

If there's consensus we want to migrate away from mox, I'm happy to start but I didn't want to invest time unless we agree it makes sense...

Thoughts?

General NAT support as an action in the framework

Capirca does not support NAT so far from what I can tell. Some ACLs (e.g. PF, 
Aruba) allow NAT as an action:

PF example:
pass out on tl0 from 192.168.1.0/24 to any nat-to $ext_ip
(http://www.openbsd.org/faq/pf/nat.html)

Aruba example:
user any some-service dst-nat 8888


To be able to use these features, Capirca as a framework should have support 
for this. I suggest adding "NAT" as an action and within options or another new 
"nat" (?) parameter, allow specifying what NAT type it should use and what NAT 
pool, port, IP and whatnot.

Original issue reported on code.google.com by [email protected] on 17 Jul 2012 at 9:05

SRX conflicting entry

If 2 different sections (from/to zones) have a term named the same way, for example:

header {
    target:: srx from-zone a to-zone b    }
    term pbx--sip {
 [...]
        }
header {
    target:: srx from-zone c to-zone b
    }
    term pbx--sip {
 [...]
        }

Capirca will fail with the following error:

Traceback (most recent call last):
  File "aclgen.py", line 498, in <module>
    main(FLAGS(sys.argv))
  File "aclgen.py", line 461, in main
    FLAGS.exp_info, write_files)
  File "aclgen.py", line 322, in RenderFile
    input_file, sys.exc_info()[0], sys.exc_info()[1]))
__main__.ACLGeneratorError: Error generating target ACL for policies/pol/offices_srx_base_policies-global.pol:
<class 'lib.junipersrx.ConflictingApplicationSets'>Application set pbx--sip has a conflicting entry

Missing dependencies ipaddr and gflags

I believe there's a broken dependency introduced as at "Sync internal and external repositories":

commit d450b92ce4efc3943a8176f56ad767c90670ea0a
... snip ...
    Sync internal and external repositories.
... snip ...
+import ipaddr
-from third_party import ipaddr

ipaddr isn't included in requirements.txt.

Running a test, eg, gives the following:

(venv) ~/Documents/Projects/capirca$ python -m tests.naming_test
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/Users/jzohrab/Documents/Projects/capirca/tests/naming_test.py", line 22, in <module>
    from lib import nacaddr
  File "lib/nacaddr.py", line 20, in <module>
    import ipaddr
ImportError: No module named ipaddr

SRX generator creates terms with "protocol" statement which is not supported by the SRX platform

What steps will reproduce the problem?
1. Create a policy like this one:

header {
  target:: srx from-zone trust to-zone untrust
}

term accept-icmp {
  protocol:: icmp
  action:: accept
}

term accept-tcp {
  protocol:: tcp
  action:: accept
}

2. Run the generator

What is the expected output?

security {
    zones {
    }
    policies {
        from-zone trust to-zone untrust {
            policy accept-icmp {
                match {
                    source-address any;
                    destination-address any;
                    application accept-icmp-app;
                }
                then {
                    permit;
                }
            }
            policy accept-tcp {
                match {
                    source-address any;
                    destination-address any;
                    application accept-tcp-app;
                }
                then {
                    permit;
                }
            }
        }
    }
}
applications {
    application accept-icmp-app {
        term t1 protocol icmp; # equals to "junos-icmp-all"
    }
    application accept-tcp-app {
        term t1 protocol tcp; # equals to "junos-tcp-any"
    }
}


What do you see instead?

security {
    zones {
    }
    policies {
        from-zone trust to-zone untrust {
            policy accept-icmp {
                match {
                    source-address any;
                    destination-address any;
                    protocol icmp;
                }
                then {
                    permit;
                }
            }
            policy accept-tcp {
                match {
                    source-address any;
                    destination-address any;
                    protocol tcp;
                }
                then {
                    permit;
                }
            }
        }
    }
}
applications {
}

Original issue reported on code.google.com by [email protected] on 6 Jun 2012 at 8:41

Patch for /trunk/lib/junipersrx.py

This patch adds support of global policies and address book on Juniper SRXs.

I tried to do it the cleanest way possible, please let me know how I can 
improve it if needed.

To use it add the keyword "global_address_book" to the target line in _all_ 
your headers (as you can't have both per zone and global address-book).

header {
  comment:: "Generated by Capirca"
  target:: srx from-zone corp to-zone vpn global_address_book
}

If you need to add the "global { }" policies block do:

header {
  comment:: "Generated by Capirca"
  target:: srx from-zone global_policies to-zone global_policies global_address_book
}

Thanks!

Original issue reported on code.google.com by xionox on 30 Oct 2014 at 1:35

Attachments:

RFC6598 (100.64.0.0/10) not in RESERVED list in NETWORK.net

100.64.0.0/10 was a IANA special allocation in 2012 and is documented in RFC6598

Shared Address Space is distinct from RFC 1918 private address space
because it is intended for use on Service Provider networks.
However, it may be used in a manner similar to RFC 1918 private
address space on routing equipment

Given this space is considered by most operators as equivalent to RFC1918, mainly for the purposes of CGN, I believe this should be included in the default NETWORK.net definitions.

Cisco generator fails to process tcp-established option properly

What steps will reproduce the problem?
1. Create a rule with protocol:: tcp and option:: tcp-established
2. Generate a cisco ACL with aclgen.py

What is the expected output? What do you see instead?

expected: something like permit 6 any  192.168.0.0 0.0.0.255  established
received: something like permit 6 any  192.168.0.0 0.0.0.255

What version of the product are you using? On what operating system?

This applies to 1.0 and svn rev 74.

Please provide any additional information below.

Patch to fix:

Index: lib/cisco.py
===================================================================
--- lib/cisco.py        (revision 74)
+++ lib/cisco.py        (working copy)
@@ -383,7 +383,7 @@
     # options
     extra_options = []
     for opt in [str(x) for x in self.term.option]:
-      if opt.find('tcp-established') == 0 and 6 in self.term.protocol:
+      if opt.find('tcp-established') == 0 and 6 in protocol:
         extra_options.append('established')
         self.term.option.remove('tcp-established')
       elif opt.find('established') == 0:

Cause: 'self.term.protocol' does not have cisco.FixupProtocol() applied;
the local variable 'protocol' has the post-fixup protocol list.

Original issue reported on code.google.com by [email protected] on 3 Dec 2009 at 6:23

General "user" support as a source/destination in the framework

Capirca does not support src/dst other than IPs/networks. Some platforms allow 
ACLs to specify sr/dst as "user" which is then interpreted by the platform 
itself.

Aruba example:
user any any permit


I am not sure if it is feasible to support this but this needs support by the 
Capirca framework itself before it can be used in one of the generators.
I tend to think that it could either be directly in the "source" and 
"destination" parameters or in new ones, depending on how easy it is to 
differentiate "user" from possible definition names.

Another similar thing is support for interface names or groups (e.g. as in PF: 
http://www.openbsd.org/faq/pf/filter.html).

Original issue reported on code.google.com by [email protected] on 17 Jul 2012 at 9:13

IPv4 and IPv6 rules in ACL mixed up

What steps will reproduce the problem?
1. run aclgen.py

What is the expected output? What do you see instead?
Expected an filter/sample.acl with IPv6-in-/outbound and IPv4in-/outbound- 
acl's grouped together.
What I see is an filter/sample.acl were IPv6 rules appear under "ip access-list 
extended edge-inbound". And IPv4 rules under "ipv6 access-list edge-inbound"
The same for "ip access-list extended edge-outbound" and "ipv6 access-list 
edge-outbound"

What version of the product are you using? On what operating system?
capirca rev 112 (Ubuntu 10.4)

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 27 Apr 2011 at 10:57

aclcheck does not accept options

What steps will reproduce the problem?
The wiki page describes the commandline options for the command
'aclcheck.py'. lib/aclcheck.py does not accepts any commandline options.

What is the expected output? What do you see instead?
Expected a program (aclcheck.py) in the root install dir which accepts
commandline options as described in the wikepage.

What version of the product are you using? On what operating system?
svn rev 98, ubuntu 9.10

Please provide any additional information below.
Attached aclcheck_run.py that does the job. Please note: I am not an
experienced programmer and with no python experience at all, so any
improvement is appreciated.


Original issue reported on code.google.com by [email protected] on 4 Jun 2010 at 12:26

Attachments:

Cisco does not support IPv6 Protocol numbers

What steps will reproduce the problem?
1. Generate a policy that references IPv6 ICMP packets:
header {
    target:: cisco iACL-V6 inet6
}

term permit-icmp {
    comment:: "Permit all ICMP traffic"
    protocol:: icmp
    action:: accept
}

2. Attempt to load generated filter file into a router:
no ipv6 access-list iACL-V6
ipv6 access-list iACL-V6
remark $Id:$
remark $Date:$

remark permit-icmp
remark Permit all ICMP traffic
 permit 1 any  any

3. Apply ACL to interface:
interface g0/0
 ipv6 traffic-filter iACL-V6 in



What is the expected output? What do you see instead?
Expect generated ACL to allow all IPv6 ICMP packets when applied to an 
interface.  Line does not match ICMP packets, and the packets are denied.  

What version of the product are you using? On what operating system?
Tested on both IOS 12.2(33)SXI1 and IOS 15.1(3)T.

Please provide any additional information below.
It appears that Cisco IOS does not correctly handle Protocol #s in IPv6 
access-lists.  Manually creating a "permit icmp any any" rule works as 
expected.  I have not tested with other protocol numbers, but would expect the 
handling to be similar.  I cannot find any reference to this limitation in the 
documentation, or in the Bug tracker.

Is there a flag to force protocol names instead of numbers in the cisco ACL 
processor?


Original issue reported on code.google.com by [email protected] on 24 Feb 2011 at 8:37

Multiprotocol terms ignore protocol in service definiations

What steps will reproduce the problem?
1. Create a service destination with multiple protocols
FOO = 10123/tcp 10456/udp

2. Create a term that references the service and lists multiple protocols
term test {
  destination-port:: FOO
  protocol:: tcp
  protocol:: udp
  action:: accept
}

3. Generate filters
python aclgen.py

What is the expected output? What do you see instead?

I would expect to see something like (using Cisco ACLs in this example):
  remark test
   permit tcp any any eq 10123
   permit udp any any eq 10456

Instead I see the following (both ports used with both protocols)
  remark test
   permit tcp any any eq 10123
   permit udp any any eq 10123
   permit tcp any any eq 10456
   permit udp any any eq 10456

What version of the product are you using? On what operating system?
Capirca SVN r92 - Mac OS X 10.6.3

Please provide any additional information below.

The selection of tcp or udp ports form a service definition that includes
both appears to work fine when a single protocol is specified in the term.

Original issue reported on code.google.com by [email protected] on 24 May 2010 at 10:37

policies with multiple "." in filename generate incorrect filter output name

What steps will reproduce the problem?
1. Copy the sample policy to another name having multiple dots in filename.

$ cp sample.pol sample.foo.pol

2. Run the generator.

$ ./aclgen.py

3. Verify that the file name does not include anything after the first dot.
 If you had two files names named similarly, one would be overwritten by
the other, resulting in only one policy instead of two generated.

Affected source code line is here:

fname = '%s%s' % (os.path.basename(input_file).split('.')[0], pol._SUFFIX)

What is the expected output? What do you see instead?

Expect to see:
$ ./aclgen.py 
writing ./filters/sample.foo.jcl
writing ./filters/sample.foo.acl
writing ./filters/sample.foo.ipt

Actually see:
$ ./aclgen.py 
writing ./filters/sample.jcl
writing ./filters/sample.ipt
writing ./filters/sample.acl

Please use labels and text to provide additional information.

dotfile, dotfiles, period, dots, dot

Original issue reported on code.google.com by [email protected] on 26 Apr 2010 at 8:08

Product roadmap or wishlist (from source maintainers)?

I've contributed a few small PRs to Capirca, including one still pending ๐Ÿ˜€ , and would like to contribute more, as I'm recommending that my networking colleagues use Capirca for ACL management.

I'd like to contribute more towards Capirca in the hopes that it will result in a better experience for my team, but don't want to change anything if a) the Capirca team is already working on it, or b) these changes will be incompatible with the release that I know your team is aiming for.

Is there a roadmap, or even a list of wished-for refactoring that the team has long wanted to do? If so, I can contribute to that, as any refactoring/cleanup that benefits you and the community will also help out me and my team.

Regards,
jz

Cisco object-group ACL not generating as expected

What steps will reproduce the problem?

1. Use the included NETWORK.net & SERVICES.svc definition files included & the 
attached policy file, test_cisco_object_group.pol.

2. Run aclgen.py on this policy file:

./aclgen.py -d def -p policies/test_cisco_object_group.pol -o output

3. Review the output file.

What is the expected output? What do you see instead?

I've attached the generated output file, test_cisco_object_group.acl.  It 
creates an object group for GOOGLE_DNS:

object-group ip address GOOGLE_DNS
 8.8.4.4 255.255.255.255
 8.8.8.8 255.255.255.255
exit

But when actually writing the ACL, it uses the IP addresses for the addgroup 
instead of the object group name:

 permit 17 addrgroup 0.0.0.0/0  addrgroup 8.8.4.4/32 portgroup 53-53
 permit 17 addrgroup 0.0.0.0/0  addrgroup 8.8.8.8/32 portgroup 53-53
 permit 17 addrgroup 0.0.0.0/0  addrgroup 2001:4860:4860::8844/128 portgroup 53-53
 permit 17 addrgroup 0.0.0.0/0  addrgroup 2001:4860:4860::8888/128 portgroup 53-53

It also uses a 0.0.0.0/0 address group which isn't a defined object group (I 
would expect it to just use the keyword any).

What version of the product are you using? On what operating system?

SVN revision 259 on OS X 10.6.8 (Python 2.7.1).

Original issue reported on code.google.com by [email protected] on 30 Oct 2014 at 9:23

Attachments:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.