Skip to content

Fix setting setuid/gid bits with uid/gid and add a test #2049

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

travier
Copy link
Member

@travier travier commented Apr 7, 2025

Support for setuid/setgid/sticky bit got added in 1 but we did not add tests and it's unclear when support for it broke.

See: #2042

@travier travier added the skip-notes This PR does not need release notes label Apr 7, 2025
@prestist
Copy link
Collaborator

prestist commented Apr 8, 2025

Test makes sense, looking at the error I am not sure; I am trying to read up on special mode bits to make sure I understand them. Would the out bits be different the in ? ( I assume yes based on your test) but I am not able to find documentation that can explain it to me.

@prestist
Copy link
Collaborator

@travier I think I found it, its because our order of setting ownership and perms were backwards. It passes locally 🤞

@travier
Copy link
Member Author

travier commented Apr 16, 2025

Nice catch!

@prestist prestist force-pushed the tests-setuid-setgid-sticky branch 3 times, most recently from 773db46 to ab57b8b Compare April 16, 2025 21:05
@travier travier force-pushed the tests-setuid-setgid-sticky branch from ab57b8b to 3fcc055 Compare April 23, 2025 15:34
@travier
Copy link
Member Author

travier commented Apr 23, 2025

So, this should fix the issue, but the problem is the same that the one we had in #1325, in that it's kind of a security issue to change this behavior for existing spec releases, as binaries that were previously not SetUID/SetGID would start becoming it after an Ignition update on new nodes.

So we might need to wait for a spec bump and update the docs as well.

@travier travier changed the title tests: Add blackbox tests for setuid/gid/sticky bit Fix setting setuid/gid bits with uid/gid and add a test Apr 23, 2025
@travier
Copy link
Member Author

travier commented Apr 23, 2025

Hum, the test is also incomplete as it does not test for the case where we both set the mode and the ownership.

@prestist
Copy link
Collaborator

So, this should fix the issue, but the problem is the same that the one we had in #1325, in that it's kind of a security issue to change this behavior for existing spec releases, as binaries that were previously not SetUID/SetGID would start becoming it after an Ignition update on new nodes.

So we might need to wait for a spec bump and update the docs as well.

Yeah; that makes sense to me, I will take a look at docs and see what can be done to make it exp only :/

@prestist
Copy link
Collaborator

Hum, the test is also incomplete as it does not test for the case where we both set the mode and the ownership.

Still have not done this

@prestist
Copy link
Collaborator

prestist commented Apr 30, 2025

Hum, the test is also incomplete as it does not test for the case where we both set the mode and the ownership.

Regarding this what would you have in mind @travier ? would I need to add a user to ignition config and then do this? for the blackbox tests?

@travier
Copy link
Member Author

travier commented Apr 30, 2025

Hum, the test is also incomplete as it does not test for the case where we both set the mode and the ownership.

Regarding this what would you have in mind @travier ? would I need to add a user to ignition config and then do this? for the blackbox tests?

Yes, we need to test root + setuid/gid and newuser + setuid/gid

@prestist prestist force-pushed the tests-setuid-setgid-sticky branch from 3118879 to dea3735 Compare April 30, 2025 20:25
@prestist
Copy link
Collaborator

Alright I added the test cases and updated version target 🤞 runs fine locally; lmk if we need anything else; otherwise I will re-base squash the fixup.

travier added 2 commits May 1, 2025 11:50
Support for setuid/setgid/sticky bit got added in [1] but we did not add
tests and it's unclear when support for it broke.

[1]: coreos#1325
See: coreos#2042
@prestist prestist force-pushed the tests-setuid-setgid-sticky branch from dea3735 to 3625bc8 Compare May 1, 2025 15:51
@travier
Copy link
Member Author

travier commented May 2, 2025

Maybe let's add a test that specifically verify that the bits are ignored in 3.4.0/3.5.0 as well.

@prestist
Copy link
Collaborator

prestist commented May 2, 2025

Maybe let's add a test that specifically verify that the bits are ignored in 3.4.0/3.5.0 as well.

Sure, I can do that :)
(after some time...)

Slightly more annoying to test then I initially thought.

So blackbox tests generate from "min version" and populate for each next version of ignition. This makes sense for most things, and makes testing that 3.6+ will have sticky bit support; however testing that older version dont have it is a bit more tricky. While locally if I do this it will pass for 3.4, 3.5, but then fail for 3.6 +. Its is because there is no "maxVersion" I.e verifying a bug continues to exist in older versions is hard to do via blackbox tests (currently)

The test object is currently structured as

type Test struct {
	Name              string
	In                []Disk // Disk state before running Ignition
	Out               []Disk // Expected disk state after running Ignition
	MntDevices        []MntDevice
	SystemDirFiles    []File
	Env               []string // Environment variables for Ignition
	Config            string
	ConfigMinVersion  string
	ConfigVersion     string
	ConfigShouldBeBad bool // Set to true to skip config validation step
	SkipCriticalCheck bool // Set to true to skip critical logging check
}

And since we have two expected outputs depending on the version of ignition, ither 0755 before 3.6 or special bits + 0755 after.

The way to fix this is likely to add a config max version, i.e defaults to "" and if max is set we simply dont create a test for that verstion or higher.

Though in implementing it I cannot seem to make that work.

@prestist prestist force-pushed the tests-setuid-setgid-sticky branch 2 times, most recently from eadc872 to 5c85381 Compare May 2, 2025 20:07
Copy link
Member Author

@travier travier left a comment

Choose a reason for hiding this comment

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

Two minor comments but I think were getting closer now. I'll do a final round tomorrow.

@travier travier removed the skip-notes This PR does not need release notes label May 5, 2025
@travier
Copy link
Member Author

travier commented May 5, 2025

We'll also need release notes.

prestist added 7 commits May 5, 2025 13:12
From https://man7.org/linux/man-pages/man2/lchown.2.html:

> When the owner or group of an executable file is changed by an
> unprivileged user, the S_ISUID and S_ISGID mode bits are cleared.
> POSIX does not specify whether this also should happen when root
> does the chown(); the Linux behavior depends on the kernel version,
> and since Linux 2.2.13, root is treated like other users.

Fixes: coreos#2042
Since a bug preventing special mode bits from being applied properly
has been fixed. Move masking of the bits for configs that are in use
which have special mode bits do not suddenly function different.
Extend the warning to trigger on 3.4.0 and 3.5.0 when special
file mode bits are set.
Due to coreos#2042 the special mode bits are not functional in versions
=< 3.6.0-exp. Add an experimental spec entry, and move docs
to that sub-section migrating-configs.
…lity

Add a field which can limit the max version of config generated from blackbox
testing. If left blank blackbox tests will act as they always have. The new
field simply limits the registration of tests to that version number. This
is for the odd case where we want to ensure functionality does not exist when
using older versions of configs.
…e 3.6.0

Ensure bugfix does not effect existing versions of configs using 'mode'. This
means 3.5.0 - 3.2.0 should continue to lose bits on permissions.
@prestist prestist force-pushed the tests-setuid-setgid-sticky branch from 5c85381 to 9371a25 Compare May 5, 2025 17:22
Copy link
Member Author

@travier travier left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM. I have some minore whitespace fixes that I'll push as a follow up PR later.

@travier
Copy link
Member Author

travier commented May 7, 2025

Hum, this is weird, I don't have the approve power anymore here.

@travier
Copy link
Member Author

travier commented May 7, 2025

Anyway, this is LGTM from my side. Someone else will have to figure out the approuve part :)

@prestist
Copy link
Collaborator

prestist commented May 7, 2025

Thanks, LGTM. I have some minore whitespace fixes that I'll push as a follow up PR later.

Yay! thank you!

Hum, this is weird, I don't have the approve power anymore here.

Ah weird, maybe because you opened the PR

Anyway, this is LGTM from my side. Someone else will have to figure out the approuve part :)

Alrighty; It looks like I can approve but that feels a bit odd, posting it to the channel.

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.

2 participants