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

tbot configure command for assisting Machine ID configuration #12517

Merged
merged 3 commits into from
May 10, 2022

Conversation

strideynet
Copy link
Contributor

@strideynet strideynet commented May 9, 2022

Closes #11483

Command outputs YAML to stdout or to a file, allowing the user to create a configuration file from parameters. This assists users with achieving a working tbot configuration as fast as possible.

The -o flag can be provided to write the configuration directly to a file, but when this is omitted, the configuration is just output to stdout:

➜  teleport git:(strideynet/machine-id-yaml-configuration-output) ✗ build/tbot configure -a "foo.com" --token "xyyzz" -o ~/test 
INFO [TBOT]      Generated config file written to file: /Users/noahstride/test tbot/main.go:177
➜  teleport git:(strideynet/machine-id-yaml-configuration-output) ✗ cat ~/test
# tbot config file generated by `configure` command
onboarding:
  token: xyyzz
  ca_path: ""
  ca_pins: []
  join_method: token
storage:
  directory:
    path: /var/lib/teleport/bot
    symlinks: try-secure
    acls: "off"
debug: false
auth_server: foo.com
certificate_ttl: 1h0m0s
renewal_interval: 20m0s
oneshot: false
➜  teleport git:(strideynet/machine-id-yaml-configuration-output) ✗ build/tbot configure -a "foo.com" --token "xyyzz"          
# tbot config file generated by `configure` command
onboarding:
  token: xyyzz
  ca_path: ""
  ca_pins: []
  join_method: token
storage:
  directory:
    path: /var/lib/teleport/bot
    symlinks: try-secure
    acls: "off"
debug: false
auth_server: foo.com
certificate_ttl: 1h0m0s
renewal_interval: 20m0s
oneshot: false

golden

This also introduces a test helper package called golden. I'm happy to extract this into a separate PR if needs be. I have found golden files to be a very convenient and effective way of handling large expected outputs from tests in a way that can be easily updated, and inspected in PR diffs.

"Golden files" are expected test outputs stored as files under testdata/ rather than embedded directly within the test table. Running the tests with the environment variable GOLDEN_UPDATE=1 causes this files to be updated, rather than asserted against.

@strideynet strideynet force-pushed the strideynet/machine-id-yaml-configuration-output branch 5 times, most recently from 7d57aa0 to 7df8370 Compare May 9, 2022 10:57
// the same across dev laptops and GCB.
// If we switch to a more dependency injected model for botfs, we can
// ensure that the test one returns the same value across operating systems.
normalizeOSDependentValues := func(data []byte) []byte {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm really not a fan of this, but I didn't want to completely refactor botfs to be a dependency injected struct without a bit more investigation.

I'm completely open to some more suggestions here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that's unfortunate. The overly-simple botfs design has caused some problems already and I'm not opposed to refactoring it.

@strideynet strideynet force-pushed the strideynet/machine-id-yaml-configuration-output branch 2 times, most recently from 116b026 to f26dd16 Compare May 9, 2022 11:27
@strideynet strideynet marked this pull request as ready for review May 9, 2022 11:28
@github-actions github-actions bot requested review from LKozlowski and zmb3 May 9, 2022 11:28
@strideynet strideynet requested a review from timothyb89 May 9, 2022 11:28
@strideynet strideynet force-pushed the strideynet/machine-id-yaml-configuration-output branch 2 times, most recently from fdde9b1 to 2ef34cd Compare May 9, 2022 13:26
lib/utils/golden/golden.go Outdated Show resolved Hide resolved
tool/tbot/main_test.go Outdated Show resolved Hide resolved
tool/tbot/main_test.go Outdated Show resolved Hide resolved
@strideynet strideynet force-pushed the strideynet/machine-id-yaml-configuration-output branch from f8b5bad to 3cda886 Compare May 9, 2022 15:34
// the same across dev laptops and GCB.
// If we switch to a more dependency injected model for botfs, we can
// ensure that the test one returns the same value across operating systems.
normalizeOSDependentValues := func(data []byte) []byte {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that's unfortunate. The overly-simple botfs design has caused some problems already and I'm not opposed to refactoring it.

@@ -292,7 +296,7 @@ func FromCLIConf(cf *CLIConf) (*BotConfig, error) {
}

if err := config.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err, "validing merged bot config")
return nil, trace.Wrap(err, "validating merged bot config")
Copy link
Contributor

Choose a reason for hiding this comment

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

🤦

@strideynet strideynet force-pushed the strideynet/machine-id-yaml-configuration-output branch from 3cda886 to 2f39587 Compare May 9, 2022 20:18
@strideynet strideynet enabled auto-merge (squash) May 9, 2022 20:18
@strideynet strideynet force-pushed the strideynet/machine-id-yaml-configuration-output branch from 2f39587 to 77dba07 Compare May 9, 2022 22:12
@strideynet strideynet force-pushed the strideynet/machine-id-yaml-configuration-output branch from 77dba07 to 93a4214 Compare May 10, 2022 06:56
@strideynet strideynet merged commit 2f00cb4 into master May 10, 2022
@strideynet strideynet deleted the strideynet/machine-id-yaml-configuration-output branch May 10, 2022 10:05
strideynet added a commit that referenced this pull request May 11, 2022
* add `tbot configure` command

* introduce golden file test helper

* address PR comments by zmb
strideynet added a commit that referenced this pull request May 17, 2022
* add `tbot configure` command

* introduce golden file test helper

* address PR comments by zmb
strideynet added a commit that referenced this pull request May 17, 2022
…) (#12576)

* add `tbot configure` command

* introduce golden file test helper

* address PR comments by zmb
@webvictim webvictim mentioned this pull request Jun 8, 2022
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.

Improve machine ID config generation
3 participants