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

feat: pk secrets env command #505

Closed
wants to merge 2 commits into from
Closed

feat: pk secrets env command #505

wants to merge 2 commits into from

Conversation

CMCDragonkai
Copy link
Member

Description

This introduces a prototype pk secrets env command to inject secrets into a command.

Right now we're going to do something simple as the kexec library is not ready (MatrixAI/Polykey-CLI#31), and plus we would probably need to make it ourselves to ensure cross platform behaviour.

For demo purposes (#504) it's sufficient to just do a subprocess.

Some differences from #265...

Instead of doing vault:secretpath:name we can do name=vault:secretpath.

This makes it closer to the behaviour of the env command.

We can add in flag -i|--ignore-environment and -C|--chdir like the env command too. Not sure if this fits our flag styles, since we would normally do -ie and -cd.

Issues Fixed

Tasks

Final checklist

  • Domain specific tests
  • Full tests
  • Updated inline-comment documentation
  • Lint fixed
  • Squash and rebased
  • Sanity check the final build

@CMCDragonkai CMCDragonkai self-assigned this Feb 3, 2023
@CMCDragonkai CMCDragonkai mentioned this pull request Feb 3, 2023
15 tasks
@ghost
Copy link

ghost commented Feb 3, 2023

👇 Click on the image for a new way to code review
  • Make big changes easier — review code in small groups of related files

  • Know where to start — see the whole change at a glance

  • Take a code tour — explore the change with an interactive tour

  • Make comments and review — all fully sync’ed with github

    Try it now!

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

@CMCDragonkai
Copy link
Member Author

I was looking at the parseSecretPath utility as this was used to parse <vaultName>:<secretPath> parameters.

The regex used here doesn't seem to be well thought out.

I traced what actually is the limitation of secretPath, anyway this is just a string that is passed to EFS.

EFS has no limitations with the string.

It does some things like:

  • Coalescing consecutive slashes into 1 slash
  • Trailing slash is considered to refer to a directory and is replaced with /. at the very end

But that's it, so that means the EFS strings are more flexible than even Linux FS path strings since they only restrict null characters (technically we could even have null characters).

However in our PK usecase allowing such arbitrary strings are a bad idea. The reason is when we are loading such files back on to the OS's FS, we will eventually hit problems with converting to to OS FS paths.

So it's better to focus on the lowest common denominator with respect to secretPath strings.

This means we combine the limitations of linux paths, windows paths and darwin paths together and create a regex in turn to match those kinds of paths.

Then the parseSecretPath should be changed to parseSecretAddress.

In the future this could be made closer to URI. In fact it makes more sense to just think of the vault name as just another component path. That is vaultName/secret/path. This is because the vault name itself is just a name of the directory in our root EFS.

But we should still call it parseSecretAddress otherwise we lose a distinction here with the remainder path.

So even the vault name itself is subject to the same requirements, however I think the vault name may have other limitations. I forgot if there was some reason we had to use a specialised vault ID, or if the vault name is just a string we put into the DB.

Thoughts @tegefaulkes?

@CMCDragonkai
Copy link
Member Author

Here's a comparison of all the limitations: https://en.wikipedia.org/wiki/Filename#Comparison_of_filename_limitations.

If we keep it simple right now, this allows us [a-zA-Z0-9\/@$! #%\-_=+^&();,.{}\[\]']+.

So we can then change our regex to capture the first vault name group with the above, then everything subsequently afterwards.

@tegefaulkes
Copy link
Contributor

tegefaulkes commented Feb 3, 2023

I've been thinking of the vault path like it's a scp remote path. having the format vaultname:some/secret/path gives a clear distinction between local files and vault files. If we run with this semantic we can even have a generic copy command that can move a secret around.

  • local fs -> vault : secrets cp local/path vault1:vault/path
  • vault -> local fs : secrets cp vault1:vault/path local/path
  • vault -> vault : secrets cp vault1:vault/path vault2:vault/path

You could even go crazy and reference secrets in a remote vault vault@nodeId:some/path but that seems doesn't really make sense.

@CMCDragonkai
Copy link
Member Author

This can no longer be implemented here, it would need to be done as part of Polykey-CLI. Closing this PR, but the issue MatrixAI/Polykey-CLI#31 is still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

The pk secrets env command for meeting Development Environment Usecase
2 participants