-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(exp): unprivileged_userns_clone sysctl file do not exist in CentOS
- Loading branch information
Showing
2 changed files
with
29 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package util | ||
|
||
import ( | ||
"io/ioutil" | ||
"strings" | ||
|
||
"github.com/cdk-team/CDK/pkg/errors" | ||
) | ||
|
||
// CheckUnpriUserNS checks if the current host enable unprivileged user namespace. | ||
// reference: | ||
// https://blog.trailofbits.com/2019/07/19/understanding-docker-container-escapes/ | ||
// https://unit42.paloaltonetworks.com/cve-2022-0492-cgroups/ | ||
// exceptional case: | ||
// the sysctl files(/proc/sys/kernel/unprivileged_userns_clone) only exist in Debian, Ubuntu. | ||
// We can not check the sysctl file in other distros, test in CentOS Linux release 8.4.2105 (Core). | ||
func CheckUnpriUserNS() error { | ||
|
||
data, err := ioutil.ReadFile("/proc/sys/kernel/unprivileged_userns_clone") | ||
if err != nil { | ||
return &errors.CDKRuntimeError{Err: err, CustomMsg: "check prerequisites error."} | ||
} | ||
|
||
if strings.TrimSuffix(string(data), "\n") != "1" { | ||
return &errors.CDKRuntimeError{Err: nil, CustomMsg: "host os does NOT enable unprivileged user namespace."} | ||
} | ||
|
||
return nil | ||
} |
19fdff2
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.