Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

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

Open
@lucj

Description

@lucj

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 ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions