# salt.states.panos

A state module to manage Palo Alto network devices.

codeauthor:

  `Spencer Ervin <spencer_ervin@hotmail.com>`

maturity:

  new

depends:

  none

platform:

  unix

## About

This state module was designed to handle connections to a Palo Alto based firewall. This module relies on the Palo Alto proxy module to interface with the devices.

This state module is designed to give extreme flexibility in the control over XPATH values on the PANOS device. It exposes the core XML API commands and allows state modules to chain complex XPATH commands.

Below is an example of how to construct a security rule and move to the top of the policy. This will take a config lock to prevent execution during the operation, then remove the lock. After the XPATH has been deployed, it will commit to the device.

    panos/takelock:
        panos.add_config_lock
    panos/service_tcp_22:
        panos.set_config:
            - xpath: /config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='vsys1']/service
            - value: <entry name='tcp-22'><protocol><tcp><port>22</port></tcp></protocol></entry>
            - commit: False
    panos/create_rule1:
        panos.set_config:
            - xpath: /config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='vsys1']/rulebase/security/rules
            - value: '
              <entry name="rule1">
                <from><member>trust</member></from>
                <to><member>untrust</member></to>
                <source><member>10.0.0.1</member></source>
                <destination><member>10.0.1.1</member></destination>
                <service><member>tcp-22</member></service>
                <application><member>any</member></application>
                <action>allow</action>
                <disabled>no</disabled>
              </entry>'
            - commit: False
    panos/moveruletop:
        panos.move_config:
            - xpath: /config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='vsys1']/rulebase/security/rules/entry[@name='rule1']
            - where: top
            - commit: False
    panos/removelock:
        panos.remove_config_lock
    panos/commit:
        panos.commit_config

## Version Specific Configurations

Palo Alto devices running different versions will have different supported features and different command structures. In order to account for this, the proxy module can be leveraged to check if the panos device is at a specific revision level.

The proxy['panos.is_required_version'] method will check if a panos device is currently running a version equal or greater than the passed version. For example, proxy['panos.is_required_version']('7.0.0') would match both 7.1.0 and 8.0.0.

    {% if proxy['panos.is_required_version']('8.0.0') %}
    panos/deviceconfig/system/motd-and-banner:
      panos.set_config:
        - xpath: /config/devices/entry[@name='localhost.localdomain']/deviceconfig/system/motd-and-banner
        - value: |
          <banner-header>BANNER TEXT</banner-header>
          <banner-header-color>color2</banner-header-color>
          <banner-header-text-color>color18</banner-header-text-color>
          <banner-header-footer-match>yes</banner-header-footer-match>
        - commit: False
    {% endif %}

See also

`Palo Alto Proxy Module`

salt.states.panos.add_config_lock(name)

  Prevent other users from changing configuration until the lock is released.

  name: The name of the module function to execute.

  SLS Example:

      panos/takelock:
          panos.add_config_lock

salt.states.panos.address_exists(name, addressname=None, vsys=1, ipnetmask=None, iprange=None, fqdn=None, description=None, commit=False)

  Ensures that an address object exists in the configured state. If it does not exist or is not configured with the specified attributes, it will be adjusted to match the specified values.

  This module will only process a single address type (ip-netmask, ip-range, or fqdn). It will process the specified value if the following order: ip-netmask, ip-range, fqdn. For proper execution, only specify a single address type.

  name: The name of the module function to execute.

  addressname(str): The name of the address object. The name is case-sensitive and can have up to 31 characters, which an be letters, numbers, spaces, hyphens, and underscores. The name must be unique on a firewall and, on Panorama, unique within its device group and any ancestor or descendant device groups.

  vsys(str): The string representation of the VSYS ID. Defaults to VSYS 1.

  ipnetmask(str): The IPv4 or IPv6 address or IP address range using the format ip_address/mask or ip_address where the mask is the number of significant binary digits used for the network portion of the address. Ideally, for IPv6, you specify only the network portion, not the host portion.

  iprange(str): A range of addresses using the format ip_address–ip_address where both addresses can be IPv4 or both can be IPv6.

  fqdn(str): A fully qualified domain name format. The FQDN initially resolves at commit time. Entries are subsequently refreshed when the firewall performs a check every 30 minutes; all changes in the IP address for the entries are picked up at the refresh cycle.

  description(str): A description for the policy (up to 255 characters).

  commit(bool): If true the firewall will commit the changes, if false do not commit changes.

  SLS Example:

      panos/address/h-10.10.10.10:
          panos.address_exists:
            - addressname: h-10.10.10.10
            - vsys: 1
            - ipnetmask: 10.10.10.10
            - commit: False

      panos/address/10.0.0.1-10.0.0.50:
          panos.address_exists:
            - addressname: r-10.0.0.1-10.0.0.50
            - vsys: 1
            - iprange: 10.0.0.1-10.0.0.50
            - commit: False

      panos/address/foo.bar.com:
          panos.address_exists:
            - addressname: foo.bar.com
            - vsys: 1
            - fqdn: foo.bar.com
            - description: My fqdn object
            - commit: False

salt.states.panos.address_group_exists(name, groupname=None, vsys=1, members=None, description=None, commit=False)

  Ensures that an address group object exists in the configured state. If it does not exist or is not configured with the specified attributes, it will be adjusted to match the specified values.

  This module will enforce group membership. If a group exists and contains members this state does not include, those members will be removed and replaced with the specified members in the state.

  name: The name of the module function to execute.

  groupname(str): The name of the address group object. The name is case-sensitive and can have up to 31 characters, which an be letters, numbers, spaces, hyphens, and underscores. The name must be unique on a firewall and, on Panorama, unique within its device group and any ancestor or descendant device groups.

  vsys(str): The string representation of the VSYS ID. Defaults to VSYS 1.

  members(str, list): The members of the address group. These must be valid address objects or address groups on the system that already exist prior to the execution of this state.

  description(str): A description for the policy (up to 255 characters).

  commit(bool): If true the firewall will commit the changes, if false do not commit changes.

  SLS Example:

      panos/address-group/my-group:
          panos.address_group_exists:
            - groupname: my-group
            - vsys: 1
            - members:
              - my-address-object
              - my-other-address-group
            - description: A group that needs to exist
            - commit: False

salt.states.panos.clone_config(name, xpath=None, newname=None, commit=False)

  Clone a specific XPATH and set it to a new name.

  name: The name of the module function to execute.

  xpath(str): The XPATH of the configuration API tree to clone.

  newname(str): The new name of the XPATH clone.

  commit(bool): If true the firewall will commit the changes, if false do not commit changes.

  SLS Example:

      panos/clonerule:
          panos.clone_config:
            - xpath: /config/devices/entry/vsys/entry[@name='vsys1']/rulebase/security/rules&from=/config/devices/
            entry/vsys/entry[@name='vsys1']/rulebase/security/rules/entry[@name='rule1']
            - value: rule2
            - commit: True

salt.states.panos.commit_config(name)

  Commits the candidate configuration to the running configuration.

  name: The name of the module function to execute.

  SLS Example:

      panos/commit:
          panos.commit_config

salt.states.panos.delete_config(name, xpath=None, commit=False)

  Deletes a Palo Alto XPATH to a specific value.

  Use the xpath parameter to specify the location of the object to be deleted.

  name: The name of the module function to execute.

  xpath(str): The XPATH of the configuration API tree to control.

  commit(bool): If true the firewall will commit the changes, if false do not commit changes.

  SLS Example:

      panos/deletegroup:
          panos.delete_config:
            - xpath: /config/devices/entry/vsys/entry[@name='vsys1']/address-group/entry[@name='test']
            - commit: True

salt.states.panos.download_software(name, version=None, synch=False, check=False)

  Ensures that a software version is downloaded.

  name: The name of the module function to execute.

  version(str): The software version to check. If this version is not already downloaded, it will attempt to download the file from Palo Alto.

  synch(bool): If true, after downloading the file it will be synched to its peer.

  check(bool): If true, the PANOS device will first attempt to pull the most recent software inventory list from Palo Alto.

  SLS Example:

      panos/version8.0.0:
          panos.download_software:
            - version: 8.0.0
            - synch: False
            - check: True

salt.states.panos.edit_config(name, xpath=None, value=None, commit=False)

  Edits a Palo Alto XPATH to a specific value. This will always overwrite the existing value, even if it is not changed.

  You can replace an existing object hierarchy at a specified location in the configuration with a new value. Use the xpath parameter to specify the location of the object, including the node to be replaced.

  This is the recommended state to enforce configurations on a xpath.

  name: The name of the module function to execute.

  xpath(str): The XPATH of the configuration API tree to control.

  value(str): The XML value to edit. This must be a child to the XPATH.

  commit(bool): If true the firewall will commit the changes, if false do not commit changes.

  SLS Example:

      panos/addressgroup:
          panos.edit_config:
            - xpath: /config/devices/entry/vsys/entry[@name='vsys1']/address-group/entry[@name='test']
            - value: <static><entry name='test'><member>abc</member><member>xyz</member></entry></static>
            - commit: True

salt.states.panos.move_config(name, xpath=None, where=None, dst=None, commit=False)

  Moves a XPATH value to a new location.

  Use the xpath parameter to specify the location of the object to be moved, the where parameter to specify type of move, and dst parameter to specify the destination path.

  name: The name of the module function to execute.

  xpath(str): The XPATH of the configuration API tree to move.

  where(str): The type of move to execute. Valid options are after, before, top, bottom. The after and before options will require the dst option to specify the destination of the action. The top action will move the XPATH to the top of its structure. The botoom action will move the XPATH to the bottom of its structure.

  dst(str): Optional. Specifies the destination to utilize for a move action. This is ignored for the top or bottom action.

  commit(bool): If true the firewall will commit the changes, if false do not commit changes. If the operation is not successful, it will not commit.

  SLS Example:

      panos/moveruletop:
          panos.move_config:
            - xpath: /config/devices/entry/vsys/entry[@name='vsys1']/rulebase/security/rules/entry[@name='rule1']
            - where: top
            - commit: True

      panos/moveruleafter:
          panos.move_config:
            - xpath: /config/devices/entry/vsys/entry[@name='vsys1']/rulebase/security/rules/entry[@name='rule1']
            - where: after
            - dst: rule2
            - commit: True

salt.states.panos.remove_config_lock(name)

  Release config lock previously held.

  name: The name of the module function to execute.

  SLS Example:

      panos/takelock:
          panos.remove_config_lock

salt.states.panos.rename_config(name, xpath=None, newname=None, commit=False)

  Rename a Palo Alto XPATH to a specific value. This will always rename the value even if a change is not needed.

  name: The name of the module function to execute.

  xpath(str): The XPATH of the configuration API tree to control.

  newname(str): The new name of the XPATH value.

  commit(bool): If true the firewall will commit the changes, if false do not commit changes.

  SLS Example:

      panos/renamegroup:
          panos.rename_config:
            - xpath: /config/devices/entry/vsys/entry[@name='vsys1']/address/entry[@name='old_address']
            - value: new_address
            - commit: True

salt.states.panos.security_rule_exists(name, rulename=None, vsys='1', action=None, disabled=None, sourcezone=None, destinationzone=None, source=None, destination=None, application=None, service=None, description=None, logsetting=None, logstart=None, logend=None, negatesource=None, negatedestination=None, profilegroup=None, datafilter=None, fileblock=None, spyware=None, urlfilter=None, virus=None, vulnerability=None, wildfire=None, move=None, movetarget=None, commit=False)

  Ensures that a security rule exists on the device. Also, ensure that all configurations are set appropriately.

  This method will create the rule if it does not exist. If the rule does exist, it will ensure that the configurations are set appropriately.

  If the rule does not exist and is created, any value that is not provided will be provided as the default. The action, to, from, source, destination, application, and service fields are mandatory and must be provided.

  This will enforce the exact match of the rule. For example, if the rule is currently configured with the log-end option, but this option is not specified in the state method, it will be removed and reset to the system default.

  It is strongly recommended to specify all options to ensure proper operation.

  When defining the profile group settings, the device can only support either a profile group or individual settings. If both are specified, the profile group will be preferred and the individual settings are ignored. If neither are specified, the value will be set to system default of none.

  name: The name of the module function to execute.

  rulename(str): The name of the security rule. The name is case-sensitive and can have up to 31 characters, which can be letters, numbers, spaces, hyphens, and underscores. The name must be unique on a firewall and, on Panorama, unique within its device group and any ancestor or descendant device groups.

  vsys(str): The string representation of the VSYS ID. Defaults to VSYS 1.

  action(str): The action that the security rule will enforce. Valid options are: allow, deny, drop, reset-client, reset-server, reset-both.

  disabled(bool): Controls if the rule is disabled. Set 'True' to disable and 'False' to enable.

  sourcezone(str, list): The source zone(s). The value 'any' will match all zones.

  destinationzone(str, list): The destination zone(s). The value 'any' will match all zones.

  source(str, list): The source address(es). The value 'any' will match all addresses.

  destination(str, list): The destination address(es). The value 'any' will match all addresses.

  application(str, list): The application(s) matched. The value 'any' will match all applications.

  service(str, list): The service(s) matched. The value 'any' will match all services. The value 'application-default' will match based upon the application defined ports.

  description(str): A description for the policy (up to 255 characters).

  logsetting(str): The name of a valid log forwarding profile.

  logstart(bool): Generates a traffic log entry for the start of a session (disabled by default).

  logend(bool): Generates a traffic log entry for the end of a session (enabled by default).

  negatesource(bool): Match all but the specified source addresses.

  negatedestination(bool): Match all but the specified destination addresses.

  profilegroup(str): A valid profile group name.

  datafilter(str): A valid data filter profile name. Ignored with the profilegroup option set.

  fileblock(str): A valid file blocking profile name. Ignored with the profilegroup option set.

  spyware(str): A valid spyware profile name. Ignored with the profilegroup option set.

  urlfilter(str): A valid URL filtering profile name. Ignored with the profilegroup option set.

  virus(str): A valid virus profile name. Ignored with the profilegroup option set.

  vulnerability(str): A valid vulnerability profile name. Ignored with the profilegroup option set.

  wildfire(str): A valid vulnerability profile name. Ignored with the profilegroup option set.

  move(str): An optional argument that ensure the rule is moved to a specific location. Valid options are 'top', 'bottom', 'before', or 'after'. The 'before' and 'after' options require the use of the 'movetarget' argument to define the location of the move request.

  movetarget(str): An optional argument that defines the target of the move operation if the move argument is set to 'before' or 'after'.

  commit(bool): If true the firewall will commit the changes, if false do not commit changes.

  SLS Example:

      panos/rulebase/security/rule01:
          panos.security_rule_exists:
            - rulename: rule01
            - vsys: 1
            - action: allow
            - disabled: False
            - sourcezone: untrust
            - destinationzone: trust
            - source:
              - 10.10.10.0/24
              - 1.1.1.1
            - destination:
              - 2.2.2.2-2.2.2.4
            - application:
              - any
            - service:
              - tcp-25
            - description: My test security rule
            - logsetting: logprofile
            - logstart: False
            - logend: True
            - negatesource: False
            - negatedestination: False
            - profilegroup: myprofilegroup
            - move: top
            - commit: False

      panos/rulebase/security/rule01:
          panos.security_rule_exists:
            - rulename: rule01
            - vsys: 1
            - action: allow
            - disabled: False
            - sourcezone: untrust
            - destinationzone: trust
            - source:
              - 10.10.10.0/24
              - 1.1.1.1
            - destination:
              - 2.2.2.2-2.2.2.4
            - application:
              - any
            - service:
              - tcp-25
            - description: My test security rule
            - logsetting: logprofile
            - logstart: False
            - logend: False
            - datafilter: foobar
            - fileblock: foobar
            - spyware: foobar
            - urlfilter: foobar
            - virus: foobar
            - vulnerability: foobar
            - wildfire: foobar
            - move: after
            - movetarget: rule02
            - commit: False

salt.states.panos.service_exists(name, servicename=None, vsys=1, protocol=None, port=None, description=None, commit=False)

  Ensures that a service object exists in the configured state. If it does not exist or is not configured with the specified attributes, it will be adjusted to match the specified values.

  name: The name of the module function to execute.

  servicename(str): The name of the security object. The name is case-sensitive and can have up to 31 characters, which an be letters, numbers, spaces, hyphens, and underscores. The name must be unique on a firewall and, on Panorama, unique within its device group and any ancestor or descendant device groups.

  vsys(str): The string representation of the VSYS ID. Defaults to VSYS 1.

  protocol(str): The protocol that is used by the service object. The only valid options are tcp and udp.

  port(str): The port number that is used by the service object. This can be specified as a single integer or a valid range of ports.

  description(str): A description for the policy (up to 255 characters).

  commit(bool): If true the firewall will commit the changes, if false do not commit changes.

  SLS Example:

      panos/service/tcp-80:
          panos.service_exists:
            - servicename: tcp-80
            - vsys: 1
            - protocol: tcp
            - port: 80
            - description: Hypertext Transfer Protocol
            - commit: False

      panos/service/udp-500-550:
          panos.service_exists:
            - servicename: udp-500-550
            - vsys: 3
            - protocol: udp
            - port: 500-550
            - commit: False

salt.states.panos.service_group_exists(name, groupname=None, vsys=1, members=None, description=None, commit=False)

  Ensures that a service group object exists in the configured state. If it does not exist or is not configured with the specified attributes, it will be adjusted to match the specified values.

  This module will enforce group membership. If a group exists and contains members this state does not include, those members will be removed and replaced with the specified members in the state.

  name: The name of the module function to execute.

  groupname(str): The name of the service group object. The name is case-sensitive and can have up to 31 characters, which an be letters, numbers, spaces, hyphens, and underscores. The name must be unique on a firewall and, on Panorama, unique within its device group and any ancestor or descendant device groups.

  vsys(str): The string representation of the VSYS ID. Defaults to VSYS 1.

  members(str, list): The members of the service group. These must be valid service objects or service groups on the system that already exist prior to the execution of this state.

  description(str): A description for the policy (up to 255 characters).

  commit(bool): If true the firewall will commit the changes, if false do not commit changes.

  SLS Example:

      panos/service-group/my-group:
          panos.service_group_exists:
            - groupname: my-group
            - vsys: 1
            - members:
              - tcp-80
              - custom-port-group
            - description: A group that needs to exist
            - commit: False

salt.states.panos.set_config(name, xpath=None, value=None, commit=False)

  Sets a Palo Alto XPATH to a specific value. This will always overwrite the existing value, even if it is not changed.

  You can add or create a new object at a specified location in the configuration hierarchy. Use the xpath parameter to specify the location of the object in the configuration

  name: The name of the module function to execute.

  xpath(str): The XPATH of the configuration API tree to control.

  value(str): The XML value to set. This must be a child to the XPATH.

  commit(bool): If true the firewall will commit the changes, if false do not commit changes.

  SLS Example:

      panos/hostname:
          panos.set_config:
            - xpath: /config/devices/entry[@name='localhost.localdomain']/deviceconfig/system
            - value: <hostname>foobar</hostname>
            - commit: True