Skip to content

Commit bca74ad

Browse files
committed
fix(credentials): reopen a Platform reconnect on the credential's stored auth mode (#9878's reconnectAuthType)
1 parent b91be10 commit bca74ad

3 files changed

Lines changed: 23 additions & 17 deletions

File tree

‎apps/sim/app/(product)/_components/service-account-modal/service-account-modal.dom.test.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ let container: HTMLDivElement
4848
let root: Root
4949
let requests: RecordedRequest[]
5050
/** The workload-identity setup; Google's has no fixed audience. */
51-
let keyless: (Omit<typeof TRUST, 'audience'> & { audience?: string }) | { available: false }
51+
let keyless:
52+
| (Omit<typeof TRUST, 'audience'> & { audience?: string; reconnectAuthType?: string })
53+
| { available: false; reconnectAuthType?: string }
5254
let createFailure: { status: number; body: unknown } | null
5355
let createdIds: string[]
5456

@@ -381,6 +383,7 @@ it("shows the server's verification failure in the dialog", async () => {
381383
})
382384

383385
it('reconnects in place, keeps the trusted subject by default and prefills no secret', async () => {
386+
keyless = { ...TRUST, reconnectAuthType: 'oidc_role' }
384387
const dialog = await open('aws-service-account', 'AWS', {
385388
replacedAccount: { credentialId: 'cred-old', displayName: 'Prod role' },
386389
})
@@ -402,6 +405,16 @@ it('reconnects in place, keeps the trusted subject by default and prefills no se
402405
expect(createdIds).toEqual(['cred-old'])
403406
})
404407

408+
it('reopens a reconnect on the stored keyed mode even where keyless is offered', async () => {
409+
keyless = { ...TRUST, reconnectAuthType: 'access_keys' }
410+
const dialog = await open('aws-service-account', 'AWS', {
411+
replacedAccount: { credentialId: 'cred-old', displayName: 'Prod keys' },
412+
})
413+
414+
expect(authTypeTrigger(dialog).textContent).toContain('Access keys')
415+
expect(labelled(dialog, 'Role ARN')).toBeNull()
416+
})
417+
405418
it('adds a keyless Snowflake service user: shows the CREATE USER statement and submits a bare host', async () => {
406419
keyless = { ...TRUST, audience: 'snowflakecomputing.com' }
407420
const dialog = await open('snowflake-service-account', 'Snowflake')

‎apps/sim/lib/credentials/config-service-accounts/descriptors.ts‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ export interface ConfigServiceAccountDescriptor {
7575
keyedDefault: string
7676
/** A new credential starts on `keyedDefault` even where keyless is offered (Google). */
7777
keyedFirst?: boolean
78-
/**
79-
* The workload-identity setup reports whether a reconnected credential is keyless, so a
80-
* reconnect opens on keyless only for one that is (Snowflake, Microsoft, Google).
81-
*/
82-
reconnectReportsMode?: boolean
8378
fields: readonly ConfigServiceAccountField[]
8479
/** Whether the keyless fields are complete enough to verify, beyond each being filled in. */
8580
keylessReady?: (values: Readonly<Record<string, string>>) => boolean
@@ -302,7 +297,6 @@ const SNOWFLAKE: ConfigServiceAccountDescriptor = {
302297
},
303298
],
304299
keyedDefault: 'programmatic_access_token',
305-
reconnectReportsMode: true,
306300
fields: [
307301
{
308302
id: 'host',
@@ -360,7 +354,6 @@ const MICROSOFT_APP: ConfigServiceAccountDescriptor = {
360354
{ value: 'certificate', label: 'Certificate' },
361355
],
362356
keyedDefault: 'client_secret',
363-
reconnectReportsMode: true,
364357
fields: [
365358
{
366359
id: 'tenantId',
@@ -442,7 +435,6 @@ const GOOGLE_KEYLESS_DESCRIPTOR: ConfigServiceAccountDescriptor = {
442435
],
443436
keyedDefault: 'json_key',
444437
keyedFirst: true,
445-
reconnectReportsMode: true,
446438
fields: [
447439
{
448440
id: 'projectNumber',

‎apps/sim/platform/lib/data/credentials/config-service-account.ts‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ export function useConfigServiceAccountForm({
6464
? DEPLOYMENT_KEYLESS_REASON
6565
: undefined
6666
const keylessType = descriptor.authTypes.find((type) => type.keyless)?.value
67-
const reconnectsKeyless = Boolean(setup.data?.available && setup.data.reconnectsKeyless)
68-
const startsKeyless =
69-
reconnectCredentialId && descriptor.reconnectReportsMode
70-
? reconnectsKeyless
71-
: !descriptor.keyedFirst || reconnectsKeyless
72-
const authType =
73-
selectedAuthType ??
74-
(keylessAvailable && keylessType && startsKeyless ? keylessType : descriptor.keyedDefault)
67+
const storedAuthType = descriptor.authTypes.find(
68+
(type) => type.value === setup.data?.reconnectAuthType && (keylessAvailable || !type.keyless)
69+
)?.value
70+
const startingAuthType = reconnectCredentialId
71+
? (storedAuthType ?? descriptor.keyedDefault)
72+
: keylessAvailable && keylessType && !descriptor.keyedFirst
73+
? keylessType
74+
: descriptor.keyedDefault
75+
const authType = selectedAuthType ?? startingAuthType
7576
const chosen = descriptor.authTypes.find((type) => type.value === authType)
7677
const keyless = Boolean(chosen?.keyless)
7778
const trust = setup.data?.available && subjectChoice === 'new' ? setup.data : undefined

0 commit comments

Comments
 (0)