Skip to content

Fix known_hosts locking by refactoring our locks in utils/fs#16364

Merged
AntonAM merged 4 commits intomasterfrom
anton/fix-windows-tsh
Sep 15, 2022
Merged

Fix known_hosts locking by refactoring our locks in utils/fs#16364
AntonAM merged 4 commits intomasterfrom
anton/fix-windows-tsh

Conversation

@AntonAM
Copy link
Copy Markdown
Contributor

@AntonAM AntonAM commented Sep 13, 2022

Turned out linux/mac and windows versions of flock work differently - on windows it's impossible to read/write file after locking, and tsh failed to read known_hosts file after locking on it.
To fix it we refactor file locks in utils/fs to take advantage of the split os approach - on non windows it will be working with just locking on target file as known_hosts currently works, but on windows we'll be creating .lock file. We still get benefits of automatic unlocking if something bad happens and process dies without explicitly unlocking the file, so we don't have to worry about handling leftover lockfiles. We also remove .lock file on unlock.

Related to #16057 and #15298
Fixes #16217

@AntonAM AntonAM added bug windows tsh tsh - Teleport's command line tool for logging into nodes running Teleport. backport/branch/v9 labels Sep 13, 2022
@AntonAM AntonAM requested review from r0mant and tigrato September 13, 2022 15:13
Comment thread lib/client/keystore.go Outdated
@ArunNadda ArunNadda added the c-stz Internal Customer Reference label Sep 14, 2022
@AntonAM AntonAM force-pushed the anton/fix-windows-tsh branch 2 times, most recently from dc5d21e to 3638f26 Compare September 14, 2022 05:19
Comment thread lib/utils/fs_windows.go Outdated
@AntonAM AntonAM changed the title Create lockfile when locking known_hosts Fix known_hosts locking by refactoring our locks in utils/fs Sep 14, 2022
@AntonAM AntonAM force-pushed the anton/fix-windows-tsh branch 2 times, most recently from 0c92076 to 8d80385 Compare September 14, 2022 14:38
@AntonAM AntonAM requested review from r0mant and tigrato September 14, 2022 15:14
Copy link
Copy Markdown
Collaborator

@r0mant r0mant left a comment

Choose a reason for hiding this comment

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

@AntonAM I'll let @tigrato and @timothyb89 to review the code but before we merge this, let's please test the following tsh login scenarios on both Linux (or Mac) and Windows to make sure nothing else breaks:

  • Simple login with local user.
  • Login with SSO (e.g. Github or Okta SAML connector).
  • Login with MFA (e.g. TouchID).

@AntonAM
Copy link
Copy Markdown
Contributor Author

AntonAM commented Sep 14, 2022

@r0mant 👍 I've already checked with OTP on Mac and Windows during development, will check the rest.

Comment thread lib/utils/fs.go Outdated
Comment thread lib/utils/fs.go Outdated
@github-actions github-actions Bot removed the request for review from atburke September 14, 2022 21:51
Comment thread lib/utils/fs.go Outdated
library and add support for windows

Flock works differently on linx/mac vs windows. On windows it's impossible to
read/write file after locking, so we need to create separate lockfile.
@AntonAM AntonAM force-pushed the anton/fix-windows-tsh branch from 117f8e1 to 91204e3 Compare September 15, 2022 15:16
@AntonAM AntonAM merged commit 7695f23 into master Sep 15, 2022
@github-actions
Copy link
Copy Markdown
Contributor

@AntonAM See the table below for backport results.

Branch Result
branch/v10 Create PR
branch/v9 Failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug c-stz Internal Customer Reference tsh tsh - Teleport's command line tool for logging into nodes running Teleport. windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace usage of file locks in utils/fs_* with flock

5 participants