-
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
Improve error handling in tbot start
#11756
Improve error handling in tbot start
#11756
Conversation
This attempts to improve a number of error handling issues while loading the bot identity from storage in `tbot start`: 1. Identity loading errors are silently ignored and the bot always attempts to generate a new identity from token. This isn't always correct and is impossible to debug as the true error is never logged. We now debug log these errors. 2. `LoadIdentity()` doesn't properly account for existing-but-empty identity files and happily tries to load empty identities from `tbot init`. This isn't hugely harmful, but produces nonsensical error logs once #1 is fixed.
I've made a dev build of this PR for testing purposes: https://get.gravitational.com/teleport-v10.0.0-dev.200-linux-amd64-bin.tar.gz |
@timothyb89 Don't forget to add test coverage. |
This behaves the same as the fs_linux secure implementation in all cases, and moves the open mode to a shared constant for good measure.
…d-improve-identity-loading-errors
tool/tbot/botfs/botfs_test.go
Outdated
data, err := Read(path, test.mode) | ||
require.NoError(t, err) | ||
|
||
require.Zero(t, bytes.Compare(data, expectedData), "read bytes must be equal to those written") |
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.
Does require.Equal
not work here? I would rather see an error message that shows the diff than an error message that says "got -1 want 0"
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.
That's fair, will change!
Co-authored-by: Zac Bergquist <[email protected]>
* Improve error handling in `tbot start` This attempts to improve a number of error handling issues while loading the bot identity from storage in `tbot start`: 1. Identity loading errors are silently ignored and the bot always attempts to generate a new identity from token. This isn't always correct and is impossible to debug as the true error is never logged. We now debug log these errors. 2. `LoadIdentity()` doesn't properly account for existing-but-empty identity files and happily tries to load empty identities from `tbot init`. This isn't hugely harmful, but produces nonsensical error logs once #1 is fixed. * Use `O_RDWR` instead of `O_WRONLY` in `botfs.openStandard()` This behaves the same as the fs_linux secure implementation in all cases, and moves the open mode to a shared constant for good measure. * Add a small unit test for symlinks mode read/write. * Fail on non-NotFound errors while reading an Identity. * Add small unit test for empty identities. * Remove outdated TODO comment * Apply suggestions from code review Co-authored-by: Zac Bergquist <[email protected]> * Address review feedback Co-authored-by: Zac Bergquist <[email protected]>
* Improve error handling in `tbot start` This attempts to improve a number of error handling issues while loading the bot identity from storage in `tbot start`: 1. Identity loading errors are silently ignored and the bot always attempts to generate a new identity from token. This isn't always correct and is impossible to debug as the true error is never logged. We now debug log these errors. 2. `LoadIdentity()` doesn't properly account for existing-but-empty identity files and happily tries to load empty identities from `tbot init`. This isn't hugely harmful, but produces nonsensical error logs once #1 is fixed. * Use `O_RDWR` instead of `O_WRONLY` in `botfs.openStandard()` This behaves the same as the fs_linux secure implementation in all cases, and moves the open mode to a shared constant for good measure. * Add a small unit test for symlinks mode read/write. * Fail on non-NotFound errors while reading an Identity. * Add small unit test for empty identities. * Remove outdated TODO comment * Apply suggestions from code review Co-authored-by: Zac Bergquist <[email protected]> * Address review feedback Co-authored-by: Zac Bergquist <[email protected]> Co-authored-by: Zac Bergquist <[email protected]>
This attempts to improve a number of error handling issues while loading the bot identity from storage in
tbot start
:NotFound
-type error.LoadIdentity()
doesn't properly account for existing-but-empty identity files and happily tries to load empty identities fromtbot init
. This isn't hugely harmful, but produces nonsensical error logs once (1) is fixed. We now check to make sure these files are non-empty and return an error if they are.symlinks: insecure
because the open mode in the fallback case was wrong (O_WRONLY
rather thanO_RDWR
as it is for secure open). We now move that to a constant and share the opening mode between both implementations.NotFound
error.