forked from kata-containers/kata-containers
-
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.
Use AGENT_POLICY=yes when building the Guest images, and add a permissive test policy to the k8s tests for: - CBL-Mariner - SEV - SNP - TDX Also, add an example of policy rejecting ExecProcessRequest. Fixes: kata-containers#7667 Signed-off-by: Dan Mihai <[email protected]>
- Loading branch information
Showing
8 changed files
with
177 additions
and
8 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,39 @@ | ||
package agent_policy | ||
|
||
default AddARPNeighborsRequest := true | ||
default AddSwapRequest := true | ||
default CloseStdinRequest := true | ||
default CopyFileRequest := true | ||
default CreateContainerRequest := true | ||
default CreateSandboxRequest := true | ||
default DestroySandboxRequest := true | ||
default GetMetricsRequest := true | ||
default GetOOMEventRequest := true | ||
default GuestDetailsRequest := true | ||
default ListInterfacesRequest := true | ||
default ListRoutesRequest := true | ||
default MemHotplugByProbeRequest := true | ||
default OnlineCPUMemRequest := true | ||
default PauseContainerRequest := true | ||
default PullImageRequest := true | ||
default ReadStreamRequest := true | ||
default RemoveContainerRequest := true | ||
default RemoveStaleVirtiofsShareMountsRequest := true | ||
default ReseedRandomDevRequest := false | ||
default ResumeContainerRequest := true | ||
default SetGuestDateTimeRequest := true | ||
default SetPolicyRequest := true | ||
default SignalProcessRequest := true | ||
default StartContainerRequest := true | ||
default StartTracingRequest := true | ||
default StatsContainerRequest := true | ||
default StopTracingRequest := true | ||
default TtyWinResizeRequest := true | ||
default UpdateContainerRequest := true | ||
default UpdateEphemeralMountsRequest := true | ||
default UpdateInterfaceRequest := true | ||
default UpdateRoutesRequest := true | ||
default WaitProcessRequest := true | ||
default WriteStreamRequest := true | ||
|
||
default ExecProcessRequest := false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env bats | ||
# | ||
# Copyright (c) 2023 Microsoft. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
load "${BATS_TEST_DIRNAME}/../../common.bash" | ||
load "${BATS_TEST_DIRNAME}/tests_common.sh" | ||
|
||
setup() { | ||
get_pod_config_dir | ||
pod_name="busybox" | ||
pod_yaml="${pod_config_dir}/busybox-pod.yaml" | ||
|
||
# String generated using "base64 -w 0 kata-containers/src/kata-opa/allow-all-except-exec-process.rego" | ||
allow_all_except_exec_policy="cGFja2FnZSBhZ2VudF9wb2xpY3kKCmRlZmF1bHQgQWRkQVJQTmVpZ2hib3JzUmVxdWVzdCA6PSB0cnVlCmRlZmF1bHQgQWRkU3dhcFJlcXVlc3QgOj0gdHJ1ZQpkZWZhdWx0IENsb3NlU3RkaW5SZXF1ZXN0IDo9IHRydWUKZGVmYXVsdCBDb3B5RmlsZVJlcXVlc3QgOj0gdHJ1ZQpkZWZhdWx0IENyZWF0ZUNvbnRhaW5lclJlcXVlc3QgOj0gdHJ1ZQpkZWZhdWx0IENyZWF0ZVNhbmRib3hSZXF1ZXN0IDo9IHRydWUKZGVmYXVsdCBEZXN0cm95U2FuZGJveFJlcXVlc3QgOj0gdHJ1ZQpkZWZhdWx0IEdldE1ldHJpY3NSZXF1ZXN0IDo9IHRydWUKZGVmYXVsdCBHZXRPT01FdmVudFJlcXVlc3QgOj0gdHJ1ZQpkZWZhdWx0IEd1ZXN0RGV0YWlsc1JlcXVlc3QgOj0gdHJ1ZQpkZWZhdWx0IExpc3RJbnRlcmZhY2VzUmVxdWVzdCA6PSB0cnVlCmRlZmF1bHQgTGlzdFJvd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UmVxdWVzdCA6PSB0cnVlCmRlZmF1bHQgVXBkYXRlUm91dGVzUmVxdWVzdCA6PSB0cnVlCmRlZmF1bHQgV2FpdFByb2Nlc3NSZXF1ZXN0IDo9IHRydWUKZGVmYXVsdCBXcml0ZVN0cmVhbVJlcXVlc3QgOj0gdHJ1ZQoKZGVmYXVsdCBFeGVjUHJvY2Vzc1JlcXVlc3QgOj0gZmFsc2UK" | ||
} | ||
|
||
@test "Kubectl exec rejected by policy" { | ||
# Add to the YAML file a policy that rejects ExecProcessRequest. | ||
yq write -i "${pod_yaml}" \ | ||
'metadata.annotations."io.katacontainers.config.agent.policy"' \ | ||
"${allow_all_except_exec_policy}" | ||
|
||
# Create the pod | ||
kubectl create -f "${pod_yaml}" | ||
|
||
# Wait for pod to start | ||
kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name" | ||
|
||
# Try executing a command in the Pod - an action rejected by the agent policy. | ||
kubectl exec "$pod_name" -- date 2>&1 | grep "ExecProcessRequest is blocked by policy" | ||
} | ||
|
||
teardown() { | ||
# Debugging information | ||
kubectl describe "pod/$pod_name" | ||
|
||
kubectl delete pod "$pod_name" | ||
} |
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
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
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