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

Provide AUTH_TOKEN as an env var or a Docker secret #18

Open
lucj opened this issue Sep 20, 2017 · 1 comment
Open

Provide AUTH_TOKEN as an env var or a Docker secret #18

lucj opened this issue Sep 20, 2017 · 1 comment

Comments

@lucj
Copy link
Contributor

lucj commented Sep 20, 2017

To ease the provisioning of the AUTH_TOKEN, and because it contains sensitive info, I was thinking the BACKEND_TOKEN could be provided as an env variable (for development) and as a Swarm secret (for production). What about adding a method in the frontend that could check those location prior checking the conf file ?

It could be something like the following which first checks if the key is present in the env and then checks if it's present in /run/secrets/label, a tmpfs file which is the default location for Docker Swarm secrets (this location could also be used to mount a secret in k8s though).

def get_param(label):
    """Get parameter from env var or Docker secret
    This function check if a given parameter is provided as an env variable,
    or as a Docker secret (within /run/secrets/label)
    :param label: The label to be retrieved
    """
    try:
        value = os.environ[label]
        return value
    except:
        pass
    try:
        with open('/run/secrets/' + label, 'r') as secret:
            value = secret.read().strip('\n')
            return value
    except:
        return None

Which could be called (in app/dashboard/utils/backend.py) like:

AUTH_TOKEN = get_param("BACKEND_TOKEN") or CONFIG_GET("BACKEND_TOKEN")

Any though ?

@MiloCasagrande
Copy link
Contributor

The approach looks good, although I would load all the configuration parameters in one single place like in the dashboard/__init__.py and store everything in the app.config context (the last load wins).

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

No branches or pull requests

3 participants