Skip to content

Careful handling when loading files#31721

Merged
jentfoo merged 16 commits intomasterfrom
jent/symlink_fixes
Sep 15, 2023
Merged

Careful handling when loading files#31721
jentfoo merged 16 commits intomasterfrom
jent/symlink_fixes

Conversation

@jentfoo
Copy link
Copy Markdown
Contributor

@jentfoo jentfoo commented Sep 11, 2023

This PR attempts to provide a common API so that the decision of when to follow symlinks is a conscious decision. Because Teleport (particularly the agent) runs in a privileged context, there is risk that following symlinks may allow information disclosure.

After review of the cases covered in this commit (and some additional cases where this API was not a natural fit), this does not appear to be a broad problem. This PR however does fix the one known flaw described in the issue https://github.com/gravitational/teleport-private/issues/1009

In many cases where this API is being adopted, symlinks are still being allowed. This is only after verifying there is no information disclosure when symlinks are followed. Although symlinks are not likely useful in many of these cases, this choice to still allow symlinks is to maintain compatibility with potentially unknown use cases. Future use of this API will almost certainly always specify a false for allowing symlinks.

Comment thread lib/cgroup/cgroup.go Outdated
Comment thread lib/utils/fs.go Outdated
@timothyb89 timothyb89 self-requested a review September 11, 2023 20:24
Comment thread lib/utils/fs.go Outdated
@Tener
Copy link
Copy Markdown
Contributor

Tener commented Sep 12, 2023

Independently, these two params are meaningful in this context:

These are available in Linux kernel 3.6+, released 11 years ago, and enabled in most contexts (but not all).

I don't think such an option is available on MacOS, though. It surely isn't the default.

Comment thread lib/utils/fs_test.go Outdated
Comment thread lib/utils/fs.go Outdated
Comment thread lib/utils/fs_test.go Outdated
@Tener
Copy link
Copy Markdown
Contributor

Tener commented Sep 12, 2023

From the compatibility point of view, this is a breaking change. I don't think it will affect many configurations, but it is possible, in principle, that one of the paths in which we will now disallow symlinks contains those. For example, you can have /home/%username%/ be a home dir for users, but symlinked to /mnt/networkshare/developers/%username%. For that reason, I'd add appropriate label as well as avoid backports to old releases.

Comment thread lib/utils/fs.go Outdated
Comment thread lib/utils/fs.go Outdated
Comment thread lib/utils/fs.go Outdated
Comment thread lib/utils/fs.go Outdated
Comment thread lib/utils/fs.go
Comment thread lib/utils/fs.go Outdated
Comment thread lib/utils/fs_test.go Outdated
Comment thread lib/utils/fs_test.go Outdated
Comment thread lib/utils/fs_test.go Outdated
Comment thread lib/utils/fs_test.go Outdated
@codingllama
Copy link
Copy Markdown
Contributor

From the compatibility point of view, this is a breaking change

Could we mention in the changelog, for example, the places where symlinks are not allowed anymore? (Ie, the places affected by the change.)

@jentfoo

@jentfoo
Copy link
Copy Markdown
Contributor Author

jentfoo commented Sep 12, 2023

Compatibility options are being discussed here: https://github.com/gravitational/teleport-private/issues/1009#issuecomment-1716028879

I think we can find a way to backport this improvement while maintaining compatibility.

@codingllama
Copy link
Copy Markdown
Contributor

I think we can find a way to backport this improvement while maintaining compatibility.

I fail to see how the behavioral change would be non-breaking. I'm not saying to not backport, no strong opinions there on my part, just asking that we document whatever gets changed.

This commit attempts to provide a common API so that the decision of when to follow symlinks is a conscious decision.
Because Teleport (particularly the agent) runs in a privilege context, there is risk that following symlinks may allow information disclosure.

After review of the cases covered in this commit (and some additional cases where this API was not a natural fit), this does not appear to be a broad problem.  This commit however does fix the one known flaw described in the issue https://github.com/gravitational/teleport-private/issues/1009
Copy link
Copy Markdown
Contributor

@codingllama codingllama left a comment

Choose a reason for hiding this comment

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

Looks good, holding out just in case you do more test changes.

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.

I don't have objections to including this change in Teleport 14 (bar potential compilation issue) but @jentfoo can you please add a section describing the user impact of this change to our draft release notes under the "Breaking changes".

I also assume you did a smoke test with this change (e.g. starting teleport and starting a session)?

Comment thread lib/utils/fs.go Outdated
@zmb3
Copy link
Copy Markdown
Collaborator

zmb3 commented Sep 14, 2023

We also build tctl for windows. We don't ship it yet, but we do build it on push and a lot of work went in to getting this far so please don't break it 🙂

Make hardlink count lookup code build conditional to avoid undefined syscall.Stat_t.
Comment thread lib/utils/fs_unix.go Outdated
Comment thread lib/utils/fs_unix.go
Comment on lines +33 to +37
if statT, ok := fi.Sys().(*syscall.Stat_t); ok {
return true, statT.Nlink
} else {
return false, 0
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd write this slightly differently in order to eliminate the else and align the happy path to the left.

statT, ok := fi.Sys().(*syscall.Stat_t)
if !ok {
    return false, 0
}
return true, statT.Nlink

Copy link
Copy Markdown
Contributor Author

@jentfoo jentfoo Sep 14, 2023

Choose a reason for hiding this comment

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

This seems basically the same to me. I tend to prefer avoiding ! conditionals when logic when both states needs to be handled anyways.

Comment thread lib/utils/fs_windows.go Outdated
Comment thread lib/utils/fs_windows.go Outdated
@jentfoo
Copy link
Copy Markdown
Contributor Author

jentfoo commented Sep 14, 2023

@r0mant I have a suggestion in the release notes for how to describe this. I tried to describe it fairly generically, but the only known use case to me is the loading of the .tsh/environment file. Feel free to DM me if you think there is any better way to describe this for our customers.

Also I have added the branch/v14 backport label so we can include this as part of Teleport 14

@jentfoo jentfoo added this pull request to the merge queue Sep 15, 2023
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 15, 2023
@jentfoo jentfoo added this pull request to the merge queue Sep 15, 2023
Merged via the queue into master with commit 4cba417 Sep 15, 2023
@jentfoo jentfoo deleted the jent/symlink_fixes branch September 15, 2023 15:18
@public-teleport-github-review-bot
Copy link
Copy Markdown

@jentfoo See the table below for backport results.

Branch Result
branch/v14 Create PR

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

Labels

machine-id size/sm tctl tctl - Teleport admin tool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants