Skip to content

Commit

Permalink
fix(sec): get rid of dependency on containerd (backport of #7387) (#7390
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.

* fix(sec): resolve confcits
* chore(lint): make check pass
* chore(lint): change indent
* chore: upgrade testcontainers-go

Signed-off-by: slonka <[email protected]>
Signed-off-by: Mike Beaumont <[email protected]>
Co-authored-by: Krzysztof Słonka <[email protected]>
Co-authored-by: Mike Beaumont <[email protected]>
  • Loading branch information
3 people authored Aug 2, 2023
1 parent 7ba3e35 commit 6983120
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 98 deletions.
56 changes: 56 additions & 0 deletions app/kuma-dp/pkg/dataplane/cgroups/cgroups.go
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
}
2 changes: 1 addition & 1 deletion app/kuma-dp/pkg/dataplane/envoy/memory_limit_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"
"strings"

"github.com/containerd/cgroups"
"github.com/kumahq/kuma/app/kuma-dp/pkg/dataplane/cgroups"
)

type UIntOrString struct {
Expand Down
62 changes: 30 additions & 32 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ require (
github.com/Masterminds/sprig/v3 v3.2.3
github.com/Nordix/simple-ipam v1.0.0
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b
github.com/containerd/cgroups v1.1.0
github.com/cilium/ebpf v0.11.0 // indirect
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4
github.com/containernetworking/cni v1.1.2
github.com/containernetworking/plugins v1.2.0
github.com/emicklei/go-restful/v3 v3.10.1
Expand Down Expand Up @@ -45,28 +45,28 @@ require (
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.15.0
github.com/spiffe/go-spiffe v0.0.0-20190820222348-6adcf1eecbcc
github.com/testcontainers/testcontainers-go v0.15.0
github.com/testcontainers/testcontainers-go v0.21.0
go.uber.org/multierr v1.9.0
go.uber.org/zap v1.24.0
golang.org/x/exp v0.0.0-20221212164502-fae10dda9338
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea
golang.org/x/net v0.8.0
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.6.0
golang.org/x/sys v0.8.0
golang.org/x/text v0.8.0
golang.org/x/time v0.3.0
google.golang.org/genproto v0.0.0-20230216225411-c8e22ba71e44
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.30.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
helm.sh/helm/v3 v3.11.1
istio.io/pkg v0.0.0-20221115183735-2aabb09bf0bb
k8s.io/api v0.26.1
k8s.io/api v0.26.2
k8s.io/apiextensions-apiserver v0.26.1
k8s.io/apimachinery v0.26.1
k8s.io/client-go v0.26.1
k8s.io/klog/v2 v2.90.0
k8s.io/apimachinery v0.26.2
k8s.io/client-go v0.26.2
k8s.io/klog/v2 v2.90.1
k8s.io/kube-openapi v0.0.0-20221207184640-f3cff1453715
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5
sigs.k8s.io/controller-runtime v0.14.1
sigs.k8s.io/controller-tools v0.11.1
// When updating this also update version in: `test/e2e_env/kubernetes/gateway/utils.go`
Expand All @@ -77,30 +77,28 @@ require (
require github.com/shopspring/decimal v1.3.1

require (
cloud.google.com/go v0.107.0 // indirect
cloud.google.com/go v0.110.0 // indirect
cloud.google.com/go/compute v1.18.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/logging v1.6.1 // indirect
cloud.google.com/go/longrunning v0.3.0 // indirect
cloud.google.com/go/logging v1.7.0 // indirect
cloud.google.com/go/longrunning v0.4.1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/Microsoft/hcsshim v0.9.6 // indirect
github.com/aws/aws-sdk-go v1.44.182 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cilium/ebpf v0.10.0 // indirect
github.com/containerd/containerd v1.6.18 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/containerd/containerd v1.7.0 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.2-beta.1+incompatible // indirect
github.com/docker/docker v20.10.24+incompatible // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v23.0.5+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
Expand All @@ -114,38 +112,39 @@ require (
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/gobuffalo/flect v0.3.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.1 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/gruntwork-io/go-commons v0.8.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.1-0.20190430135223-99e2f22d1c94 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/patternmatcher v0.5.0 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/sys/mount v0.3.3 // indirect
github.com/moby/sys/mountinfo v0.6.2 // indirect
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
Expand All @@ -154,8 +153,7 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc4 // indirect
github.com/opencontainers/runc v1.1.5 // indirect
github.com/opencontainers/runtime-spec v1.1.0-rc.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pquerna/otp v1.2.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
Expand All @@ -165,7 +163,7 @@ require (
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/urfave/cli v1.22.12 // indirect
github.com/vishvananda/netlink v1.2.1-beta.2 // indirect
Expand All @@ -177,18 +175,18 @@ require (
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/oauth2 v0.4.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/tools v0.6.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/api v0.108.0 // indirect
google.golang.org/api v0.110.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.4.0 // indirect
k8s.io/component-base v0.26.1 // indirect
k8s.io/component-base v0.26.2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)
Expand Down
Loading

0 comments on commit 6983120

Please sign in to comment.