diff --git a/.changeset/mighty-bikes-divide.md b/.changeset/mighty-bikes-divide.md new file mode 100644 index 0000000..3573c81 --- /dev/null +++ b/.changeset/mighty-bikes-divide.md @@ -0,0 +1,5 @@ +--- +'@open-iga/aws': patch +--- + +Adjust account id in handler schema diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 74ca3c5..e74516f 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -7,6 +7,10 @@ on: permissions: contents: read +concurrency: + group: pr-${{ github.event.pull_request.number }} + cancel-in-progress: true + jobs: ci: runs-on: ubuntu-latest @@ -40,6 +44,7 @@ jobs: run: bunx turbo run typecheck "//#lint" test compile changeset-check: + needs: ci runs-on: ubuntu-latest # Version PRs (changeset-release/*) and dependency bots don't carry changesets if: ${{ !startsWith(github.head_ref, 'changeset-release/') }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 78e8f6e..c86d695 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,6 +8,10 @@ permissions: contents: write pull-requests: write +concurrency: + group: release + cancel-in-progress: false + jobs: release: runs-on: ubuntu-latest diff --git a/connectors/aws/e2e/account-acctions.create.test.ts b/connectors/aws/e2e/account-acctions.create.test.ts index 1bb2715..15e01cf 100644 --- a/connectors/aws/e2e/account-acctions.create.test.ts +++ b/connectors/aws/e2e/account-acctions.create.test.ts @@ -35,8 +35,8 @@ describe('account-actions.create', () => { expect(result.ok).toBe(true); if (result.ok) { - expect(typeof result.output.id).toBe('string'); - expect(result.output.id.length).toBeGreaterThan(0); + expect(typeof result.output.accountId).toBe('string'); + expect(result.output.accountId.length).toBeGreaterThan(0); } // The connector must deliver credentials via the Host email capability. @@ -75,7 +75,7 @@ describe('account-actions.create', () => { expect(second.ok).toBe(true); if (second.ok) { - expect(second.output).toEqual({ id: first.output.id, created: false }); + expect(second.output).toEqual({ accountId: first.output.accountId, created: false }); } // No new password is sent for an existing user expect(host.hostFunctions.sentEmails.length).toBe(emailsBefore); @@ -91,7 +91,7 @@ describe('account-actions.create', () => { }); expect(created.ok).toBe(true); if (!created.ok) return; - await host.callAccountActions('iam-user', 'disable', { tenant, id: created.output.id }); + await host.callAccountActions('iam-user', 'disable', { tenant, accountId: created.output.accountId }); const again = await host.callAccountActions('iam-user', 'create', { tenant, diff --git a/connectors/aws/e2e/account-actions.lifecycle.test.ts b/connectors/aws/e2e/account-actions.lifecycle.test.ts index a663b89..bc4499e 100644 --- a/connectors/aws/e2e/account-actions.lifecycle.test.ts +++ b/connectors/aws/e2e/account-actions.lifecycle.test.ts @@ -52,40 +52,40 @@ describe('account-actions.lifecycle', () => { }); expect(created.ok).toBe(true); if (!created.ok) return; - const id = created.output.id; + const { accountId } = created.output; expect(await hasLoginProfile(userName)).toBe(true); // Read — exists and enabled. - const afterCreate = await host.callAccountActions('iam-user', 'read', { tenant, id }); + const afterCreate = await host.callAccountActions('iam-user', 'read', { tenant, accountId }); expect(afterCreate.ok).toBe(true); if (afterCreate.ok) expect(afterCreate.output).toEqual({ exists: true, enabled: true }); // Disable — console access revoked. - const disabled = await host.callAccountActions('iam-user', 'disable', { tenant, id }); + const disabled = await host.callAccountActions('iam-user', 'disable', { tenant, accountId }); expect(disabled.ok).toBe(true); if (disabled.ok) expect(disabled.output.disabled).toBe(true); expect(await hasLoginProfile(userName)).toBe(false); // Read — still exists, now disabled. - const afterDisable = await host.callAccountActions('iam-user', 'read', { tenant, id }); + const afterDisable = await host.callAccountActions('iam-user', 'read', { tenant, accountId }); expect(afterDisable.ok).toBe(true); if (afterDisable.ok) expect(afterDisable.output).toEqual({ exists: true, enabled: false }); // Enable — console access restored and credentials re-sent via the email capability. - const enabled = await host.callAccountActions('iam-user', 'enable', { tenant, id }); + const enabled = await host.callAccountActions('iam-user', 'enable', { tenant, accountId }); expect(enabled.ok).toBe(true); if (enabled.ok) expect(enabled.output.enabled).toBe(true); expect(await hasLoginProfile(userName)).toBe(true); expect(host.hostFunctions.sentEmails.at(-1)?.subject).toBe('Your AWS access has been re-enabled'); // Delete — user removed entirely. - const deleted = await host.callAccountActions('iam-user', 'delete', { tenant, id }); + const deleted = await host.callAccountActions('iam-user', 'delete', { tenant, accountId }); expect(deleted.ok).toBe(true); if (deleted.ok) expect(deleted.output.deleted).toBe(true); expect(await hasLoginProfile(userName)).toBe(false); // Read — no longer exists. - const afterDelete = await host.callAccountActions('iam-user', 'read', { tenant, id }); + const afterDelete = await host.callAccountActions('iam-user', 'read', { tenant, accountId }); expect(afterDelete.ok).toBe(true); if (afterDelete.ok) expect(afterDelete.output).toEqual({ exists: false, enabled: false }); }); diff --git a/connectors/aws/e2e/entitlements.test.ts b/connectors/aws/e2e/entitlements.test.ts index 6ba1fab..793516d 100644 --- a/connectors/aws/e2e/entitlements.test.ts +++ b/connectors/aws/e2e/entitlements.test.ts @@ -63,7 +63,7 @@ describe('entitlements', () => { }); expect(created.ok).toBe(true); if (!created.ok) return; - const userArn = created.output.id; + const userArn = created.output.accountId; // Discover to get a real group ARN to grant. const discovered = await host.callEntitlements('iam-user-group', 'discover', { tenant }); @@ -74,28 +74,28 @@ describe('entitlements', () => { // Grant — the user is added to the group. const granted = await host.callEntitlements('iam-user-group', 'grant', { tenant, - id: userArn, + accountId: userArn, entitlementId: groupArn, }); expect(granted.ok).toBe(true); if (granted.ok) expect(granted.output.granted).toBe(true); // Read (drift detection) — the group ARN is reported back. - const readGranted = await host.callEntitlements('iam-user-group', 'read', { tenant, id: userArn }); + const readGranted = await host.callEntitlements('iam-user-group', 'read', { tenant, accountId: userArn }); expect(readGranted.ok).toBe(true); if (readGranted.ok) expect(readGranted.output.entitlementIds).toContain(groupArn); // Revoke — the user is removed from the group. const revoked = await host.callEntitlements('iam-user-group', 'revoke', { tenant, - id: userArn, + accountId: userArn, entitlementId: groupArn, }); expect(revoked.ok).toBe(true); if (revoked.ok) expect(revoked.output.revoked).toBe(true); // Read after revoke — no longer reported. - const readRevoked = await host.callEntitlements('iam-user-group', 'read', { tenant, id: userArn }); + const readRevoked = await host.callEntitlements('iam-user-group', 'read', { tenant, accountId: userArn }); expect(readRevoked.ok).toBe(true); if (readRevoked.ok) expect(readRevoked.output.entitlementIds).not.toContain(groupArn); }); diff --git a/connectors/aws/src/account-actions/create.ts b/connectors/aws/src/account-actions/create.ts index 0f41778..6075265 100644 --- a/connectors/aws/src/account-actions/create.ts +++ b/connectors/aws/src/account-actions/create.ts @@ -65,7 +65,7 @@ export const registerAccountActionCreation = (plugin: typeof awsConnector) => { if (!(await hasLoginProfile({ endpoint: IAM_ENDPOINT, credentials: assumed, userName }))) { throw new Error(`IAM user "${userName}" exists without console access; enable or delete it first`); } - return { id: existing.arn, created: false }; + return { accountId: existing.arn, created: false }; } // To grant the console access to user with a one-time password that must be changed after the first login @@ -95,7 +95,7 @@ export const registerAccountActionCreation = (plugin: typeof awsConnector) => { }); return { - id: created.arn, + accountId: created.arn, created: true, }; }, diff --git a/connectors/aws/src/account-actions/delete.ts b/connectors/aws/src/account-actions/delete.ts index 66a67cc..ccb9f3c 100644 --- a/connectors/aws/src/account-actions/delete.ts +++ b/connectors/aws/src/account-actions/delete.ts @@ -27,7 +27,7 @@ export const registerAccountActionDelete = (plugin: typeof awsConnector) => { roleSessionName: 'openiga-aws-iam-user-delete', }); - const userName = userNameFromArn(input.id); + const userName = userNameFromArn(input.accountId); // DeleteUser fails if a login profile still exists — remove it first (best-effort). try { diff --git a/connectors/aws/src/account-actions/disable.ts b/connectors/aws/src/account-actions/disable.ts index 8a117f7..4e1577d 100644 --- a/connectors/aws/src/account-actions/disable.ts +++ b/connectors/aws/src/account-actions/disable.ts @@ -26,7 +26,7 @@ export const registerAccountActionDisable = (plugin: typeof awsConnector) => { roleSessionName: 'openiga-aws-iam-user-disable', }); - const userName = userNameFromArn(input.id); + const userName = userNameFromArn(input.accountId); try { await deleteLoginProfile({ endpoint: IAM_ENDPOINT, credentials: assumed, userName }); diff --git a/connectors/aws/src/account-actions/enable.ts b/connectors/aws/src/account-actions/enable.ts index 854eb71..3c5aed9 100644 --- a/connectors/aws/src/account-actions/enable.ts +++ b/connectors/aws/src/account-actions/enable.ts @@ -28,7 +28,7 @@ export const registerAccountActionEnable = (plugin: typeof awsConnector) => { roleSessionName: 'openiga-aws-iam-user-enable', }); - const userName = userNameFromArn(input.id); + const userName = userNameFromArn(input.accountId); // Restore console access with a fresh one-time password the user must change at login. const temporaryPassword = generateTemporaryPassword(); @@ -39,7 +39,7 @@ export const registerAccountActionEnable = (plugin: typeof awsConnector) => { password: temporaryPassword, }); - const loginUrl = `https://${accountIdFromArn(input.id)}.signin.aws.amazon.com/console`; + const loginUrl = `https://${accountIdFromArn(input.accountId)}.signin.aws.amazon.com/console`; sendEmail({ subject: 'Your AWS access has been re-enabled', body: [ diff --git a/connectors/aws/src/account-actions/read.ts b/connectors/aws/src/account-actions/read.ts index 14abbf1..4eefb07 100644 --- a/connectors/aws/src/account-actions/read.ts +++ b/connectors/aws/src/account-actions/read.ts @@ -27,7 +27,7 @@ export const registerAccountActionRead = (plugin: typeof awsConnector) => { roleSessionName: 'openiga-aws-iam-user-read', }); - const userName = userNameFromArn(input.id); + const userName = userNameFromArn(input.accountId); const exists = await userExists({ endpoint: IAM_ENDPOINT, credentials: assumed, userName }); if (!exists) { diff --git a/connectors/aws/src/entitlements/iam-user-groups/grant.ts b/connectors/aws/src/entitlements/iam-user-groups/grant.ts index 28797d1..9d14f6e 100644 --- a/connectors/aws/src/entitlements/iam-user-groups/grant.ts +++ b/connectors/aws/src/entitlements/iam-user-groups/grant.ts @@ -29,7 +29,7 @@ export const registerEntitlementGrant = (plugin: typeof awsConnector) => { await addUserToGroup({ endpoint: IAM_ENDPOINT, credentials: assumed, - userName: userNameFromArn(input.id), + userName: userNameFromArn(input.accountId), groupName: nameFromArn(input.entitlementId), }); diff --git a/connectors/aws/src/entitlements/iam-user-groups/read.ts b/connectors/aws/src/entitlements/iam-user-groups/read.ts index c8913cd..069b8d3 100644 --- a/connectors/aws/src/entitlements/iam-user-groups/read.ts +++ b/connectors/aws/src/entitlements/iam-user-groups/read.ts @@ -29,7 +29,7 @@ export const registerEntitlementRead = (plugin: typeof awsConnector) => { const groups = await listGroupsAssignedToUser({ endpoint: IAM_ENDPOINT, credentials: assumed, - userName: userNameFromArn(input.id), + userName: userNameFromArn(input.accountId), }); return { entitlementIds: groups.map((group) => group.arn) }; diff --git a/connectors/aws/src/entitlements/iam-user-groups/revoke.ts b/connectors/aws/src/entitlements/iam-user-groups/revoke.ts index eb0c6f1..2be6edd 100644 --- a/connectors/aws/src/entitlements/iam-user-groups/revoke.ts +++ b/connectors/aws/src/entitlements/iam-user-groups/revoke.ts @@ -30,7 +30,7 @@ export const registerEntitlementRevoke = (plugin: typeof awsConnector) => { await removeUserFromGroup({ endpoint: IAM_ENDPOINT, credentials: assumed, - userName: userNameFromArn(input.id), + userName: userNameFromArn(input.accountId), groupName: nameFromArn(input.entitlementId), }); } catch (error) { diff --git a/connectors/aws/src/utils/arn.ts b/connectors/aws/src/utils/arn.ts index a2b4f8b..ba83aea 100644 --- a/connectors/aws/src/utils/arn.ts +++ b/connectors/aws/src/utils/arn.ts @@ -1,5 +1,5 @@ // IAM ARN shape: arn:aws:iam:::user/ -// The account actions receive the ARN as the stable `id`, so both the account id and the username are derived from it. +// The account actions receive the ARN as the stable `accountId`, so both the account id and the username are derived from it. export const accountIdFromArn = (arn: string): string => arn.split(':')[4] ?? ''; export const userNameFromArn = (arn: string): string => arn.split('/').pop() ?? ''; diff --git a/packages/connector-sdk/lib/iga/connector/validation-schema/connector.account-action-handler.schema.ts b/packages/connector-sdk/lib/iga/connector/validation-schema/connector.account-action-handler.schema.ts index 93fdfa5..0f7fa0e 100644 --- a/packages/connector-sdk/lib/iga/connector/validation-schema/connector.account-action-handler.schema.ts +++ b/packages/connector-sdk/lib/iga/connector/validation-schema/connector.account-action-handler.schema.ts @@ -18,7 +18,7 @@ const creationHandlerSchema = { metadata: metadataSchema, }), output: z.object({ - id: z.string(), + accountId: z.string(), // false when an existing account was returned created: z.boolean(), metadata: metadataSchema, @@ -28,7 +28,7 @@ const creationHandlerSchema = { const enableHandlerSchema = { input: z.object({ tenant: tenantSchema, - id: z.string(), + accountId: z.string(), }), output: z.object({ enabled: z.boolean(), @@ -38,7 +38,7 @@ const enableHandlerSchema = { const disableHandlerSchema = { input: z.object({ tenant: tenantSchema, - id: z.string(), + accountId: z.string(), }), output: z.object({ disabled: z.boolean(), @@ -48,7 +48,7 @@ const disableHandlerSchema = { const deleteHandlerSchema = { input: z.object({ tenant: tenantSchema, - id: z.string(), + accountId: z.string(), }), output: z.object({ deleted: z.boolean(), @@ -58,7 +58,7 @@ const deleteHandlerSchema = { const readHandlerSchema = { input: z.object({ tenant: tenantSchema, - id: z.string(), + accountId: z.string(), }), // Read is an account-drift primitive: it reports whether the account still exists and // whether it is enabled, rather than echoing profile attributes. @@ -77,7 +77,7 @@ const listHandlerSchema = { output: z.object({ accounts: z.array( z.object({ - id: z.string(), + accountId: z.string(), email: z.string(), enabled: z.boolean(), firstname: z.optional(z.string()), diff --git a/packages/connector-sdk/lib/iga/connector/validation-schema/connector.entitlement-handler.schema.ts b/packages/connector-sdk/lib/iga/connector/validation-schema/connector.entitlement-handler.schema.ts index c51c840..8440b8f 100644 --- a/packages/connector-sdk/lib/iga/connector/validation-schema/connector.entitlement-handler.schema.ts +++ b/packages/connector-sdk/lib/iga/connector/validation-schema/connector.entitlement-handler.schema.ts @@ -24,8 +24,8 @@ const discoverHandlerSchema = { const grantHandlerSchema = { input: z.object({ tenant: tenantSchema, - // id returned by the account creation handler - id: z.string(), + // accountId returned by the account creation handler + accountId: z.string(), // id returned by the entitlement discovery handler entitlementId: z.string(), }), @@ -37,8 +37,8 @@ const grantHandlerSchema = { const revokeHandlerSchema = { input: z.object({ tenant: tenantSchema, - // id returned by the account creation handler - id: z.string(), + // accountId returned by the account creation handler + accountId: z.string(), // id returned by the entitlement discovery handler entitlementId: z.string(), }), @@ -47,13 +47,13 @@ const revokeHandlerSchema = { }), }; -// Drift detection: given the account id from account creation, return the entitlement ids the +// Drift detection: given the accountId from account creation, return the entitlement ids the // account currently holds, so the host can reconcile them against its recorded grants. const readHandlerSchema = { input: z.object({ tenant: tenantSchema, - // id returned by the account creation handler - id: z.string(), + // accountId returned by the account creation handler + accountId: z.string(), }), output: z.object({ entitlementIds: z.array(z.string()), diff --git a/packages/connector-sdk/lib/iga/dispatcher.test.ts b/packages/connector-sdk/lib/iga/dispatcher.test.ts index 24e077a..8e0b09a 100644 --- a/packages/connector-sdk/lib/iga/dispatcher.test.ts +++ b/packages/connector-sdk/lib/iga/dispatcher.test.ts @@ -24,7 +24,7 @@ const validInput = { }; const buildPlugin = ( - handler: AccountAction['handler'] = () => ({ id: 'user-1', created: true }), + handler: AccountAction['handler'] = () => ({ accountId: 'user-1', created: true }), config: ConnectorConfig = [], ) => new OpenIgaConnector({ @@ -87,7 +87,7 @@ describe('createRuntimeDispatcher', () => { it('should throw error if the required config from the connector is missing', async () => { const dispatch = createRuntimeDispatcher( - buildPlugin(() => ({ id: 'user-1' }) as never, [{ name: 'REGION', description: 'region', required: true }]), + buildPlugin(() => ({ accountId: 'user-1' }) as never, [{ name: 'REGION', description: 'region', required: true }]), ); setHostInput({ ...routing, config: {}, input: validInput }); // REGION intentionally left out of the envelope config @@ -115,7 +115,7 @@ describe('createRuntimeDispatcher', () => { ({ config, input }) => { expect(config).toEqual({ REGION: 'us-east-1' }); expect(input.email).toBe(validInput.email); - return { id: 'user-1', created: false, metadata: { region: (config as { REGION: string }).REGION } } as never; + return { accountId: 'user-1', created: false, metadata: { region: (config as { REGION: string }).REGION } } as never; }, [{ name: 'REGION', description: 'region', required: true }], ), @@ -125,7 +125,7 @@ describe('createRuntimeDispatcher', () => { const code = await dispatch(); expect(code).toBe(0); - expect(readHostOutput()).toEqual({ id: 'user-1', created: false, metadata: { region: 'us-east-1' } }); + expect(readHostOutput()).toEqual({ accountId: 'user-1', created: false, metadata: { region: 'us-east-1' } }); }); it('should dispatch a paged account list', async () => { @@ -140,7 +140,7 @@ describe('createRuntimeDispatcher', () => { endpoints: [{ method: 'GET', url: 'https://domain.com', description: 'endpoint' }], handler: ({ input }) => { expect(input.cursor).toBe('p1'); - return { accounts: [{ id: 'user-1', email: 'a@b.co', enabled: true }], nextCursor: 'p2' }; + return { accounts: [{ accountId: 'user-1', email: 'a@b.co', enabled: true }], nextCursor: 'p2' }; }, }); setHostInput({