Skip to content

feat(kubectl-plugin): add policy ack subcommand#734

Merged
kyledong-suse merged 1 commit into
rancher-sandbox:mainfrom
kyledong-suse:kubectl-plugin
Jul 14, 2026
Merged

feat(kubectl-plugin): add policy ack subcommand#734
kyledong-suse merged 1 commit into
rancher-sandbox:mainfrom
kyledong-suse:kubectl-plugin

Conversation

@kyledong-suse

Copy link
Copy Markdown
Collaborator

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:

  • squashed commits into logical changes
  • includes documentation
  • adds unit tests
  • adds or updates e2e tests

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 ack cobra subcommand under the existing policy command.
  • Implements policy ack logic: resolves policy + violation ID, resolves a reason (flag or interactive prompt), and updates the policy annotation (with --dry-run support).
  • 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.

Comment thread internal/kubectlplugin/policy_ack.go
Comment thread internal/kubectlplugin/policy_ack.go Outdated
Comment thread internal/kubectlplugin/policy_ack.go

@holyspectral holyspectral left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you!

"strconv"
"strings"

apiv1alpha1 "github.com/rancher-sandbox/runtime-enforcer/api/v1alpha1"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: I think we either use v1alpha1 or securityv1alpha1.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agree, I'll create another PR to rename the usage in kubectlplugin

Comment on lines 35 to 41
### 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah we probably have to also sync this doc to the official doc repo too in addition to the crd ones.

Comment thread internal/kubectlplugin/policy_ack.go
Comment on lines +169 to +187
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
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Perhaps you can make runPolicyExec(), runPolicyModeSet() and waitForWorkloadPolicy() use this helper?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Will do this refactor in the separate PR with renaming the package.

Comment thread internal/kubectlplugin/policy_ack_test.go
Comment thread internal/kubectlplugin/policy_ack_test.go
Comment thread internal/kubectlplugin/policy_ack.go
Comment thread internal/kubectlplugin/policy_ack.go Outdated
)
}

func updateAckWorkloadPolicy(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not sure if you can use this helper elsewhere too.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'll check in the refactor PR later.

@dottorblaster dottorblaster left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just some sparse comments, feel free to address the ones you see fit for, then we are good to merge. Thanks!

Comment thread internal/kubectlplugin/policy_ack.go Outdated
Comment thread test/e2e/helpers_test.go
Comment thread internal/kubectlplugin/policy_ack.go Outdated
Comment thread internal/kubectlplugin/policy_ack.go Outdated

@dottorblaster dottorblaster left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: Kyle Dong <kyle.dong@suse.com>
@kyledong-suse kyledong-suse merged commit 3ef087a into rancher-sandbox:main Jul 14, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(kubectl-plugin): add policy ack subcommand

4 participants