Skip to content

Commit

Permalink
Add ALLOW_RUN_AS_ROOT environment variable support
Browse files Browse the repository at this point in the history
  • Loading branch information
mbround18 committed Apr 21, 2024
1 parent 079fd1c commit 5982ebd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions Dockerfile.odin
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ RUN make release PROFILE=production
FROM debian:${DEBIAN_VERSION}-slim as runtime
WORKDIR /apps
COPY --from=builder /data/odin/target/release/odin /data/odin/target/release/huginn ./
ENV ALLOW_RUN_AS_ROOT="1"
ENTRYPOINT ["/apps/odin"]
CMD ["--version"]
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
odin:
image: mbround18/odin:latest
image: mbround18/odin:sha-179b1b5
build:
context: .
dockerfile: ./Dockerfile.odin
Expand All @@ -10,7 +10,7 @@ services:
valheim:
depends_on:
- odin
image: mbround18/valheim:latest
image: mbround18/valheim:sha-179b1b5
environment:
PORT: 2456
NAME: "Created With Valheim Docker"
Expand Down
5 changes: 5 additions & 0 deletions src/odin/utils/is_root.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use std::env;
use users::{get_current_uid, get_user_by_uid};

pub fn is_root() -> bool {
let bypass = env::var("ALLOW_RUN_AS_ROOT").unwrap_or(String::from("0"));
if bypass.eq("1") || bypass.eq("true") {
return true;
}
let current_uid = get_current_uid();
match get_user_by_uid(current_uid) {
Some(user) => user.uid() == 0,
Expand Down

0 comments on commit 5982ebd

Please sign in to comment.