-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
) * fix(sec): get rid of dependency on containerd (#7387) Containerd shows up time and time again with a CVE that does not actually impact our codebase but looks not great in scan results. I copied the code from the source so we no longer rely on it. Signed-off-by: slonka <[email protected]> Co-authored-by: Krzysztof Słonka <[email protected]>
- Loading branch information
1 parent
9524fc5
commit 2fd5084
Showing
4 changed files
with
57 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package cgroups | ||
|
||
import ( | ||
"path/filepath" | ||
"sync" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
// TAKEN FROM https://github.com/containerd/cgroups/blob/v1.1.0/utils.go | ||
// to get rid of dependency on containerd because of it's various CVEs | ||
|
||
// CGMode is the cgroups mode of the host system | ||
type CGMode int | ||
|
||
const unifiedMountpoint = "/sys/fs/cgroup" | ||
|
||
const ( | ||
// Unavailable cgroup mountpoint | ||
Unavailable CGMode = iota | ||
// Legacy cgroups v1 | ||
Legacy | ||
// Hybrid with cgroups v1 and v2 controllers mounted | ||
Hybrid | ||
// Unified with only cgroups v2 mounted | ||
Unified | ||
) | ||
|
||
var ( | ||
checkMode sync.Once | ||
cgMode CGMode | ||
) | ||
|
||
// Mode returns the cgroups mode running on the host | ||
func Mode() CGMode { | ||
checkMode.Do(func() { | ||
var st unix.Statfs_t | ||
if err := unix.Statfs(unifiedMountpoint, &st); err != nil { | ||
cgMode = Unavailable | ||
return | ||
} | ||
switch st.Type { | ||
case unix.CGROUP2_SUPER_MAGIC: | ||
cgMode = Unified | ||
default: | ||
cgMode = Legacy | ||
if err := unix.Statfs(filepath.Join(unifiedMountpoint, "unified"), &st); err != nil { | ||
return | ||
} | ||
if st.Type == unix.CGROUP2_SUPER_MAGIC { | ||
cgMode = Hybrid | ||
} | ||
} | ||
}) | ||
return cgMode | ||
} |
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
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