Repository navigation
kubectl-ate: add apply for access-policy and egress-policy - #4180
Open
Mofi Rahman (moficodes) wants to merge 4 commits into
Open
Mofi Rahman (moficodes) wants to merge 4 commits into
Mofi Rahman (moficodes) wants to merge 4 commits into
Conversation
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>
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
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Updating an access policy or egress policy currently requires separate
createandupdatesteps, plus aget -o yamlround-trip to supplymetadata.uidandmetadata.versionpreconditions. Scripts and CI jobs cannot reapply a policy manifest idempotently.Part of #3900 (Phase 1:
access-policyandegress-policy). Multi-resourcekubectl ate apply -fis deferred to follow-up work (building on #4102 if it merges).Behavior
kubectl ate applywith two singular subcommands:kubectl ate apply access-policy (-a <atespace> | --global) -f <manifest>kubectl ate apply egress-policy <actor-name> -a <atespace> -f <manifest>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 withUpdate*.metadataand runningdefaults.Applyon both clones, so omitted HTTP/HTTPS default ports (80/443) onEgressPolicyrules do not trigger no-op updates.metadata) for unknown protobuf fields withprotorange.Rangebefore checking pinned preconditions or updating, so an olderkubectl-aterefuses to overwrite fields added by a newer server.metadata.uidandmetadata.versionmust both be omitted (apply uses the storeduidandversion) or both be set withversion >= 1(enforced as update preconditions and rejected if the policy is missing or changed). Partial pairs and negative versions fail before dialing.AlreadyExists,Aborted, orNotFoundresponses.stdoutusing the standardtable,yaml, orjsonformat (matchingcreateandupdate). Intablemode only, prints<policy> created|updated|unchangedtostderr;-o yamland-o jsonleavestderrempty.Commit map
cmd/ateapi/internal/defaultstointernal/defaultsand updatecmd/ateapiimports soate-api-serverandkubectl-ateshare resource defaulting.kubectl ate apply(verbs.goand the sharedapplySingletonflow inapply.go), wireaccess-policyandegress-policy, add unit and CLI validation tests, and updatedocs/reference/kubectl-ate.mdanddocs/guides/authorization.md.singletonApplierwithpolicyMessage, check stored body unknown fields ahead of pinned preconditions, format runnablekubectl ate gethints, 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.shAI use: AI-assisted for implementation, tests, and self-review; I reviewed the diff and test results.