PaloAltoNetworks / pan-os-python

The PAN-OS SDK for Python is a package to help interact with Palo Alto Networks devices (including physical and virtualized Next-generation Firewalls and Panorama). The pan-os-python SDK is object oriented and mimics the traditional interaction with the device via the GUI or CLI/API.
https://pan-os-python.readthedocs.io
ISC License
344 stars 170 forks source link

AuthenticationProfile path is broken #526

Closed cdot65 closed 8 months ago

cdot65 commented 1 year ago

Describe the bug

As it stands today, a misspelling of the word lockout is breaking the path when trying to create AuthenticationProfile objects

Expected behavior

from config import settings
from panos.firewall import Firewall
from panos.device import AuthenticationProfile

fw = Firewall(settings.nyc.base_url, api_key=settings.api_key)

auth_profile = AuthenticationProfile(
    name="MyRADIUS",
    profile_type="radius",
    server_profile="test",
    retrieve_user_group=False,
    failed_attempts=3,
    lockout_time=600
)

fw.add(auth_profile)
auth_profile.create()

Current behavior

from config import settings
from panos.firewall import Firewall
from panos.device import AuthenticationProfile

fw = Firewall(settings.nyc.base_url, api_key=settings.api_key)

auth_profile = AuthenticationProfile(
    name="MyRADIUS",
    profile_type="radius",
    server_profile="test",
    retrieve_user_group=False,
    failed_attempts=3,
    lockout_time=600
)

fw.add(auth_profile)
auth_profile.create()

PanXapiError                              Traceback (most recent call last)
File /usr/local/lib/python3.10/site-packages/panos/base.py:3878, in PanDevice.XapiWrapper.make_method.<locals>.method(self, *args, **kwargs)
   3874 try:
   3875     # This device has not failed, or both have failed
   3876     # and this device is active
   3877     # First get the superclass method
-> 3878     super_method(self, *args, **kwargs)
   3879     result = copy.deepcopy(self.element_root)

File /usr/local/lib/python3.10/site-packages/pan/xapi.py:741, in PanXapi.set(self, xpath, element, extra_qs)
    740     query['element'] = element
--> 741 self.__type_config('set', query, extra_qs)

File /usr/local/lib/python3.10/site-packages/pan/xapi.py:805, in PanXapi.__type_config(self, action, query, extra_qs)
    804 if not self.__set_response(response):
--> 805     raise PanXapiError(self.status_detail)

PanXapiError:  authentication-profile -> MyRADIUS -> locakout unexpected here

During handling of the above exception, another exception occurred:

PanDeviceXapiError                        Traceback (most recent call last)
Cell In[9], line 1
----> 1 auth_profile.create()

File /usr/local/lib/python3.10/site-packages/panos/base.py:652, in PanObject.create(self)
    650 element = self.element_str()
    651 if self.HA_SYNC:
--> 652     device.active().xapi.set(
    653         self.xpath_short(), element, retry_on_peer=self.HA_SYNC
    654     )
    655 else:
    656     device.xapi.set(self.xpath_short(), element, retry_on_peer=self.HA_SYNC)

File /usr/local/lib/python3.10/site-packages/panos/base.py:3899, in PanDevice.XapiWrapper.make_method.<locals>.method(self, *args, **kwargs)
   3897                 raise the_exception
   3898         else:
-> 3899             raise the_exception
   3900 return result

PanDeviceXapiError:  authentication-profile -> MyRADIUS -> locakout unexpected here

Possible solution

Resolved in PR 525

Steps to reproduce

from panos.firewall import Firewall
from panos.device import AuthenticationProfile

fw = Firewall("192.168.1.1", api_key="mysecretapikey")

auth_profile = AuthenticationProfile(
    name="MyRADIUS",
    profile_type="radius",
    server_profile="test",
    retrieve_user_group=False,
    failed_attempts=3,
    lockout_time=600
)

fw.add(auth_profile)
auth_profile.create()

Screenshots

image

Context

Unable to create AuthenticationProfiles

Your Environment

vscode ➜ .../marmot/python/configuration/auth_profile (main) $ pip freeze | grep pan
pan-os-python==1.11.0
pan-python==0.17.0
panos-upgrade-assurance==0.1.4
vscode ➜ .../marmot/python/configuration/auth_profile (main) $ python --version
Python 3.10.12
shinmog commented 8 months ago

Fixed by #525