Incorrect behaviour when rotating SDS managed TLS certs using ADS + java control plane library
Description: We're working on switching to dynamic listeners and PKI managed certificates in our envoy layer. Our setup is
- Dynamic listener (using tls inspector) matching hostname and using a SDS managed cert by reference
- Listeners and SDS sent using ADS
- Control plane creates a new ADS snapshot with a new listener config refering to a new sds secret
- Envoy accepts the new listener config and starts draining the old listener
- The new listener refers to the new sds secret
- envoy sends a sds subscription for [oldsecret,newsecret]
- java control plane library rejects this subscription because the latest snapshot only contains [newsecret], code: https://github.com/envoyproxy/java-control-plane/blob/main/cache/src/main/java/io/envoyproxy/controlplane/cache/SimpleCache.java#L320
So I have two questions:
- xDS API docs state that
For [non listener / cluster] resource types, an empty DiscoveryResponse is effectively a no-op from the client’s perspective.<-- does this mean that the java control plane is behaving incorrectly when rejecting a subscription for a nonexisting resource? - Should envoy be subscribing to a secret that's only present in a draining listener in the first place?
In our setup, we use ADS (java-control-plane) for listeners but a separate xDS server for SDS. we have seen rotation work just fine in this setup without changing the secret name (there are no changes to the listener at all), the SDS server returns new material for the same secret name when it needs to be rotated. Is there a reason that you want to tie secret changes to listener changes? If they are necessarily tied together, couldn't the secrets be inlined into the listener configuration?
Is there a reason that you want to tie secret changes to listener changes?
I think the primary motivation for this is that we want to minimize change, as we're moving from a mostly static config to dynamic. We're using SotW updates over ADS for all other configuration, and feel that it's simple and easy to reason about (= safe).
If they are necessarily tied together, couldn't the secrets be inlined into the listener configuration
That's a very good point! So basically using tls_certificates instead of tls_certificate_sds_secret_configs in the common_tls_context? Looks like that would unblock us until this is fixed. Thanks!
So basically using tls_certificates instead of tls_certificate_sds_secret_configs in the common_tls_context?
exactly!
Is java-control-plane actually rejecting? The code seems to indicating it's skipping the response. In any case, this seems broken, it should probably just deal with the live secret. @snowp. Can you file in https://github.com/envoyproxy/java-control-plane?
I think to prevent races, you will need in general to have your control plane hang onto oldsecret until the new listener rollout is completed if you do use SDS here.
I think to prevent races, you will need in general to have your control plane hang onto oldsecret until the new listener rollout is completed if you do use SDS here.
Even if oldlistener is the only resource that has a reference to oldsecret?
Across a fleet of Envoys you will have different Envoys at different points in the LDS switchover. xDS is eventually consistent - you can't assume anything about one resource when modifying another, either at the node level or across a set of nodes.
hmm i don't understand in what scenario an envoy in the fleet of envoys (using ADS) would require the control plane to have retained the old secret, since there isn't anything in the control plane retaining a reference to it.
once the control plane sotw snapshot is updated, any envoy that checks in would receive a new sotw with no reference to oldsecret, right?
Yes, but existing Envoys will go through a period in which some of the fleet has the old listener and some of it has the new one.
Is there a scenario where the envoys with the old listener would request the old secret (or old listener for that matter) from the control plane?
Sure - imagine the old listener is warming on the old secret when you do the rotation, for example. In control planes with multiple xDS servers you also have the situation potentially where some have the new secret but no the new listener etc. It's advisable to be defensive against this when building robust xDS control planes. That said, maybe there are specifics of your setup that allow for this. In any case, this is drifting off topic from the original issue I think.
Thank you for engaging, and apologies if I'm misunderstanding how this is supposed to work :smile:
Sure - imagine the old listener is warming on the old secret when you do the rotation, for example.
I can see how this would be an issue when not using SotW, but not with it?
drifting off topic
Alright, let's get back to the questions, that were about what the correct behaviour should be in a secret rotation scenario using ADS/SotW updates.
You said I think to prevent races, you will need in general to have your control plane hang onto oldsecret until the new listener rollout is completed, is this true when using SDS over ADS as well? If so, it implies that the control plane needs to retain resources from previous snapshots/"world-states"?
.. until the new listener rollout is completed <-- how would the control plane know when the listener rollout is completed?
If you are doing this over ADS, there are very specific situations in which you can achieve dropping the oldsecret during the rotation, but it requires the following:
- You need to know that clients have LDS ACKed and the corresponding SDS fetch was also received and ACKed by the client.
- You need to avoid responding to any new client LDS fetches during a period in which you switch to both the new listener and the new secret.
Maybe then it would work? I would personally try and avoid getting into this kind of complex behavior and prefer to either inline the secret in LDS in your case if that works or do a proper make-before-break rotation.
You can tell when listener rollouts complete when clients have all ACKed hte latest version.
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.
This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted" or "no stalebot". Thank you for your contributions.
/open
I think this also happens in go-control-plane. I'm using ADS for both Listener and Secret.
The listener will be patched by some of our business logic. The patch will add or remove a transport_socket config in the listener. When the tls is disabled, the Secret resource also is not presented in DiscoveryResponse, but when I dump the envoy config, the listener still be patched (the transport_socker is removed) but dynamic_active_secrets still there. What I expect is the dynamic_active_secrets must be not presented.