-
Notifications
You must be signed in to change notification settings - Fork 63
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
go-selinux: add coverage for LfileLabel, LsetFileLabel #194
Conversation
A few changes. |
go-selinux/selinux_linux_test.go
Outdated
if err != nil { | ||
t.Fatalf("LfileLabel failed: %s", err) | ||
} | ||
if linkLabel != "" { |
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.
This should be linkLabel == con
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.
My thinking here was that no label should be set at all on the symlink, correct?
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.
All files have labels. Getting a file without a label on an SELinux system is difficult.
go-selinux/selinux_stub_test.go
Outdated
if _, err := LfileLabel("/etc"); err != nil { | ||
t.Error(err) | ||
} | ||
if err := LsetFileLabel("/etc", testLabel); err != nil { |
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.
This could be dangerous if run as root.
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.
Yes, I was looking for a good path to use (this is for the stubs, so should not do anything, but the existing tests also used /etc
)
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.
Updated to use a temp-file to test with 👍
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.
If we are using system directories elsewhere we probably should not.
(oh! forgot to post); Hmm... right, so this won't help a lot; while looking, of course I stumbled upon this ticket from @kolyshkin 😂 actions/runner-images#2307 Also had a look if we could install SELinux on Ubuntu, but it requires a reboot, so not an option 😞
|
c6b1f77
to
5440774
Compare
We really should be testing on Centos or Fedora. |
|
Apply this patch to yours and the tests passes. |
I remember @avagin implemented a complicated trick with upgrading the kernel and rebooting a travis machine while keeping the process that connects to travis infra intact (using CRIU), which helped us to test newer kernels. Today, we can use something like cirrus-ci which you can use to install centos (7, 8, or 9) and also run fedora via KVM. See runc's .cirrus.yml for example. We can also use github ci to run fedora in a KVM, but this is more error prone since the only way is to use Mac OS X and there's a 5 to 10% chance that it will fail, based on what I saw. |
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.
A nits to simplify code by using t.TempDir more directly
go-selinux/label/label_stub_test.go
Outdated
tmpFile := filepath.Join(t.TempDir(), "test_file") | ||
out, err := os.OpenFile(tmpFile, os.O_WRONLY|os.O_CREATE, 0) | ||
if err != nil { | ||
t.Fatal(err) | ||
} |
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.
Why not merely use t.TempDir()
. It returns a directory name which you can use directly as an argument to FileLabel
and SetFileLabel
.
go-selinux/selinux_stub_test.go
Outdated
@@ -13,12 +15,18 @@ func TestSELinuxStubs(t *testing.T) { | |||
if GetEnabled() { | |||
t.Error("SELinux enabled on non-linux.") | |||
} | |||
tmpFile := filepath.Join(t.TempDir(), "test_file") |
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.
ditto
@thaJeztah Still working on this? |
5440774
to
eaeb0ab
Compare
Oh! Looks like I somehow missed the comments here; updated 👍 |
While these stubs shouldn't make actual changes, it's better to not use `/etc` in the tests, as they may be run as `root`. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
updates: 1b18907 Co-authored-by: Daniel J Walsh <dwalsh@redhat.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
eaeb0ab
to
d6656c6
Compare
LGTM |
@lsm5 PTAL |
Oh! Voice from the past. It's been a while since we interacted (hope you're doing well!) |
@lsm5 has shown interest in SELinux so I figured I would ping him. |
@thaJeztah 👋 I'm good, hope you are too! 😄
@rhatdan shown interest yes, but this is outta my reviewing capacity atm, LGTM from a cursory look though. Also Also, RE: fedora/centos testing, do you want that to be a CI task here? |
It would be awesome if we could test Fedora or Centos here. |
Yeah, it's complicated. It's possible to attach custom runners to GitHub actions, but those would need to be maintained somewhere (possibly the CNCF has infra for this?). Some caution is needed for these as well to prevent those runners from also be running on forks (and to be sure they're only running on "good" pull requests, to prevent crypto miners from using them). Of course the ideal would be for GitHub to provide at least "one" variant of an rpm/yum/dnf flavoured distro. |
I have an open issue to make the CI VM images public, given there's no real secret sauce in them. That would probably go a long way toward making this easier. The second piece is getting a dedicated GCE or AWS project setup and paid for by someone (potentially forever). That's more likely the most difficult part of the two. Minor note: I would not recommend trying to re-use an existing project, unless you absolutely don't care about some nasty code escaping confinement and wrecking anything else running there. Trying to lock-down CI-jobs and damage-control an escape with security policy, is a fools-errand IMHO. Easier to just keep the "wild-west" completely separate from civilization. |
updates: 1b18907 (#169)