Repository navigation
Resolve listener TLS certificates through an extension server - #10142
Conversation
✅ Deploy Preview for cerulean-figolla-1f9435 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #10142 +/- ##
==========================================
- Coverage 82.29% 82.20% -0.09%
==========================================
Files 277 277
Lines 43617 44005 +388
==========================================
+ Hits 35894 36174 +280
- Misses 7722 7830 +108
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Would it make sense to make this API generic for Envoy secrets instead of listener certificates? For example, we could rename |
Hey @zhaohuabing , Thanks for reviewing it. Done, generalized the extension API to secrets (SecretResources, ResolveSecret, XDSSecret). I kept the listener certificate IR and translator logic certificate-specific, since that's just one consumer of the generic hook, for future secret types (CA bundles, client certs) can reuse ResolveSecret |
Add ExtensionManager.SecretResources and the Secret translator hook. A listener's tls.certificateRefs may reference a registered kind in place of a Kubernetes Secret. Validation requires the Secret hook when secretResources is set. Signed-off-by: Weiwei Li <[email protected]>
ResolveSecret asks the owning extension how Envoy should obtain a secret referenced from a registered kind. The response is an SdsSecretConfig, or a failure reason and message when the secret is not resolved. Signed-off-by: Weiwei Li <[email protected]>
Add ResolveSecretHook to the hook client. The hook does not chain: with multiple extension managers, each secret kind is owned by exactly one extension, selected by the referenced resource's group and kind. Signed-off-by: Weiwei Li <[email protected]>
…ificates An extension-resolved certificate is carried as a reference to the registered resource, without key material. It is exclusive with SDS and inline certificate fields. Signed-off-by: Weiwei Li <[email protected]>
Resolve each extension-provided listener certificate through ResolveSecret and add the returned SDS config to the filter chain. A certificate the extension reports as unresolved is left out, and a listener whose extension certificates all fail to resolve is skipped rather than built without a certificate. Hook errors fail translation unless the extension fails open. Signed-off-by: Weiwei Li <[email protected]>
A listener certificate ref to a registered secret kind is checked against a ReferenceGrant and for existence, then passed into the IR as an ExtensionRef. Its status is not read; readiness is the extension's decision at xDS time. Signed-off-by: Weiwei Li <[email protected]>
Watch and list the kinds registered in secretResources and add them to the resource tree with their status. The watch omits the generation-change filter so a status-only update from the provider retriggers resolution, and a kind whose CRD is missing is skipped. The offline controller registers and lists these kinds as well. Signed-off-by: Weiwei Li <[email protected]>
f23f927 to
0fbb7f6
Compare
|
Following the API rename, I just renamed the internal plumbing that serves SecretResources (provider watch/loader, resource tree field, lookup helpers, composite hook router) from certificate to secret. The listener-specific parts (IR, listener ref validation, xDS) keep certificate naming. The rename touched every layer and it's the only feedback so far, so I force pushed to regroup the commmit history into one commit per layer. Hope this could make it easier for other maintainers to review. |
|
@wweiwei-li can you fix the conflict? |
Should a secret resolution failure always be treated as an error regardless of failOpen/failClose? For other hooks, some mutations were not applied, but it's still possible that the base EG-generated XDS is valid. If a listener TLS secret is missing, is it better to fail (and keep proxy config as-is)? |
guydc
left a comment
There was a problem hiding this comment.
Hi @wweiwei-li. Thanks for this work. Some initial thoughts.
Additionally, in general, there is a security aspect to this feature that we need to consider. If a local extension resource can reference any SDS config and gain access to that secret, integrity issues are possible.
We need to think about:
- How do we prevent users from referencing static/dynamic system-generated certs, like the EG client cert. That should be pretty easy with a post-resolution denylist.
- Is there any sort of reasonable validation that we can perform that will prevent unauthorized use of SDS secrets? If not, we need to very explicitly state this concern in our docs and threat model and document it as an extension-server implementor responsibility.
| // The secret resource that was referenced. | ||
| SecretResource *ExtensionResource `protobuf:"bytes,1,opt,name=secret_resource,json=secretResource,proto3" json:"secret_resource,omitempty"` | ||
| // Namespace and name of the Gateway owning the listener. | ||
| GatewayNamespace string `protobuf:"bytes,2,opt,name=gateway_namespace,json=gatewayNamespace,proto3" json:"gateway_namespace,omitempty"` |
There was a problem hiding this comment.
Passing GW-API context here (GW/Listener Name, Namespaces) is a bit unprecedented in the extension server API. So far, the API was really focused on XDS and user-provided context resources. Are these fields strictly required for every implemention, or can they be encoded into the user-provided context resource in cases where they are needed?
There was a problem hiding this comment.
Passing GW-API context here (GW/Listener Name, Namespaces) is a bit unprecedented in the extension server API. So far, the API was really focused on XDS and user-provided context resources. Are these fields strictly required for every implemention, or can they be encoded into the user-provided context resource in cases where they are needed?
removed listener_name in 7f9de03. but I had to keep GW namespace and name. For our usage, the secret separately for each Gateway'. so the same resource can be ready on one Gateway and not yet on another. the hook needs to know which gateway it is resolving for
There was a problem hiding this comment.
Can you store this information in the custom resource? The secret CRD will define not only the secret name but also its scope of attachment? This might mean duplicating a CRD that was previously referenced by multiple GWs, but I'm not sure how common it is to share a server cert across GWs.
I'm just hesitant to tie GW-API metadata in the XDS-driven extension server interface...
There was a problem hiding this comment.
hey @guydc, Thanks. I understand your hesitation. Specifying the attachment in the secret CRD could work, but it has two drawbacks:
- Duplication: sharing a server cert across Gateways is common for our case
- We rely on users to keep the scope and the references consistent as the extension doesn't know which Gateway is asking, so it trusts the scope written in the CR. If Gateway B references a CR scoped to Gateway A, the extension answers for A, and B fails silently. Catching that would need every extension to add its own validation.
Having EG pass it avoids both: one CR can serve any number of Gateways, and the value always matches the listener being built, because it comes from EG.
If you'd rather keep Gateway API out of the interface, I can pass the proxy infra name/namespace instead (the same identity EG gives the infrastructure provider extension in ProxyInfra. It identifies the data plane, and it also works with mergeGateways.
Or, if you still think the secret CRD should cover this, Please let me know.
There was a problem hiding this comment.
Passing the id of the dataplane for which this xds is being built sounds reasonable to me, and creates consistency across extension servers that deal with both infra and xds.
Would appreciate input from @envoyproxy/gateway-maintainers.
There was a problem hiding this comment.
sounds good to me, it shouldn't be a common for all the contexts.
There was a problem hiding this comment.
Thank you both. Made this change in 3a7c555: the secret hook context now carries the proxy infra (proxy.name, proxy.namespace) instead of the Gateway namespace/name.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…secrets Signed-off-by: Weiwei Li <[email protected]>
…s did not resolve Signed-off-by: Weiwei Li <[email protected]>
…on resource registry Signed-off-by: Weiwei Li <[email protected]>
Signed-off-by: Weiwei Li <[email protected]>
Signed-off-by: Weiwei Li <[email protected]>
Signed-off-by: Weiwei Li <[email protected]>
Signed-off-by: Weiwei Li <[email protected]> # Conflicts: # internal/provider/kubernetes/controller.go
Signed-off-by: Weiwei Li <[email protected]>
4afa870 to
61b7253
Compare
…ension manager Signed-off-by: Weiwei Li <[email protected]>
Signed-off-by: Weiwei Li <[email protected]> # Conflicts: # internal/extension/registry/composite_hook_client_test.go # internal/gatewayapi/resource/load_test.go # proto/extension/context.pb.go
…he secret hook context Signed-off-by: Weiwei Li <[email protected]>
Signed-off-by: Weiwei Li <[email protected]> # Conflicts: # internal/provider/kubernetes/controller.go
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7eb2568d42
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
|
||
| // Close the listeners none of whose extension certificates resolved. This runs after the other | ||
| // listeners are built, so it joins the xDS listener they share a port with. HTTP/3 is not | ||
| // closed this way, as a QUIC filter chain cannot be built without a certificate. |
There was a problem hiding this comment.
Prevent unresolved QUIC SNIs from reaching wildcard listeners
When two HTTPS listeners share a port, HTTP/3 is enabled, and an extension-only listener's certificate is unresolved, this path adds a rejecting TCP chain but no QUIC chain for that listener's SNI. If a resolved peer has a wildcard/default QUIC filter chain covering that hostname, the QUIC ClientHello selects the peer and serves its certificate/routes instead of refusing the unresolved listener, which can misroute traffic across listeners or merged Gateways. Suppress the shared QUIC listener or install an equivalent rejecting QUIC chain for these SNIs.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This is not introduced by this PR. On QUIC, an unresolved listener behaves the same as an invalid one does today. This PR adds a closed filter chain on TCP
| namespace: secretNS, | ||
| name: string(secretRef.Name), | ||
| } | ||
| refGrant, err := r.findReferenceGrant(ctx, from, to) |
There was a problem hiding this comment.
Match ReferenceGrant groups before selecting one
When the target namespace contains grants for the same source namespace and target kind/name in different API groups, this call can load the wrong grant: findReferenceGrant compares only namespace/kind/name and returns the first match, ignoring both From.Group and To.Group. The Gateway API validator later performs exact group matching, so a valid extension certificate reference is rejected even when another correct grant exists; pass the source/target groups into the lookup or retain all candidate grants.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
findReferenceGrant is existing helper
| BackendTLSPolicies []*gwapiv1.BackendTLSPolicy `json:"backendTLSPolicies,omitempty" yaml:"backendTLSPolicies,omitempty"` | ||
| EnvoyExtensionPolicies []*egv1a1.EnvoyExtensionPolicy `json:"envoyExtensionPolicies,omitempty" yaml:"envoyExtensionPolicies,omitempty"` | ||
| ExtensionServerPolicies []unstructured.Unstructured `json:"extensionServerPolicies,omitempty" yaml:"extensionServerPolicies,omitempty"` | ||
| ExtensionSecrets []unstructured.Unstructured `json:"extensionSecrets,omitempty" yaml:"extensionSecrets,omitempty"` |
There was a problem hiding this comment.
Sort extension secrets before storing snapshots
When a registered secret kind has multiple objects, processExtensionSecrets preserves the cache's list order, but Resources.Sort never orders this new ExtensionSecrets slice. If the cache returns the same objects in a different order, ControllerResourcesContext.Equal's deep comparison treats the snapshot as changed and unnecessarily reruns translation and per-certificate extension hooks; add deterministic sorting for this slice like the other unstructured resource collections.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Yeah, I can add this sort
…napshot Signed-off-by: Weiwei Li <[email protected]>
|
Hey @zhaohuabing I saw you removed this from v1.10.0-rc.1 Release, Can we have it ? I addressed all the feedbacks. @guydc @zirain Can you take another look when you get a chance ? |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8395d2a2b8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…er store Signed-off-by: Weiwei Li <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ae25238463
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } | ||
| for _, gvk := range em.SecretResources { | ||
| key := fmt.Sprintf("%s/%s/%s", gvk.Group, gvk.Version, gvk.Kind) | ||
| extGVKMap[key] = extSecret |
There was a problem hiding this comment.
Retain all categories for an extension GVK
When standalone/file-provider configuration registers the same GVK in secretResources and any of resources, policyResources, or backendResources, this single-valued map lets one category overwrite the other, and the switch below appends the object to only one resource slice. This overlap is accepted by configuration validation and the Kubernetes provider collects the categories independently; for example, a backend registration is processed after this assignment, so the object never reaches ExtensionSecrets and a listener referencing it is reported as InvalidCertificateRef. Store all applicable categories rather than only the last one.
Useful? React with 👍 / 👎.
| for i := range config.extensionCertificates { | ||
| tlsListenerConfigs.Certificates = append(tlsListenerConfigs.Certificates, | ||
| t.getTLSCertificateFromExtensionRef(&config.extensionCertificates[i], gwIR, gatewayCtx)) |
There was a problem hiding this comment.
Preserve certificateRefs order across source types
When a listener places an extension-backed certificate before a Kubernetes or SDS Secret in certificateRefs, validation stores the two source types in separate slices and this loop appends every extension certificate after every Secret. The resulting IR and xDS order therefore differs from the configured order; for a wildcard listener with no SNI, or whenever multiple compatible certificates remain, Envoy's first compatible certificate can become the later Secret rather than the configured extension certificate. Preserve the original interleaving when constructing Certificates.
Useful? React with 👍 / 👎.
|
Codex is leaving new comments on each push. I addressed findings that are specific to this PR changes, and leaving existing behavior outside its scope for followups if maintainers think they need to be fixed |
| // Version is intentionally dropped so matching aligns with runner.ExtensionGroupKinds | ||
| // and Manager.HasExtension, which also compare by group+kind only. | ||
| func buildManagerGKSets(ext *egv1a1.ExtensionManager) (sets.Set[schema.GroupKind], sets.Set[schema.GroupKind]) { | ||
| func buildManagerGKSets(ext *egv1a1.ExtensionManager) (sets.Set[schema.GroupKind], sets.Set[schema.GroupKind], sets.Set[schema.GroupKind]) { |
There was a problem hiding this comment.
nit (non-blocking, fine as a follow-up): with secretGKSet this now returns three values of the same type, so swapping them at a call site would compile and silently misroute matching. The sets also get copied field by field into namedManager and then into hookClientEntry, so each new category touches every call site.
Consider returning a struct that flows through unchanged:
type extensionGKSets struct {
resource sets.Set[schema.GroupKind] // Resources + BackendResources
policy sets.Set[schema.GroupKind] // PolicyResources
secret sets.Set[schema.GroupKind] // SecretResources
}
func buildManagerGKSets(ext *egv1a1.ExtensionManager) extensionGKSetswith namedManager / hookClientEntry holding a single gkSets extensionGKSets field. Happy to do this in a separate PR.
Signed-off-by: Weiwei Li <[email protected]> # Conflicts: # internal/gatewayapi/helpers.go
Signed-off-by: Weiwei Li <[email protected]>
|
Merged the latest main and resolved the conflict. The failing e2e test (TestE2E/ClientMTLS) timed out waiting was not related to my change. It looks like a flaky test. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 615f3f011c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if t.ExtensionManager == nil { | ||
| return nil, fmt.Errorf("certificate %q requires an extension server but none is configured", cert.Name) | ||
| } | ||
| hookClient, err := (*t.ExtensionManager).GetPostXDSHookClient(egv1a1.XDSSecret) |
There was a problem hiding this comment.
Select only the owning Secret client
When multiple extension managers enable Secret, resolving a certificate for manager B calls GetPostXDSHookClient here before the referenced group/kind is considered. CompositeManager.collectHookClients eagerly initializes every manager and returns any non-fail-open setup error (internal/extension/registry/composite_manager.go:141-148); for example, GenerateGRPCOptions errors when unrelated manager A's TLS credential Secret is missing (internal/extension/grpc.go:79-91). This blocks B's otherwise healthy certificate and therefore the entire xDS update despite this hook being non-chaining, so select the owner by group/kind before constructing clients.
Useful? React with 👍 / 👎.
|
/retest |
2 similar comments
|
/retest |
|
/retest |
guydc
left a comment
There was a problem hiding this comment.
LGTM. Remaining P2 findings can be completed in a follow-up.
|
Hey @zhaohuabing , FileAccessLog in e2e-test (v1.37.0, dual, gateway-namespace-mode) is failing , retried it but no luck. The only code change since the last pass for it is the extensionGKSets refactor, it won't introduce issue to it. It looks like a flaky or test-side issue. Can you check whether we can override it? |
zirain
left a comment
There was a problem hiding this comment.
LGTM, please fix the remaining before 1.10.0(Nov 4)
feat: resolve listener TLS certificates through an extension server
What this PR does / why we need it:
Envoy Gateway can only source listener TLS certificates from Kubernetes Secrets today. This PR lets an extension server supply them, so certificates managed outside of Secrets (for example, issued and rotated by an external provider) can back a Gateway listener.
An extension registers one or more kinds via a new
ExtensionManager.SecretResourcesfield. A listener'stls.certificateRefsmay then point at a resource of a registered kind. During xDS translation, Envoy Gateway calls a newResolveSecrethook on the owning extension, which returns how Envoy should obtain the secret: anSdsSecretConfig, resolved by name or served over SDS. The resolved config is wired into the listener's TLS transport socket.The change is layered so each concern is reviewable on its own:
ExtensionManager.SecretResourcesand theSecrettranslator-hook enum value; validation requires theSecrethook whensecretResourcesis set.ResolveSecretRPC and the corresponding hook. The hook is non-chaining: a secret kind is owned by exactly one extension, selected by the referenced resource's group/kind.TLSCertificate.ExtensionRefso an extension-resolved certificate can be represented without key material.failure_reason) is left out. A listener whose certificates are all extension-provided and none resolve is skipped rather than emitting a certificate-less filter chain. Hook errors fail translation unless the extension setsfailOpen, in which case the certificate is treated as unresolved.Behavior for existing configurations is unchanged: listeners that use only Secret-backed certificates never touch the extension path.
Which issue(s) this PR fixes:
#10008
PR Checklist
git commit -s). See DCO: Sign your work./api), the API was discussed and agreed before the implementation. The API change can be in a separate PR, or in the same PR, but the API must be agreed before implementation. N/A if this PR does not contain API changes.make generate gen-check,make lint, and the unit-test/coverage build pass. (Flaky e2e failures are not considered breakages, butgen-check,lint, and coverage MUST pass.)release-notes/current/<section>/<pr-number>-<slug>.md(seerelease-notes/current/README.mdfor sections and naming). N/A if this PR does not contain non-trivial changes.make gen-checkand committed the result if API/helm charts/modules changed.release-notes/current/breaking_changes/.