-
Notifications
You must be signed in to change notification settings - Fork 4
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
Remove newlines by default when exporting contents using secrets env
#329
Conversation
We are using Also, there was a minor inaccuracy in the command, where the command would fail without any environment variables being provided. This is different than the Unix |
In our case |
By default, when no variables are provided to In our case, it does not make much sense, but is a deviation from the standard Unix behaviour, which is why I wanted to ask and confirm this. |
After talking about this with Brian, I have realised that the Polykey client is actually stopped before the commands are even run. This means that, without a connection to Polykey, the websocket errors won't happen, and that is a non-issue in this case. I did a manual sanity check by using a long-running command in |
ca35a71
to
074595b
Compare
The syntax to preserve newlines for a secret is as follows: [aryanj@matrix-34xx:~]$ polykey secrets env vault:SECRET1 vault:SECRET2
SECRET1='testing123'
SECRET2='testing123'
[aryanj@matrix-34xx:~]$ polykey secrets env -pn vault:SECRET1 vault:SECRET2
SECRET1='testing123
'
SECRET2='testing123'
[aryanj@matrix-34xx:~]$ polykey secrets env --preserve-newline VAULT:SECRET3
SECRET3='newlines-after-this
'
[aryanj@matrix-34xx:~]$ polykey secrets env VAULT:SECRET3
SECRET3='newlines-after-this
' If the newlines should be preserved, then the flag |
How should I handle providing the same secret in two different contexts? If What about cases where we export entire vaults? Currently, the flag does preserve newlines of all the secrets exported from the vault, but what if we need one secret to have newlines, and the rest can be trimmed? Or vice-versa, where all secrets need to have preserved newlines, but one secret needs to be trimmed? How would be handle those cases? With the way how the command is currently structured, is it not possible to preserve the order of the secrets, so they can't be used for prioritisation. Currently, the preserving newline takes precedence over trimming them. For example, the following will preserve newlines for all secrets: [aryanj@matrix-34xx:~]$ polykey secrets env -pn vault vault:SECRET1
SECRET1='testing123
'
SECRET2='testing123
' Should this be the intentional behaviour? @CMCDragonkai |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've run into a roadblock and need some inputs from @CMCDragonkai and @tegefaulkes to help me with some issues.
You can have a global flag or the flags are applied per spec. I would do something like that. |
By default secret env is going to need to trim a single trailing newline. Repeating the spec is an interesting situation I would argue that you maintain order in line with whatever the order of the specification is. In the case of env shells the last one takes priority because of how shell processes them. |
After a discussion with Brian, we have come to the following conclusion: Instead of using a separate option like This means that all secrets specified are, by default, trimmed. However, if a secret name is present in the list to preserve newlines, then the newlines will be preserved. This approach does cause duplication to the secret path, but that's not a huge concern, as most of the times, the newlines would be trimmed as usual. This approach solves all the issues. The newline preservation takes precedence. If the newlines must be trimmed, then don't specify it to be preserved. As the arguments need to be populated anyways, they will never be empty, and the usual checks can be done from within the parser without need of manually creating an empty object or throwing an error from the action. This also, to an extent, treats the symptoms of |
Can you also review MatrixAI/Polykey#222 (comment)? I want to make sure we're laying foundations to enable egress schema implementation. |
Just to confirm, this egress schema refers to a schema which would allow formatting of the secrets in a particular way at the time of egress, which would be using the |
76a1e6f
to
6bc2f06
Compare
Key changes in this PR:
Need input on:
|
If we are using exec, subprocess failure should be temporary on Unix systems, because of process replacement. It would be more accurate to say that you were not able to execute the subprocess. Also I prefer the name ChildProcess. On windows however there is no process replacement. It's always a child process. Did you do cross platform sanity checks? |
Oh, it completely slipped my mind. I will do this today before merging. |
|
feat: added option to preserve newlines chore: removed listeners after closing edit process chore: added fastcheck tests for added features chore: automatically removing -- from parsed command list chore: added comments for empty cases chore: optimised handling of newline preservation chore: updated tests
6bc2f06
to
cee36f4
Compare
The CI is passing, and the PR has been approved. I will be merging it now. |
This was a significant change to the UX of secrets env. Now it is actually usable. |
Description
The standard to end all files in Unix is adding a newline at the end of the file. All editors, including
vim
do it. However, adding a stray newline at the end of a secret, like a password, can have adverse effects.As such, this PR will, by default, trim the single trailing newline, with an option to disable it if needed.
Issues Fixed
secrets env
to omit single trailing\n
from files which automatically include it #296 (REF ENG-416)secrets env
needs--
to be passed twice to parse the command #325 (REF ENG-466)Tasks
Final checklist