From bbbadbfe20792c1c53b9dc1e2a04f2c74edf5d70 Mon Sep 17 00:00:00 2001 From: Justin Gasper Date: Mon, 9 Nov 2026 11:51:26 +1100 Subject: [PATCH] Prepare dev Identity RS256 signing and issuer policies --- deploy/dev-jwt-issuer-policies.json | 47 +++++++++++++++++++ deploy/dev.json | 2 +- docs/identity-rs256-dev.md | 13 +++++ package.json | 2 +- pnpm-lock.yaml | 12 ++--- .../access-token-signer.service.spec.ts | 17 +++++++ src/config/configuration.service.spec.ts | 30 ++++++++++++ src/config/configuration.service.ts | 13 ++++- 8 files changed, 127 insertions(+), 9 deletions(-) create mode 100644 deploy/dev-jwt-issuer-policies.json create mode 100644 docs/identity-rs256-dev.md create mode 100644 src/config/configuration.service.spec.ts diff --git a/deploy/dev-jwt-issuer-policies.json b/deploy/dev-jwt-issuer-policies.json new file mode 100644 index 0000000..7da612a --- /dev/null +++ b/deploy/dev-jwt-issuer-policies.json @@ -0,0 +1,47 @@ +[ + { + "issuer": "https://api.topcoder-dev.com", + "algorithm": "RS256", + "audience": "https://api.topcoder-dev.com/v6", + "jwksUri": "https://api.topcoder-dev.com/v6/authorizations/.well-known/jwks.json" + }, + { + "issuer": "https://auth.topcoder-dev.com/", + "algorithm": "RS256", + "audience": "BXWXUWnilVUPdN01t2Se29Tw2ZYNGZvH", + "jwksUri": "https://auth.topcoder-dev.com/.well-known/jwks.json" + }, + { + "issuer": "https://topcoder-dev.auth0.com/", + "algorithm": "RS256", + "audience": [ + "BXWXUWnilVUPdN01t2Se29Tw2ZYNGZvH", + "https://m2m.topcoder-dev.com/" + ], + "jwksUri": "https://topcoder-dev.auth0.com/.well-known/jwks.json" + }, + { + "issuer": "https://keycloak.topcoder-dev.com/realms/topcoder-m2m-dev", + "algorithm": "RS256", + "audience": "https://m2m.topcoder-dev.com/", + "jwksUri": "https://keycloak.topcoder-dev.com/realms/topcoder-m2m-dev/protocol/openid-connect/certs" + }, + { + "issuer": "https://testsachin.topcoder-dev.com/", + "algorithm": "RS256", + "audience": [ + "BXWXUWnilVUPdN01t2Se29Tw2ZYNGZvH", + "https://m2m.topcoder-dev.com/" + ], + "jwksUri": "https://testsachin.topcoder-dev.com/.well-known/jwks.json" + }, + { + "issuer": "https://test-sachin-rs256.auth0.com/", + "algorithm": "RS256", + "audience": [ + "BXWXUWnilVUPdN01t2Se29Tw2ZYNGZvH", + "https://m2m.topcoder-dev.com/" + ], + "jwksUri": "https://test-sachin-rs256.auth0.com/.well-known/jwks.json" + } +] diff --git a/deploy/dev.json b/deploy/dev.json index 7680bd1..6ec0238 100644 --- a/deploy/dev.json +++ b/deploy/dev.json @@ -4,7 +4,7 @@ "accountId": "811668436784", "region": "us-east-1", "deployRoleArn": "arn:aws:iam::811668436784:role/identity-api-v6-dev-deploy", - "taskRoleArn": null, + "taskRoleArn": "arn:aws:iam::811668436784:role/identity-api-v6-dev-signing-task", "executionRoleArn": "arn:aws:iam::811668436784:role/ecsTaskExecutionRole", "cluster": "identity-service-serverless", "service": "identity-api-v6", diff --git a/docs/identity-rs256-dev.md b/docs/identity-rs256-dev.md new file mode 100644 index 0000000..0b8cb74 --- /dev/null +++ b/docs/identity-rs256-dev.md @@ -0,0 +1,13 @@ +# Identity RS256 preparation for dev + +This PR pins tc-core-library-js 4.0.0-rc.4 at commit `c7c8fab502b7152dd06b1ce46cdb703e0e13b357`. It requires explicit issuer policies and retains verified-email and identity-denylist enforcement. + +The public settings are staged in dev Parameter Store under `/config/identity-rs256-dev-staged/`; running services do not reference that namespace. The checked-in JSON is a reviewed configuration proposal, not an automatically applied deployment change. + +Before merging/deploying, coordinate with Identity and all token consumers. Set `JWT_ISSUER_POLICIES` to the JSON in `deploy/dev-jwt-issuer-policies.json`, retaining the service's machine audience and authorization checks. Merely adding `AUTH_SECRET` no longer enables HMAC trust. If a transition needs HS256, configure only that exact issuer with a finite UTC retirement deadline, then replace it with RS256 at the coordinated cutover. Never accept both algorithms for one issuer. + +Identity additionally needs the dedicated signing task role in `deploy/dev.json`, the staged KMS key ARN, `AUTH_DOMAIN=topcoder-dev.com`, API audience, and 900-second TTL. The task-role and deploy-role PassRole changes must be applied together with the reviewed manifest; the release pipeline deliberately rejects a role mismatch. Keep `ACCESS_TOKEN_SIGNING_ALGORITHM=HS256` while first publishing the public key. + +Publish the Identity public key first; then test fresh login, expiry/refresh, logout, cross-app access, human authorization, machine authorization, wrong-audience rejection and legacy-HMAC rejection. Remove AUTH_SECRET only from public-key-only API verifiers; keep separate keys for application proofs, cursors, and independent local-login tokens. Existing browser sessions continue to use Auth0; do not put Identity-issued tokens into the Accounts connector cookie without implementing an Identity-aware refresh flow. + +Production is not changed. This dev policy intentionally does not trust the production Topcoder issuer. Do not merge this into production without its separately reviewed environment policy and key. diff --git a/package.json b/package.json index ade9daa..f184298 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "reflect-metadata": "^0.2.2", "rxjs": "^7.8.2", "swagger-ui-express": "^5.0.1", - "tc-core-library-js": "https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c2df92b2227089909ab6e229df0ec6b658bb431a", + "tc-core-library-js": "https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c7c8fab502b7152dd06b1ce46cdb703e0e13b357", "trolleyhq": "^1.1.0", "winston": "^3.17.0" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 210ed5c..9c33519 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -165,8 +165,8 @@ importers: specifier: ^5.0.1 version: 5.0.1(express@5.2.1(supports-color@8.1.1)) tc-core-library-js: - specifier: https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c2df92b2227089909ab6e229df0ec6b658bb431a - version: https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c2df92b2227089909ab6e229df0ec6b658bb431a(supports-color@8.1.1) + specifier: https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c7c8fab502b7152dd06b1ce46cdb703e0e13b357 + version: https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c7c8fab502b7152dd06b1ce46cdb703e0e13b357(supports-color@8.1.1) trolleyhq: specifier: ^1.1.0 version: 1.1.0(debug@4.4.3(supports-color@8.1.1))(supports-color@8.1.1) @@ -4117,9 +4117,9 @@ packages: tar-stream@3.1.7: resolution: {integrity: sha512-qJj60CXt7IU1Ffyc3NJMjh6EkuCFej46zUqJ4J7pqYlThyd9bO0XBTmcOIhSzZJVWfsLks0+nle/j538YAW9RQ==} - tc-core-library-js@https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c2df92b2227089909ab6e229df0ec6b658bb431a: - resolution: {gitHosted: true, integrity: sha512-n+4KUOeV4LEIsTI/R216dBc6bUkbSyO/2O0LpoY3Hk7eqKsRQFUHloB3y0hfK/v1rzf8qYQxTdv8ikeRGBn4pQ==, tarball: https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c2df92b2227089909ab6e229df0ec6b658bb431a} - version: 4.0.0-rc.2.1 + tc-core-library-js@https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c7c8fab502b7152dd06b1ce46cdb703e0e13b357: + resolution: {gitHosted: true, integrity: sha512-6Cx3QMnGU0fwNQHX3ix714U/XPs04js8cMJ4Ojge0S+QGGaPnUawttOKmR+Zu6o7vs+IZt3g2XjlplQme3h1TQ==, tarball: https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c7c8fab502b7152dd06b1ce46cdb703e0e13b357} + version: 4.0.0-rc.4 engines: {node: '>=22.13'} teleport-javascript@1.0.0: @@ -8934,7 +8934,7 @@ snapshots: - bare-abort-controller - react-native-b4a - tc-core-library-js@https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c2df92b2227089909ab6e229df0ec6b658bb431a(supports-color@8.1.1): + tc-core-library-js@https://codeload.github.com/topcoder-platform/tc-core-library-js/tar.gz/c7c8fab502b7152dd06b1ce46cdb703e0e13b357(supports-color@8.1.1): dependencies: '@types/jsonwebtoken': 9.0.10 jsonwebtoken: 9.0.3 diff --git a/src/api/authorization/access-token-signer.service.spec.ts b/src/api/authorization/access-token-signer.service.spec.ts index 84abb34..e870786 100644 --- a/src/api/authorization/access-token-signer.service.spec.ts +++ b/src/api/authorization/access-token-signer.service.spec.ts @@ -67,6 +67,23 @@ function setup(values: Record = settings) { } describe('isolated access-token signing', () => { + it('preserves the default legacy login without a KMS key or credentials', async () => { + const { signer, send } = setup({}); + await signer.onModuleInit(); + const token = await signer.sign({ + userId: '42', + emailVerified: true, + exp: Math.floor(Date.now() / 1000) + 300, + }); + expect( + jwt.verify(token, common.getCommon().authSecret, { + algorithms: ['HS256'], + }), + ).toMatchObject({ userId: '42', emailVerified: true }); + expect(signer.getJwks()).toEqual({ keys: [] }); + expect(send).not.toHaveBeenCalled(); + }); + it('signs server-bound claims with RS256 and publishes only the matching public key', async () => { const { signer, send } = setup(); await signer.onModuleInit(); diff --git a/src/config/configuration.service.spec.ts b/src/config/configuration.service.spec.ts new file mode 100644 index 0000000..f39a6e3 --- /dev/null +++ b/src/config/configuration.service.spec.ts @@ -0,0 +1,30 @@ +import { ConfigService } from '@nestjs/config'; +import { ConfigurationService } from './configuration.service'; + +describe('Identity issuer configuration', () => { + const issuers = [ + 'https://api.topcoder-dev.com', + 'https://auth.topcoder-dev.com/', + ]; + + it.each([JSON.stringify(issuers), issuers.join(', ')])( + 'preserves exact issuer URLs from JSON or comma-separated configuration', + (VALID_ISSUERS) => { + const service = new ConfigurationService( + new ConfigService({ VALID_ISSUERS }), + ); + expect(service.getCommon().validIssuers).toEqual(issuers); + }, + ); + + it.each(['[null]', '[123]', '[""]', '[bad'])( + 'rejects malformed issuer configuration: %s', + (VALID_ISSUERS) => { + expect(() => + new ConfigurationService( + new ConfigService({ VALID_ISSUERS }), + ).getCommon(), + ).toThrow(); + }, + ); +}); diff --git a/src/config/configuration.service.ts b/src/config/configuration.service.ts index 7f0d31c..750d122 100644 --- a/src/config/configuration.service.ts +++ b/src/config/configuration.service.ts @@ -7,7 +7,18 @@ export class ConfigurationService { getCommon() { const issuerValue = this.configService.get('VALID_ISSUERS', '[]'); - const issuers = issuerValue.split(',').map((t) => t.trim()); + const issuers: string[] = issuerValue.trim().startsWith('[') + ? JSON.parse(issuerValue) + : issuerValue + .split(',') + .map((t) => t.trim()) + .filter(Boolean); + if ( + !Array.isArray(issuers) || + issuers.some((issuer) => typeof issuer !== 'string' || !issuer.trim()) + ) { + throw new Error('VALID_ISSUERS must contain issuer strings'); + } return { authSecret: this.configService.get('AUTH_SECRET'), authDomain: this.configService.get('AUTH_DOMAIN'),