Skip to content

Commit 80dc86a

Browse files
committed
fix(credentials): check the audience in the connect dialog before showing setup commands
1 parent d419cd0 commit 80dc86a

5 files changed

Lines changed: 47 additions & 15 deletions

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67119,6 +67119,13 @@
6711967119
"sha256": "b867716c5b178cc345e9ec091ffd5db588c778b02f244e3e51513c9266fbaf8a",
6712067120
"bytes": 733,
6712167121
"line": 199
67122+
},
67123+
{
67124+
"lang": "bash",
67125+
"meta": null,
67126+
"sha256": "9027a7d2a3cca34b202d5fdb0c5166f12a6273f412dfe19b918cdedc9a330c8f",
67127+
"bytes": 115,
67128+
"line": 236
6712267129
}
6712367130
],
6712467131
"links": [
@@ -141594,6 +141601,13 @@
141594141601
"bytes": 169,
141595141602
"line": 29
141596141603
},
141604+
{
141605+
"lang": "sql",
141606+
"meta": null,
141607+
"sha256": "8ba22e026d880965c3aa9a33b6d11244442b5057801b4d08e6d031d5178b950e",
141608+
"bytes": 86,
141609+
"line": 42
141610+
},
141597141611
{
141598141612
"lang": "sql",
141599141613
"meta": null,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export function GoogleKeylessFields({ input, onChange, setup }: GoogleKeylessFie
132132
const delegated = value.delegatedServices.length > 0
133133
const providerAudience = trustComplete ? googleWorkloadIdentityAudience(value) : undefined
134134
const commands =
135-
trustComplete && setup.trust
135+
trustComplete && setup.trust && !setup.audienceError
136136
? googleWorkloadIdentitySetupCommands({
137137
ref: value,
138138
serviceAccountEmail: value.serviceAccountEmail,

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
WORKLOAD_IDENTITY_PROVIDER_AUTH_TYPES,
1111
type WorkloadIdentityProvider,
1212
type WorkloadIdentityProviderAuthType,
13+
workloadIdentityAudienceSchema,
1314
} from '@/lib/credentials/workload-identity/audiences'
1415
import {
1516
useCreateScopedCredential,
@@ -67,8 +68,13 @@ export function useKeylessSetup<P extends WorkloadIdentityProvider>({
6768
const audienceValue = audienceInput ?? setup.data?.reconnectAudience ?? ''
6869
const defaultAudience = setup.data?.available ? setup.data.audience : undefined
6970
const typedAudience = audienceValue.trim()
70-
const customAudience =
71-
typedAudience && typedAudience !== defaultAudience ? typedAudience : undefined
71+
const typedCustom = typedAudience && typedAudience !== defaultAudience ? typedAudience : undefined
72+
const audienceCheck = typedCustom
73+
? workloadIdentityAudienceSchema(provider).safeParse(typedCustom)
74+
: undefined
75+
const audienceError =
76+
audienceCheck && !audienceCheck.success ? audienceCheck.error.issues[0]?.message : undefined
77+
const customAudience = audienceError ? undefined : typedCustom
7278
const storedAuthType = providerAuthType(provider, setup.data?.reconnectAuthType)
7379
// A keyless credential reopens on keyless only where this deployment can still sign.
7480
const reconnectAuthType =
@@ -99,12 +105,14 @@ export function useKeylessSetup<P extends WorkloadIdentityProvider>({
99105
setAudienceInput,
100106
/** The provider's default audience; undefined for Google, whose default is each credential's provider. */
101107
defaultAudience,
102-
/** The audience typed into the field, unless it is blank or the default. */
108+
/** The audience typed into the field, unless it is blank, the default, or invalid. */
103109
customAudience,
104-
/** The audience tokens carry: the custom one, else the default. */
105-
audience: customAudience ?? defaultAudience,
110+
/** Why the typed audience can't be used; setup snippets stay hidden until it can. */
111+
audienceError,
112+
/** The audience tokens carry: the custom one, else the default; undefined while invalid. */
113+
audience: audienceError ? undefined : (customAudience ?? defaultAudience),
106114
/** Ready to submit a keyless configuration. */
107-
ready: subjectChoice === 'keep' ? Boolean(credentialId) : Boolean(trust),
115+
ready: !audienceError && (subjectChoice === 'keep' ? Boolean(credentialId) : Boolean(trust)),
108116
error: setup.isError ? setup.error : null,
109117
}
110118
}
@@ -202,6 +210,7 @@ export function KeylessTrustFields({
202210
value={setup.audienceInput}
203211
onChange={setup.setAudienceInput}
204212
placeholder={defaultAudience ?? 'Default audience'}
213+
error={setup.audienceError}
205214
hint={
206215
setup.isReconnect && !setup.trust
207216
? 'If you change the audience, add the new value to your trust configuration before saving.'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ function SnowflakeAccountForm({
264264
}
265265

266266
const createUserStatement =
267-
authType === 'workload_identity' && keyless.trust
267+
authType === 'workload_identity' && keyless.trust && !keyless.audienceError
268268
? buildCreateUserStatement(
269269
keyless.trust.issuer,
270270
keyless.trust.subject,

‎apps/sim/lib/credentials/workload-identity/audiences.ts‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,7 @@ const MAX_WORKLOAD_IDENTITY_AUDIENCE_LENGTH = 255
166166
*/
167167
const AUDIENCE_PATTERN = /^[A-Za-z0-9._~:/?#@&+=%-]+$/
168168

169-
/**
170-
* A keyless credential's own `aud` claim, so a customer can pin their trust
171-
* configuration to an audience no other Sim credential is issued for (their
172-
* Databricks account ID, say). Another relying party's default is refused: a
173-
* credential for one cloud never carries a token another cloud would accept.
174-
*/
175-
export function workloadIdentityAudienceSchema(provider: WorkloadIdentityProvider) {
169+
function buildAudienceSchema(provider: WorkloadIdentityProvider) {
176170
const othersDefaults = new Set(
177171
WORKLOAD_IDENTITY_PROVIDERS.filter((other) => other !== provider).flatMap((other) => {
178172
const audience = fixedWorkloadIdentityAudience(other)
@@ -199,6 +193,21 @@ export function workloadIdentityAudienceSchema(provider: WorkloadIdentityProvide
199193
})
200194
}
201195

196+
const AUDIENCE_SCHEMAS = Object.fromEntries(
197+
WORKLOAD_IDENTITY_PROVIDERS.map((provider) => [provider, buildAudienceSchema(provider)])
198+
) as Record<WorkloadIdentityProvider, ReturnType<typeof buildAudienceSchema>>
199+
200+
/**
201+
* A keyless credential's own `aud` claim, so a customer can pin their trust
202+
* configuration to an audience no other Sim credential is issued for (their
203+
* Databricks account ID, say). Another relying party's default is refused: a
204+
* credential for one cloud never carries a token another cloud would accept.
205+
* Built once per provider, so the connect dialog can check each keystroke.
206+
*/
207+
export function workloadIdentityAudienceSchema(provider: WorkloadIdentityProvider) {
208+
return AUDIENCE_SCHEMAS[provider]
209+
}
210+
202211
/** A Google workload identity provider's resource-name audience. */
203212
function isGoogleProviderAudience(audience: string): boolean {
204213
return /^(https:)?\/\/iam\.googleapis\.com\//i.test(audience)

0 commit comments

Comments
 (0)