Skip to content

Conversation

@parameja1
Copy link
Contributor

@parameja1 parameja1 commented Sep 17, 2025

Problem

  • IAM credentials is not updating in Sagemaker instances due to incorrect comparison logic which prevents credential refresh and hence users cant interact with Q chat after the initial expiration time
image

Solution

  • Add custom comparator logic and method to properly compare credentials by their actual values (accessKeyId,
    secretAccessKey, sessionToken) instead of string comparison
  • Added 60-second expiration buffer to credential validation. similar to SSO token logic here for grace-time
  • Tested by building a debug artefact on a SMUS CodeEditor instance and verified q chat is triggering refresh credentials
  • npm run package && npm run test succeeded
  • https://drive.corp.amazon.com/documents/parameja@/PR-8070/IAM-Credentials-Refresh-Q-Chat.mov

  • Treat all work as PUBLIC. Private feature/x branches will not be squash-merged at release time.
  • Your code changes must meet the guidelines in CONTRIBUTING.md.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@parameja1 parameja1 requested a review from a team as a code owner September 17, 2025 23:33
@amazon-inspector-ohio
Copy link

⏳ I'm reviewing this pull request for security vulnerabilities and code quality issues. I'll provide an update when I'm done

@github-actions
Copy link

  • This pull request implements a feat or fix, so it must include a changelog entry (unless the fix is for an unreleased feature). Review the changelog guidelines.
    • Note: beta or "experiment" features that have active users should announce fixes in the changelog.
    • If this is not a feature or fix, use an appropriate type from the title guidelines. For example, telemetry-only changes should use the telemetry type.

@amazon-inspector-ohio
Copy link

✅ I finished the code review, and didn't find any security or code quality issues.

@ashishrp-aws
Copy link
Contributor

/retryBuilds

}

public updateIamCredentials = onceChanged(this._updateIamCredentials.bind(this))
private areCredentialsEqual(creds1: any, creds2: any): boolean {

Choose a reason for hiding this comment

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

nit: move to util as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack, let me check if it can be moved to auth related util

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in new commit


public updateIamCredentials = onceChanged(this._updateIamCredentials.bind(this))
private areCredentialsEqual(creds1: any, creds2: any): boolean {
if (!creds1 && !creds2) return true

Choose a reason for hiding this comment

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

Shouldn't this be false? We want this method to return true only if the creds are not empty and contain the same values right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, refactored logic however when credentials object is empty, we don't want updateIAM call to be invoked right?

  • the wrapper controls when to invoke update iam call alone and doesn't force creating a new credential object

Choose a reason for hiding this comment

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

Okay, makes sense

if (creds !== undefined && creds.credentialsHashCode === provider.getHashCode()) {
return creds.credentials
}
return undefined

Choose a reason for hiding this comment

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

Why do we need this change?

Copy link
Contributor Author

@parameja1 parameja1 Sep 18, 2025

Choose a reason for hiding this comment

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

By default the method returns undefined, added explicit statement, can this be nit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed

import { getLogger } from '../../shared/logger/logger'
import { asString, CredentialsProvider, CredentialsId } from '../providers/credentials'
import { CredentialsProviderManager } from '../providers/credentialsProviderManager'
// import { get } from 'lodash'

Choose a reason for hiding this comment

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

clean up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed with new commit

return expiration !== undefined ? expiration >= new globals.clock.Date() : true
const now = new globals.clock.Date()
const bufferedNow = new globals.clock.Date(now.getTime() + expirationBufferMs)
const isValid = expiration !== undefined ? expiration >= bufferedNow : true

Choose a reason for hiding this comment

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

Why are we adding 60 seconds? Not sure I follow the buffer logic. Can you explain this via inline code comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Adding buffer time as a defensive programming practice here to refresh/rotate credentials before they actually expire
  • SSO Token expiration logic also follows similar pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Already added inline comment

@laileni-aws laileni-aws enabled auto-merge (squash) September 18, 2025 18:21
@laileni-aws
Copy link
Contributor

/retryBuilds

auto-merge was automatically disabled September 18, 2025 18:22

Pull request was closed

@laileni-aws laileni-aws reopened this Sep 18, 2025
@amazon-inspector-ohio
Copy link

⏳ I'm reviewing this pull request for security vulnerabilities and code quality issues. I'll provide an update when I'm done

@amazon-inspector-ohio
Copy link

✅ I finished the code review, and didn't find any security or code quality issues.

@rli rli enabled auto-merge (squash) September 18, 2025 19:39
@rli rli merged commit 42e38c6 into aws:master Sep 18, 2025
30 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants