-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 a .tsh/config file, add support for configuring custom http headers from the config file #10336
Conversation
7269027
to
a1c87ee
Compare
How can I test this myself? I wanted to see how I created a request bin on requestbin.com, I compiled
When I do |
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 just want to say that I'm new to both Teleport and Go, so I looked at the changes included in this PR just as GitHub shows them to me, but it'd be hard for me to say if there's a place we forgot to add the extra headers to.
Looks good in general, I just have a small question about hardcoding the path.
Also, when do we document such changes? Do other people write docs for them?
Is there a log at the beginning of the tsh output complaining about the .yaml file format? I think '*' needs to be in quotes. Currently it just continues, but maybe it should fail if a config file is invalid, I'm not sure which would be preferred. |
I scrolled up to see what was the output after running tsh and there was no log related to the error in config. However, I did git pull and it updated your branch from ce1acad to a1c87ee and now everything works as expected: the extra headers are sent to But yeah, I'm also not sure if it should fail if the config file has invalid YAML. I'd ask people more familiar with tsh than me. In case the header itself is invalid, tsh fails only when making the actual request, but I think that's okay. |
tool/tsh/tsh.go
Outdated
confOptions, err := loadConfig() | ||
if err != nil { | ||
fmt.Println("Failed to load tsh config: ", err) | ||
} |
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.
If I remove the config file completely, tsh logs this message:
Failed to load tsh config: open /Users/rav/.tsh/config/config.yaml: no such file or directory
I'm pretty sure we would like to avoid logging this, right? It seems like having no config file should let tsh continue as if confOptions
was nil.
We could take inspiration from kubeconfig.Load
:
teleport/lib/kube/kubeconfig/kubeconfig.go
Lines 218 to 220 in 84b64fe
// Load tries to read a kubeconfig file and if it can't, returns an error. | |
// One exception, missing files result in empty configs, not an error. | |
func Load(path string) (*clientcmdapi.Config, error) { |
A design decision I don't agree with, but at least the behavior would be consistent across different config files. ;)
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.
Ah yes - sorry didn't see this comment. I guess it's consistent but it's a poor user experience when replacing a binary on a patch change.
a1c87ee
to
7322f67
Compare
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'm not sure about the arg change that I pointed out, but the rest of the code looks fine to me, minus those failing tests.
Leaving an approve so that I don't obstruct your progress there after someone more familiar with the project reviews the PR.
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.
Also might be useful to share a dev build with a customer to make sure it addresses their use-case and we didn't miss any requests headers should be injected into.
7322f67
to
cbeb23f
Compare
@r0mant This makes sense, I did try to be thorough while trying to find places headers could be inserted from tsh commands. |
37e8151
to
66cb586
Compare
5210182
to
c7a29d2
Compare
// .tsh config must go in a subdir as all .yaml files in .tsh get | ||
// parsed automatically by the profile loader and results in yaml | ||
// unmarshal errors. |
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.
Can the profile loader be updated to ignore config.yaml
file instead?
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.
It could be but I think this would mean clusters couldn't be named config
which doesn't seem ideal
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.
This makes sense. Let me check with the product team on this. I think another option could be to just do something like ~/.tshrc
which seems consistent with where e.g. shells keep their preferences and it would have another benefit that we won't have to touch ~/.tsh
directory. But let's check with product first.
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.
@lxea We have decided that keeping it under ~/.tsh/config/config.yaml
is ok for now. Let's merge this as-is.
// .tsh config must go in a subdir as all .yaml files in .tsh get | ||
// parsed automatically by the profile loader and results in yaml | ||
// unmarshal errors. |
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.
@lxea We have decided that keeping it under ~/.tsh/config/config.yaml
is ok for now. Let's merge this as-is.
@lxea please don't forget to open a docs PR documenting this new config file |
When this file is missing the |
This adds a tsh config file to
~/.tsh/config/config.yaml
. It includes support for configuring custom http headers as specified in #9838. Support for the aliases configuration option will be created in a seprate PR.Current supported config file:
Also includes a change to stop tsh logout from blowing all of ~/.tsh away so config files can be retained.