feat: add ADC-backed admission validation for APISIX CRDs#2758
Open
AlinsRan wants to merge 1 commit intoapache:masterfrom
Open
feat: add ADC-backed admission validation for APISIX CRDs#2758AlinsRan wants to merge 1 commit intoapache:masterfrom
AlinsRan wants to merge 1 commit intoapache:masterfrom
Conversation
Validate ApisixRoute, ApisixConsumer, ApisixTls and Consumer resources against a live APISIX instance during admission instead of only producing warnings. Key changes: - Add ADCValidationErrors / ADCValidationError types (internal/types) - Add Validate() to HTTPADCExecutor and Client; introduce the /configs/validate endpoint support in executor.go (TLS min-version set to 1.2, request body no longer logged in full) - Add internal/controller/webhook_validation.go: lightweight helpers (PrepareApisixRouteForValidation, PrepareApisixConsumerForValidation, PrepareConsumerForValidation, PrepareApisixTlsForValidation) that build a TranslateContext without starting the full reconciler loop - Add internal/webhook/v1/adc_validation.go: adcAdmissionValidator that translates a CRD into an ADC payload and posts it to APISIX for structural validation; fails open on infrastructure errors - Wire adcAdmissionValidator into all four webhook validators; init errors are logged and ignored (fail-open) - ApisixTls: skip ADC validation when secrets are missing to preserve the existing warn-only behaviour for that case - Consumer: validate duplicate key-auth credential keys scoped to the same GatewayRef using a field-index query; malformed inline JSON is logged and skipped (not a hard denial) - global_rules and plugin_metadata are now populated in the ADC validate payload so APISIX can resolve plugin references Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Summary
This PR adds live ADC-backed admission validation to the existing webhook validators for
ApisixRoute,ApisixConsumer,ApisixTls, andConsumerresources.Previously the webhooks only emitted warnings for missing references (services, secrets). With this change, resources are also structurally validated against a live APISIX instance before being admitted.
Changes
Core infrastructure
internal/types/error.go: AddADCValidationErrors,ADCValidationError,ADCValidationServerAddrError, andADCValidationDetailtypes to carry structured validation error details.internal/adc/client/executor.go:Validate()to theADCExecutorinterface andHTTPADCExecutorrunHTTPValidate/runHTTPValidateForSingleServerthat POST to the/configs/validateendpointbuildHTTPRequestto accept an HTTP method and path (supporting both/syncand/configs/validate)internal/adc/client/client.go: AddClient.Validate()which calls the executor's validate path and aggregatesADCValidationErrors.Webhook validation helpers
internal/controller/webhook_validation.go(new): LightweightPrepare*ForValidationhelpers for each CRD type that build aTranslateContextwithout running the full reconciler loop. Used by the admission webhook to resolve references before translating.Admission validator
internal/webhook/v1/adc_validation.go(new):adcAdmissionValidatorthat:client.Validate()ADCValidationErrorscause denial)global_rulesandplugin_metadatain the validate payload so plugin references can be resolvedWebhook wiring
apisixroute_webhook.go,apisixconsumer_webhook.go,apisixtls_webhook.go,consumer_webhook.go: WireadcAdmissionValidator; ADC init errors are logged and ignored (fail-open).apisixtls_webhook.go: Skip ADC validation when secrets are missing to preserve the existing warn-only behaviour for that case.consumer_webhook.go: Validate duplicatekey-authcredential keys scoped to the sameGatewayRefusing a field-index query (O(1) instead of O(N) full list). Malformed inline JSON credentials are logged and skipped rather than causing a hard denial.Behaviour notes