Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mighty-bikes-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@open-iga/aws': patch
---

Adjust account id in handler schema
5 changes: 5 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/') }}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ permissions:
contents: write
pull-requests: write

concurrency:
group: release
cancel-in-progress: false

jobs:
release:
runs-on: ubuntu-latest
Expand Down
8 changes: 4 additions & 4 deletions connectors/aws/e2e/account-acctions.create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions connectors/aws/e2e/account-actions.lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
Expand Down
10 changes: 5 additions & 5 deletions connectors/aws/e2e/entitlements.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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);
});
Expand Down
4 changes: 2 additions & 2 deletions connectors/aws/src/account-actions/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -95,7 +95,7 @@ export const registerAccountActionCreation = (plugin: typeof awsConnector) => {
});

return {
id: created.arn,
accountId: created.arn,
created: true,
};
},
Expand Down
2 changes: 1 addition & 1 deletion connectors/aws/src/account-actions/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion connectors/aws/src/account-actions/disable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
4 changes: 2 additions & 2 deletions connectors/aws/src/account-actions/enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion connectors/aws/src/account-actions/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion connectors/aws/src/entitlements/iam-user-groups/grant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});

Expand Down
2 changes: 1 addition & 1 deletion connectors/aws/src/entitlements/iam-user-groups/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
Expand Down
2 changes: 1 addition & 1 deletion connectors/aws/src/entitlements/iam-user-groups/revoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion connectors/aws/src/utils/arn.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// IAM ARN shape: arn:aws:iam::<accountId>:user/<userName>
// 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() ?? '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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.
Expand All @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}),
Expand All @@ -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(),
}),
Expand All @@ -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()),
Expand Down
10 changes: 5 additions & 5 deletions packages/connector-sdk/lib/iga/dispatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const validInput = {
};

const buildPlugin = (
handler: AccountAction<ConnectorConfig, [], 'create'>['handler'] = () => ({ id: 'user-1', created: true }),
handler: AccountAction<ConnectorConfig, [], 'create'>['handler'] = () => ({ accountId: 'user-1', created: true }),
config: ConnectorConfig = [],
) =>
new OpenIgaConnector({
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }],
),
Expand All @@ -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 () => {
Expand All @@ -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({
Expand Down
Loading