Skip to content

Commit bc17218

Browse files
committed
resmgr: disallow untested runtimes by default.
Refuse to talk to untested runtimes unless explicitly told to do so using the --allow-untested-runtimes command line option.
1 parent 2930193 commit bc17218

File tree

6 files changed

+91
-47
lines changed

6 files changed

+91
-47
lines changed

docs/setup.md

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -341,36 +341,11 @@ Starting from scratch:
341341
* [Cgroup and Kata containers](https://github.com/kata-containers/kata-containers/blob/stable-2.0.0/docs/design/host-cgroups.md)
342342

343343

344-
## Using Docker\* as the runtime
344+
## Running with Untested Runtimes
345345

346-
If you must use `docker` as the runtime then the proxying setup is slightly
347-
more complex. Docker does not natively support the CRI API. Normally kubelet
348-
runs an internal protocol translator, `dockershim` to translate between CRI
349-
and the native docker API. To let CRI Resource Manager effectively proxy
350-
between kubelet and `docker` it needs to actually proxy between kubelet and
351-
`dockershim`. For this to be possible, you need to run two instances of
352-
kubelet:
353-
354-
1. The real instance, talking to CRI Resource Manager/CRI
355-
2. The dockershim instance, acting as a CRI-docker protocol translator
356-
357-
Run the real kubelet instance as you would normally with any other real CRI
358-
runtime, but specify the dockershim socket for the CRI Image Service, as
359-
shown below:
360-
361-
```
362-
kubelet <other-kubelet-options> --container-runtime=remote \
363-
--container-runtime-endpoint=unix:///var/run/cri-resmgr/cri-resmgr.sock \
364-
--image-service-endpoint=unix:///var/run/dockershim.sock
365-
```
366-
367-
Run the dockershim instance as shown below, picking the cgroupfs driver
368-
according to the configuration of the real kubelet instance:
369-
370-
```
371-
kubelet --experimental-dockershim --port 11250 --cgroup-driver {systemd|cgroupfs}
372-
373-
```
346+
CRI Resource Manager is tested with `containerd` and `CRI-O`. If any other runtime is
347+
detected during startup, `cri-resmgr` will refuse to start. This default behavior can
348+
be changed using the `--allow-untested-runtimes` command line option.
374349

375350
## Logging and debugging
376351

pkg/cri/resource-manager/flags.go

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,33 @@ import (
2424

2525
// Options captures our command line parameters.
2626
type options struct {
27-
ImageSocket string
28-
RuntimeSocket string
29-
RelaySocket string
30-
RelayDir string
31-
AgentSocket string
32-
ConfigSocket string
33-
PidFile string
34-
ResctrlPath string
35-
FallbackConfig string
36-
ForceConfig string
37-
ForceConfigSignal string
38-
DisablePolicySwitch bool
39-
ResetPolicy bool
40-
ResetConfig bool
41-
MetricsTimer time.Duration
42-
RebalanceTimer time.Duration
43-
DisableUI bool
27+
ImageSocket string
28+
RuntimeSocket string
29+
RelaySocket string
30+
RelayDir string
31+
AllowUntestedRuntimes bool
32+
AgentSocket string
33+
ConfigSocket string
34+
PidFile string
35+
ResctrlPath string
36+
FallbackConfig string
37+
ForceConfig string
38+
ForceConfigSignal string
39+
DisablePolicySwitch bool
40+
ResetPolicy bool
41+
ResetConfig bool
42+
MetricsTimer time.Duration
43+
RebalanceTimer time.Duration
44+
DisableUI bool
4445
}
4546

4647
// Relay command line options.
4748
var opt = options{}
4849

50+
const (
51+
allowUntestedRuntimesFlag = "allow-untested-runtimes"
52+
)
53+
4954
// Register us for command line option processing.
5055
func init() {
5156
flag.StringVar(&opt.ImageSocket, "image-socket", sockets.Containerd,
@@ -56,6 +61,9 @@ func init() {
5661
"Unix domain socket path where the resource manager should serve requests on.")
5762
flag.StringVar(&opt.RelayDir, "relay-dir", "/var/lib/cri-resmgr",
5863
"Permanent storage directory path for the resource manager to store its state in.")
64+
flag.BoolVar(&opt.AllowUntestedRuntimes, allowUntestedRuntimesFlag, false,
65+
"Allow proxying for untested CRI runtimes. Usually this is not a good idea.")
66+
5967
flag.StringVar(&opt.AgentSocket, "agent-socket", sockets.ResourceManagerAgent,
6068
"local socket of the cri-resmgr agent to connect")
6169
flag.StringVar(&opt.ConfigSocket, "config-socket", sockets.ResourceManagerConfig,

pkg/cri/resource-manager/requests.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package resmgr
1717
import (
1818
"context"
1919
"fmt"
20+
"strings"
2021

2122
criapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
2223

@@ -28,6 +29,15 @@ import (
2829
"github.com/intel/cri-resource-manager/pkg/cri/server"
2930
)
3031

32+
const (
33+
kubeAPIVersion = "0.1.0"
34+
)
35+
36+
var knownRuntimes = []string{
37+
"containerd",
38+
"cri-o",
39+
}
40+
3141
// setupRequestProcessing prepares the resource manager for CRI request processing.
3242
func (m *resmgr) setupRequestProcessing() error {
3343
interceptors := map[string]server.Interceptor{
@@ -898,3 +908,30 @@ func (m *resmgr) sendCRIRequest(ctx context.Context, request interface{}) (inter
898908
return nil, resmgrError("sendCRIRequest: unhandled request type %T", request)
899909
}
900910
}
911+
912+
func (m *resmgr) checkRuntime(ctx context.Context) error {
913+
version, err := m.relay.Client().Version(ctx, &criapi.VersionRequest{
914+
Version: kubeAPIVersion,
915+
})
916+
if err != nil {
917+
return resmgrError("failed to query runtime version: %v", err)
918+
}
919+
920+
for _, name := range knownRuntimes {
921+
if strings.HasPrefix(version.RuntimeName, name) {
922+
return nil
923+
}
924+
}
925+
926+
if opt.AllowUntestedRuntimes {
927+
m.Warnf("running with untested/unknown runtime %q", version.RuntimeName)
928+
return nil
929+
}
930+
931+
return rejectRuntimeError(version.RuntimeName)
932+
}
933+
934+
func rejectRuntimeError(name string) error {
935+
return resmgrError("rejecting untested runtime %s, use --%s to allow it",
936+
name, allowUntestedRuntimesFlag)
937+
}

pkg/cri/resource-manager/resource-manager.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package resmgr
1616

1717
import (
18+
"context"
1819
"os"
1920
"os/signal"
2021
"path/filepath"
@@ -152,6 +153,10 @@ func (m *resmgr) Start() error {
152153
m.Lock()
153154
defer m.Unlock()
154155

156+
if err := m.checkRuntime(context.Background()); err != nil {
157+
return err
158+
}
159+
155160
if err := m.startControllers(); err != nil {
156161
return err
157162
}

test/functional/e2e_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ func (env *testEnv) Run(name string, testFunction func(context.Context, *testEnv
8888
if err := flag.Set("config-socket", filepath.Join(tmpDir, "config.sock")); err != nil {
8989
t.Fatalf("unable to set config-socket")
9090
}
91+
if err := flag.Set("allow-untested-runtimes", "true"); err != nil {
92+
t.Fatalf("unable to allow untested runtimes: %v", err)
93+
}
9194

9295
if env.forceConfig != "" {
9396
path := filepath.Join(tmpDir, "forcedconfig.cfg")

test/functional/fake_cri_server_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ import (
3131
api "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
3232
)
3333

34+
const (
35+
fakeKubeAPIVersion = "0.1.0"
36+
fakeRuntimeName = "fake-CRI-runtime"
37+
fakeRuntimeVersion = "v0.0.0"
38+
fakeRuntimeAPIVersion = "v1"
39+
)
40+
3441
type fakeCriServer struct {
3542
t *testing.T
3643
socket string
@@ -125,7 +132,16 @@ func (s *fakeCriServer) callHandler(ctx context.Context, request interface{}, de
125132
// Implementation of api.RuntimeServiceServer
126133

127134
func (s *fakeCriServer) Version(ctx context.Context, req *api.VersionRequest) (*api.VersionResponse, error) {
128-
response, err := s.callHandler(ctx, req, nil)
135+
response, err := s.callHandler(ctx, req,
136+
func(*fakeCriServer, context.Context, *api.VersionRequest) (*api.VersionResponse, error) {
137+
return &api.VersionResponse{
138+
Version: fakeKubeAPIVersion,
139+
RuntimeName: fakeRuntimeName,
140+
RuntimeVersion: fakeRuntimeVersion,
141+
RuntimeApiVersion: fakeRuntimeAPIVersion,
142+
}, nil
143+
},
144+
)
129145
return response.(*api.VersionResponse), err
130146
}
131147

0 commit comments

Comments
 (0)