-
Notifications
You must be signed in to change notification settings - Fork 68
feat: add support for new setAllowHardBoundTokens field. #3467
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
Changes from 9 commits
09eb2b2
db51f4e
fd1015e
960084d
ddb3b79
60dafd0
e193cc9
0e40f22
6a27af6
591ef68
90a32af
a7f8384
4fe44cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,16 +126,32 @@ public final class InstantiatingGrpcChannelProvider implements TransportChannelP | |
| @Nullable private final Boolean allowNonDefaultServiceAccount; | ||
| @VisibleForTesting final ImmutableMap<String, ?> directPathServiceConfig; | ||
| @Nullable private final MtlsProvider mtlsProvider; | ||
| @Nullable private final List<HardBoundTokenTypes> allowedHardBoundTokenTypes; | ||
| @VisibleForTesting final Map<String, String> headersWithDuplicatesRemoved = new HashMap<>(); | ||
|
|
||
| @Nullable | ||
| private final ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> channelConfigurator; | ||
|
|
||
| /* | ||
| * Experimental feature | ||
| * | ||
| * <p>{@link HardBoundTokenTypes} specifies if hard bound tokens should be used if DirectPath | ||
| * or S2A is used to estabilsh a connection to Google APIs. | ||
| * | ||
| */ | ||
| public enum HardBoundTokenTypes { | ||
| // Use ALTS bound tokens when using DirectPath | ||
| ALTS, | ||
| // Use MTLS bound tokens when using S2A | ||
| MTLS_S2A | ||
| } | ||
|
|
||
| private InstantiatingGrpcChannelProvider(Builder builder) { | ||
| this.processorCount = builder.processorCount; | ||
| this.executor = builder.executor; | ||
| this.headerProvider = builder.headerProvider; | ||
| this.endpoint = builder.endpoint; | ||
| this.allowedHardBoundTokenTypes = builder.allowedHardBoundTokenTypes; | ||
| this.mtlsProvider = builder.mtlsProvider; | ||
| this.envProvider = builder.envProvider; | ||
| this.interceptorProvider = builder.interceptorProvider; | ||
|
|
@@ -620,6 +636,7 @@ public static final class Builder { | |
| @Nullable private Boolean attemptDirectPathXds; | ||
| @Nullable private Boolean allowNonDefaultServiceAccount; | ||
| @Nullable private ImmutableMap<String, ?> directPathServiceConfig; | ||
| @Nullable private List<HardBoundTokenTypes> allowedHardBoundTokenTypes; | ||
|
|
||
| private Builder() { | ||
| processorCount = Runtime.getRuntime().availableProcessors(); | ||
|
|
@@ -700,6 +717,30 @@ public Builder setEndpoint(String endpoint) { | |
| return this; | ||
| } | ||
|
|
||
| /* | ||
| * Sets the allowed hard bound token types for this TransportChannelProvider. | ||
| * | ||
| * <p>This is optional; if it is not provided, bearer tokens will be used. | ||
| * | ||
| * <p>Examples: | ||
| * | ||
| * <p>allowedValues is {HardBoundTokenTypes.ALTS}: If DirectPath is used to create the channel, | ||
| * use hard ALTS-bound tokens for requests sent on that channel. | ||
| * | ||
| * <p>allowedValues is {HardBoundTokenTypes.MTLS_S2A}: If MTLS via S2A is used to create the | ||
| * channel, use hard MTLS-bound tokens for requests sent on that channel. | ||
| * | ||
| * <p>allowedValues is {HardBoundTokenTypes.ALTS, HardBoundTokenTypes.MTLS_S2A}: if DirectPath | ||
| * is used to create the channel, use hard ALTS-bound tokens for requests sent on that channel. | ||
| * If MTLS via S2A is used to create the channel, use hard MTLS-bound tokens for requests sent | ||
| * on that channel. | ||
|
||
| */ | ||
| @InternalApi | ||
blakeli0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public Builder setAllowHardBoundTokenTypes(List<HardBoundTokenTypes> allowedValues) { | ||
| this.allowedHardBoundTokenTypes = allowedValues; | ||
| return this; | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| Builder setMtlsProvider(MtlsProvider mtlsProvider) { | ||
| this.mtlsProvider = mtlsProvider; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to also mark this as internal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree on making this internal as well.
Thinking twice about it though, I see that it is an
Experimental feature, is it that we will always set the tokens to certain values? Or it's just this feature is not stable yet, internal teams could still set this to different values? If it's the former, then we don't have to introduce another public enum since they would be obsolete soon.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that this should be marked as
Internal Api, since this is intended to be set by client libraries. Done in 591ef68This is being marked as experimental for now, since we are in progress of adding the related logic (e.g #3548, #3572) and then piloting, as discussed in the internal doc + chat. When the feature is non-experimental, the field (
allowedHardBoundTokenTypes) will be set for all gapics to include both (MTLS_S2AandALTS), however handwritten libraries will continue to set this field (allowedHardBoundTokenTypes) themselves in their handwritten layer (e.g. GCS). Additionally, when it is non-experimental, gapics + handwritten libraries will have the option to override the default value of theallowedHardBoundTokenTypes. I think the enum helps to proves clarity on the options.