MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / assumeRole

Function assumeRole

packages/components/src/awsToolsUtils.ts:141–203  ·  view source on GitHub ↗

* Assume an IAM role using AWS STS and return temporary session credentials. * * This is an internal helper called by getAWSCredentialConfig when a `roleArn` * is present. It creates an STS client with the provided base credentials (or the SDK * default credential chain if none are suppl

(params: {
    accessKeyId?: string
    secretAccessKey?: string
    sessionToken?: string
    roleArn: string
    externalId?: string
    region: string
    logger?: any
})

Source from the content-addressed store, hash-verified

139 * @throws {Error} When the STS API call fails — The full error is logged server-side.
140 */
141async function assumeRole(params: {
142 accessKeyId?: string
143 secretAccessKey?: string
144 sessionToken?: string
145 roleArn: string
146 externalId?: string
147 region: string
148 logger?: any
149}): Promise<AWSCredentials> {
150 const { accessKeyId, secretAccessKey, sessionToken, roleArn, externalId, region, logger } = params
151
152 // Build STS client config
153 const stsConfig: STSClientConfig = { region }
154
155 // Use explicit credentials if provided; otherwise SDK default chain
156 if (accessKeyId && secretAccessKey) {
157 stsConfig.credentials = {
158 accessKeyId,
159 secretAccessKey,
160 ...(sessionToken && { sessionToken })
161 }
162 }
163
164 const stsClient = new STSClient(stsConfig)
165
166 const assumeRoleInput: AssumeRoleCommandInput = {
167 RoleArn: roleArn,
168 RoleSessionName: `FlowiseSession-${Date.now()}`
169 }
170
171 if (externalId) {
172 assumeRoleInput.ExternalId = externalId
173 }
174
175 try {
176 const response = await stsClient.send(new AssumeRoleCommand(assumeRoleInput))
177
178 if (!response.Credentials?.AccessKeyId || !response.Credentials?.SecretAccessKey || !response.Credentials?.SessionToken) {
179 throw new Error('STS AssumeRole returned incomplete credentials')
180 }
181
182 return {
183 accessKeyId: response.Credentials.AccessKeyId,
184 secretAccessKey: response.Credentials.SecretAccessKey,
185 sessionToken: response.Credentials.SessionToken
186 }
187 } catch (error) {
188 if (error instanceof Error && error.message === 'STS AssumeRole returned incomplete credentials') {
189 throw error
190 }
191 const rawMessage = error instanceof Error ? error.message : String(error)
192 // Log full error server-side for operator debugging (includes IAM principal ARNs, account IDs, etc.)
193 if (logger) {
194 logger.error(`[AWS STS] AssumeRole failed for role "${roleArn}": ${rawMessage}`)
195 }
196 // Return sanitized error to user — no raw STS message that may contain internal infrastructure details
197 throw new Error(
198 'Failed to assume IAM role. ' +

Callers 1

getAWSCredentialConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected