HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/proxy/__pycache__/panos.cpython-310.pyc
o

�N�g�<�@s�dZddlZddlmmZddlZddlm	m
ZdgZddiZ
iZe�e�ZdZdd�Zdd	�Zd
d�Zddd
�Zddd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)a
Proxy Minion interface module for managing Palo Alto firewall devices
=====================================================================

.. versionadded:: 2018.3.0

:codeauthor: ``Spencer Ervin <spencer_ervin@hotmail.com>``
:maturity:   new
:depends:    none
:platform:   unix

This proxy minion enables Palo Alto firewalls (hereafter referred to
as simply 'panos') to be treated individually like a Salt Minion.

The panos proxy leverages the XML API functionality on the Palo Alto
firewall. The Salt proxy must have access to the Palo Alto firewall on
HTTPS (tcp/443).

More in-depth conceptual reading on Proxy Minions can be found in the
:ref:`Proxy Minion <proxy-minion>` section of Salt's
documentation.


Configuration
=============

To use this integration proxy module, please configure the following:

Pillar
------

Proxy minions get their configuration from Salt's Pillar. Every proxy must
have a stanza in Pillar and a reference in the Pillar top-file that matches
the ID. There are four connection options available for the panos proxy module.

- Direct Device (Password)
- Direct Device (API Key)
- Panorama Pass-Through (Password)
- Panorama Pass-Through (API Key)


Direct Device (Password)
------------------------

The direct device configuration configures the proxy to connect directly to
the device with username and password.

.. code-block:: yaml

    proxy:
      proxytype: panos
      host: <ip or dns name of panos host>
      username: <panos username>
      password: <panos password>
      verify_ssl: True

proxytype
^^^^^^^^^

The ``proxytype`` key and value pair is critical, as it tells Salt which
interface to load from the ``proxy`` directory in Salt's install hierarchy,
or from ``/srv/salt/_proxy`` on the Salt Master (if you have created your
own proxy module, for example). To use this panos Proxy Module, set this to
``panos``.

host
^^^^

The location, or ip/dns, of the panos host. Required.

username
^^^^^^^^

The username used to login to the panos host. Required.

password
^^^^^^^^

The password used to login to the panos host. Required.

Direct Device (API Key)
------------------------

Palo Alto devices allow for access to the XML API with a generated 'API key'_
instead of username and password.

.. _API key: https://www.paloaltonetworks.com/documentation/71/pan-os/xml-api/get-started-with-the-pan-os-xml-api/get-your-api-key

.. code-block:: yaml

    proxy:
      proxytype: panos
      host: <ip or dns name of panos host>
      apikey: <panos generated api key>

proxytype
^^^^^^^^^

The ``proxytype`` key and value pair is critical, as it tells Salt which
interface to load from the ``proxy`` directory in Salt's install hierarchy,
or from ``/srv/salt/_proxy`` on the Salt Master (if you have created your
own proxy module, for example). To use this panos Proxy Module, set this to
``panos``.

host
^^^^

The location, or ip/dns, of the panos host. Required.

apikey
^^^^^^

The generated XML API key for the panos host. Required.

Panorama Pass-Through (Password)
--------------------------------

The Panorama pass-through method sends all connections through the Panorama
management system. It passes the connections to the appropriate device using
the serial number of the Palo Alto firewall.

This option will reduce the number of connections that must be present for the
proxy server. It will only require a connection to the Panorama server.

The username and password will be for authentication to the Panorama server,
not the panos device.

.. code-block:: yaml

    proxy:
      proxytype: panos
      serial: <serial number of panos host>
      host: <ip or dns name of the panorama server>
      username: <panorama server username>
      password: <panorama server password>

proxytype
^^^^^^^^^

The ``proxytype`` key and value pair is critical, as it tells Salt which
interface to load from the ``proxy`` directory in Salt's install hierarchy,
or from ``/srv/salt/_proxy`` on the Salt Master (if you have created your
own proxy module, for example). To use this panos Proxy Module, set this to
``panos``.

serial
^^^^^^

The serial number of the panos host. Required.

host
^^^^

The location, or ip/dns, of the Panorama server. Required.

username
^^^^^^^^

The username used to login to the Panorama server. Required.

password
^^^^^^^^

The password used to login to the Panorama server. Required.

Panorama Pass-Through (API Key)
-------------------------------

The Panorama server can also utilize a generated 'API key'_ for authentication.

.. _API key: https://www.paloaltonetworks.com/documentation/71/pan-os/xml-api/get-started-with-the-pan-os-xml-api/get-your-api-key

.. code-block:: yaml

    proxy:
      proxytype: panos
      serial: <serial number of panos host>
      host: <ip or dns name of the panorama server>
      apikey: <panos generated api key>

proxytype
^^^^^^^^^

The ``proxytype`` key and value pair is critical, as it tells Salt which
interface to load from the ``proxy`` directory in Salt's install hierarchy,
or from ``/srv/salt/_proxy`` on the Salt Master (if you have created your
own proxy module, for example). To use this panos Proxy Module, set this to
``panos``.

serial
^^^^^^

The serial number of the panos host. Required.

host
^^^^

The location, or ip/dns, of the Panorama server. Required.

apikey
^^^^^^^^

The generated XML API key for the Panorama server. Required.
�NZpanos�vendorz	Palo AltocCstS)z7
    Only return if all the modules are available.
    )�__virtualname__�rr�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/proxy/panos.py�__virtual__�srcCsD|j�dd�}|r|j�dd�|j�dd�|D]}t|�}q|S)z�
    Removes dirtyID tags from the candidate config result. Palo Alto devices will make the candidate configuration with
    a dirty ID after a change. This can cause unexpected results when parsing.
    ZdirtyIdNZadmin�time)Zattrib�pop�_strip_dirty)ZxmltreeZdirty�childrrrr	�s
r	cCs�d|dvr
t�d�dSd|dvr-d|dvr t�d�dSd|dvr-t�d	�dSd
�|dd�td<|ddtd<|d�dd
�td<d|dvr�|d�d�td<d|dvrrt�d�dtd<|d�d�td<nPt�d�dtd<|d�d�td<|d�d�td<n4d|dvr�t�d�dtd<|d�d�td<nt�d�dtd<|d�d�td<|d�d�td<t�d�ddd�}t|�t�d�d
td<dS)z�
    This function gets called when the proxy starts up. For
    panos devices, a determination is made on the connection type
    and the appropriate connection details that must be cached.
    �host�proxyz-No 'host' key found in pillar for this proxy.F�apikey�usernamez1No 'username' key found in pillar for this proxy.�passwordz2No 'passwords' key found in pillar for this proxy.zhttps://{}/api/�url�
verify_sslT�serialz/Selected pan_key method for panos proxy module.�pan_key�methodz0Selected pan_pass method for panos proxy module.�pan_passz/Selected dev_key method for panos proxy module.�dev_keyz0Selected dev_pass method for panos proxy module.�dev_passz*Attempting to connect to panos proxy host.�op�+<show><system><info></info></system></show>��type�cmdz+Successfully connected to panos proxy host.�initializedN)�log�critical�format�DETAILS�get�debug�call)�opts�queryrrr�init�sH









r'cCs.d}z�tddkr'dtdi}|�|�tdtd|dd	d
tdd
d
d�}notdd
krFtdtdtdtd|dd	d
tdd
d
d�
}nPtddkrmtdtdd�}|�|�tdtd|dd	d
tdd
d
d�}n)tddkr�dtdi}|�|�tdtdtdtd|dd	d
tdd
d
d�
}Wnty�}ztj�d��d}~ww|s�tj�d��t|d�dvr�t|d�dkr�tj�d��t|d�dkr�tj�d��t|d�dkr�tj�d��t|d�dkr�tj�d ��tj�d��t�	|d!�}|d"d#k�r|d$d%k�rt
|�}t�|d
�S)&zW
    This function captures the query string and sends it to the Palo Alto device.
    Nrr�keyr
z
http.queryr�POST�plainTr)�datar�decode_type�decoder�status�raise_errorrrr)	rrr+rr,r-rr.r/rr)r(�targetrr0z+Did not receive a valid response from host.r.)Z200Z201Z204Z400z<The server cannot process the request due to a client error.Z401zpThe server cannot process the request because it lacks valid authentication credentials for the target resource.Z403z,The server refused to authorize the request.Z404z*The requested resource could not be found.�textrZconfig�actionr")
r!�updateZ	__utils__�KeyError�salt�
exceptionsZCommandExecutionError�str�ETZ
fromstringr	�xmlZto_dict)�payload�rZconditional_payload�errZxmldatarrrr$/s�
�
��
�

�����������r$�0.0.0c
Csdtdvr
tdd}ndS|�d�}|�d�}z]t|d�t|d�kr)WdSt|d�t|d�kr8WdSt|d�t|d�krGWdSt|d�t|d�krVWdSt|d�t|d�kreWdSt|d�t|d�krtWdSWdSty�}zWYd	}~dSd	}~ww)
z�
    Because different versions of Palo Alto support different command sets, this function
    will return true if the current version of Palo Alto supports the required command.
    z
sw-version�grains_cacheF�.rT��N)r!�split�int�	Exception)Zrequired_versionZcurrent_versionZrequired_version_splitZcurrent_version_splitr<rrr�is_required_version�s.

��rEcCst�dd�S)z�
    Since grains are loaded in many different places and some of those
    places occur before the proxy can be initialized, return whether
    our init() function has been called
    rF)r!r"rrrrr�src
Cspt�di�s4ttd<zddd�}t|�ddtd<WtdSty3}z	WYd}~tdSd}~wwtdS)z0
    Get the grains from the proxied device
    r>rrr�result�systemN)r!r"�GRAINS_CACHEr$rD�r&r<rrr�grains�s
�
��rJcCsdtd<t�S)z4
    Refresh the grains from the proxied device
    Nr>)r!rJrrrr�grains_refresh�srKc
CsJzddd�}dt|�vrWdSWdSty$}zWYd}~dSd}~ww)z>
    Returns true if the device is reachable, else false.
    rrrrFTFN)r$rDrIrrr�ping�s
��rLcCst�d�dS)z_
    Shutdown the connection to the proxy device. For this proxy,
    shutdown is a no-op.
    zPanos proxy shutdown() called.N)rr#rrrr�shutdown�srM)N)r=)�__doc__�loggingZxml.etree.ElementTreeZetreeZElementTreer8Zsalt.exceptionsr5Zsalt.utils.xmlutil�utilsZxmlutilr9Z__proxyenabled__rHr!�	getLogger�__file__rrrr	r'r$rErrJrKrLrMrrrr�<module>s*N

6
m$