-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Specification
- The
pk secrets envcommand should operate similar to the unixenvcommand - We can use
pk secrets envto do double duty: inject environment variables into a new subcommand, or allow sourcing of environment variables into an existing subshell - The task for the development environment usecase is specified in https://github.com/MatrixAI/Polykey-Desktop/issues/77
- The
pk secrets env someprogram arg1 arg2should do a proper process replacement when possible
Additional context
- Exposing different interfaces for use of secrets within polykey Polykey#55 (comment) - old comment about the env interface and the "chording" idea
Copied excerpt:
Now when we want to start development on the project, we have 2 options:
- Open up a shell with Polykey sourcing the environment variables
- Use Polykey to inject environment variables into a sub-shell
Either result is the same, because you'll be running a shell with environment variables set so that your test runs of your software can inherit this environment configuration. Let's demonstrate both.
In the first case, we will reuse the
sourcecommand and askpkto constuct the equivalent of the.envfile but entirely in-memory and only for this specific usage. We must also use process substitution<(...)so that thepkcommand output can be redirected into a temporary file descriptor that is read by thesourcecommand.# one secret source <(pk secrets env my-software-project:AWS_ACCESS_KEY_ID) # multiple secrets source <(pk secrets env my-software-project:AWS_ACCESS_KEY_ID my-software-project:GOOGLE_MAPS_API_KEY) # globbing style (you can use globstar as well, this will only export immediate files) source <(pk secrets env my-software-project:*) # use the -e flag to export all variables source <(pk secrets env -e my-software-project:*) # use the -- to separate so you can export just one out of many source <(pk secrets env -- my-software-project:AWS_ACCESS_KEY_ID -e my-software-project:GOOGLE_MAPS_API_KEY) source <(pk secrets env -e -- my-software-project:AWS_ACCESS_KEY_ID my-software-project:GOOGLE_MAPS_API_KEY)Now your shell has the relevant environment variables set by Polykey, and they will exist for as long as this current shell is alive.
In the second case, we ill use
pk secrets envcommand to run a subshell, it can run any subprogram, but in the context of a development environment, you usually want a shell.# one secret pk secrets env my-software-project:AWS_ACCESS_KEY_ID bash # multiple secrets pk secrets env my-software-project:AWS_ACCESS_KEY_ID my-software-project:GOOGLE_MAPS_API_KEY bash # globbing style pk secrets env my-software-project:* bash # the -e flag has no effect when using it this way # this is because the subprogram determines whether to export variable or not # it usually exports the variable pk secrets env -e my-software-project:* bashNow you have a subshell that has the environment variables configured, it will also automatically export it to child programs. When you have finished your development, you can just
exitthe shell, and the environment variables are gone!
Tasks
- Ensure that
pk secrets envcan be used to inject environment variables and run a subprocess - Ensure that
pk secrets envcan be used to source environment variables and output something that can be used as a file to be sourced by a shell - Deal with the fact that nodejs doesn't have an exec that can replace the current node process: Ability to replace current Node process with another nodejs/node#21664
- You can deal with this the way babel deals with it
- Babel attempts to use
kexecwhere available, which is a POSIX-only module that replaces the process literally. Absent that, it falls back to its own implementation that works like the other two examples.