Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SSO variables to configuration file, so they can be added to the environment files #1139

Open
SaschaSchwarzK opened this issue Jan 20, 2024 · 1 comment

Comments

@SaschaSchwarzK
Copy link

Desired Behavior

We are using the docker version of netbox and SSO with a Okta backend.

We have to change configuration.py to get the authentication settings from the environment variables.

I think it would be much more convenient for all users if they can simply add the settings for SSO(at least for the integrations outlined in the netbox documentation) in the environment variables, instead of editing the configuration.py. Just like this is done for most other settings as well.

Contrast to Current Behavior

Currently only the basic REMOTE_AUTH settings can be set in the environment variables.

Required Changes

I suggest to change the file configurations.py and add the lines below to support at least the SSO integrations outlined in the documentation.

SOCIAL_AUTH_OKTA_OPENIDCONNECT_KEY = environ.get('SOCIAL_AUTH_OKTA_OPENIDCONNECT_KEY')
SOCIAL_AUTH_OKTA_OPENIDCONNECT_SECRET = environ.get('SOCIAL_AUTH_OKTA_OPENIDCONNECT_SECRET')
SOCIAL_AUTH_OKTA_OPENIDCONNECT_API_URL = environ.get('SOCIAL_AUTH_OKTA_OPENIDCONNECT_API_URL')
SOCIAL_AUTH_AZUREAD_OAUTH2_KEY = environ.get('SOCIAL_AUTH_AZUREAD_OAUTH2_KEY')
SOCIAL_AUTH_AZUREAD_OAUTH2_SECRET = environ.get('SOCIAL_AUTH_AZUREAD_OAUTH2_SECRET')

Discussion: Benefits and Drawbacks

No response

@marsteel
Copy link

marsteel commented Oct 8, 2024

In case some one would like to pass python dict SOCIAL_AUTH_BACKEND_ATTRS as environment variable to customize SSO display name and icon, here is the solution by adding to extra.py. I'm using Keycloak

from os import environ
import base64
import pickle

# Use ENV
REMOTE_AUTH_BACKEND=environ.get('REMOTE_AUTH_BACKEND')
#SOCIAL_AUTH_BACKEND_ATTRS=environ.get('SOCIAL_AUTH_BACKEND_ATTRS')
if environ.get('SOCIAL_AUTH_BACKEND_ATTRS_BASE64') is not None:
    SOCIAL_AUTH_BACKEND_ATTRS=pickle.loads(base64.b64decode(environ.get('SOCIAL_AUTH_BACKEND_ATTRS_BASE64')))
    #print("Debug SOCIAL_AUTH_BACKEND_ATTRS")
    #print(SOCIAL_AUTH_BACKEND_ATTRS)

#import base64
#import pickle
#To pass below python dict
#SOCIAL_AUTH_BACKEND_ATTRS={
#    'keycloak': ("Login with Keycloak", "https://www.svgrepo.com/show/331455/keycloak.svg"),
#}
#}
#print(base64.b64encode(pickle.dumps(SOCIAL_AUTH_BACKEND_ATTRS)))
# Pass the result of base64.b64encode(pickle.dumps(SOCIAL_AUTH_BACKEND_ATTRS)) as AWS ECS Environment Variable(ENV).
# ENV name SOCIAL_AUTH_BACKEND_ATTRS_BASE64
# ENV value gASVWgAAAAAAAAB9lIwIa2V5Y2xvYWuUjBNMb2dpbiB3aXRoIEtleWNsb2FrlIwwaHR0cHM6Ly93d3cuc3ZncmVwby5jb20vc2hvdy8zMzE0NTUva2V5Y2xvYWsuc3ZnlIaUcy4=
# https://stackoverflow.com/questions/76248652/how-to-add-in-aws-env-variable-which-is-not-a-simple-string-contains-nested-br
# https://stackoverflow.com/questions/24508726/how-to-encode-python-dictionary

SOCIAL_AUTH_KEYCLOAK_KEY=environ.get('SOCIAL_AUTH_KEYCLOAK_KEY')
SOCIAL_AUTH_KEYCLOAK_SECRET=environ.get('SOCIAL_AUTH_KEYCLOAK_SECRET')
SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL=environ.get('SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL')
SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL=environ.get('SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL')
SOCIAL_AUTH_KEYCLOAK_ID_KEY=environ.get('SOCIAL_AUTH_KEYCLOAK_ID_KEY')
SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY=environ.get('SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY')

More
https://stackoverflow.com/questions/76248652/how-to-add-in-aws-env-variable-which-is-not-a-simple-string-contains-nested-br
https://stackoverflow.com/questions/24508726/how-to-encode-python-dictionary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants