Skip to content

Conversation

Zgoda91
Copy link

@Zgoda91 Zgoda91 commented Aug 1, 2025

implementing gRFC A65 grpc/proposal/pull/372

This change contains:

  1. Updated TlsChannelCredentials instantiation process, which involves reading trust certificates from paths provided in the bootstrap configuration file.
  2. Trust certificates polling mechanism is going to be closed once given TlsChannelCredentials are no longer used (as per [xDS] A65 mTLS credentials in bootstrap (part1) #12350)

@ejona86 ejona86 added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Aug 6, 2025
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Aug 6, 2025
@ejona86 ejona86 self-requested a review August 6, 2025 21:54
@Zgoda91
Copy link
Author

Zgoda91 commented Aug 11, 2025

@ejona86 Could you please review this PR when you get a chance? Thanks!

@Zgoda91 Zgoda91 requested a review from kannanjgithub August 27, 2025 13:31
kannanjgithub
kannanjgithub previously approved these changes Aug 28, 2025
@ejona86 ejona86 added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Aug 28, 2025
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Aug 28, 2025
Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One quick/important comment. But I'll need to look over this a bit more before merging.

@kannanjgithub kannanjgithub dismissed their stale review August 29, 2025 12:00

Based on Eric's comment.

@Zgoda91 Zgoda91 force-pushed the A65_mtls_creds_in_bootstrap branch from 8248816 to faaa15c Compare September 3, 2025 11:09
@Zgoda91 Zgoda91 changed the title [xDS] A65 mTLS credentials in bootstrap [xDS] A65 mTLS credentials in bootstrap (part 2) Sep 10, 2025
@Zgoda91 Zgoda91 force-pushed the A65_mtls_creds_in_bootstrap branch 2 times, most recently from 5a59b20 to 46f7ddc Compare September 10, 2025 14:07
@Zgoda91 Zgoda91 force-pushed the A65_mtls_creds_in_bootstrap branch from 46f7ddc to 434579a Compare September 10, 2025 14:47
@Zgoda91
Copy link
Author

Zgoda91 commented Sep 11, 2025

@ejona86 - PR ready for the third round. Mind that there is a part 1 implemented separately here for visiblity

public final class TlsXdsCredentialsProvider extends XdsCredentialsProvider {
private static final Logger logger = Logger.getLogger(TlsXdsCredentialsProvider.class.getName());
private static final String CREDS_NAME = "tls";
private static final String CERT_FILE_KEY = "certificate_file";
Copy link
Contributor

@kannanjgithub kannanjgithub Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The grfc says implementations should be able to reuse the FileWatcherCertificateProvider. It is a bit more work though - we could do similar to CertProvidersslContextProvider's usage here. (You can see it getting used during XdsClientServerSecurityTest)

  1. passing the plugin name as file_watcher and
  2. Make this class (TlsXdsCredentialsProvider) implement Watcher interface for the Watcher parameter that receives certificate updates
  3. Add the returned Handle to the list of Closeables in ResourceAllocationChannelProvider.
  4. This will require making CertificateProviderStore.Handle public.

@ejona86 WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're reading C++-isms, which ignore everything that isn't C++. Java has two sets of classes: FileWatcherCertificateProvider and AdvancedTlsX509TrustManager/KeyManager. C++ only has one. I have no desire to use FileWatcherCertificateProvider and the abomination of plumbing to make that work. If anything, we should delete parts of FileWatcherCertificateProvider to use more of AdvancedTlsX509TrustManager/KeyManager (which were created later). The closest code in Java to FileWatcherCertificateProvider for this purpose is AdvancedTlsX509TrustManager/KeyManager.

@ejona86
Copy link
Member

ejona86 commented Sep 30, 2025

Please avoid the rebases until the reviewers agree it is a good time to rebase. I'd much rather have conflicts and be able to know what the new changes are than have to re-review the entire PR.

* instantiation of a given {@code ChannelCredentials} object, which must be closed once
* mentioned {@code ChannelCredentials} are no longer in use.
*/
public final class ResourceAllocatingChannelCredentials extends ChannelCredentials {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this in XDS. We don't want a new public type to workaround our internals.


@Override
protected Object getImplSpecificConfig(Map<String, ?> serverConfig, String serverUri)
protected ImmutableMap<String, ?> getImplSpecificConfig(Map<String, ?> serverConfig,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this plumbing change should go back to the old way. We need to parse early so that it is actually validated. Instead, we communicate through the ChannelCredentials. (I'll make a comment elsewhere.)

if (config == null) {
config = ImmutableMap.of();
}
ChannelCredentials channelCredentials = provider.newChannelCredentials(config);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating the ChannelCredentials now, which is necessary because your ResourceAllocatingChannelCredentials API can only release the resources once, we want to share the credentials and keep track of how many usages there are.

public final class ResourceAllocatingChannelCredentials extends ChannelCredentials {
  public static ChannelCredentials create(
      ChannelCredentials channelCreds, Supplier<Closeable> resource) {
    return new ResourceAllocatingChannelCredentials(channelCreds, resource);
  }

  private final ChannelCredentials channelCreds;
  private final Closeable resourceReleaser;
  private final int refCount;

  // constructor...

  public synchronized ChannelCredentials acquireChannelCredentials() {
    if (refCount++ == 0) {
      this.resourceReleaser = resource.get();
    }
    return channelCreds;
  }

  public synchronized releaseChannelCredentials() {
    if (--refCount == 0) {
      resourceReleaser.close();
      resourceReleaser = null;
    }
    assert refCount >= 0;
  }

  @Override
  public ChannelCredentials withoutBearerTokens() {
    // Could be implemented, but unnecessary. Would need to return a ResourceAllocatingChannelCredentials or similar class
    throw new UnsupportedOperationException();
  }
}

Unfortunately, the error handling in resource.get() gets ugly; AdvancedTlsx509TrustManager.updateTrustCredentials() throws. To limp along, we should probably let that throw, and if it throws we return a FailingXdsTransport here.

That's not really what we want, as we don't want a transient failure to become permanent, but it seems really hard to "correctly," so I think we should accept something lesser for the while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants