feat: Implement refreshCredentialsIfRequired for intermediate token r…#1583
Merged
nbayati merged 19 commits intogoogleapis:client-side-cabfrom Jan 2, 2025
Merged
feat: Implement refreshCredentialsIfRequired for intermediate token r…#1583nbayati merged 19 commits intogoogleapis:client-side-cabfrom
nbayati merged 19 commits intogoogleapis:client-side-cabfrom
Conversation
…efresh Implement `refreshCredentialsIfRequired`, called by `generateToken()`, to handle token refresh. It uses `refreshMargin` and `minimumTokenLifetime` to decide on synchronous or asynchronous refresh
|
lqiu96
reviewed
Nov 25, 2024
...java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java
Outdated
Show resolved
Hide resolved
lqiu96
reviewed
Nov 25, 2024
...java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java
Outdated
Show resolved
Hide resolved
lqiu96
reviewed
Nov 25, 2024
...java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java
Outdated
Show resolved
Hide resolved
lqiu96
reviewed
Nov 25, 2024
...java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java
Outdated
Show resolved
Hide resolved
lqiu96
reviewed
Nov 25, 2024
...java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java
Show resolved
Hide resolved
lqiu96
reviewed
Nov 25, 2024
...java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java
Outdated
Show resolved
Hide resolved
Introduced a refresh task to manage concurrent refresh requests, preventing redundant attempts and potential race conditions. This aligns the refresh mechanism with the pattern used in OAuth2Credentials and ensures more robust credential management.
lqiu96
reviewed
Dec 10, 2024
...java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java
Outdated
Show resolved
Hide resolved
lqiu96
reviewed
Dec 10, 2024
.../com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactoryTest.java
Outdated
Show resolved
Hide resolved
lqiu96
reviewed
Dec 11, 2024
...java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java
Show resolved
Hide resolved
lqiu96
reviewed
Dec 11, 2024
...java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java
Show resolved
Hide resolved
lqiu96
reviewed
Dec 11, 2024
...java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java
Outdated
Show resolved
Hide resolved
lqiu96
approved these changes
Dec 11, 2024
Member
lqiu96
left a comment
There was a problem hiding this comment.
LGTM, thanks! Added a few smaller comments but the overall flow is similar to Oauth2Credentials
4 tasks
aeitzman
approved these changes
Dec 12, 2024
.../com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactoryTest.java
Outdated
Show resolved
Hide resolved
...java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java
Outdated
Show resolved
Hide resolved
...java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java
Outdated
Show resolved
Hide resolved
...java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java
Outdated
Show resolved
Hide resolved
...java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java
Outdated
Show resolved
Hide resolved
...java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java
Outdated
Show resolved
Hide resolved
...java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java
Outdated
Show resolved
Hide resolved
lqiu96
reviewed
Dec 20, 2024
.../com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactoryTest.java
Show resolved
Hide resolved
lqiu96
reviewed
Dec 20, 2024
.../com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactoryTest.java
Outdated
Show resolved
Hide resolved
lqiu96
reviewed
Dec 20, 2024
.../com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactoryTest.java
Outdated
Show resolved
Hide resolved
lqiu96
reviewed
Dec 20, 2024
.../com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactoryTest.java
Show resolved
Hide resolved
lqiu96
reviewed
Dec 20, 2024
Comment on lines
296
to
298
| // After the delay, the request count should be 2, indicating that the async refresh has made | ||
| // a single request to the STS endpoint. | ||
| assertEquals(2, mockStsTransportFactory.transport.getRequestCount()); |
Member
There was a problem hiding this comment.
qq, why is this 2 and not 4 as similar to BLOCKING?
Member
There was a problem hiding this comment.
Oh wait, is it because we wait for the first async thread to finish? If so, can we add a comment that explain that
Contributor
Author
There was a problem hiding this comment.
Correct. The async calls will re-use the same refreshTask, so only 1 additional call to the STS is made. I've updated the comment to explain that.
lqiu96
reviewed
Dec 20, 2024
.../com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactoryTest.java
Outdated
Show resolved
Hide resolved
This reverts commit 2157fdb.
lqiu96
reviewed
Dec 27, 2024
.../com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactoryTest.java
Outdated
Show resolved
Hide resolved
lqiu96
reviewed
Dec 27, 2024
.../com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactoryTest.java
Outdated
Show resolved
Hide resolved
lqiu96
reviewed
Dec 27, 2024
.../com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactoryTest.java
Outdated
Show resolved
Hide resolved
lqiu96
reviewed
Dec 27, 2024
.../com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactoryTest.java
Show resolved
Hide resolved
lqiu96
reviewed
Dec 27, 2024
aeitzman
approved these changes
Jan 2, 2025
lqiu96
pushed a commit
that referenced
this pull request
Feb 4, 2025
…ality (#1629) * feat: Implement ClientSideCredentialAccessBoundaryFactory (#1562) * feat: Implement ClientSideCredentialAccessBoundaryFactory.refreshCredentials() Set up the ClientSideCredentialAccessBoundaryFactory class and module. Implement the function to fetch and refresh intermediary tokens from STS. * feat: Add the generated ClientSideAccessBoundaryProto class for Client-Side CAB feature. (#1571) Change-Id: Ic7ef3cbd80b2ad778d61b9ccabf780561d3cc709 * feat: Implement refreshCredentialsIfRequired for intermediate token r… (#1583) * feat: Implement refreshCredentialsIfRequired for intermediate token refresh Implement `refreshCredentialsIfRequired`, called by `generateToken()`, to handle token refresh. It uses `refreshMargin` and `minimumTokenLifetime` to decide on synchronous or asynchronous refresh * Add unit tests for the builder and refreshCredentials() * Improve concurrency handling during credential refresh. Introduced a refresh task to manage concurrent refresh requests, preventing redundant attempts and potential race conditions. This aligns the refresh mechanism with the pattern used in OAuth2Credentials and ensures more robust credential management. * Update existing unit tests for compatibility and readability. * Add unit tests for refreshCredentialsIfRequired. * Fix a merge issue. * Temporary add sonatype-snapshots repository and cel version to fix the build error. * Remove duplicated code. * Fix lint issue. * Fix: Propagate credential refresh exceptions in blocking refresh. * Change cel version * Change cel version * Add jsr305 dependency * Fix Javadoc error * Minor code readability enhancements. * Revert "Fix Javadoc error" This reverts commit 2157fdb. * Address comments (add javadoc and use assertThrows in tests) * Run format script * feat: Implement Client-Side CAB token generation. (#1598) * feat: Implement Client-Side CAB token generation. Change-Id: I2c217656584cf5805297f02340cbbabca471f609 * Use IllegalStateException(String, Throwable) to capture upstream exception during Tink initialization Change-Id: I12af5b84eae4dcec5865adfdad1f9396d54c0200 * Rethrow exceptions from tink and CEL Change-Id: If8c94c786ee39201029d9c27856fd2eafb61e51c * Add tests for invalid keys from upstream, and rename test cases. Change-Id: Ib41cb81c779534fc6efd74d66bf4728efd743906 * Add additional throws comment for generatToken method. Change-Id: I9cfc589ade8a91040fc9c447740493fd49e392af * Refactor tests for better readability. Change-Id: Icfd0bc24c1694f220bcbffc6cde41462c59119c4 * Catch and rethrow the exception of session key not being base64 encoded. Change-Id: I5fa0c25fe020e9612735e4ac5df2b85a2a5aab11 * Format the code using mvn com.coveo:fmt-maven-plugin:format. Change-Id: I46572488dcd28de450a6b1b2f732bee5baa86910 * Fix a typo in the javadoc comment. Change-Id: Icef9ef5f7c3567224ec507303543b78e61f43ec1 * chore: Update version tag in cab-token-generator pom.xml This commit updates the version tag in the pom.xml file. * feat: Add integration test for the client side cab * Remove volatile keyword and use refreshLock when reading intermediateCredentials. * Define new default values for refreshMargin and minimumTokenLifetime. * Update version in pom.xml * Run formatter to resolve lint errors * add missing dependency * Swap the assertEquals parameters so the expected value is first. * Docs: Added javadocs Improvements: Cleaned up code, resolved readability enhancements --------- Co-authored-by: Jiahua Huang <jh@jiahuah.com> Co-authored-by: aeitzman <12433791+aeitzman@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


This PR implements
refreshCredentialsIfRequiredwhich will be called by generateToken(). The refresh logic was implemented based on the design doc, which takes into account therefreshMarginandminimumTokenLifetime, and decides on either async or synchronous refresh if one is needed.Notes: