Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Add RuntimeHandler support #891

Merged
merged 2 commits into from
Sep 10, 2018
Merged

Conversation

tallclair
Copy link
Contributor

Implement the changes proposed in #879:

  1. Deprecate plugins.cri.containerd.untrusted_workload_runtime. If it is provided, give it the implicit configuration name of untrusted.
  2. Introduce a new ContainerdConfig field: Runtimes map[string]Runtime
  3. Modify criService.getSandboxRuntime to take the runtime handler as a parameter, and map it to the correct runtime config

Integration tests to follow

/cc @Random-Liu

@Random-Liu
Copy link
Member

/ok-to-test

@Random-Liu Random-Liu self-assigned this Sep 4, 2018
@mikebrow mikebrow self-assigned this Sep 4, 2018
@Random-Liu Random-Liu added this to the v1.12 milestone Sep 5, 2018
@Random-Liu
Copy link
Member

@tallclair Please use git commit --amend -s to sign your commits.

Signed-off-by: Tim Allclair <tallclair@google.com>
@tallclair
Copy link
Contributor Author

Done.

Copy link
Member

@Random-Liu Random-Liu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than comments.

cri.go Outdated
@@ -104,6 +108,18 @@ func initCRIService(ic *plugin.InitContext) (interface{}, error) {
return s, nil
}

// validateConfig validates that the given configuration.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


const (
// RuntimeUntrusted is the implicit runtime defined for ContainerdConfig.UntrustedWorkloadRuntime
RuntimeUntrusted = "unstrusted"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/unstrusted/untrusted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, good catch. Done.

defaultRuntime: defaultRuntime,
runtimes: map[string]criconfig.Runtime{"foo": fooRuntime},
expectErr: true,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing test case: should return error if both annotation and runtime handler are specified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

DefaultRuntime Runtime `toml:"default_runtime" json:"defaultRuntime"`
// UntrustedWorkloadRuntime is a runtime to run untrusted workloads on it.
// DEPRECATED: use Runtimes instead. If provided, this runtime is mapped to the runtime handler
// named 'untrusted'. It is a configuration error to provide both.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this: It is a configuration error to provide both the (now deprecated) UntrustedWorkloadRuntime and a handler in the Runtimes handler map (below) for 'untrusted' workloads at the same time. Please provide one or the other.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

UntrustedWorkloadRuntime Runtime `toml:"untrusted_workload_runtime" json:"untrustedWorkloadRuntime"`
// Runtimes maps a CRI RuntimeHandler string to a runtime configuration.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this: Runtimes is a map from CRI RuntimeHandler strings, that specify types of workloads, to runtimes for handling those types of workloads.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not entirely accurate that the RuntimeHandler "specifies types of workloads". For example, one user might want their ngnix workload to be sandboxed, while another is comfortable running it with native isolation. It's not that those are different workloads, necessarily, just different threat models.

Copy link
Member

@mikebrow mikebrow Sep 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be any type of classification. Development, Test, Production; or High, low, no threat model; or multi-tenant vs. uni-tenant; or ... Is it any type system or class dreamed up by the user mapped to particular runtimes chosen by the user?

At any rate the amount of threat secured by the runtime will be dependent on other factors outside just the version of the runtime selected. If we are saying these are threat model classes who's to say which runtime is best for which type of threat model?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I like your text as it's vague enough here I suppose. Just needs some explanation elsewhere for patterns of use.

@@ -33,10 +33,15 @@ type Runtime struct {
type ContainerdConfig struct {
// Snapshotter is the snapshotter used by containerd.
Snapshotter string `toml:"snapshotter" json:"snapshotter"`
// DefaultRuntime is the runtime to use in containerd.
// DefaultRuntime is the default runtime to use in containerd.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation for these fields has to be cut and pasted to here: https://github.com/containerd/cri/blame/master/docs/config.md#L52

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I missed that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Add a clarification about the example to the runtimes entry.

if untrustedWorkload(config) {
// If the untrusted annotation is provided, runtimeHandler MUST be empty.
if runtimeHandler != "" {
return criconfig.Runtime{}, errors.New("untrusted workload with explicit runtime handler is not allowed")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we match untrusted workloads with a runtime handler for untrusted workloads? I must be missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose I add the untrusted annotation, and ask for the 'native' runtime? Those are conflictiing. Originally, I was thinking RuntimeHandler should take precedence, but that would be "failing open" in this case, and potentially present a security risk.

However, to smooth roll out / upgrade, I decided we should allow setting the untrusted annotation and setting the 'untrusted' runtimeHandler.

Copy link
Contributor Author

@tallclair tallclair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review!

cri.go Outdated
@@ -104,6 +108,18 @@ func initCRIService(ic *plugin.InitContext) (interface{}, error) {
return s, nil
}

// validateConfig validates that the given configuration.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


const (
// RuntimeUntrusted is the implicit runtime defined for ContainerdConfig.UntrustedWorkloadRuntime
RuntimeUntrusted = "unstrusted"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, good catch. Done.

if untrustedWorkload(config) {
// If the untrusted annotation is provided, runtimeHandler MUST be empty.
if runtimeHandler != "" {
return criconfig.Runtime{}, errors.New("untrusted workload with explicit runtime handler is not allowed")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose I add the untrusted annotation, and ask for the 'native' runtime? Those are conflictiing. Originally, I was thinking RuntimeHandler should take precedence, but that would be "failing open" in this case, and potentially present a security risk.

However, to smooth roll out / upgrade, I decided we should allow setting the untrusted annotation and setting the 'untrusted' runtimeHandler.

UntrustedWorkloadRuntime Runtime `toml:"untrusted_workload_runtime" json:"untrustedWorkloadRuntime"`
// Runtimes maps a CRI RuntimeHandler string to a runtime configuration.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not entirely accurate that the RuntimeHandler "specifies types of workloads". For example, one user might want their ngnix workload to be sandboxed, while another is comfortable running it with native isolation. It's not that those are different workloads, necessarily, just different threat models.

DefaultRuntime Runtime `toml:"default_runtime" json:"defaultRuntime"`
// UntrustedWorkloadRuntime is a runtime to run untrusted workloads on it.
// DEPRECATED: use Runtimes instead. If provided, this runtime is mapped to the runtime handler
// named 'untrusted'. It is a configuration error to provide both.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -33,10 +33,15 @@ type Runtime struct {
type ContainerdConfig struct {
// Snapshotter is the snapshotter used by containerd.
Snapshotter string `toml:"snapshotter" json:"snapshotter"`
// DefaultRuntime is the runtime to use in containerd.
// DefaultRuntime is the default runtime to use in containerd.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Add a clarification about the example to the runtimes entry.

defaultRuntime: defaultRuntime,
runtimes: map[string]criconfig.Runtime{"foo": fooRuntime},
expectErr: true,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/LGTM with one small nit..

Cheers!

cri.go Outdated
// It is an error to provide both an UntrustedWorkloadRuntime & define an 'untrusted' runtime.
if _, ok := c.ContainerdConfig.Runtimes[criconfig.RuntimeUntrusted]; ok {
if c.ContainerdConfig.UntrustedWorkloadRuntime.Type != "" {
return errors.New("conflicting untrusted runtimes defined")
Copy link
Member

@mikebrow mikebrow Sep 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe: "duplicate/conflicting definitions, configuration includes untrusted_workload_runtime and runtimes[untrusted]"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


const (
// RuntimeUntrusted is the implicit runtime defined for ContainerdConfig.UntrustedWorkloadRuntime
RuntimeUntrusted = "untrusted"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if we could move this string over to CRI maybe a TODO?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't an "official" concept, even though most (all?) runtimes have implemented it. We've talked about something like that with RuntimeClass, but for now we decided to keep it open ended. I just used this string as a transitional thing while migrating to the runtime handler based configuration. Once the annotation is no longer used, the runtime can be called anything.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true.. yet it would be beneficial to have example patterns and reserved names that have more meaning than .. anything :-)

Signed-off-by: Tim Allclair <tallclair@google.com>
Copy link
Contributor Author

@tallclair tallclair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed comments & squashed commits.

cri.go Outdated
// It is an error to provide both an UntrustedWorkloadRuntime & define an 'untrusted' runtime.
if _, ok := c.ContainerdConfig.Runtimes[criconfig.RuntimeUntrusted]; ok {
if c.ContainerdConfig.UntrustedWorkloadRuntime.Type != "" {
return errors.New("conflicting untrusted runtimes defined")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@Random-Liu
Copy link
Member

Random-Liu commented Sep 6, 2018

The e2e test is completely broken now, probably caused by #895, but I need to verify.

Before that I'll avoid merging any new PRs.

@Random-Liu
Copy link
Member

/lgtm

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants