Skip to content

Improve deploying env variables safely #144

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

Closed
dkundel opened this issue Jun 25, 2020 · 2 comments · Fixed by #146
Closed

Improve deploying env variables safely #144

dkundel opened this issue Jun 25, 2020 · 2 comments · Fixed by #146
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@dkundel
Copy link
Contributor

dkundel commented Jun 25, 2020

Right now the way we are deploying .env files intuitive if you deploy from your own machine but isn't really friendly for a CI/CD environment. Essentially you have to create a ".env.production" file and it could potentially contain secrets you don't want to expose. Especially for OSS projects.

I've been thinking about two options.

Option 1
The start command already supports a flag --load-local-env that loads all environment variables that are available on the system and provides them as env variables during local dev as backup for the ones in the .env file. We could add the same flag to both promote and to deploy but that would mean we would just take all of the environment variables we find, not giving you a fine grained control.

Option 2
We support basic "templating" in the .env file. That way you could have a .env.prod file that is checked into your repository but it looks something like this:

ACCOUNT_SID={{$TWILIO_ACCOUNT_SID}}
AUTH_TOKEN={{$TWILIO_AUTH_TOKEN}}
MY_PHONE_NUMBER={{$MY_SECRET_PHONE_NUMBER}}
GREETING=hello

This would swap out $TWILIO_ACCOUNT_SID, $TWILIO_AUTH_TOKEN and $MY_SECRET_PHONE_NUMBER with the respective system environment variables.

We could start introducing this as an experimental flag first and then fully ship it with the next major version. I think this gives folks a bit more control.

@dkundel dkundel self-assigned this Jun 25, 2020
@dkundel
Copy link
Contributor Author

dkundel commented Jun 25, 2020

The third option would be to give a flag that lets you pass environment variables one by one but they could pop up in logs again. So not viable

@dkundel
Copy link
Contributor Author

dkundel commented Jun 25, 2020

After talking with @philnash the design we'll go with is a mix of the two options.

The behavior is the following:

If the user runs twilio-run deploy --load-local-env --env .env.production, the Serverless Toolkit will only load the system environment variables that also have a corresponding key inside the specified .env file (in this case .env.production). If --load-local-env is used without a --env flag, it will throw an error.

For the start command we will mimic the described behavior if both flags are passed. For compatibility reasons we will keep the currently start behavior if only --load-local-env is passed.

@dkundel dkundel added enhancement New feature or request good first issue Good for newcomers labels Jun 25, 2020
dkundel added a commit that referenced this issue Jun 26, 2020
This PR adds support for a --load-system-env flag. This works similar to the existing
--load-local-env variable on the start command but is required to be used in tandem with the --env
flag and will use the file specified in --env as a filter. Only empty values in the env file will be
populated by the system env variables. This PR doesn't add that behavior to the "start" command as
this would be a breaking change that will be introduced in a separate version.

fix #144
dkundel added a commit that referenced this issue Jun 29, 2020
This PR adds support for a --load-system-env flag. This works similar to the existing
--load-local-env variable on the start command but is required to be used in tandem with the --env
flag and will use the file specified in --env as a filter. Only empty values in the env file will be
populated by the system env variables. This PR doesn't add that behavior to the "start" command as
this would be a breaking change that will be introduced in a separate version.

fix #144
dkundel added a commit that referenced this issue Jun 29, 2020
This PR adds support for a --load-system-env flag. This works similar to the existing
--load-local-env variable on the start command but is required to be used in tandem with the --env
flag and will use the file specified in --env as a filter. Only empty values in the env file will be
populated by the system env variables. This PR doesn't add that behavior to the "start" command as
this would be a breaking change that will be introduced in a separate version.

fix #144
dkundel added a commit that referenced this issue Jul 6, 2020
This PR adds support for a --load-system-env flag. This works similar to the existing
--load-local-env variable on the start command but is required to be used in tandem with the --env
flag and will use the file specified in --env as a filter. Only empty values in the env file will be
populated by the system env variables. This PR doesn't add that behavior to the "start" command as
this would be a breaking change that will be introduced in a separate version.

fix #144
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant