Skip to content

Commit

Permalink
hostsfile: Copy the SELinux context to the temp file before overwrite
Browse files Browse the repository at this point in the history
On SELinux-enabled systems, /etc/hosts has a different type `net_conf_t`
than the other files in /etc, so the temporary file that overwrites it
ends up with the wrong context, resulting in many system services
becoming unable to access the file. To fix this, manually look up the
context /etc/hosts has and copy it to the temporary file before
the rename.

In order to avoid depending on libselinux on systems that don't use it,
this support is gated behind the new "selinux" feature. It *is*
installed and enabled in the Dockerfile, however, in order to ensure
that it still builds.
  • Loading branch information
refi64 authored and bschwind committed May 4, 2024
1 parent 85c8cc3 commit 9011c36
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 6 deletions.
205 changes: 201 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ wireguard-control = { path = "../wireguard-control" }
once_cell = "1.17.1"
tempfile = "3"

[features]
selinux = ["hostsfile/selinux"]

[package.metadata.deb]
assets = [
["target/release/innernet", "usr/bin/", "755"],
Expand Down
4 changes: 2 additions & 2 deletions docker-tests/Dockerfile.innernet
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ RUN mkdir /repo \
####################################################################################################
FROM rust:slim-bookworm
RUN apt-get update && \
apt-get install -y --no-install-recommends libsqlite3-dev iproute2 iputils-ping build-essential clang libclang-dev && \
apt-get install -y --no-install-recommends libsqlite3-dev iproute2 iputils-ping build-essential clang libclang-dev libselinux1-dev && \
rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY . .
RUN cargo build \
RUN cargo build --features client/selinux \
&& strip /app/target/debug/innernet /app/target/debug/innernet-server \
&& cp /app/target/debug/innernet /app/target/debug/innernet-server /usr/bin/ \
&& cargo clean
Expand Down
1 change: 1 addition & 0 deletions hostsfile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ version = "1.2.0"

[dependencies]
log = "0.4"
selinux = { version = "0.4", optional = true }

[dev-dependencies]
tempfile = "3"
Loading

0 comments on commit 9011c36

Please sign in to comment.