Skip to content

Error handling in periodic credential update #989

Open
@ynishinaka

Description

The fromWebIdentity passes to fetchAuthInBackground the action that performs the AssumeRoleWithWebIdentity [1]. AssumeRoleWithWebIdentity may throw ServiceError (as exception Amazonka.Types.Error), not just HTTPException. However, fetchAuthInBackground catches and throws only HTTPException to the original thread by throwTo, leaving other exceptions to the default handler [2]. Thus, if a ServiceError is thrown, the temporary credential update will be interrupted without the original thread being aware of it.

So, I believe that fetchAuthInBackground should either re-throw other exceptions raised by the action to the original thread or have some error recovery method.


[1]

let getCredentials = do
token <- Text.readFile tokenFile
let assumeRoleWithWebIdentity =
STS.newAssumeRoleWithWebIdentity
roleArn
sessionName
token
resp <- runResourceT $ sendUnsigned env assumeRoleWithWebIdentity
pure $ resp ^. STS.assumeRoleWithWebIdentityResponse_credentials
-- As the credentials from STS are temporary, we start a thread that is able
-- to fetch new ones automatically on expiry.
keys <- liftIO $ fetchAuthInBackground getCredentials

[2] Because the RetrievalError constructor accepts an argument of type HTTPException, e must be of the same type:

env <- Exception.try ma
case env of
Left e -> Exception.throwTo p (RetrievalError e)

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions