Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing AllowElevated policy check when creating a container #1624

Merged
merged 2 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions internal/guest/runtime/hcsv2/uvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/Microsoft/hcsshim/pkg/annotations"
"github.com/Microsoft/hcsshim/pkg/securitypolicy"
"github.com/mattn/go-shellwords"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -324,6 +325,7 @@ func (h *Host) CreateContainer(ctx context.Context, id string, settings *prot.VM
settings.OCISpecification.Process.Env,
settings.OCISpecification.Process.Cwd,
settings.OCISpecification.Mounts,
isPrivilegedContainerCreationRequest(settings.OCISpecification),
)
if err != nil {
return nil, errors.Wrapf(err, "container creation denied due to policy")
Expand Down Expand Up @@ -989,3 +991,9 @@ func processOCIEnvToParam(envs []string) map[string]string {

return paramEnv
}

// isPrivilegedContainerCreationRequest returns if a given container
// creation request would create a privileged container
func isPrivilegedContainerCreationRequest(spec *specs.Spec) bool {
return spec.Annotations[annotations.LCOWPrivileged] == "true"
helsaawy marked this conversation as resolved.
Show resolved Hide resolved
}
23 changes: 23 additions & 0 deletions pkg/securitypolicy/framework.rego
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ workingDirectory_ok(working_dir) {
input.workingDir == working_dir
}

privileged_ok(elevation_allowed) {
not input.privileged
}

privileged_ok(elevation_allowed) {
input.privileged
input.privileged == elevation_allowed
}

default container_started := false

container_started {
Expand All @@ -221,6 +230,7 @@ create_container := {"metadata": [updateMatches, addStarted],
# mount list
possible_containers := [container |
container := data.metadata.matches[input.containerID][_]
privileged_ok(container.allow_elevated)
workingDirectory_ok(container.working_dir)
command_ok(container.command)
mountList_ok(container.mounts, container.allow_elevated)
Expand Down Expand Up @@ -706,6 +716,19 @@ errors["no matching containers for overlay"] {
not overlay_matches
}

default privileged_matches := false

privileged_matches {
input.rule == "create_container"
some container in data.metadata.matches[input.containerID]
privileged_ok(container.allow_elevated)
}

errors["privileged escalation not allowed"] {
input.rule in ["create_container"]
not privileged_matches
}

default command_matches := false

command_matches {
Expand Down
Loading