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

Add the ability to print curl commands from CLI #6113

Merged
merged 9 commits into from
Feb 1, 2019
Merged

Add the ability to print curl commands from CLI #6113

merged 9 commits into from
Feb 1, 2019

Conversation

jefferai
Copy link
Member

This adds a flag -output-curl-string which will, instead of running the request, output an equivalent cURL string.

It's structured in such a way that we could easily add alternative formats (httpie, wget) without having to rename things in the API or have them be totally out of date.

@jefferai jefferai added this to the 1.0.3 milestone Jan 26, 2019
command/main.go Outdated Show resolved Hide resolved
// Build cURL string
d.parsedCurlString = "curl "
d.parsedCurlString = fmt.Sprintf("%s-X %s ", d.parsedCurlString, d.Request.Method)
for k, v := range d.Request.Header {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to redact known-sensitive headers such as X-Vault-Token?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, when it comes down to it if someone is sitting at your terminal they can easily get your token other ways. We could maybe require they put the token in an env var but it kind of breaks the point.

Maybe I'll just enhance the flag doc to explicitly mention it will do this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just added a commit that changes things a little, and I'm curious about feedback. Instead of printing the token, I added a vault print token command (although maybe if we think there might be more things like this coming up it should be vault debug print-token or so), and the curl string now uses that in a bash escape.

Three items for feedback:

  1. This will work with bash and zsh but not fish. Fish doesn't use backticks either, so...I guess if someone is interested they can submit a PR to check for the running shell env var and change up the output. It also obviously does not work on Windows; same story there, if people want it they could submit a PR to modify the output based on GOOS

  2. Is this even a good idea? I'm not sure it's a bad idea. There are plenty of ways to fetch the Vault token: read the env var, read the file, or if you are using an external token helper this will still require any extra authentication to be performed as with a normal Vault call. You could also, on a machine with a connection to Vault and a normal default policy, call vault token lookup and get it. On the flip side, doing it this way means the curl commands are emailable/portable -- you can send someone the line without having to do substitution. So I think it's a net neutral or positive.

  3. vault print token vs. vault debug print-token. Depends what we think we might have in the future. If we think we might have debuggish type stuff the latter makes sense. If we think we'll have more things to specifically print later, the former makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the approach as you've implemented it. Keeps the token out of the history but output is still generally copy-pasteable. I think I prefer vault print token, as this feels like a generally useful capability, especially when token helpers are in the mix.

@jefferai jefferai merged commit f404e0a into master Feb 1, 2019
@jefferai jefferai deleted the curl-cmds branch February 1, 2019 22:13
@ryan-moore-nw
Copy link

Hi @jefferai does this work with all vault commands?
I get:
$ vault kv list app-secrets/foo/ -output-curl-string cURL command not set by API operation; run without -output-curl-string to see the generated error
and without -output-curl-string, I get a list of keys in foo

@jaydipdave
Copy link

Same thing for me.

cURL command not set by API operation; run without -output-curl-string to see the generated error

@aalimovs
Copy link

@ryan-moore-nw @jaydipdave it's the location of your -output-curl-string option, it doesn't work if it's at the end of the command

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

Successfully merging this pull request may close these issues.

5 participants