feat(kubectl-plugin): add policy ack subcommand#734
Conversation
091160a to
aa63455
Compare
There was a problem hiding this comment.
Pull request overview
Adds a new kubectl runtime-enforcer policy ack subcommand to improve operator UX for acknowledging WorkloadPolicy violations by writing the corresponding acknowledgement annotation.
Changes:
- Registers a new
policy ackcobra subcommand under the existingpolicycommand. - Implements
policy acklogic: resolves policy + violation ID, resolves a reason (flag or interactive prompt), and updates the policy annotation (with--dry-runsupport). - Adds unit tests and generated CLI docs for the new subcommand.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/kubectlplugin/policy.go | Wires the new ack subcommand into the policy command. |
| internal/kubectlplugin/policy_ack.go | Implements the policy ack command, completion, validation, and annotation update behavior. |
| internal/kubectlplugin/policy_ack_test.go | Adds unit tests covering reason resolution, dry-run output, no-op, overwrite, and unknown violation handling. |
| docs/kubectl-plugin/runtime-enforcer_policy.md | Adds policy ack to the policy command documentation index. |
| docs/kubectl-plugin/runtime-enforcer_policy_ack.md | Adds generated documentation for the new policy ack subcommand. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
aa63455 to
b977d6c
Compare
| "strconv" | ||
| "strings" | ||
|
|
||
| apiv1alpha1 "github.com/rancher-sandbox/runtime-enforcer/api/v1alpha1" |
There was a problem hiding this comment.
nit: I think we either use v1alpha1 or securityv1alpha1.
There was a problem hiding this comment.
Agree, I'll create another PR to rename the usage in kubectlplugin
| ### SEE ALSO | ||
|
|
||
| * [runtime-enforcer](runtime-enforcer.md) - | ||
| * [runtime-enforcer policy ack](runtime-enforcer_policy_ack.md) - Acknowledge a WorkloadPolicy violation | ||
| * [runtime-enforcer policy allow](runtime-enforcer_policy_allow.md) - allow executables for a WorkloadPolicy container | ||
| * [runtime-enforcer policy deny](runtime-enforcer_policy_deny.md) - deny executables for a WorkloadPolicy container | ||
| * [runtime-enforcer policy monitor](runtime-enforcer_policy_monitor.md) - Set WorkloadPolicy mode to monitor |
There was a problem hiding this comment.
Ah we probably have to also sync this doc to the official doc repo too in addition to the crd ones.
| func getWorkloadPolicy( | ||
| ctx context.Context, | ||
| client securityclient.SecurityV1alpha1Interface, | ||
| namespace, name string, | ||
| ) (*apiv1alpha1.WorkloadPolicy, error) { | ||
| policy, err := client.WorkloadPolicies(namespace).Get(ctx, name, metav1.GetOptions{}) | ||
| if err != nil { | ||
| if apierrors.IsNotFound(err) { | ||
| return nil, fmt.Errorf("workloadpolicy %q not found in namespace %q", name, namespace) | ||
| } | ||
| return nil, fmt.Errorf( | ||
| "failed to get WorkloadPolicy %q in namespace %q: %w", | ||
| name, | ||
| namespace, | ||
| err, | ||
| ) | ||
| } | ||
| return policy, nil | ||
| } |
There was a problem hiding this comment.
Perhaps you can make runPolicyExec(), runPolicyModeSet() and waitForWorkloadPolicy() use this helper?
There was a problem hiding this comment.
Will do this refactor in the separate PR with renaming the package.
| ) | ||
| } | ||
|
|
||
| func updateAckWorkloadPolicy( |
There was a problem hiding this comment.
Not sure if you can use this helper elsewhere too.
There was a problem hiding this comment.
I'll check in the refactor PR later.
37d1938 to
89f36fd
Compare
dottorblaster
left a comment
There was a problem hiding this comment.
Just some sparse comments, feel free to address the ones you see fit for, then we are good to merge. Thanks!
3877e95 to
67bcc52
Compare
Signed-off-by: Kyle Dong <kyle.dong@suse.com>
67bcc52 to
2e6fb88
Compare
What this PR does / why we need it:
Add kubectl-plugin subcommand for
policy ack POLICY_NAME <violation-id> [--reason "xxx"]Which issue(s) this PR fixes
fixes #697
Special notes for your reviewer:
Checklist: