Skip to content

Commit 3caa269

Browse files
authored
fix(credentials): cap the Databricks identity check with a deadline and report no hold for an unheld reconnect subject (#10021)
1 parent 68f4c69 commit 3caa269

8 files changed

Lines changed: 62 additions & 29 deletions

File tree

‎apps/docs/scripts/fixtures/content-baseline.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3073,7 +3073,7 @@
30733073
"lang": "bash",
30743074
"meta": null,
30753075
"sha256": "866eaf5e25ac2d6471b52118f082a507d5300b7c80cd82ecbe3cfbce598c5f6a",
3076-
"bytes": 44,
3076+
"bytes": 54,
30773077
"line": 351
30783078
},
30793079
{
@@ -11198,7 +11198,7 @@
1119811198
"lang": "bash",
1119911199
"meta": null,
1120011200
"sha256": "866eaf5e25ac2d6471b52118f082a507d5300b7c80cd82ecbe3cfbce598c5f6a",
11201-
"bytes": 44,
11201+
"bytes": 54,
1120211202
"line": 800
1120311203
},
1120411204
{

‎apps/sim/app/api/v2/credentials/workload-identity/subjects/route.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export const POST = defineV2JsonRoute({
4848
if (!result.available) {
4949
throw new WorkloadIdentityNotConfiguredError()
5050
}
51+
// This route only issues or renews subjects Sim holds, so the hold is always reported.
52+
const { subjectIssuedAt, subjectHeldUntil } = result
53+
if (!subjectIssuedAt || !subjectHeldUntil) {
54+
throw new Error('A held workload identity subject must report its hold')
55+
}
5156
const { authType, requiredFields, optionalFields } =
5257
WORKLOAD_IDENTITY_KEYLESS_CONFIGS[workloadIdentityProviderFor(body.providerId)]
5358
return {
@@ -57,8 +62,8 @@ export const POST = defineV2JsonRoute({
5762
subject: result.subject,
5863
subjectProof: result.subjectProof,
5964
expiresAt: result.expiresAt,
60-
subjectIssuedAt: result.subjectIssuedAt,
61-
subjectHeldUntil: result.subjectHeldUntil,
65+
subjectIssuedAt,
66+
subjectHeldUntil,
6267
keylessConfig: { authType, subject: result.subject, subjectProof: result.subjectProof },
6368
requiredConfigFields: [...requiredFields],
6469
optionalConfigFields: [...optionalFields],

‎apps/sim/app/workspace/[workspaceId]/integrations/components/connect-service-account-modal/keyless-connection.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,11 @@ export function KeylessTrustFields({
234234
title='Subject'
235235
value={setup.trust.subject}
236236
copyLabel='Copy subject'
237-
hint={`Your trust configuration must allow exactly this subject. Sim holds it for you until ${formatDate(new Date(setup.trust.subjectHeldUntil))}.`}
237+
hint={
238+
setup.trust.subjectHeldUntil
239+
? `Your trust configuration must allow exactly this subject. Sim holds it for you until ${formatDate(new Date(setup.trust.subjectHeldUntil))}.`
240+
: 'Your trust configuration must allow exactly this subject.'
241+
}
238242
/>
239243
</>
240244
)}

‎apps/sim/lib/api/contracts/credentials.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,11 @@ export const prepareWorkloadIdentityContract = defineRouteContract({
646646
z.object({
647647
available: z.literal(true),
648648
...workloadIdentitySubjectGrantShape,
649+
/** Absent when Sim does not hold the subject: a reconnect that keeps its own. */
650+
subjectIssuedAt: workloadIdentitySubjectGrantShape.subjectIssuedAt.optional(),
651+
subjectHeldUntil: workloadIdentitySubjectGrantShape.subjectHeldUntil.optional(),
649652
/** Whether `subject` was issued earlier, so a trust configuration may already allow it. */
650-
subjectReused: z.boolean(),
653+
subjectReused: z.boolean().optional(),
651654
reconnectAuthType: reconnectAuthTypeSchema,
652655
reconnectDelegation: reconnectDelegationSchema,
653656
reconnectCloud: reconnectCloudSchema,

‎apps/sim/lib/credentials/__integration__/workload-identity-pending-subject.integration.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ describe('holding an unsaved keyless subject', () => {
198198

199199
expect(renewed.subject).toBe(held.subject)
200200
expect(renewed.subjectIssuedAt).toBe(tenDaysAgo.toISOString())
201-
expect(Date.parse(renewed.subjectHeldUntil)).toBeGreaterThan(
201+
expect(Date.parse(renewed.subjectHeldUntil ?? '')).toBeGreaterThan(
202202
Date.now() + PENDING_SUBJECT_HOLD_MS - DAY_MS
203203
)
204204
expect(saved.success).toBe(true)

‎apps/sim/lib/credentials/application/prepare-workload-identity.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,25 @@ describe('preparing a reconnect', () => {
361361
expect(await prepare()).not.toHaveProperty('reconnectCloud')
362362
})
363363

364+
it('reports no hold for a reconnect subject Sim does not hold', async () => {
365+
reconnecting(keylessSecret)
366+
367+
const result = await prepareWorkloadIdentity.execute({
368+
principal,
369+
input: {
370+
workspaceId: 'workspace-1',
371+
provider: 'snowflake',
372+
credentialId: 'cred-1',
373+
subjectRequest: { kind: 'unheld' },
374+
},
375+
})
376+
377+
expect(result).toMatchObject({ available: true, subject: expect.any(String) })
378+
expect(result).not.toHaveProperty('subjectHeldUntil')
379+
expect(result).not.toHaveProperty('subjectIssuedAt')
380+
expect(result).not.toHaveProperty('subjectReused')
381+
})
382+
364383
it('gives Google no fixed audience', async () => {
365384
reconnecting(STORED_MODES[11].secret, { providerId: 'google-service-account' })
366385
expect(await prepare('google')).not.toHaveProperty('audience')

‎apps/sim/lib/credentials/application/prepare-workload-identity.ts‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ export type PrepareWorkloadIdentityResult =
7171
subject: string
7272
subjectProof: string
7373
expiresAt: string
74-
/** When Sim first issued `subject`. */
75-
subjectIssuedAt: string
74+
/** When Sim first issued `subject`; absent when Sim does not hold it (an `unheld` request). */
75+
subjectIssuedAt?: string
7676
/** Until when Sim keeps holding `subject` for this person if no credential saves it. */
77-
subjectHeldUntil: string
77+
subjectHeldUntil?: string
7878
/** Whether `subject` was issued earlier, so a trust configuration may already allow it. */
79-
subjectReused: boolean
79+
subjectReused?: boolean
8080
} & ReconnectFields)
8181

8282
/** What a provider's stored-secret reader returns: the non-secret fields a reconnect keeps. */
@@ -147,27 +147,14 @@ async function storedReconnectFields(
147147
return STORED_RECONNECT[provider](decrypted)
148148
}
149149

150-
/**
151-
* Starts a keyless cloud connection (an AWS role, a Databricks service
152-
* principal, a Snowflake service user, a Microsoft app, or a Google service account): the subject the customer's trust
153-
* configuration will pin, signed for this person and workspace so only they can attach it to the credential
154-
* they are about to create. Sim holds the subject for them until a credential saves it, so a trust
155-
* configuration applied days later still matches. Reports `available: false` when this deployment
156-
* cannot sign tokens, so the connect dialog offers only key-based modes. On a
157-
* reconnect it also reports the credential's stored mode, signing or not.
158-
*/
150+
/** The signed subject to hand out, and Sim's hold on it; no hold for an `unheld` request. */
159151
async function subjectGrant(
160152
input: PrepareWorkloadIdentityInput,
161153
owner: { workspaceId: string },
162154
userId: string
163155
) {
164156
if (input.subjectRequest.kind === 'unheld') {
165-
const grant = issueWorkloadIdentitySubject(input.provider, owner, userId)
166-
const now = new Date()
167-
return {
168-
grant,
169-
pending: { issuedAt: now, heldUntil: new Date(grant.expiresAt), reused: false },
170-
}
157+
return { grant: issueWorkloadIdentitySubject(input.provider, owner, userId), pending: null }
171158
}
172159
const pending = await resolvePendingWorkloadIdentitySubject(
173160
{ provider: input.provider, workspaceId: input.workspaceId, userId },
@@ -179,6 +166,15 @@ async function subjectGrant(
179166
}
180167
}
181168

169+
/**
170+
* Starts a keyless cloud connection (an AWS role, a Databricks service
171+
* principal, a Snowflake service user, a Microsoft app, or a Google service account): the subject the customer's trust
172+
* configuration will pin, signed for this person and workspace so only they can attach it to the credential
173+
* they are about to create. Sim holds the subject for them until a credential saves it, so a trust
174+
* configuration applied days later still matches. Reports `available: false` when this deployment
175+
* cannot sign tokens, so the connect dialog offers only key-based modes. On a
176+
* reconnect it also reports the credential's stored mode, signing or not.
177+
*/
182178
export const prepareWorkloadIdentity = defineAuthorizedWorkspaceUseCase({
183179
operation: credentialOperations.prepareWorkloadIdentity,
184180
resolveContext: async ({ input }: { input: PrepareWorkloadIdentityInput }) => {
@@ -207,9 +203,13 @@ export const prepareWorkloadIdentity = defineAuthorizedWorkspaceUseCase({
207203
issuer: getWorkloadIdentityIssuer(),
208204
...(audience ? { audience } : {}),
209205
...grant,
210-
subjectIssuedAt: pending.issuedAt.toISOString(),
211-
subjectHeldUntil: pending.heldUntil.toISOString(),
212-
subjectReused: pending.reused,
206+
...(pending
207+
? {
208+
subjectIssuedAt: pending.issuedAt.toISOString(),
209+
subjectHeldUntil: pending.heldUntil.toISOString(),
210+
subjectReused: pending.reused,
211+
}
212+
: {}),
213213
...reconnect,
214214
}
215215
},

‎apps/sim/lib/credentials/databricks-service-account.server.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ async function verifyWorkspaceIdentity(
324324
{
325325
profile: 'configuredEndpoint',
326326
headers: { Authorization: `Bearer ${token}`, Accept: 'application/json' },
327+
// `timeout` resets on activity; the signal caps the whole call, DNS included.
327328
timeout: REQUEST_TIMEOUT_MS,
329+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
328330
maxRedirects: 0,
329331
// An oversized body rejects here and fails verification rather than
330332
// saving the host as the identity.

0 commit comments

Comments
 (0)