Skip to content
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

fix: adjust IAM token expiration time #268

Merged
merged 1 commit into from
Feb 28, 2024
Merged

fix: adjust IAM token expiration time #268

merged 1 commit into from
Feb 28, 2024

Conversation

padamstx
Copy link
Member

@padamstx padamstx commented Feb 27, 2024

This commit changes the IAM, Container and VPC Instance authenticators slightly so that an IAM access token will be viewed as "expired" when the current time is within 10 seconds of the official expiration time. IOW, we'll expire the access token 10 secs earlier than the IAM server-computed expiration time.
We're doing this to avoid a scenario where
an IBM Cloud service receives a request along
with an "almost expired" access token and then uses that token to perform downstream requests in a
somewhat longer-running transaction and then the
access token expires while that transaction is
still active.

Checklist
  • npm test passes (tip: npm run lint-fix can correct most style issues)
  • tests are included
  • documentation is changed or added

@padamstx padamstx self-assigned this Feb 27, 2024
@@ -229,7 +229,7 @@ export class TokenManager {
* Checks if currently-stored token should be refreshed
* i.e. past the window to request a new token
*/
private tokenNeedsRefresh(): boolean {
protected tokenNeedsRefresh(): boolean {
Copy link
Member Author

Choose a reason for hiding this comment

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

technically, I didn't need to override tokenNeedsRefresh() but it didn't seem right leaving it as the only private function :)

Copy link
Member

Choose a reason for hiding this comment

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

On looking at it, I'm of the mind that we should only expose things when necessary to prevent expanding our public maintenance burden - even if the private function is lonely 🙂 But I'm fine with this going either way.

Copy link
Member

@dpopp07 dpopp07 left a comment

Choose a reason for hiding this comment

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

Looks good but I want to check on the isTokenExpired implementation in the VPC Instance TM before approving.

@@ -229,7 +229,7 @@ export class TokenManager {
* Checks if currently-stored token should be refreshed
* i.e. past the window to request a new token
*/
private tokenNeedsRefresh(): boolean {
protected tokenNeedsRefresh(): boolean {
Copy link
Member

Choose a reason for hiding this comment

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

On looking at it, I'm of the mind that we should only expose things when necessary to prevent expanding our public maintenance burden - even if the private function is lonely 🙂 But I'm fine with this going either way.

Copy link
Member

@pyrooka pyrooka left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@dpopp07 dpopp07 left a comment

Choose a reason for hiding this comment

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

Looks good! 👍

This commit changes the IAM, Container and VPC Instance
authenticators slightly so that an IAM access token
will be viewed as "expired" when the current time is
within 10 seconds of the official expiration time.
IOW, we'll expire the access token 10 secs earlier
than the IAM server-computed expiration time.
We're doing this to avoid a scenario where
an IBM Cloud service receives a request along
with an "almost expired" access token and then uses
that token to perform downstream requests in a
somewhat longer-running transaction and then the
access token expires while that transaction is
still active.

Signed-off-by: Phil Adams <phil_adams@us.ibm.com>
@padamstx padamstx merged commit 9b975e0 into main Feb 28, 2024
4 checks passed
@padamstx padamstx deleted the issue-3862 branch February 28, 2024 17:04
ibm-devx-sdk pushed a commit that referenced this pull request Feb 28, 2024
## [4.2.4](v4.2.3...v4.2.4) (2024-02-28)

### Bug Fixes

* adjust IAM token expiration time ([#268](#268)) ([9b975e0](9b975e0))
@ibm-devx-sdk
Copy link

🎉 This PR is included in version 4.2.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

4 participants