fix: reject invalid plugin config instead of applying an empty one#441
fix: reject invalid plugin config instead of applying an empty one#441shreemaan-abhishek wants to merge 1 commit into
Conversation
A plugin config that fails to unmarshal (e.g. a non-object value) was logged and dropped, and the plugin was still applied with an empty or secret-only config. Translation now fails so the resource keeps its last good state and the admission webhook rejects the change upfront. Aligns fillPluginFromExtensionRef, which silently skipped such plugins, to the same fail-hard behavior.
📝 WalkthroughWalkthroughPlugin configuration parsing now returns errors through APISIX, HTTPRoute, GRPCRoute, Ingress, and global-rule translation paths. New tests cover malformed configurations, valid secret references, and propagation behavior. ChangesPlugin configuration error propagation
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/adc/translator/pluginconfig_test.go (1)
39-183: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd test coverage for consumer and stream-route error propagation paths.
The test suite covers
buildPlugins,buildPluginConfig,TranslateApisixGlobalRule,loadPluginConfigPluginsForIngress, andfillPluginFromExtensionRef, but two changed error-propagation paths lack regression tests:
TranslateApisixConsumer(apisixconsumer.golines 104-107): No test verifies that a malformed consumer plugin config fails consumer translation.translateStreamRule(apisixroute.golines 491-493): No test verifies that a malformed stream-route plugin config fails stream rule translation.Adding these tests would close the coverage gap for the fail-closed behavior this PR introduces.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/adc/translator/pluginconfig_test.go` around lines 39 - 183, Add regression tests for malformed plugin configurations through TranslateApisixConsumer and translateStreamRule. Use the existing non-object plugin config fixture, construct the required consumer and stream-route resources and translation context, then assert translation returns an error and no result; preserve the fail-closed assertions used by the existing buildPlugins and global-rule tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/adc/translator/pluginconfig_test.go`:
- Around line 39-183: Add regression tests for malformed plugin configurations
through TranslateApisixConsumer and translateStreamRule. Use the existing
non-object plugin config fixture, construct the required consumer and
stream-route resources and translation context, then assert translation returns
an error and no result; preserve the fail-closed assertions used by the existing
buildPlugins and global-rule tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d947cdf1-b6b3-4bd4-be0e-c5213d143552
📒 Files selected for processing (7)
internal/adc/translator/apisixconsumer.gointernal/adc/translator/apisixroute.gointernal/adc/translator/globalrule.gointernal/adc/translator/grpcroute.gointernal/adc/translator/httproute.gointernal/adc/translator/ingress.gointernal/adc/translator/pluginconfig_test.go
conformance test report - apisix-standalone modeapiVersion: gateway.networking.k8s.io/v1
date: "2026-07-20T11:11:02Z"
gatewayAPIChannel: experimental
gatewayAPIVersion: v1.3.0
implementation:
contact: null
organization: APISIX
project: apisix-ingress-controller
url: https://github.com/apache/apisix-ingress-controller.git
version: v2.0.0
kind: ConformanceReport
mode: default
profiles:
- core:
result: success
statistics:
Failed: 0
Passed: 12
Skipped: 0
name: GATEWAY-GRPC
summary: Core tests succeeded.
- core:
result: partial
skippedTests:
- HTTPRouteHTTPSListener
statistics:
Failed: 0
Passed: 32
Skipped: 1
extended:
result: partial
skippedTests:
- HTTPRouteRedirectPortAndScheme
statistics:
Failed: 0
Passed: 11
Skipped: 1
supportedFeatures:
- GatewayAddressEmpty
- GatewayPort8080
- HTTPRouteBackendProtocolWebSocket
- HTTPRouteDestinationPortMatching
- HTTPRouteHostRewrite
- HTTPRouteMethodMatching
- HTTPRoutePathRewrite
- HTTPRoutePortRedirect
- HTTPRouteQueryParamMatching
- HTTPRouteRequestMirror
- HTTPRouteResponseHeaderModification
- HTTPRouteSchemeRedirect
unsupportedFeatures:
- GatewayHTTPListenerIsolation
- GatewayInfrastructurePropagation
- GatewayStaticAddresses
- HTTPRouteBackendProtocolH2C
- HTTPRouteBackendRequestHeaderModification
- HTTPRouteBackendTimeout
- HTTPRouteParentRefPort
- HTTPRoutePathRedirect
- HTTPRouteRequestMultipleMirrors
- HTTPRouteRequestPercentageMirror
- HTTPRouteRequestTimeout
name: GATEWAY-HTTP
summary: Core tests partially succeeded with 1 test skips. Extended tests partially
succeeded with 1 test skips.
- core:
result: partial
skippedTests:
- TLSRouteSimpleSameNamespace
statistics:
Failed: 0
Passed: 10
Skipped: 1
name: GATEWAY-TLS
summary: Core tests partially succeeded with 1 test skips. |
conformance test report - apisix modeapiVersion: gateway.networking.k8s.io/v1
date: "2026-07-20T11:12:11Z"
gatewayAPIChannel: experimental
gatewayAPIVersion: v1.3.0
implementation:
contact: null
organization: APISIX
project: apisix-ingress-controller
url: https://github.com/apache/apisix-ingress-controller.git
version: v2.0.0
kind: ConformanceReport
mode: default
profiles:
- core:
result: success
statistics:
Failed: 0
Passed: 12
Skipped: 0
name: GATEWAY-GRPC
summary: Core tests succeeded.
- core:
failedTests:
- HTTPRouteInvalidBackendRefUnknownKind
result: failure
skippedTests:
- HTTPRouteHTTPSListener
statistics:
Failed: 1
Passed: 31
Skipped: 1
extended:
result: partial
skippedTests:
- HTTPRouteRedirectPortAndScheme
statistics:
Failed: 0
Passed: 11
Skipped: 1
supportedFeatures:
- GatewayAddressEmpty
- GatewayPort8080
- HTTPRouteBackendProtocolWebSocket
- HTTPRouteDestinationPortMatching
- HTTPRouteHostRewrite
- HTTPRouteMethodMatching
- HTTPRoutePathRewrite
- HTTPRoutePortRedirect
- HTTPRouteQueryParamMatching
- HTTPRouteRequestMirror
- HTTPRouteResponseHeaderModification
- HTTPRouteSchemeRedirect
unsupportedFeatures:
- GatewayHTTPListenerIsolation
- GatewayInfrastructurePropagation
- GatewayStaticAddresses
- HTTPRouteBackendProtocolH2C
- HTTPRouteBackendRequestHeaderModification
- HTTPRouteBackendTimeout
- HTTPRouteParentRefPort
- HTTPRoutePathRedirect
- HTTPRouteRequestMultipleMirrors
- HTTPRouteRequestPercentageMirror
- HTTPRouteRequestTimeout
name: GATEWAY-HTTP
summary: Core tests failed with 1 test failures. Extended tests partially succeeded
with 1 test skips.
- core:
result: partial
skippedTests:
- TLSRouteSimpleSameNamespace
statistics:
Failed: 0
Passed: 10
Skipped: 1
name: GATEWAY-TLS
summary: Core tests partially succeeded with 1 test skips. |
conformance test reportapiVersion: gateway.networking.k8s.io/v1
date: "2026-07-20T11:29:03Z"
gatewayAPIChannel: experimental
gatewayAPIVersion: v1.3.0
implementation:
contact: null
organization: APISIX
project: apisix-ingress-controller
url: https://github.com/apache/apisix-ingress-controller.git
version: v2.0.0
kind: ConformanceReport
mode: default
profiles:
- core:
failedTests:
- GatewayModifyListeners
result: failure
statistics:
Failed: 1
Passed: 11
Skipped: 0
name: GATEWAY-GRPC
summary: Core tests failed with 1 test failures.
- core:
failedTests:
- GatewayModifyListeners
result: failure
skippedTests:
- HTTPRouteHTTPSListener
statistics:
Failed: 1
Passed: 31
Skipped: 1
extended:
result: partial
skippedTests:
- HTTPRouteRedirectPortAndScheme
statistics:
Failed: 0
Passed: 11
Skipped: 1
supportedFeatures:
- GatewayAddressEmpty
- GatewayPort8080
- HTTPRouteBackendProtocolWebSocket
- HTTPRouteDestinationPortMatching
- HTTPRouteHostRewrite
- HTTPRouteMethodMatching
- HTTPRoutePathRewrite
- HTTPRoutePortRedirect
- HTTPRouteQueryParamMatching
- HTTPRouteRequestMirror
- HTTPRouteResponseHeaderModification
- HTTPRouteSchemeRedirect
unsupportedFeatures:
- GatewayHTTPListenerIsolation
- GatewayInfrastructurePropagation
- GatewayStaticAddresses
- HTTPRouteBackendProtocolH2C
- HTTPRouteBackendRequestHeaderModification
- HTTPRouteBackendTimeout
- HTTPRouteParentRefPort
- HTTPRoutePathRedirect
- HTTPRouteRequestMultipleMirrors
- HTTPRouteRequestPercentageMirror
- HTTPRouteRequestTimeout
name: GATEWAY-HTTP
summary: Core tests failed with 1 test failures. Extended tests partially succeeded
with 1 test skips.
- core:
failedTests:
- GatewayModifyListeners
- TLSRouteSimpleSameNamespace
result: failure
statistics:
Failed: 2
Passed: 9
Skipped: 0
name: GATEWAY-TLS
summary: Core tests failed with 2 test failures. |
Type of change:
What this PR does / why we need it:
When a plugin's
configfails to unmarshal into an object (for example anon-object value like
config: ["10.0.0.0/8"], which the CRD acceptsbecause
configusesx-kubernetes-preserve-unknown-fields), the errorwas logged and discarded, and the plugin was still applied with an empty
(or secret-only) config. So an
ip-restrictionplugin with a malformedwhitelistsilently becameip-restriction: {}on the published route,enforcing nothing while the resource reconciled green. The same path
serves
ApisixGlobalRule, so a malformed global plugin config wasapplied gateway-wide in mutated form.
This changes
buildPluginConfigto return an error on a malformedconfig and propagates it through every caller (route plugins,
stream-route plugins, referenced
ApisixPluginConfig,ApisixGlobalRule,Ingress plugin-config annotation,
ApisixConsumerplugins). Translationnow fails instead of publishing a fabricated empty object, so the
resource keeps its last good state and the admission webhook rejects the
invalid config upfront.
fillPluginFromExtensionRef, which silentlyskipped such plugins, is aligned to the same fail-hard behavior.
Pre-submission checklist:
Summary by CodeRabbit
Bug Fixes
Tests