-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
chcon: added implementation and integration tests #2075
Conversation
I think some of the failing checks are due to the test environment lacking the packages |
Running tests without root I get:
Running with root privileges I also get:
Running with root privileges and
|
I saw that you're the author of selinux-sys and used it for this PR. Since this crate uses raw Rust bindings for In addition to other applications directly related to selinux, i.e. Would you be interested in also writing the |
Can you provide some pointers on how to fix that in the CI build? |
Interesting, so SELinux is actually enabled and enforcing on some CI build server. That is something I didn't expect. I'll fix that. Good catch! |
I made it to support this pull request.
I agree, and I dislike
True. However, my goal was to enable a fast and reasonable contribution to this project. Providing an ergonomic wrapper is a more involved work which covers way more than the API used by
Thank you for this resume of potential dependencies. You're right, such a crate is needed in more than a few places.
I'm interested in writing it. But when I started exploring the SELinux API/headers, I found out that roughly 90% of the SELinux API is irrelevant to I suggest we integrate this pull request depending on the |
Someone with access needs to run |
I didn't expect this behavior, and I don't know how to explain it as of now. I'll need to debug this. Could you provide more information on the host running the test, so that I try to reproduce the issue locally? |
Fedora |
I'll try to run it in a VM. LXC containers require configuring the kernel to use SELinux inside them. Did you perform explicit steps to enable SELinux, or was it enabled by default? |
Kudos for the https://github.com/koutheir/selinux-sys project :) |
I fixed the integration tests. Most of the tests are still ignored by default. On systems without SELinux configured, the ignored tests need to run as |
As you know, SELinux is Linux-specific, so the command and tests should not be built for other systems. What should I modify in order to achieve this? |
Do like: coreutils/tests/by-util/test_who.rs Line 4 in 4873c8a
|
I need a way to avoid building the |
In cargo.toml you put chcon in |
Why not make a |
You asked for a way to be able to separately build chcon. As far as I can tell, that can be achieved by not putting chcon in I looked at the features some more. Based on what is already there it would make sense to have:
(Also TIL that currently, macos is |
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.
great start, not reviewed for now but some first comments
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Failure { command: "\"pkg-config\" \"--libs\" \"--cflags\" \"libselinux\"", output: Output { status: ExitStatus(ExitStatus(256)), stdout: "", stderr: "Package libselinux was not found in the pkg-config search path.\nPerhaps you should add the directory containing `libselinux.pc\'\nto the PKG_CONFIG_PATH environment variable\nNo package \'libselinux\' found\n" } }', /cargo/registry/src/github.com-1ecc6299db9ec823/selinux-sys-0.3.1/build.rs:18:61
you should install the missing package, no ?
should be done in
https://github.com/uutils/coreutils/blob/master/.github/workflows/CICD.yml
Thank you for the hint. I added the necessary References:
I'll try the operation in a container to fix the issue. |
The problem seems to be the implicit docker images that the |
@koutheir don't know, sorry :) did you look at the github action doc? thanks |
It seems |
Given that testing is driven by the I experimented doing this for a few platforms, and it seems to work fine. For example, targeting the
[build.env]
passthrough = [
"RUST_BACKTRACE",
# ...
]
[target.aarch64-unknown-linux-gnu]
image = "my/cross-with-selinux:aarch64-unknown-linux-gnu-0.2.1"
# ...
FROM rustembedded/cross:aarch64-unknown-linux-gnu-0.2.1
RUN dpkg --add-architecture arm64 && \
apt-get update && \
apt-get upgrade --assume-yes && \
apt-get install --assume-yes --no-install-recommends build-essential clang-8 libclang-8-dev llvm-8-dev libselinux1-dev:arm64 && \
ln -s /usr/bin/clang-8 /usr/local/bin/clang
$ docker build -t 'my/cross-with-selinux:aarch64-unknown-linux-gnu-0.2.1' 'docker/aarch64-unknown-linux-gnu'
$ env RUST_BACKTRACE=1 cross test --target aarch64-unknown-linux-gnu This works for some target platforms, and doesn't for others, for different reasons related to the configuration of I have no idea how complicated this is within the build/test architecture of this project. Can someone help with this? The reason why the |
@koutheir are you still interested by finishing this PR? thanks |
If no one can help me resolve the infrastructure issues this PR faces, then I cannot proceed alone. |
@sylvestre Can we install |
SELinux needs to be supported and configured on a kernel level. AFAIK, running it inside containers is not a supported configuration. I personally use QEMU to run the tests of a crate I'm currently developing exposing the |
Ah, I see. That makes it more complicated. Is there maybe some way to mock it? |
With the state of SELinux distributed over the kernel, the file system, and the libselinux memory, I suspect it would be difficult to faithfully mock its APIs. If you have some easier approach, then I'm open to try it. |
Yeah, it is clearly super interesting and I have been monitoring your PR. However, we cannot land it until it is green. |
Thank you for confirming this work is still useful to someone.
I understand, and I was trying for some time to get it to work. However, that's proving difficult due to the nature of
I was trying to be faithful to the original GNU implementation of I can go back and try to introduce a very limited version of @sylvestre, please confirm that this approach makes sense to you. |
Maybe if we can't run the tests on the CI in the near future, we should just skip the tests on the CI and merge this? It's not ideal, but at least there are tests we can run locally |
I don't like the idea of a watered down version specifically tailored to run on the docker image.
That's also what I was thinking, however the problem is that (at the moment) this can't be build inside a docker image. |
@jhscheer, could you elaborate on how to implement this solution? |
Is it possible to raise the minimum supported Rust version? Or do we have to do whatever it takes to keep the current MSRV? |
The approach used to collect coverage information hits this bug #78011 due to setting This bug is hit due to the usage of |
The problem with defining a dedicated coverage profile in We should probably consider a different way to build coverage information. Please consider the approach used by my |
Hello there! If I follow this conversation correctly, @koutheir implemented the selinux crate (cool stuff!) specifically to allow handling of SELinux through rust, but it can't be used because it breaks the CI which runs in a docker container. Is that correct? I was interested in picking up on #2404 in the near future as SELinux is part of a few of the utils. But without a solution to this discussion I'm afraid there isn't much of a point to that. Is there a chance I could help here?
Is the "decoupling" from CI a separate step from the feature gate, or do these imply each other? I.e. couldn't one add a feature "selinux" and then have the CI build and test explicitly without that for now? Oh and since there's talk about "workarounds" and "quick solutions" here I wonder if there's some place where one could document all these sorts of things? Something like a documentation or a project-wide TODO, or should we just open issues for this sort of thing? |
From everything I read so far it is not possible to have SELinux support for CICD github actions.
see below
That is precisely what I had in mind and I implemented this here last night for Now cargo run --features feat_selinux -- id -Z
cargo run --features "id" -- id
cargo build -p uu_id --no-default-features --features feat_selinux
cargo build -p uu_id --no-default-features
cargo test test_id --features feat_selinux
cargo test test_id --features id --no-default-features The |
I think that this deserves a Wiki page so other contributors can find it and the coding is somewhat uniform across utilities, what do you think? I've prepared something, maybe you want to add to it? (If it is of interest to the project) |
I agree. I'll contribute to the wiki page to document my experience with integrating SELinux, in the hope it eases the life of future contributors.
Here is my take on it: selinux-wikipage.md |
That wikipage looks good to me. With approval from @sylvestre, I'll add it to the wiki. Too bad there is no PR-like workflow for the wiki... |
1.53.0 is a significant bump. there isn't older version that we could use? |
I'm aware of the following dependencies (for compiling
I'm in favour for a bump to |
if we can update it to 1.47, i would accept this PR now :) |
I was attempting to get the CI to o work somehow, and that 1.53.0 was not a specific choice; it simply represented latest stable. I'll revert the MSRV to 1.47.0. I'm waiting for any other PR to handle the issue of depending on SELinux and still please the CI servers somehow. Once that is done, I'll modify this PR to handle the issue in a similar fashion. Then you might consider reviewing this PR again. |
@koutheir Other PR approved! :) |
@sylvestre, could you please review? I executed the tests for |
The ToDo list was updated to mark `chcon` as done. Building and testing `chcon` requires enabling the `feat_selinux` feature. If `make` is used for building, then please specify `SELINUX_ENABLED=1` if building and testing on a system where SELinux is not enabled.
FYI, I'm done developing this PR. I'm only continuing to rebase it over |
Manual testing successful:
|
Now that this PR is merged, I'll try to reduce the amount of |
bravo for your hard work on this btw :) |
@sylvestre, @Funky185540, can someone insert the document |
This implementation continues in #2563. |
@koutheir https://github.com/uutils/coreutils/wiki/Supporting-SELinux-in-the-coreutils added, sorry for the latency |
The ToDo list was updated to mark
chcon
as done.Building and testing
chcon
requires enabling thefeat_selinux
feature. Ifmake
is used for building, then please specifySELINUX_ENABLED=1
if building and testing on a system where SELinux is not enabled.Closes #1041