add option to resolve symlinks in WithLinuxDevice#7523
Conversation
|
Hi @ginglis13. Thanks for your PR. I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
/ok-to-test |
04056f6 to
748ac11
Compare
|
/cc @cpuguy83 @thaJeztah saw you folks had some work on related issues in containerd and docker, PTAL |
|
As this is a change in behavior, and other project may be using the existing functions, I wonder if (for the containerd library code), it should be opt-in to follow symlinks (also see moby/moby#20684 (comment), which suggested at the time to have a user-facing option as well); this could be a separate ( Whatever decision we get to, at least this behavior should be included in the function documentation so that consumers of those functions are aware of it. Happy to hear other's thoughts on that though. |
@thaJeztah Yea I agree that following device symlinks should be optional, I anticipated some security concerns, hence why I opened a PR for some feedback :) I'll rework this PR to provide an option |
748ac11 to
2d073a9
Compare
2d073a9 to
b2b8573
Compare
b2b8573 to
f9e6126
Compare
f9e6126 to
a913017
Compare
| if tc.expectError { | ||
| assert.Error(t, err) | ||
| } else { | ||
| require.NoError(t, err) |
There was a problem hiding this comment.
Why require here and not assert?
There was a problem hiding this comment.
The thought here was if we expect an error, then assert and log that error. However, if we do not expect an error and encounter one, then fail fast with require. But I see that's mostly just assuming the happy path. Changed to have both assert for consistency.
| } | ||
| if len(tc.expectedLinuxDevices) != 0 { | ||
| require.NotNil(t, spec.Linux) | ||
| require.NotNil(t, spec.Linux.Devices) |
There was a problem hiding this comment.
You probably want require.Len here instead.
7f6472e to
09d7507
Compare
This change modifies WithLinuxDevice to take an option `followSymlink` and be unexported as `withLinuxDevice`. An option `WithLinuxDeviceFollowSymlinks` will call this unexported option to follow a symlink, which will resolve a symlink before calling `DeviceFromPath`. `WithLinuxDevice` has been changed to call `withLinuxDevice` without following symlinks. Signed-off-by: Gavin Inglis <[email protected]>
09d7507 to
81bbd9d
Compare
|
The tests are all green finally! @samuelkarp Can you take a look again? |
This change adds
withLinuxDeviceto take an optionfollowSymlinks. An optionWithLinuxDeviceFollowSymlinkswill call this unexported option tofollow a symlink, which will resolve a symlink before calling
DeviceFromPath.WithLinuxDevicehas been changed to callwithLinuxDevicewithout following symlinks.Previously DeviceFromPath used Lstat to get information about a device file, but Lstat will not follow symlinks; stat will. The use case could be using a tool likeudevwhich will create symlinks to devices and wishing to attach one of these devices to a container.It looks likeDeviceFromPathis coming from runc, which does use Lstat instead of Stat but I didn't find any discussions as to why not resolve symlinks: opencontainers/runc/libcontainer/devices/device_unix.goDocker is resolving symlinks themselves before calling this function:
moby/moby/oci/devices_linux.go
which they did after some previous discussions in these issues/PRs:
Fixes #7006
Signed-off-by: Gavin Inglis [email protected]