-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[xDS] A97 - JWT token file call creds #12242
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
Open
Zgoda91
wants to merge
15
commits into
grpc:master
Choose a base branch
from
Zgoda91:A97_jwt_token_call_creds
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6b79ff2
JWT token file call creds
Zgoda91 f7fe53a
Moving JwtToken related classes to xds package
Zgoda91 494439c
Fixing bazel build issues
Zgoda91 f3d5108
Fixing typo in documentation
Zgoda91 13881d8
Removing separate CallCredentials from ServerInfo
Zgoda91 b61de62
Default implementation for `newCallCredentials`
Zgoda91 fb3805a
Removed redundant method
Zgoda91 bdcfc0a
Reverted change from transport factory
Zgoda91 dd1de65
Improved JWT Token utils lib
Zgoda91 76e9e8f
Moved JWT call credentials to internal package
Zgoda91 3a36865
Removed hardcoded class list for Android
Zgoda91 743c248
Improved `JwtTokenFileXdsCredentialsProvider`
Zgoda91 20a50c8
Inverted condition statements for readability
Zgoda91 b7c4e55
Added new provider and registry classes
Zgoda91 ae8d9e3
Activated new registry class in bootstrapping code
Zgoda91 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
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
66 changes: 66 additions & 0 deletions
66
xds/src/main/java/io/grpc/xds/internal/JwtTokenFileCallCredentials.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,66 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
| import com.google.api.client.json.gson.GsonFactory; | ||
| import com.google.api.client.json.webtoken.JsonWebSignature; | ||
| import com.google.auth.oauth2.AccessToken; | ||
| import com.google.auth.oauth2.OAuth2Credentials; | ||
| import com.google.common.io.Files; | ||
| import io.grpc.CallCredentials; | ||
| import io.grpc.auth.MoreCallCredentials; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Date; | ||
|
|
||
| /** | ||
| * JWT token file call credentials. | ||
| * See gRFC A97 (https://github.com/grpc/proposal/pull/492). | ||
| */ | ||
| public final class JwtTokenFileCallCredentials extends OAuth2Credentials { | ||
| private static final long serialVersionUID = 0L; | ||
| private final String path; | ||
|
|
||
| private JwtTokenFileCallCredentials(String path) { | ||
| this.path = checkNotNull(path, "path"); | ||
| } | ||
|
|
||
| @Override | ||
| public AccessToken refreshAccessToken() throws IOException { | ||
| String tokenString = new String(Files.toByteArray(new File(path)), StandardCharsets.UTF_8); | ||
| Long expTime = JsonWebSignature.parse(new GsonFactory(), tokenString) | ||
| .getPayload() | ||
| .getExpirationTimeSeconds(); | ||
| if (expTime == null) { | ||
| throw new IOException("No expiration time found for JWT token"); | ||
| } | ||
|
|
||
| return AccessToken.newBuilder() | ||
| .setTokenValue(tokenString) | ||
| .setExpirationTime(new Date(expTime * 1000L)) | ||
| .build(); | ||
| } | ||
|
|
||
| // using {@link MoreCallCredentials} adapter to be compatible with {@link CallCredentials} iface | ||
| public static CallCredentials create(String path) { | ||
| JwtTokenFileCallCredentials jwtTokenFileCallCredentials = new JwtTokenFileCallCredentials(path); | ||
| return MoreCallCredentials.from(jwtTokenFileCallCredentials); | ||
| } | ||
| } |
68 changes: 68 additions & 0 deletions
68
xds/src/main/java/io/grpc/xds/internal/JwtTokenFileXdsCredentialsProvider.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; | ||
|
|
||
| import io.grpc.CallCredentials; | ||
| import io.grpc.ChannelCredentials; | ||
| import io.grpc.internal.JsonUtil; | ||
| import io.grpc.xds.XdsCredentialsProvider; | ||
| import io.grpc.xds.internal.JwtTokenFileCallCredentials; | ||
Zgoda91 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import java.io.File; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * A wrapper class that supports {@link JwtTokenFileXdsCredentialsProvider} for | ||
| * Xds by implementing {@link XdsCredentialsProvider}. | ||
| */ | ||
| public final class JwtTokenFileXdsCredentialsProvider extends XdsCredentialsProvider { | ||
| private static final String CREDS_NAME = "jwt_token_file"; | ||
|
|
||
| @Override | ||
| protected ChannelCredentials newChannelCredentials(Map<String, ?> jsonConfig) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| protected CallCredentials newCallCredentials(Map<String, ?> jsonConfig) { | ||
| if (jsonConfig == null) { | ||
| return null; | ||
| } | ||
|
|
||
| String jwtTokenPath = JsonUtil.getString(jsonConfig, getName()); | ||
| if (jwtTokenPath == null || !new File(jwtTokenPath).isFile()) { | ||
Zgoda91 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Zgoda91 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return null; | ||
| } | ||
|
|
||
| return JwtTokenFileCallCredentials.create(jwtTokenPath); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getName() { | ||
| return CREDS_NAME; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isAvailable() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public int priority() { | ||
| return 5; | ||
| } | ||
|
|
||
| } | ||
1 change: 1 addition & 0 deletions
1
xds/src/main/resources/META-INF/services/io.grpc.xds.XdsCredentialsProvider
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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| io.grpc.xds.internal.GoogleDefaultXdsCredentialsProvider | ||
| io.grpc.xds.internal.InsecureXdsCredentialsProvider | ||
| io.grpc.xds.internal.JwtTokenFileXdsCredentialsProvider | ||
| io.grpc.xds.internal.TlsXdsCredentialsProvider |
Oops, something went wrong.
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.