mirror of
https://github.com/aws-actions/configure-aws-credentials.git
synced 2026-08-23 04:15:08 +09:00
fix: PackedPolicyTooLarge detection in STS tags (#1899)
Closes #1898. Due to a bundling, checking for `error instanceof PackedPolicyTooLargeException` fails. Instead we need to explicitly check for `error.name`.
This commit is contained in:
+2
-6
@@ -2,11 +2,7 @@ import assert from 'node:assert';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import type { AssumeRoleCommandInput, STSClient, Tag } from '@aws-sdk/client-sts';
|
import type { AssumeRoleCommandInput, STSClient, Tag } from '@aws-sdk/client-sts';
|
||||||
import {
|
import { AssumeRoleCommand, AssumeRoleWithWebIdentityCommand } from '@aws-sdk/client-sts';
|
||||||
AssumeRoleCommand,
|
|
||||||
AssumeRoleWithWebIdentityCommand,
|
|
||||||
PackedPolicyTooLargeException,
|
|
||||||
} from '@aws-sdk/client-sts';
|
|
||||||
import type { CredentialsClient } from './CredentialsClient';
|
import type { CredentialsClient } from './CredentialsClient';
|
||||||
import { errorMessage, isDefined, readFileUtf8, sanitizeGitHubVariables } from './helpers';
|
import { errorMessage, isDefined, readFileUtf8, sanitizeGitHubVariables } from './helpers';
|
||||||
|
|
||||||
@@ -65,7 +61,7 @@ async function assumeRoleWithCredentials(params: AssumeRoleCommandInput, client:
|
|||||||
const creds = await client.send(new AssumeRoleCommand({ ...params }));
|
const creds = await client.send(new AssumeRoleCommand({ ...params }));
|
||||||
return creds;
|
return creds;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof PackedPolicyTooLargeException) {
|
if ((error as { name?: string })?.name === 'PackedPolicyTooLargeException') {
|
||||||
core.info('Session tag size is too large; dropping droppable tags and retrying.');
|
core.info('Session tag size is too large; dropping droppable tags and retrying.');
|
||||||
const droppableKeys = new Set(DROPPABLE_TAG_SOURCES.map((s) => s.key));
|
const droppableKeys = new Set(DROPPABLE_TAG_SOURCES.map((s) => s.key));
|
||||||
params.Tags = params.Tags?.filter((tag) => !droppableKeys.has(tag.Key ?? ''));
|
params.Tags = params.Tags?.filter((tag) => !droppableKeys.has(tag.Key ?? ''));
|
||||||
|
|||||||
+5
-5
@@ -3,7 +3,6 @@ import {
|
|||||||
AssumeRoleCommand,
|
AssumeRoleCommand,
|
||||||
AssumeRoleWithWebIdentityCommand,
|
AssumeRoleWithWebIdentityCommand,
|
||||||
GetCallerIdentityCommand,
|
GetCallerIdentityCommand,
|
||||||
PackedPolicyTooLargeException,
|
|
||||||
STSClient,
|
STSClient,
|
||||||
} from '@aws-sdk/client-sts';
|
} from '@aws-sdk/client-sts';
|
||||||
import { mockClient } from 'aws-sdk-client-mock';
|
import { mockClient } from 'aws-sdk-client-mock';
|
||||||
@@ -331,10 +330,11 @@ describe('Configure AWS Credentials', {}, () => {
|
|||||||
});
|
});
|
||||||
it('drops droppable tags and retries on PackedPolicyTooLargeException', {}, async () => {
|
it('drops droppable tags and retries on PackedPolicyTooLargeException', {}, async () => {
|
||||||
vi.mocked(core.getInput).mockImplementation(mocks.getInput(mocks.IAM_ASSUMEROLE_INPUTS));
|
vi.mocked(core.getInput).mockImplementation(mocks.getInput(mocks.IAM_ASSUMEROLE_INPUTS));
|
||||||
mockedSTSClient
|
// Reject with a plain error carrying only the `name`, NOT an instance of the SDK class. This
|
||||||
.on(AssumeRoleCommand)
|
// mirrors the bundled action, where the error can be deserialized by a second, non-identical
|
||||||
.rejectsOnce(new PackedPolicyTooLargeException({ message: 'too large', $metadata: {} }))
|
// copy of PackedPolicyTooLargeException so `instanceof` fails; the recovery must key off `name`.
|
||||||
.resolvesOnce(mocks.outputs.STS_CREDENTIALS);
|
const packedPolicyError = Object.assign(new Error('too large'), { name: 'PackedPolicyTooLargeException' });
|
||||||
|
mockedSTSClient.on(AssumeRoleCommand).rejectsOnce(packedPolicyError).resolvesOnce(mocks.outputs.STS_CREDENTIALS);
|
||||||
await run();
|
await run();
|
||||||
expect(core.info).toHaveBeenCalledWith('Session tag size is too large; dropping droppable tags and retrying.');
|
expect(core.info).toHaveBeenCalledWith('Session tag size is too large; dropping droppable tags and retrying.');
|
||||||
const retryInput = mockedSTSClient.commandCalls(AssumeRoleCommand)[1].args[0].input;
|
const retryInput = mockedSTSClient.commandCalls(AssumeRoleCommand)[1].args[0].input;
|
||||||
|
|||||||
Reference in New Issue
Block a user