forked from kumahq/kuma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sec): get rid of dependency on containerd (backport of kumahq#7387)…
… (kumahq#7389) * fix(sec): get rid of dependency on containerd (kumahq#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. * fix(sec): resolve confcits * chore(lint): change indent * chore: upgrade testcontainers-go Signed-off-by: Krzysztof Słonka <slonka@users.noreply.github.com> Signed-off-by: Mike Beaumont <mjboamail@gmail.com> Co-authored-by: Krzysztof Słonka <slonka@users.noreply.github.com> Co-authored-by: Mike Beaumont <mjboamail@gmail.com>
- Loading branch information
1 parent
854edc7
commit ffae6c2
Showing
4 changed files
with
148 additions
and
97 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
Oops, something went wrong.