-
Notifications
You must be signed in to change notification settings - Fork 3.9k
xds: SslContext updates handling when using system root certs #12340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kannanjgithub
merged 27 commits into
grpc:master
from
kannanjgithub:systemrootcerts-ignore-trusted-root-updates
Sep 25, 2025
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
4076998
Save changes.
kannanjgithub 968d564
Save changes.
kannanjgithub 4cf653d
Merge branch 'master' into systemrootcerts-ignore-trusted-root-updates
kannanjgithub 6c1898a
Save changes.
kannanjgithub 5be2aa2
Save changes.
kannanjgithub 90abe55
style
kannanjgithub 4c44e4c
Add comment and rename some confusing method names.
kannanjgithub ae74a9e
Merge branch 'clientsidenormaltls-systemrootcert-handle' into systemr…
kannanjgithub 199cc69
style.
kannanjgithub 37cd044
Handle Sslcontext updates for System root certs with and without Mtls.
kannanjgithub 139805e
Style changes.
kannanjgithub 7f48afa
Remove special-casing for System root certs in SslContextProviderSupp…
kannanjgithub d2b722a
Formatting changes.
kannanjgithub e95725d
Trust manager handling for system root certs.
kannanjgithub 180f373
Fix style
kannanjgithub 381beb2
Fixes.
kannanjgithub 18f5d5a
Fix unit tests to cover both mtls and non-mtls for system root certs.
kannanjgithub e18d6cd
Suppress warning.
kannanjgithub 3845e16
Use non wildcard SAN in the SAN matchers in validation context.
kannanjgithub f135943
xds: Plumb system root certs similarly to CertProviders
ejona86 0d5eb0a
Fix certs not updated for handshake.
kannanjgithub 08391fb
Merge branch 'master' into systemrootcerts-ignore-trusted-root-updates
kannanjgithub d6acdfc
Merge branch 'ejona86_xds_system_cert' into systemrootcerts-ignore-tr…
kannanjgithub c14a488
More fixes for system root certs.
kannanjgithub 733f57c
More fixes for system root certs.
kannanjgithub 967fe8c
Address review comment to remove reundant if block
kannanjgithub 0edfb2f
Address review comments.
kannanjgithub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
68 changes: 68 additions & 0 deletions
68
xds/src/main/java/io/grpc/xds/internal/security/certprovider/IgnoreUpdatesWatcher.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2025 The gRPC Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.grpc.xds.internal.security.certprovider; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import io.grpc.Status; | ||
import java.security.PrivateKey; | ||
import java.security.cert.X509Certificate; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public final class IgnoreUpdatesWatcher implements CertificateProvider.Watcher { | ||
private final CertificateProvider.Watcher delegate; | ||
private final boolean ignoreRootCertUpdates; | ||
|
||
public IgnoreUpdatesWatcher( | ||
CertificateProvider.Watcher delegate, boolean ignoreRootCertUpdates) { | ||
this.delegate = requireNonNull(delegate, "delegate"); | ||
this.ignoreRootCertUpdates = ignoreRootCertUpdates; | ||
} | ||
|
||
@Override | ||
public void updateCertificate(PrivateKey key, List<X509Certificate> certChain) { | ||
if (ignoreRootCertUpdates) { | ||
delegate.updateCertificate(key, certChain); | ||
} | ||
} | ||
|
||
@Override | ||
public void updateTrustedRoots(List<X509Certificate> trustedRoots) { | ||
if (!ignoreRootCertUpdates) { | ||
delegate.updateTrustedRoots(trustedRoots); | ||
} | ||
} | ||
|
||
@Override | ||
public void updateSpiffeTrustMap(Map<String, List<X509Certificate>> spiffeTrustMap) { | ||
if (!ignoreRootCertUpdates) { | ||
delegate.updateSpiffeTrustMap(spiffeTrustMap); | ||
} | ||
} | ||
|
||
@Override | ||
public void onError(Status errorStatus) { | ||
delegate.onError(errorStatus); | ||
} | ||
|
||
@VisibleForTesting | ||
public CertificateProvider.Watcher getDelegate() { | ||
return delegate; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...c/main/java/io/grpc/xds/internal/security/certprovider/SystemRootCertificateProvider.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2020 The gRPC Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.grpc.xds.internal.security.certprovider; | ||
|
||
import io.grpc.Status; | ||
import java.security.KeyStore; | ||
import java.security.KeyStoreException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.cert.X509Certificate; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import javax.net.ssl.TrustManager; | ||
import javax.net.ssl.TrustManagerFactory; | ||
import javax.net.ssl.X509TrustManager; | ||
|
||
/** | ||
* An non-registered provider for CertProviderSslContextProvider to use the same code path for | ||
* system root certs as provider-obtained certs. | ||
*/ | ||
final class SystemRootCertificateProvider extends CertificateProvider { | ||
public SystemRootCertificateProvider(CertificateProvider.Watcher watcher) { | ||
super(new DistributorWatcher(), false); | ||
getWatcher().addWatcher(watcher); | ||
} | ||
|
||
@Override | ||
public void start() { | ||
try { | ||
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance( | ||
TrustManagerFactory.getDefaultAlgorithm()); | ||
trustManagerFactory.init((KeyStore) null); | ||
|
||
List<TrustManager> trustManagers = Arrays.asList(trustManagerFactory.getTrustManagers()); | ||
List<X509Certificate> rootCerts = trustManagers.stream() | ||
.filter(X509TrustManager.class::isInstance) | ||
.map(X509TrustManager.class::cast) | ||
.map(trustManager -> Arrays.asList(trustManager.getAcceptedIssuers())) | ||
.flatMap(Collection::stream) | ||
.collect(Collectors.toList()); | ||
getWatcher().updateTrustedRoots(rootCerts); | ||
} catch (KeyStoreException | NoSuchAlgorithmException ex) { | ||
getWatcher().onError(Status.UNAVAILABLE | ||
.withDescription("Could not load system root certs") | ||
.withCause(ex)); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
// Unnecessary because there's no more callbacks, but do it for good measure | ||
for (Watcher watcher : getWatcher().getDownstreamWatchers()) { | ||
getWatcher().removeWatcher(watcher); | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.