Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add customizable header command #119

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

Merged
merged 8 commits into from
Aug 18, 2023
Merged

Add customizable header command #119

merged 8 commits into from
Aug 18, 2023

Conversation

code-asher
Copy link
Member

@code-asher code-asher commented Aug 4, 2023

The command will be executed before requests and before configuring SSH to set custom headers.

Some notes:

  1. When I use --header I seem to get the value set twice. For example if I use coder --header X-MY-CUSTOM-HEADER=hello-there then on the server end I see x-my-custom-header: hello-there, hello-there so we should look into that.
  2. I went with environment variables to pass data to the credentials process for now since I figured that would be easier than parsing command-line arguments but opinions are welcome here. Only CODER_URL right now. Are there others needed?
  3. More importantly, I am not sure about the config SSH portion. Since configuration might only happen on the first connect, the headers we hardcode into the SSH config could expire.

I have two main ideas for fixing the SSH config issue:

  1. Modify the CLI to call out to the same process to get the headers. --credentials-process or something like that. The CLI executes the process just as the extension does and sets the headers. We set --credentials-process in the SSH config on the plugin side and are off to the races.
  2. Add a second VS Code setting for a proxy command wrapper which gets passed the path to the Coder binary and is responsible for adding the appropriate --header flags and passing through any other flags. This way this credential process is called every time SSH is invoked. Or instead of a separate setting it could be an environment variable/flag and we reuse the same process; it can switch behavior depending on what task it needs to do (output JSON or execute the Coder binary).

An example of the second option: ProxyCommand my-wrapper --wrapper-flags -- --coder-flags where my-wrapper is essentially exec $CODER_BINARY --header my-custom-header "$@" except everything after -- should get passed through to the Coder binary and the rest can be flags to the wrapper itself in case we need them.

Thoughts? I am inclined to go the first route since the second requires more complexity on the user side but the second does at least have the advantage (or danger) of allowing more control over how the Coder binary executes.

I also considered substitution in the proxy command (something similar to coder $(/path/to/credentials-process) ssh dev.dev --stdio) but I am not sure that is portable.

Sorted the above, --header-command has been added to the CLI although we will need the next release before this can be used in the plugin.

Closes #76 and supersedes #81.

@code-asher code-asher force-pushed the asher/credentials-process branch 3 times, most recently from 8b4e951 to 0423107 Compare August 4, 2023 22:22
@kylecarbs
Copy link
Member

Option 1 seems correct to me as well.

For the naming, should we call this proxy-credential-process or something else instead? credential-process sounds idiomatic, but could easily be confused for Coder credentials instead of middleware credentials.

@code-asher
Copy link
Member Author

Ooo yeah good point, technically could you actually use this for Coder credentials by supplying the token header? But we might not want to encourage that type of use.

I think proxy-credential-process makes it sound like it only works for authenticating to proxies and although VPN is pretty much a proxy I wonder if folks will see proxy and only think about reverse proxies. Or there could be a case where no proxy is involved but they have some required header.

Maybe since we have --header we can base it off that and have something like --header-process? It could be unfortunate if we want to support more than headers in the future but I am not sure what else we might want and if something else does come up we might want it to be a separate process in that case anyway.

@code-asher
Copy link
Member Author

Or --config-process if we think we might need to be more generic.

@liorb-canva
Copy link

@code-asher option 1 seems fine as well for us

@code-asher code-asher force-pushed the asher/credentials-process branch from 0423107 to 534be09 Compare August 14, 2023 21:17
@code-asher code-asher changed the title Add customizable credentials process Add customizable header command Aug 14, 2023
This was causing issues with the header flag as those contain equal
signs.
@code-asher code-asher force-pushed the asher/credentials-process branch 6 times, most recently from 36c842b to 2625f25 Compare August 14, 2023 23:37
@code-asher
Copy link
Member Author

I am not sure if we need to check the Coder version before setting the new flag but since it only sets if you provide the value maybe it is OK to just rely on the user only adding it if their version supports the new flag?

@code-asher code-asher requested a review from kylecarbs August 14, 2023 23:38
This will be called before requests and added to the SSH config.
@code-asher code-asher force-pushed the asher/credentials-process branch from 2625f25 to 811673f Compare August 14, 2023 23:40
I got this once, not sure how to reproduce it now though.
Forgot escape adds its own wrapping quotes.
src/extension.ts Outdated
...config,
headers: {
...(await storage.getHeaders()),
...creds.headers,

Choose a reason for hiding this comment

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

hey @code-asher this does not compile..
I've tried to run it locally and it failed

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah just realized I messed this up, fixing now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Pushed a fix!

Copy link
Member Author

@code-asher code-asher Aug 18, 2023

Choose a reason for hiding this comment

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

Turns out I had another issue where the URL in storage was not set yet (for the login request) resulting in no headers. I think everything is working now, will test a bit more then merge this in. Let me know if you find anything else wrong!

First, I replaced the wrong line, needed to replace the second one.

Secondly, seems you cannot actually spread like this because
config.headers actually has a bunch of functions on it.
To avoid an error like "127.0.0.1:80 ECONNREFUSED".  Before we did not
log the error so this did not matter so much but now we do to catch
header issues.
At this stage the URL may not be set.  Or it could be set to the
previous URL.  We need to use the URL of the actual request.
@code-asher code-asher force-pushed the asher/credentials-process branch from 2bb02f9 to a7f21be Compare August 18, 2023 06:58
@code-asher code-asher merged commit 3ab3aad into main Aug 18, 2023
@code-asher code-asher deleted the asher/credentials-process branch August 18, 2023 07:03
@bpmct bpmct mentioned this pull request Aug 18, 2023
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.

pass headers to coder api
3 participants