Capability to configure both default `CallCredentials` and custom `SslContext` on netty `ManagedChannel`
See original GitHub issueThe problem
I would like to create a netty ManagedChannel
which has both a default CallCredentials
and a custom SslContext
.
I can do the former with
return NettyChannelBuilder.forTarget(
target,
CompositeChannelCredentials.create(TlsChannelCredentials.create(), callCredentials))
.build();
and I can do the latter with
return NettyChannelBuilder.forTarget(target)
.sslContext(sslContext)
.build();
but I can’t see a way to do both at once.
Solution ideas
I can see two possible API additions which would achieve this.
- Make it possible to configure an
SslContext
on aChannelCredentials
instance. I guess this couldn’t be done onTlsChannelCredentials
since that’s in core and can’t depend on the nettySslContext
, so it would have to be a netty-specificChannelCredentials
implementation. Then I could do something like
return NettyChannelBuilder.forTarget(
target,
CompositeChannelCredentials.create(NettyTlsChannelCredentials.create().withSslContext(sslContext), callCredentials))
.build();
- Make it possible to configure a default
CallCredentials
on aNettyChannelBuilder
without aChannelCredentials
. Then I could do something like
return NettyChannelBuilder.forTarget(target)
.defaultCallCredentials(callCredentials)
.sslContext(sslContext)
.build();
From what I’ve seen of the source code, 2. would probably be the easier change to make, but might fit in less well with the direction you want to take the API in.
My current workaround
The workaround we’re intending to use right now is to create a channel which has the correct SslContext
but no default CallCredentials
, and instead configure the CallCredentials
directly on every stub I create. To make this easier, we’ll wrap the ManagedChannel
and the CallCredentials
together into an object of our own so that we can pass them around together. Something like
return GrpcChannelWithCallCredentials.create(
NettyChannelBuilder.forTarget(target)
.sslContext(sslContext)
.build(),
callCredentials);
where GrpcChannelWithCallCredentials
is our wrapper class. This is a bit ugly, and involves a change in every bit of code where we create a stub, rather than being able to do it once where we create the channel.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
Thanks, that’s exactly what I wanted!
I guess the only issue here is the lack of discoverability of this class. If you’re tracking the docs update elsewhere, I’m happy to close this.
Documentation update is merged, so closing. If more information is provided or there’s a follow-up question, comment and we can reopen.