Skip to content
This repository has been archived by the owner on Jun 11, 2019. It is now read-only.

Add exec command #19

Merged
merged 10 commits into from
Oct 15, 2018
Merged

Add exec command #19

merged 10 commits into from
Oct 15, 2018

Conversation

remen
Copy link
Contributor

@remen remen commented Jun 16, 2017

When embedding standalone static binaries in a docker container, it feels nice to use the empty "scratch" docker image as a starting point. However, this fails when also wanting secretary support, since the current workflow requires a shell.

This PR adds the support for secretary exec -- cmd [args..] which will decrypt all environment variables and all command line arguments without requiring an embedding shell to do the work.

@codecov-io
Copy link

codecov-io commented Jun 16, 2017

Codecov Report

Merging #19 into master will decrease coverage by 1.85%.
The diff coverage is 36.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #19      +/-   ##
==========================================
- Coverage   51.48%   49.63%   -1.86%     
==========================================
  Files           8        8              
  Lines         606      683      +77     
==========================================
+ Hits          312      339      +27     
- Misses        254      306      +52     
+ Partials       40       38       -2
Impacted Files Coverage Δ
main.go 0% <0%> (ø) ⬆️
commands.go 83.01% <81.48%> (+3.01%) ⬆️
box.go 72.03% <89.47%> (+9.53%) ⬆️
marathon.go 83.67% <0%> (-0.33%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ca56ce1...495365c. Read the comment docs.

box.go Outdated
@@ -150,6 +150,29 @@ func genkey(publicKeyFile string, privateKeyFile string) {
pemWrite(privateKey, privateKeyFile, "NACL PRIVATE KEY", 0600)
}

func decryptEnvelopes(input string, decryptor DecryptionStrategy) (output string, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add test case where the base64 encoded envelope contains whitespaces and newlines, for example if it's broken into fixed-width blocks. I think there may be a stripWhitespace lacking somewhere in this function, like the decryptStream() and decryptEnvironment() commands do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

commands.go Outdated

decryptedArgs[0] = path.Base(cmd) // By unix convention argv[0] has to be set to basename of command
for i, arg := range args[1:] {
decryptedArg, subErr := decryptEnvelopes(arg, crypto)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you consider refactoring atleast decryptStream() and possibly decryptEnvironment() to use the decryptEnvelopes() function as well? Cut's down the complexity now that you've extracted a nice reusable function here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

main.go Outdated
},
}

cmdExec.SetUsageTemplate(`Usage:{{if .Runnable}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? None of the other commands need to specify a convoluted template like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment explaining the rationale


# Decrypt secrets
if [ "$SERVICE_PUBLIC_KEY" != "" ]; then
SECRETS=$(secretary decrypt -e --service-key=/service/keys/service-private-key.pem)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exec command example doesn't support using the service key. This optional key provides more security by ensuring that the secret can only be decrypted on a specific set of machines that hold the private service key on local disk. Not sure how to solve this right off, could we have a chat about it?

Copy link
Contributor Author

@remen remen Jun 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's discuss this briefly tomorrow. Could it be solved by allowing for either --service-key or SERVICE_PUBLIC_KEY environment variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... it seems there is support already here: https://github.com/meltwater/secretary/pull/19/files#diff-7ddfb3e035b42cd70649cc33393fe32cR162 (line 162). However, we do remove the logic of "by default use /service/keys/service-private-key.pem if it exists".

Copy link
Contributor Author

@remen remen Jun 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now supports setting a path to a pem file in SERVICE_PRIVATE_KEY

Also updated documentation about how to properly set this in marathon config

@remen remen requested a review from dezmodue June 21, 2017 07:42
@remen
Copy link
Contributor Author

remen commented Sep 16, 2018

@dezmodue or other @meltwater/foundation members. Can we merge this and release a new version of secretary? It would enable us to more easily use non-meltwater base images that don't necessarily have a shell.

@jcsorvasi jcsorvasi merged commit 5134958 into master Oct 15, 2018
@jcsorvasi jcsorvasi deleted the exec_command branch October 15, 2018 14:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants