-
Notifications
You must be signed in to change notification settings - Fork 46
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
podvm: allow setting custom agent-policy #434
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,53 @@ | ||
# Kata Agent Policy | ||
|
||
Agent Policy is a Kata Containers feature that enables the Guest VM to perform additional validation | ||
for each agent API request. A custom agent policy can be set either by a policy file provided at | ||
image creation time or through pod annotations. | ||
|
||
## Set Policy At Image Creation | ||
|
||
By default Openshift Sandboxed Container sets preconfigured policy, Peer-Pods images will be set with an | ||
allow-all policy while CoCo images will be set with an allow-all exept for the `ReadStreamRequest` and | ||
`ExecProcessRequest` calls. | ||
|
||
To set custom policy at image creation time, make sure to encode the policy file (e.g., | ||
[allow-all-except-exec-process.rego](allow-all-except-exec-process.rego)) in base64 format and set it as | ||
the value for the AGENT_POLICY key in your `<azure/aws-podvm>-image-cm` ConfigMap. | ||
|
||
```sh | ||
ENCODED_POLICY=$(cat allow-all-except-exec-process.rego | base64 -w 0) | ||
kubectl patch cm aws-podvm-image-cm -p "{\"data\":{\"AGENT_POLICY\":\"${ENCODED_POLICY}\"}}" -n openshift-sandboxed-containers-operator | ||
``` | ||
|
||
## Set Policy Via Pod Annotation | ||
|
||
As long as the `SetPolicyRequest` call was not disabled at image creation time, users set custom | ||
policy through annotation at pod creation time. To set policy through annotation, encode your policy | ||
file (e.g., [allow-all-except-exec-process.rego](allow-all-except-exec-process.rego)) in base64 format | ||
and set it to the `io.katacontainers.config.agent.policy` annotation. | ||
|
||
**note:** annotation policy will override any previous policy (as long as `SetPolicyRequest` is allowed) | ||
|
||
```sh | ||
ENCODED_POLICY=$(cat allow-all-except-exec-process.rego | base64 -w 0) | ||
cat <<-EOF | kubectl apply -f - | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: sleep | ||
annotations: | ||
io.containerd.cri.runtime-handler: kata-remote | ||
io.katacontainers.config.agent.policy: ${ENCODED_POLICY} | ||
spec: | ||
runtimeClassName: kata-remote | ||
containers: | ||
- name: sleeping | ||
image: fedora | ||
command: ["sleep"] | ||
args: ["infinity"] | ||
EOF | ||
``` | ||
|
||
## Example Policies | ||
- [allow-all.rego](allow-all.rego) | ||
- [allow-all-except-exec-process.rego](allow-all-except-exec-process.rego) |
39 changes: 39 additions & 0 deletions
39
config/peerpods/podvm/agent-policy/allow-all-except-exec-process.rego
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 := true | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
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 ExecProcessRequest := 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 := true | ||
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 |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there a better way to validate the syntax than grepping ? Couldn't https://www.openpolicyagent.org/docs/latest/cli/#opa-check be used here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, my intention wasn't to actually validate the format rather to validate the output isn't ruined because of missing couple of characters when copied the encoded string.
This opa check is indeed an option, it will require to install the binary in the container, can certainly be done at future point.