Commit 357f8e3
fix: require SELinux Permissive mode for scenario tests (#414)
* Initial plan
* Add SELinux mode check and remove ContainerMountFlagZ
- Created SELinux helper functions in scenario/internal/testhelpers/selinux.go
- Added TestMain to scenario package to check SELinux mode before running tests
- Removed ContainerMountFlagZ from image_customize_test.go that caused issues with SELinux enforcing
- Tests now fail fast with clear error message if SELinux is in enforcing mode
Co-authored-by: tobiasb_microsoft <115835401+tobiasb_microsoft@users.noreply.github.com>
* Fix linting issues in SELinux test
- Changed test package to testhelpers_test for proper separation
- Use require.NoError instead of assert.NoError for error assertions
- Updated references to use qualified names with testhelpers prefix
Co-authored-by: tobiasb_microsoft <115835401+tobiasb_microsoft@users.noreply.github.com>
* Address code review feedback
- Consolidated multiple fmt.Fprintf calls into single call in setup_test.go
- Kept newline before error format specifier per repo coding standards
Co-authored-by: tobiasb_microsoft <115835401+tobiasb_microsoft@users.noreply.github.com>
* Use getenforce command instead of reading file directly
- Use exec.CommandContext with getenforce as primary method
- Fall back to reading /sys/fs/selinux/enforce if getenforce not available
- Leverages system's standard way of determining SELinux status
Co-authored-by: tobiasb_microsoft <115835401+tobiasb_microsoft@users.noreply.github.com>
* Use opencontainers/selinux package for SELinux detection
- Replaced custom implementation with github.com/opencontainers/selinux/go-selinux
- Simplified code by leveraging existing, well-maintained package
- Uses GetEnabled() and EnforceMode() from the package
Co-authored-by: tobiasb_microsoft <115835401+tobiasb_microsoft@users.noreply.github.com>
* Add comments explaining edge cases in SELinux detection
- Clarify that Disabled case is for completeness but shouldn't be reached
- Document that unknown modes are treated as disabled to avoid blocking tests
Co-authored-by: tobiasb_microsoft <115835401+tobiasb_microsoft@users.noreply.github.com>
* Remove redundant GetEnabled() check
- EnforceMode() already returns selinux.Disabled when SELinux is not enabled
- Simplified code by removing unnecessary GetEnabled() call
- Removed obsolete comment about unreachable case
Co-authored-by: tobiasb_microsoft <115835401+tobiasb_microsoft@users.noreply.github.com>
* Remove unused error return from GetSELinuxMode
- Function never returns an error, so simplified signature
- Updated callers to not handle error that can never occur
- Removed unused require import from test
Co-authored-by: tobiasb_microsoft <115835401+tobiasb_microsoft@users.noreply.github.com>
* Remove SELinux helper and use go-selinux APIs directly
- Deleted scenario/internal/testhelpers/selinux.go and selinux_test.go
- Updated setup_test.go to use selinux.EnforceMode() directly
- Simplified by removing wrapper types and using go-selinux constants
- go-selinux package now available for production code use
Co-authored-by: tobiasb_microsoft <115835401+tobiasb_microsoft@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tobiasb_microsoft <115835401+tobiasb_microsoft@users.noreply.github.com>1 parent 664e664 commit 357f8e3
4 files changed
Lines changed: 53 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| 75 | + | |
74 | 76 | | |
75 | 77 | | |
76 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
| 81 | + | |
80 | 82 | | |
81 | 83 | | |
82 | 84 | | |
| |||
219 | 221 | | |
220 | 222 | | |
221 | 223 | | |
| 224 | + | |
| 225 | + | |
222 | 226 | | |
223 | 227 | | |
224 | 228 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
0 commit comments