Skip to content

Commit 8a5cf2e

Browse files
authored
ci: run chcon only if selinux is enforcing, add more CI checks for flagd (#31)
Signed-off-by: Eren Atas <[email protected]>
1 parent af1bd6e commit 8a5cf2e

File tree

2 files changed

+65
-10
lines changed

2 files changed

+65
-10
lines changed

.github/workflows/flagd-check.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Flagd Checks
2+
3+
on:
4+
push:
5+
paths:
6+
- 'crates/flagd/**'
7+
- '.github/workflows/flagd-check.yml'
8+
pull_request:
9+
paths:
10+
- 'crates/flagd/**'
11+
- '.github/workflows/flagd-check.yml'
12+
13+
jobs:
14+
check:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Update git submodules
21+
run: git submodule update --init --recursive
22+
23+
- name: Install protobuf compiler
24+
run: |
25+
sudo apt-get update
26+
sudo apt-get install -y protobuf-compiler
27+
28+
- name: Install cargo-msrv and cargo-readme
29+
working-directory: crates/flagd
30+
run: |
31+
cargo install cargo-msrv --locked
32+
cargo install cargo-readme
33+
34+
- name: Verify Minimum Supported Rust Version
35+
working-directory: crates/flagd
36+
run: cargo msrv verify
37+
38+
- name: Check README is up-to-date
39+
working-directory: crates/flagd
40+
run: |
41+
cargo readme --no-title --no-license > README.md.generated
42+
diff README.md README.md.generated
43+

crates/flagd/tests/common/mod.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,30 @@ impl ConfigFile {
154154

155155
// Platform-specific security configuration
156156
if cfg!(target_os = "linux") {
157-
// SELinux context for container access
158-
let status = std::process::Command::new("chcon")
159-
.arg("--type=container_file_t")
160-
.arg(temp_file.path())
161-
.status();
162-
163-
// Fallback to container-specific context if needed
164-
if status.is_err() {
165-
let _ = std::process::Command::new("chcon")
166-
.arg("--type=svirt_sandbox_file_t")
157+
// Check if SELinux is enforcing
158+
let selinux_enforcing = std::process::Command::new("getenforce")
159+
.output()
160+
.map(|output| {
161+
String::from_utf8_lossy(&output.stdout)
162+
.trim()
163+
.eq_ignore_ascii_case("enforcing")
164+
})
165+
.unwrap_or(false);
166+
167+
if selinux_enforcing {
168+
// SELinux context for container access
169+
let status = std::process::Command::new("chcon")
170+
.arg("--type=container_file_t")
167171
.arg(temp_file.path())
168172
.status();
173+
174+
// Fallback to container-specific context if needed
175+
if status.is_err() {
176+
let _ = std::process::Command::new("chcon")
177+
.arg("--type=svirt_sandbox_file_t")
178+
.arg(temp_file.path())
179+
.status();
180+
}
169181
}
170182
} else if cfg!(target_os = "macos") {
171183
// Ensure POSIX permissions for Docker Desktop

0 commit comments

Comments
 (0)