• Stars
    star
    107
  • Rank 321,722 (Top 7 %)
  • Language
    Python
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Netbox plugin for SSO using SAML2

Netbox Plugin for SSO using SAML2

Netbox 2.8 provides enhancements to support remote user authentication uses specific variables defined in the configuration.py file, as described here:

https://netbox.readthedocs.io/en/stable/configuration/optional-settings/

This repository provides a Netbox plugin that can be used to integrate with a SAML SSO system, such as Okta.

NOTE: This approach uses a reverse-proxy URL rewrite so that the standard Netbox Login will redirect the User to the SSO system. Please refer to the example nginx.conf file.

*NOTE: Netbox plugin for SSO, v2.0+, supports Netbox 2.8, 2.9, 2.10, 2.11, 3.0.

System Requirements

You will need to install the django3-auth-saml2 into your Netbox environment.

Netbox Configuration

In the configuration.py you will need to enable and configure these REMOTE_AUTH_xxx options at a minimum:

REMOTE_AUTH_ENABLED = True
REMOTE_AUTH_BACKEND = 'utilities.auth_backends.RemoteUserBackend'
# For v2.8+:
# REMOTE_AUTH_BACKEND = 'netbox.authentication.RemoteUserBackend'
# For backends included with this plugin:
# REMOTE_AUTH_BACKEND = 'django3_saml2_nbplugin.backends.<Backend>'
REMOTE_AUTH_AUTO_CREATE_USER = True

You can also create the other options REMOTE_AUTH_DEFAULT_GROUPS and REMOTE_AUTH_DEFAULT_PERMISSIONS as described in the online docs.

Next you will need to configure this plugin, provding your specific configuraiton values as described in django3-okta-saml2 repo, for example:

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.company.com',

        # Populates the Issuer element in authn reques e.g defined as "Audience URI (SP Entity ID)" in SSO
        'ENTITY_ID': 'https://netbox.conpany.com/',

        # Metadata is required, choose either remote url
        'METADATA_AUTO_CONF_URL': "https://mycorp.okta.com/app/sadjfalkdsflkads/sso/saml/metadata",
        # or local file path
        'METADATA_LOCAL_FILE_PATH': '/opt/netbox/saml2.xml',

        # Settings for SAML2CustomAttrUserBackend. Optional.
        'CUSTOM_ATTR_BACKEND': {
            # See the note below about SAML attributes

            # 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': {
                'saml-group3': 'netbox-group'
            }
        }
    }
}

Please note that METADATA_AUTO_CONF_URL and METADATA_LOCAL_FILE_PATH are mutually exclusive. Don't use both settings at the same time.

Attributes

Newer versions of pysaml2 uses an attribute map. For example, instead of http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress in the configuration above, emailAddress should be used instead.

See here for details.

New Plugin URLs

This plugin will provide two new URLs to Netbox:

/api/plugins/sso/login/
This URLs redirects the User login to the SSO system (Okta) for authentication. This is the URL that needs to be used in the reverse-proxy redirect, for examlple see nginx.conf.

/api/plugins/sso/acs/
This URLs should be configured into your SSO system as the route to use to single-sign-on/redirection URL the User into Netbox after the User has authenticated with the SSO system.

Customizing on Create New User Configuration

If you want to customize the way a User is created, beyond what is provided by the Netbox REMOTE_AUTH variables, you can create a custom RemoteBackend class. See the samples in backends.py.

Using A Reverse Proxy Redirect

The use of this plugin requires a reverse-proxy URL redirect to override the default Netbox /login/ URL. There are two notes in this process:

  1. You MAY need to disable port in redirect depending on your Netbox installation. If your Netbox server URL does not include a port, then you must disable port redirect. For example see nginx.conf.
  2. You MUST add the ULR rewrite for the /login/ URL to use /plugins/sso/login/, for example nginx.conf.

Adding a SSO Login Button

Instead of using a reverse proxy redirect, you can add a SSO login button above the NetBox login form. This has the added benefit of allowing both local and SAML login options.

Add the following to your configuration.py:

BANNER_LOGIN = '<a href="/api/plugins/sso/login" class="btn btn-primary btn-block">Login with SSO</a>'

More Repositories

1

netcfgbu

Network Configuration Backup
Python
101
star
2

nanog77-nrfu-tutorial

NANOG77 NRFU Tutorial
Python
34
star
3

demo-beginner-concurrency

Demo repo for PyCharm Webcast 2022-Feb-22
Python
26
star
4

ansible-csv2hosts

Demo - CSV to Ansible 'hosts' and 'host_vars'
Python
21
star
5

netcadcam

Network Configuration Database
Python
20
star
6

netbox-pyswagger

Python Swagger client for Netbox
Python
18
star
7

genie-quickstart

Cisco pyATS Genie Quickstart Example
Python
17
star
8

iterm2-colors2rgb

Convert an iTerm2 profile color settings to RGB values
Python
10
star
9

demo_host_csv_template_render

Demonstrate taking a CSV data file and producing multiple host-specific configs
Python
9
star
10

slack-scim-rbac

Role Based Access Control for Slack-Bolt Applications
Python
8
star
11

netcfg-grep

Network Device Configuration Grep Tool
Python
8
star
12

halutz

Halutz is a python library for Swagger, inspired by working with network engineers that are getting started with Python.
Python
8
star
13

django3-auth-saml2

Django3 SSO using SAML 2.0
Python
8
star
14

nwkautomaniac

network automation package of utilities and libraries
Python
8
star
15

slackapp-pyez

For when you want to create a slack app
Python
7
star
16

ipf-netbox

IP Fabric - Netbox Toolkit
Python
7
star
17

bracket_expansion

Generator for bracket-expansion function
Python
7
star
18

idreamofgenie

Toolbox of modules and scripts using pyATS Genie
Python
6
star
19

aio-ipfabric

Python 3.8 asycnio client for IP Fabric
Python
6
star
20

xml-tutorial

XML/XPath tutorial for Network Engineers
Python
6
star
21

genie-parser-extension

Cisco pyATS Genie parser example - dynamically adding new parsers
Python
5
star
22

slack-click

Click support for Slack-Bolt Applications
Python
5
star
23

ipf-netcfgbu

Network Config Backups from IP Fabric
Python
4
star
24

netcad-netbox

NetBox integration with NetCAD/CAM system
Python
4
star
25

demo-ztpserver

Arista EOS ZTPServer demo setup
Shell
4
star
26

slackapptk

Create Slack apps using slackclient 2.0
Python
4
star
27

netcad-demo-clabs1

NetCadCam demo using ContainerLabs - Basic Switching Topology of 3 cEOS devices
Python
4
star
28

aio-eapi

Arista EOS API asyncio client
Python
4
star
29

cvp-pyez

Arista Cloud Vision PyEZ Toolbox
Python
4
star
30

aio-nxapi

Cisco NX-API asyncio client
Python
3
star
31

macaddr

For working with MAC address values
Python
3
star
32

junospyez-ossh-server

Library to provide an Outbound SSH server for use with Junos-PyEZ
Python
2
star
33

py-demo-simple-template

Demonstrating simple template render using Python or Ansible
Python
2
star
34

pydantic-env

Pydantic Models for use with System and Environment Variables
Python
1
star
35

lxml-xpath-ipaddress

IP address extension library for LXML
Python
1
star
36

pyzayo

Python 3.8 asyncio client for the Zayo API
Python
1
star
37

netcam-aioeos

Python
1
star
38

rich-consoleimager

Create PNG image from Rich Console output
Python
1
star