|
|
@@ -1,51 +1,83 @@
|
|
|
# Microsoft Entra ID
|
|
|
|
|
|
-This guide explains how to configure single sign-on (SSO) support for NetBox using [Microsoft Entra ID](https://www.microsoft.com/en-us/security/business/identity-access/microsoft-entra-id) as an authentication backend.
|
|
|
+NetBox supports single sign-on (SSO) with [Microsoft Entra ID](https://www.microsoft.com/en-us/security/business/identity-access/microsoft-entra-id) (formerly Azure Active Directory), so users can log in with their existing Microsoft credentials instead of separate NetBox account credentials.
|
|
|
|
|
|
-## Entra ID Configuration
|
|
|
+This centralizes access control and simplifies user management, letting administrators grant or revoke NetBox access directly from Entra ID.
|
|
|
|
|
|
-### 1. Create a test user (optional)
|
|
|
+## Prerequisites
|
|
|
|
|
|
-Create a new user in AD to be used for testing. You can skip this step if you already have a suitable account created.
|
|
|
+Before configuring Entra ID authentication, ensure you have:
|
|
|
|
|
|
-### 2. Create an app registration
|
|
|
+**Microsoft Entra ID requirements:**
|
|
|
|
|
|
-Under the Azure Active Directory dashboard, navigate to **Add > App registration**.
|
|
|
+* Permissions to create app registrations in Entra ID
|
|
|
+* Test user account for validation (optional but recommended)
|
|
|
|
|
|
-
|
|
|
+**NetBox requirements:**
|
|
|
|
|
|
-Enter a name for the registration (e.g. "NetBox") and ensure that the "single tenant" option is selected.
|
|
|
+* Access to `configuration.py` and permission to restart the NetBox services
|
|
|
+* HTTPS configured for production deployments
|
|
|
+* Your NetBox URL (used for redirect URI configuration)
|
|
|
|
|
|
-Under "Redirect URI", select "Web" for the platform and enter the path to your NetBox installation, ending with `/oauth/complete/azuread-oauth2/`. Note that this URI **must** begin with `https://` unless you are referencing localhost (for development purposes).
|
|
|
+## Entra ID configuration
|
|
|
|
|
|
-
|
|
|
+!!! tip
|
|
|
+ We recommend that you first [create a new Entra ID user](https://learn.microsoft.com/en-us/entra/fundamentals/how-to-create-delete-users) for testing.
|
|
|
|
|
|
-Once finished, make note of the application (client) ID; this will be used when configuring NetBox.
|
|
|
+ You can skip this step if you already have a suitable account created.
|
|
|
|
|
|
-
|
|
|
+### Register an app
|
|
|
|
|
|
-!!! tip "Multitenant authentication"
|
|
|
- NetBox also supports multitenant authentication via Azure AD; however, it requires a different backend and an additional configuration parameter. Please see the [`python-social-auth` documentation](https://python-social-auth.readthedocs.io/en/latest/backends/azuread.html#tenant-support) for details concerning multitenant authentication.
|
|
|
+Begin by registering an app for NetBox.
|
|
|
|
|
|
-### 3. Create a secret
|
|
|
+1. Open the [Microsoft Entra admin center](https://entra.microsoft.com/#home) and select **Entra ID > App registrations** in the left menu.
|
|
|
|
|
|
-When viewing the newly-created app registration, click the "Add a certificate or secret" link under "Client credentials". Under the "Client secrets" tab, click the "New client secret" button.
|
|
|
+2. Click **New registration**.
|
|
|
|
|
|
-
|
|
|
+3. Complete the following fields:
|
|
|
|
|
|
-You can optionally specify a description and select a lifetime for the secret.
|
|
|
+ * **Name**: Enter a name for the registration (e.g. "NetBox").
|
|
|
|
|
|
-
|
|
|
+ * **Account type**: Select the single-tenant option.
|
|
|
|
|
|
-Once finished, make note of the secret value (not the secret ID); this will be used when configuring NetBox.
|
|
|
+ !!! tip "Multitenant authentication"
|
|
|
+ NetBox also supports multitenant authentication via Entra ID. However, this requires a different backend and an additional configuration parameter. See [Multitenant authentication](#multitenant-authentication) below.
|
|
|
|
|
|
-
|
|
|
+ * **Redirect URI**: Select **Web** and enter the path to your NetBox installation, ending with `/oauth/complete/azuread-oauth2/`.
|
|
|
|
|
|
-## NetBox Configuration
|
|
|
+ For example: `https://<your-netbox-domain>/oauth/complete/azuread-oauth2/`
|
|
|
|
|
|
-### 1. Enter configuration parameters
|
|
|
+ Note:
|
|
|
|
|
|
-Enter the following configuration parameters in `configuration.py`, substituting your own values:
|
|
|
+ * Use HTTPS in production (HTTP only allowed for localhost testing)
|
|
|
+ * This must match exactly what you configure in Entra ID (including the trailing slash)
|
|
|
+
|
|
|
+ 
|
|
|
+
|
|
|
+4. Note the application (client) ID and the directory (tenant) ID. You will need these when configuring SSO from NetBox.
|
|
|
+
|
|
|
+ 
|
|
|
+
|
|
|
+### Create a secret
|
|
|
+
|
|
|
+1. From the page for your new NetBox app registration, select **Certificates & secrets** in the menu on the left.
|
|
|
+
|
|
|
+2. Under **Client secrets**, click **New client secret**.
|
|
|
+
|
|
|
+3. Provide a description and optionally select an expiration period.
|
|
|
+
|
|
|
+4. After creating the secret, note its **Value** (not the secret ID). You will need this when configuring NetBox.
|
|
|
+
|
|
|
+ 
|
|
|
+
|
|
|
+!!! warning
|
|
|
+ This value is only displayed once; copy it immediately.
|
|
|
+
|
|
|
+## NetBox configuration
|
|
|
+
|
|
|
+### Enter configuration parameters
|
|
|
+
|
|
|
+Add the following configuration to `configuration.py`, replacing the placeholder values:
|
|
|
|
|
|
```python
|
|
|
REMOTE_AUTH_BACKEND = 'social_core.backends.azuread.AzureADOAuth2'
|
|
|
@@ -53,9 +85,15 @@ SOCIAL_AUTH_AZUREAD_OAUTH2_KEY = '{APPLICATION_ID}'
|
|
|
SOCIAL_AUTH_AZUREAD_OAUTH2_SECRET = '{SECRET_VALUE}'
|
|
|
```
|
|
|
|
|
|
-### 2. Restart NetBox
|
|
|
+* `APPLICATION_ID` is the **Application (client) ID** you copied from the **Overview** page for your NetBox app registration.
|
|
|
+* `SECRET_VALUE` is the **Value** you copied from the **Certificates & secrets** page for your NetBox app registration.
|
|
|
+
|
|
|
+!!! note
|
|
|
+ If you are deploying multitenant authentication, you will need to use a different `REMOTE_AUTH_BACKEND` backend. See [Multitenant authentication](#multitenant-authentication) below.
|
|
|
|
|
|
-Restart the NetBox services so that the new configuration takes effect. This is typically done with the command below:
|
|
|
+### Restart NetBox
|
|
|
+
|
|
|
+Configuration changes require restarting the application. This is typically done with the command below:
|
|
|
|
|
|
```no-highlight
|
|
|
sudo systemctl restart netbox
|
|
|
@@ -63,26 +101,86 @@ sudo systemctl restart netbox
|
|
|
|
|
|
## Testing
|
|
|
|
|
|
-Log out of NetBox if already authenticated, and click the "Log In" button at top right. You should see the normal login form as well as an option to authenticate using Azure AD. Click that link.
|
|
|
+Log out of NetBox and click the "Log In" button at top right. You should see the normal login form as well as an option to authenticate using Entra ID.
|
|
|
+
|
|
|
+Click the option to log in with Microsoft Entra ID.
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+You will be redirected to Microsoft's authentication portal where you can log in with your test user's Microsoft credentials. You may also be prompted to grant this application access to your account.
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+If successful, you will be logged in as the Entra ID user. You can verify this by clicking your login ID in the upper right and selecting **Profile**.
|
|
|
+
|
|
|
+This user account is now replicated within NetBox, and can be assigned groups and permissions.
|
|
|
+
|
|
|
+## Assign permissions
|
|
|
|
|
|
-
|
|
|
+New users have no permissions by default. To assign permissions:
|
|
|
|
|
|
-You should be redirected to Microsoft's authentication portal. Enter the username/email and password of your test account to continue. You may also be prompted to grant this application access to your account.
|
|
|
+1. From NetBox, navigate to **Admin > Authentication > Users** (requires admin access).
|
|
|
|
|
|
-
|
|
|
+2. Locate the Entra ID user and assign appropriate groups or individual [permissions](../permissions.md).
|
|
|
|
|
|
-If successful, you will be redirected back to the NetBox UI, and will be logged in as the AD user. You can verify this by navigating to your profile (using the button at top right).
|
|
|
+3. Set [staff or superuser status](../../models/users/user.md), if needed:
|
|
|
|
|
|
-This user account has been replicated locally to NetBox, and can now be assigned groups and permissions.
|
|
|
+ * **Staff**: Allows the user to log into the legacy Django admin site. Most NetBox functionality is exposed via the standard UI, so staff status is rarely needed.
|
|
|
+ * **Superuser**: Grants the user all permissions implicitly, bypassing all permission checks.
|
|
|
+
|
|
|
+!!! warning "Security considerations"
|
|
|
+ Exercise extreme caution when configuring Superuser users or groups.
|
|
|
+
|
|
|
+ Superusers have unrestricted access to NetBox and can:
|
|
|
+
|
|
|
+ * Modify any data, including configuration
|
|
|
+ * Elevate other users to superuser status
|
|
|
+
|
|
|
+## Multitenant authentication
|
|
|
+
|
|
|
+NetBox supports multitenant authentication for organizations using multiple Entra ID tenants. This requires a different backend configuration.
|
|
|
+
|
|
|
+**Multitenant backend:**
|
|
|
+
|
|
|
+```python
|
|
|
+REMOTE_AUTH_BACKEND = 'social_core.backends.azuread_tenant.AzureADTenantOAuth2'
|
|
|
+SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_KEY = '{APPLICATION_ID}'
|
|
|
+SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_SECRET = '{SECRET_VALUE}'
|
|
|
+SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID = '{TENANT_ID}'
|
|
|
+```
|
|
|
+
|
|
|
+When creating the app registration, select **Multiple Entra ID tenants** instead of single tenant.
|
|
|
+
|
|
|
+For detailed multitenant configuration, refer to the [Python Social Auth documentation](https://python-social-auth.readthedocs.io/en/latest/backends/azuread.html#tenant-support).
|
|
|
|
|
|
## Troubleshooting
|
|
|
|
|
|
-### Redirect URI does not Match
|
|
|
+### Redirect URI does not match
|
|
|
+
|
|
|
+Entra ID requires that the authenticating client request a redirect URI that matches the one you configured for the app registration.
|
|
|
+
|
|
|
+This URI must begin with `https://` (unless using `localhost` for the domain) and must match **exactly** what you configured in Entra ID (including the trailing slash). The redirect URI is where Entra ID sends users after authentication. NetBox uses the following pattern:
|
|
|
+
|
|
|
+```text
|
|
|
+https://<your-netbox-domain>/oauth/complete/azuread-oauth2/
|
|
|
+```
|
|
|
+
|
|
|
+If Entra ID complains that the requested URI starts with `http://` (not HTTPS), it's likely that your HTTP server is misconfigured or sitting behind a load balancer, so NetBox is not aware that HTTPS is being used. To force the use of an HTTPS redirect URI, set the following in `configuration.py` per the [python-social-auth docs](https://python-social-auth.readthedocs.io/en/latest/configuration/settings.html#processing-redirects-and-urlopen):
|
|
|
+
|
|
|
+```python
|
|
|
+SOCIAL_AUTH_REDIRECT_IS_HTTPS = True
|
|
|
+```
|
|
|
+
|
|
|
+### Not logged in after authenticating
|
|
|
+
|
|
|
+If you are redirected to the NetBox UI after authenticating successfully, but are not logged in, double-check the `REMOTE_AUTH_BACKEND` value configured in `configuration.py` against your Entra ID app registration.
|
|
|
+
|
|
|
+The instructions provided above are only applicable to the `azuread.AzureADOAuth2` backend using a single-tenant app registration. Confirm too that `SOCIAL_AUTH_AZUREAD_OAUTH2_KEY` matches the application (client) ID in Entra ID, and that `SOCIAL_AUTH_AZUREAD_OAUTH2_SECRET` is the secret value rather than its ID.
|
|
|
|
|
|
-Azure requires that the authenticating client request a redirect URI that matches what you've configured for the app in step two. This URI **must** begin with `https://` (unless using `localhost` for the domain).
|
|
|
+### Expired client secret
|
|
|
|
|
|
-If Azure complains that the requested URI starts with `http://` (not HTTPS), it's likely that your HTTP server is misconfigured or sitting behind a load balancer, so NetBox is not aware that HTTPS is being use. To force the use of an HTTPS redirect URI, set `SOCIAL_AUTH_REDIRECT_IS_HTTPS = True` in `configuration.py` per the [python-social-auth docs](https://python-social-auth.readthedocs.io/en/latest/configuration/settings.html#processing-redirects-and-urlopen).
|
|
|
+If authentication fails and you see an error such as "invalid_client" or "secret expired", this means your client secret has expired.
|
|
|
|
|
|
-### Not Logged in After Authenticating
|
|
|
+Generate a new client secret in Entra ID, update `configuration.py` with the new value, and restart the NetBox services.
|
|
|
|
|
|
-If you are redirected to the NetBox UI after authenticating successfully, but are _not_ logged in, double-check the configured backend and app registration. The instructions in this guide pertain only to the `azuread.AzureADOAuth2` backend using a single-tenant app registration.
|
|
|
+To prevent this, we recommend setting a calendar reminder to rotate and update your secret.
|