Skip to content

kubectl-ate: add apply for access-policy and egress-policy - #4180

Open
Mofi Rahman (moficodes) wants to merge 4 commits into
agent-substrate:mainfrom
moficodes:feat/3900-kubectl-ate-apply
Open

Mofi Rahman (moficodes) wants to merge 4 commits into
agent-substrate:mainfrom
moficodes:feat/3900-kubectl-ate-apply

Conversation

@moficodes

@moficodes Mofi Rahman (moficodes) commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Updating an access policy or egress policy currently requires separate create and update steps, plus a get -o yaml round-trip to supply metadata.uid and metadata.version preconditions. Scripts and CI jobs cannot reapply a policy manifest idempotently.

Part of #3900 (Phase 1: access-policy and egress-policy). Multi-resource kubectl ate apply -f is deferred to follow-up work (building on #4102 if it merges).

Behavior

  • Adds kubectl ate apply with two singular subcommands:
    • kubectl ate apply access-policy (-a <atespace> | --global) -f <manifest>
    • kubectl ate apply egress-policy <actor-name> -a <atespace> -f <manifest>
  • Reads the stored policy with Get*, then creates it if missing (after confirming the parent atespace or actor exists), leaves it unchanged when the normalized body matches, or replaces it with Update*.
  • Compares desired and stored policy bodies after stripping metadata and running defaults.Apply on both clones, so omitted HTTP/HTTPS default ports (80/443) on EgressPolicy rules do not trigger no-op updates.
  • Checks the stored policy body (after stripping metadata) for unknown protobuf fields with protorange.Range before checking pinned preconditions or updating, so an older kubectl-ate refuses to overwrite fields added by a newer server.
  • Supports optional optimistic concurrency: metadata.uid and metadata.version must both be omitted (apply uses the stored uid and version) or both be set with version >= 1 (enforced as update preconditions and rejected if the policy is missing or changed). Partial pairs and negative versions fail before dialing.
  • Fails without retrying on concurrent AlreadyExists, Aborted, or NotFound responses.
  • Prints the resource to stdout using the standard table, yaml, or json format (matching create and update). In table mode only, prints <policy> created|updated|unchanged to stderr; -o yaml and -o json leave stderr empty.

Commit map

  1. Move cmd/ateapi/internal/defaults to internal/defaults and update cmd/ateapi imports so ate-api-server and kubectl-ate share resource defaulting.
  2. Add kubectl ate apply (verbs.go and the shared applySingleton flow in apply.go), wire access-policy and egress-policy, add unit and CLI validation tests, and update docs/reference/kubectl-ate.md and docs/guides/authorization.md.
  3. Tighten singletonApplier with policyMessage, check stored body unknown fields ahead of pinned preconditions, format runnable kubectl ate get hints, and harden pre-dial and state-machine unit tests.

Verification

  • go test -race -count=3 -shuffle=on ./cmd/kubectl-ate/... ./internal/defaults/...
  • go test -race ./cmd/ateapi/internal/apivalidation/... ./cmd/ateapi/internal/controlapi/...
  • ./hack/verify-all.sh

AI use: AI-assisted for implementation, tests, and self-review; I reviewed the diff and test results.

  • Tests pass
  • Docs updated

Move cmd/ateapi/internal/defaults to internal/defaults and update the
ateapi import paths. The package depends only on api/ateapi/v1 and
google.golang.org/protobuf/proto, so sharing it lets kubectl-ate apply
the same field defaults as ate-api-server when comparing policy
manifests against stored resources.

Signed-off-by: Mofi Rahman <mofi@google.com>
Add the kubectl ate apply verb with singular access-policy and
egress-policy subcommands. Updating a policy previously required
separate create and update steps plus a get -o yaml round-trip for
metadata.uid and metadata.version preconditions.

applySingleton reads the stored policy, confirms the parent atespace or
actor exists before creating when missing, skips updates when the
defaulted bodies match, and replaces via optimistic-concurrency update
otherwise. Stored policies containing protobuf fields unknown to this
binary are rejected via protorange.Range so an older kubectl-ate refuses
to overwrite fields from a newer server. If a manifest supplies both
metadata.uid and metadata.version, those preconditions are enforced.
Partial pairs fail before dialing, and concurrent conflicts fail without
retrying. Output follows create and update on stdout, writing the
created, updated, or unchanged status line to stderr in table mode only.

Signed-off-by: Mofi Rahman <mofi@google.com>
@moficodes Mofi Rahman (moficodes) added kind/feature An enhancement / feature request or implementation area/cli labels Nov 27, 2026
Constrain singletonApplier to a policyMessage interface, drop redundant
nil/validity guards, and check unknown protobuf fields on the stored
policy body (after stripping ResourceMetadata) ahead of pinned
preconditions so an older binary prompts an upgrade directly. Format
quoted kubectl ate get hints with the concrete target flags and actor
name so they run as printed.

Tighten apply unit tests by pinning a missing kubeconfig in the
pre-dial precondition test, asserting create and printed policy
payloads in TestApplySingleton, and adding cases for runnable get
hints, unknown fields ahead of stale preconditions, and empty -a with
--global.

Signed-off-by: Mofi Rahman <mofi@google.com>
Empty commit to re-run CI after a transient TestRequestParking flake.

Signed-off-by: Mofi Rahman <mofi@google.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cli kind/feature An enhancement / feature request or implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant