Panic in ExportAccessTokenToCache when assuming a role-chained profile (role_arn + source_profile) #969
Replies: 1 comment
|
Two separate defects stacked here, and it is worth separating them because only one of them is the crash. The segfault is a missing nil check. return &SSOPlainTextOut{
AccessToken: token.AccessToken,
ExpiresAt: token.Expiry.Format(time.RFC3339),
Region: ssoRegion,
SSOSessionName: awsConfig.SSOSessionName,
StartUrl: ssoStartURL,
}
Why it is nil in your case is the real bug, and it is upstream in tokenKey := profile.SSOStartURL() + profile.AWSConfig.SSOSessionName
cachedToken := secureSSOTokenStorage.GetValidSSOToken(ctx, tokenKey)The key is built from the profile being assumed. With There is a nice irony a few lines down. ssoRegion := awsConfig.SSORegion
if ssoRegion == "" && awsConfig.SSOSession != nil {
ssoRegion = awsConfig.SSOSession.SSORegion
}
ssoStartURL := awsConfig.SSOStartURL
if ssoStartURL == "" && awsConfig.SSOSession != nil {
ssoStartURL = awsConfig.SSOSession.SSOStartURL
}So the function already anticipates the values not sitting where you first look — just not for the token key that decides whether there is a token at all. Worth asking for both in the issue, since fixing only the nil check turns a panic into a silent no-export and leaves role chaining without the cache entry you enabled the setting for. The traversal is the fix; the guard is what stops the next unforeseen empty-key case being a crash. Related, in case it is useful context for whoever picks this up: the same helper's profile-shaped signature is why |
Uh oh!
There was an error while loading. Please reload this page.
Summary
assumepanics with a nil pointer dereference inExportAccessTokenToCachewhen:ExportSSOToken = trueis set in~/.granted/configrole_arn+source_profile(role chaining)The assume itself succeeds (credentials are valid), but the post-assume SSO token export crashes because it looks at the assumed profile for SSO session info rather than traversing the
source_profilechain.Stack trace
Reproduction
~/.granted/config~/.aws/configSteps
granted sso login(authenticate successfully)assume my-org-target-accountExportAccessTokenToCacheExpected behavior
ExportAccessTokenToCacheshould traverse thesource_profilechain to find the SSO session and export the token, or gracefully skip the export when no SSO session is resolvable on the assumed profile.Actual behavior
The function looks at the assumed profile directly, finds no SSO session info (all
{0x0, 0x0}nil fields in the SSO token struct), and dereferences a nil pointer atssotoken.go:42.Related
--export-sso-token#571 (similar crash path, fixed for profiles withsso_sessionset but nosso_start_urlon the profile itself)granted_sso_*fields are missing)Environment
Workaround
Set
ExportSSOToken = falsein~/.granted/config. This prevents the crash but disables the SSO token cache export feature entirely.All reactions