jeremyschulman / netbox-plugin-auth-saml2

Netbox plugin for SSO using SAML2
120 stars 21 forks source link

'CUSTOM_ATTR_BACKEND': { SyntaxError: invalid syntax #25

Closed tomasaberg closed 3 years ago

tomasaberg commented 3 years ago

Hi!

Thank you for creating this plugin. I've got it to work but I want to add some custom values for Okta configuration. However, when I add CUSTOM_ATTR_BACKEND:{} to configuration.py I get the error below

Traceback (most recent call last):
  File "netbox/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 345, in execute
    settings.INSTALLED_APPS
  File "/opt/netbox/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 83, in __getattr__
    self._setup(name)
  File "/opt/netbox/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 70, in _setup
    self._wrapped = Settings(settings_module)
  File "/opt/netbox/venv/lib/python3.8/site-packages/django/conf/__init__.py", line 177, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/opt/netbox/netbox/netbox/settings.py", line 40, in <module>
    from netbox import configuration
  File "/opt/netbox/netbox/netbox/configuration.py", line 260
    'CUSTOM_ATTR_BACKEND': {
                         ^
SyntaxError: invalid syntax

This config is added at the bottom in configuration.py

# Enable installed plugins. Add the name of each plugin to the list.
PLUGINS = ['django3_saml2_nbplugin']
PLUGINS_CONFIG = {
    'django3_saml2_nbplugin': {
        # Use the Netbox default remote backend
        'AUTHENTICATION_BACKEND': REMOTE_AUTH_BACKEND,
        # Custom URL to validate incoming SAML requests against
        'ASSERTION_URL': "https://netbox-dev.company.com",
        # Populates the Issuer element in authn reques e.g defined as "Audience URI (SP Entity ID)" in SSO
        'ENTITY_ID': "https://netbox-dev.company.com",
        # Metadata is required, choose either remote url or local file path
        'METADATA_AUTO_CONF_URL': "https://company.okta.com/app/<censored>/sso/saml/metadata"

#        # Settings for SAML2CustomAttrUserBackend. Optional.
        'CUSTOM_ATTR_BACKEND': {
#            # Attribute containing the username. Optional.
#            'USERNAME_ATTR': 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress',
#            # Attribute containing the user's email. Optional.
#            'MAIL_ATTR': 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress',
#            # Attribute containing the user's first name. Optional.
#            'FIRST_NAME_ATTR': 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname',
#            # Attribute containing the user's last name. Optional.
#            'LAST_NAME_ATTR': 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname',
#            # Set to True to always update the user on logon
#            # from SAML attributes on logon. Defaults to False.
#            'ALWAYS_UPDATE_USER': False,
#            # Attribute that contains groups. Optional.
#            'GROUP_ATTR': 'http://schemas.microsoft.com/ws/2008/06/identity/claims/groups',
#            # Dict of user flags to groups.
#            # If the user is in the group then the flag will be set to True. Optional.
#            'FLAGS_BY_GROUP': {
#                'is_staff': 'saml-group1',
#                'is_superuser': 'saml-group2'
#            },
#            # Dict of SAML groups to NetBox groups. Optional.
#            # Groups must be created beforehand in NetBox.
#            'GROUP_MAPPINGS': {
#                'okta-group1: 'netbox-group'
#            }
        }
    }
}

Is there anything I'm doing wrong?

Netbox version: v2.10.5

jeremyschulman commented 3 years ago

@tomasaberg - thank you. Unfortunately 2.10 is not currently supported; even though the (prior) README indicated it was. I am not currently running 2.10. I am hoping to update in the next month or so; but for not I am looking for any contributors that could help (see associated issue #26.

I also just updated the release to 2.2 in PyPi that does fix a known issue. You could try that latest release to see if that resolves your specific issue.

I'll leave this issue open for now.

tomasaberg commented 3 years ago

I tried upgrading, unfortunately the same error. I have very limited knowledge about python but I'm happy to help try out things if needed

jeremyschulman commented 3 years ago

@tomasaberg - if you are admin of your Okta and have some time we could setup a Zoom and try to get it working together. I am located US/Eastern timezone.

devon-mar commented 3 years ago

@jeremyschulman 2.2 on pypi doesn't seem to have the SAML2CustomAttrUserBackend included in backends.py.

I noticed that only the master branch had the backend but not the main branch. Perhaps it was built from main?

devon-mar commented 3 years ago

@tomasaberg I'm running this on 2.10.5 currently and it seems to be working.

It looks like you're missing a comma at the end of METADATA_AUTO_CONF_URL.

jeremyschulman commented 3 years ago

@devon-mar - thank you for assisting and pointing out the master->main issue. That was my bad. I just fixed this and posted 2.3 to PyPi. Also, thank you for confirming that this plugin works on 2.10.5!

tomasaberg commented 3 years ago

@tomasaberg I'm running this on 2.10.5 currently and it seems to be working.

It looks like you're missing a comma at the end of METADATA_AUTO_CONF_URL.

My bad, you're correct. It seems to work on 2.10.6 as well. Sorry @jeremyschulman for taking so long to answer you :)