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

Make API Keys & Access Keys out of serverConfig or ProxyAuthConfig configurable via Env Vars #148

Open
t83714 opened this issue Feb 25, 2022 · 4 comments

Comments

@t83714
Copy link
Member

t83714 commented Feb 25, 2022

Make API Keys & Access Keys out of serverConfig or ProxyAuthConfig configurable via Env Vars

It's a good practice that separate API Keys & Access Keys config from other non-credential configs and make them configurable via environment variables.

This also allows those credential configs to be stored in specialised storage designed for credentials.

e.g. on k8s cluster, it's a good practice to store credentials in k8s secrets.

this can be done with the yargs (or the dotenv-expand solution @zoran995 suggested) we used at this moment:

var yargs = require('yargs')

e.g.

.option("sessionSecret", {
            describe:
                "The secret to use to sign session cookies.  This can also be specified with the SESSION_SECRET environment variable.",
            type: "string",
            default:
                process.env.SESSION_SECRET ||
                process.env.npm_package_config_SESSION_SECRET,
            demand: true
        })

Acceptance Criteria

  • Move out any API keys & Access Keys from ServerConfig and ProxyAuthConfig
  • Make all API keys & Access Keys configurable via environment variables
@zoran995
Copy link

zoran995 commented Feb 28, 2022

An idea, what about something like dotenv-expand just for JSON, still using .json config file but expanding values with environment variables on startup ($ENV_VAR is replaced). Have done this recently for another project and can share it if interested

@t83714
Copy link
Member Author

t83714 commented Mar 1, 2022

@zoran995 Thanks for the suggestion and it might be a good idea 👍
As long as we can accept passing keys via env vars, we can keep the current config JSON structure internally.
Probably can overwrite the config JSON fields with key values here:

this.configFile = getConfigFile(argv.configFile, 'serverconfig.json');

either manually or as you suggested simply using dotenv-expand.

@zoran995
Copy link

zoran995 commented Mar 1, 2022

dotenv-expand was just a reference how they implemented it as their function already does the job of interpolating value, not sure if it is exported from dotenv-expand but we can take that function entirely in our codebase and maintain it for our needs (with referencing the original implementation)

Yeah that would be that 😀

I have implemented same thing here zoran995/geoportal-server@2dd9090 in zoran995/geoportal-server#14. Project is basically a rewrite of terriajs-server using NestJs architecture, I can try to get some time to create a PR here also

@joelsundholm
Copy link

For anyone reading this today and thinking about k8s deployment:

We use an initContainer with envsubst which writes the secrets into the config file which is in a mounted volume that we then mount to the main container. This way the actual TerriaJS image doesn't need to be cluttered or modified in any way.

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

3 participants