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:
Tom Keller
2026-07-22 11:25:24 -07:00
committed by GitHub
parent 42e118a656
commit fa8d6a57bb
2 changed files with 7 additions and 11 deletions
+2 -6
View File
@@ -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
View File
@@ -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;