Skip to content

Commit 677f474

Browse files
committed
fix(plugin-auth): a SCIM connection id is at most 246 characters, leaving room for its audit actor
A SCIM connection's own writes are audited as `svc:scim:<connectionId>` (#30960) in sys_audit_log.actor, which holds 255 characters. The mint door now refuses a longer id with the existing 400 INVALID_REQUEST, so a connection can never be minted whose every audit insert would fail. Pin: 246 characters mint, 247 are refused and nothing is stored. Claude-Session: https://claude.ai/code/session_016WV4cycHNJyS5MXHqaGsFE Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6c7e436 commit 677f474

4 files changed

Lines changed: 33 additions & 5 deletions

File tree

‎.changeset/30958-scim-connection-credential-door.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Skills-docs: updated here — `content/docs/permissions/authentication.mdx` ("SC
1010

1111
An identity provider (Okta, Entra ID) provisions users through `/api/v1/auth/scim/v2/*` with a bearer credential that this platform issues, but nothing could issue one: the mint existed with no caller, and the credential object refuses create on the data API, so no identity provider could connect. Two routes now do it, for the platform administrator only (the shared ADR-0068 gate: anyone else is refused `403 PERMISSION_DENIED`, `401 UNAUTHENTICATED` when signed out):
1212

13-
- `POST /api/v1/auth/admin/scim/mint-credential` with `{ connectionId, label?, expiresAt?, provisioningDomainId?, organizationId? }` answers `{ credentialId, connectionId, token, expiresAt }`. The `token` is shown once, in that response only (`Cache-Control: no-store`); only its keyed one-way digest is stored, and it is not readable through the data API, the audit log or the logs. Refused `503 SERVICE_UNAVAILABLE` while SCIM is off. The credential row is owned by `organizationId` when given (it must exist), otherwise by the Default Organization.
13+
- `POST /api/v1/auth/admin/scim/mint-credential` with `{ connectionId, label?, expiresAt?, provisioningDomainId?, organizationId? }` answers `{ credentialId, connectionId, token, expiresAt }`. `connectionId` is at most 246 characters, so the connection's audit actor `svc:scim:<connectionId>` fits `sys_audit_log.actor`. The `token` is shown once, in that response only (`Cache-Control: no-store`); only its keyed one-way digest is stored, and it is not readable through the data API, the audit log or the logs. Refused `503 SERVICE_UNAVAILABLE` while SCIM is off. The credential row is owned by `organizationId` when given (it must exist), otherwise by the Default Organization.
1414
- `POST /api/v1/auth/admin/scim/revoke-credential` with `{ credentialId }` switches the credential off, so the identity provider's next SCIM request with it answers `401`. `404 RESOURCE_NOT_FOUND` for an unknown credential, `409 RESOURCE_CONFLICT` for one already revoked. Served whether or not SCIM is on.
1515

1616
Rotation is a second mint for the same `connectionId`, moving the identity provider to the new bearer, then revoking the old one. Each mint and each revoke writes one `sys_audit_log` row naming the administrator and the connection, never the credential. Nothing that existed changes: no route, response or stored row moves, and the credential object stays read-only on the data API.

‎content/docs/permissions/authentication.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,8 @@ curl -X POST http://localhost:3000/api/v1/auth/admin/scim/mint-credential \
11831183
```
11841184

11851185
- `connectionId` (required) names the connection every provisioned resource
1186-
is scoped to. Optional: `label`, `expiresAt` (a future ISO date-time),
1186+
is scoped to: at most 246 characters, so the connection's audit actor
1187+
`svc:scim:<connectionId>` fits the audit log's 255. Optional: `label`, `expiresAt` (a future ISO date-time),
11871188
`provisioningDomainId`, and `organizationId` (the organization that owns the
11881189
credential row; the Default Organization when omitted).
11891190
- The `token` is shown **once**, in this response only (`Cache-Control:

‎packages/plugins/plugin-auth/src/scim-connection-admin.test.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ describe('[#30958] mint: the platform admin gets a bearer the SCIM plugin accept
264264
{ connectionId: '' },
265265
{ connectionId: ' padded ' },
266266
{ connectionId: 42 },
267-
{ connectionId: 'x'.repeat(256) },
267+
{ connectionId: 'x'.repeat(247) },
268268
{ connectionId: 'okta-bad-expiry', expiresAt: 'not-a-date' },
269269
{ connectionId: 'okta-bad-expiry', expiresAt: new Date(Date.now() - 60_000).toISOString() },
270270
{ connectionId: 'okta-bad-label', label: 7 },
@@ -277,6 +277,24 @@ describe('[#30958] mint: the platform admin gets a bearer the SCIM plugin accept
277277
expect(await credentialRows('okta-bad-label')).toEqual([]);
278278
});
279279

280+
it('a connection id leaves room for the svc:scim: audit actor: 246 characters mint, 247 are refused', async () => {
281+
// A SCIM connection's own writes are audited as `svc:scim:<connectionId>`
282+
// (#30960) in `sys_audit_log.actor`, which holds 255 characters.
283+
expect('svc:scim:'.length + 246).toBe(255);
284+
const longest = 'c'.repeat(246);
285+
const minted = await door('mint-credential', { connectionId: longest });
286+
expect(minted.status, JSON.stringify(minted.body)).toBe(200);
287+
expect(minted.body.data.connectionId).toBe(longest);
288+
expect(await credentialRows(longest)).toHaveLength(1);
289+
290+
const tooLong = 'c'.repeat(247);
291+
const refused = await door('mint-credential', { connectionId: tooLong });
292+
expect(refused.status).toBe(400);
293+
expect(refused.body.error.code).toBe('INVALID_REQUEST');
294+
expect(refused.body.error.message).toContain('at most 246 characters');
295+
expect(await credentialRows(tooLong)).toEqual([]);
296+
});
297+
280298
it('a future expiry is stored and answered', async () => {
281299
const at = new Date(Date.now() + 86_400_000).toISOString();
282300
const res = await door('mint-credential', { connectionId: 'okta-expiring', expiresAt: at });

‎packages/plugins/plugin-auth/src/scim-connection-admin.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ export const SCIM_REVOKE_CREDENTIAL_PATH = '/admin/scim/revoke-credential';
7878
/** The longest value the credential row's text columns store. */
7979
const MAX_TEXT = 255;
8080

81+
/**
82+
* The longest connection id the door accepts: 246, not {@link MAX_TEXT}.
83+
* A write made by a SCIM connection is audited with the service actor
84+
* `svc:scim:<connectionId>` (#30960), and `sys_audit_log.actor` holds 255
85+
* characters, so a longer id would make that audit insert fail for every
86+
* request the connection makes. 255 minus the 9-character prefix.
87+
*/
88+
const MAX_SCIM_CONNECTION_ID = MAX_TEXT - 'svc:scim:'.length;
89+
8190
/** Execution context for the store reads and the audit write. */
8291
const SYSTEM_CTX = { isSystem: true } as const;
8392

@@ -248,11 +257,11 @@ export async function runMintScimCredential(
248257
const body = reading.body;
249258

250259
const connectionId = body.connectionId;
251-
if (typeof connectionId !== 'string' || connectionId.length === 0 || connectionId.trim() !== connectionId || connectionId.length > MAX_TEXT) {
260+
if (typeof connectionId !== 'string' || connectionId.length === 0 || connectionId.trim() !== connectionId || connectionId.length > MAX_SCIM_CONNECTION_ID) {
252261
return fail(
253262
400,
254263
'INVALID_REQUEST',
255-
`connectionId is required: the connection's identifier (e.g. "okta-prod"), a non-empty string of at most ${MAX_TEXT} characters with no surrounding whitespace`,
264+
`connectionId is required: the connection's identifier (e.g. "okta-prod"), a non-empty string of at most ${MAX_SCIM_CONNECTION_ID} characters with no surrounding whitespace`,
256265
);
257266
}
258267
const optional: Record<'label' | 'provisioningDomainId' | 'organizationId', string | undefined> = {

0 commit comments

Comments
 (0)