-
Notifications
You must be signed in to change notification settings - Fork 122
OIDC assigned resources #7160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
OIDC assigned resources #7160
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3ecc012
Add oidc resource assignment api and ui
jdolle 94c52d8
Early return over conditional return
jdolle 42f25de
Fix parenthesis
jdolle 02c0864
Remove leaked schema proposal enum
jdolle aa83422
add integration tests for oidc default assigned resources
jdolle 90d4fb3
Adding a query for oidc resources
jdolle c1eca91
Add oidc resource selector to use new query; add save icon
jdolle 21ed3b9
Remove log line
jdolle 152ab1e
Fix mutate error icon condition
jdolle 1b0ff11
fix lint issue
jdolle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
266 changes: 266 additions & 0 deletions
266
integration-tests/tests/api/oidc-integrations/assigned-resources.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,266 @@ | ||
| import { graphql } from 'testkit/gql'; | ||
| import { ResourceAssignmentModeType } from 'testkit/gql/graphql'; | ||
| import { execute } from 'testkit/graphql'; | ||
| import { initSeed } from 'testkit/seed'; | ||
|
|
||
| const AssignedResourcesSpec_CreateOIDCIntegrationMutation = graphql(` | ||
| mutation AssignedResourcesSpec_CreateOIDCIntegrationMutation( | ||
| $input: CreateOIDCIntegrationInput! | ||
| ) { | ||
| createOIDCIntegration(input: $input) { | ||
| ok { | ||
| createdOIDCIntegration { | ||
| id | ||
| defaultResourceAssignment { | ||
| mode | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| `); | ||
|
|
||
| const AssignedResourcesSpec_ReadDefaultTest = graphql(` | ||
| query AssignedResourcesSpec_ReadDefaultTest($organizationSlug: String!) { | ||
| organization(reference: { bySelector: { organizationSlug: $organizationSlug } }) { | ||
| id | ||
| oidcIntegration { | ||
| defaultResourceAssignment { | ||
| mode | ||
| projects { | ||
| project { | ||
| id | ||
| slug | ||
| } | ||
| targets { | ||
| mode | ||
| targets { | ||
| target { | ||
| id | ||
| slug | ||
| } | ||
| services { | ||
| mode | ||
| services | ||
| } | ||
| appDeployments { | ||
| mode | ||
| appDeployments | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| `); | ||
|
|
||
| const AssignedResourcesSpec_UpdateDefaultMutation = graphql(` | ||
| mutation AssignedResourcesSpec_UpdateDefaultMutation( | ||
| $input: UpdateOIDCDefaultResourceAssignmentInput! | ||
| ) { | ||
| updateOIDCDefaultResourceAssignment(input: $input) { | ||
| ok { | ||
| updatedOIDCIntegration { | ||
| id | ||
| defaultResourceAssignment { | ||
| mode | ||
| projects { | ||
| project { | ||
| id | ||
| slug | ||
| } | ||
| targets { | ||
| mode | ||
| targets { | ||
| target { | ||
| id | ||
| slug | ||
| } | ||
| services { | ||
| mode | ||
| services | ||
| } | ||
| appDeployments { | ||
| mode | ||
| appDeployments | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| error { | ||
| message | ||
| } | ||
| } | ||
| } | ||
| `); | ||
|
|
||
| async function setup() { | ||
| const { ownerToken, createOrg } = await initSeed().createOwner(); | ||
| const { organization, createOrganizationAccessToken } = await createOrg(); | ||
|
|
||
| const result = await execute({ | ||
| document: AssignedResourcesSpec_CreateOIDCIntegrationMutation, | ||
| variables: { | ||
| input: { | ||
| organizationId: organization.id, | ||
| clientId: 'foo', | ||
| clientSecret: 'foofoofoofoo', | ||
| tokenEndpoint: 'http://localhost:8888/oauth/token', | ||
| userinfoEndpoint: 'http://localhost:8888/oauth/userinfo', | ||
| authorizationEndpoint: 'http://localhost:8888/oauth/authorize', | ||
| }, | ||
| }, | ||
| authToken: ownerToken, | ||
| }).then(r => r.expectNoGraphQLErrors()); | ||
|
|
||
| // no default exists at creation | ||
| expect(result.createOIDCIntegration.ok?.createdOIDCIntegration.defaultResourceAssignment).toBe( | ||
| null, | ||
| ); | ||
| return { | ||
| organization, | ||
| ownerToken, | ||
| oidcIntegrationId: result.createOIDCIntegration.ok?.createdOIDCIntegration.id!, | ||
| createOrganizationAccessToken, | ||
| }; | ||
| } | ||
|
|
||
| describe('read OIDC', () => { | ||
| describe('permissions="organization:integrations"', () => { | ||
| test.concurrent('success', async ({ expect }) => { | ||
| const { organization, ownerToken, oidcIntegrationId } = await setup(); | ||
|
|
||
| await execute({ | ||
| document: AssignedResourcesSpec_UpdateDefaultMutation, | ||
| variables: { | ||
| input: { | ||
| oidcIntegrationId, | ||
| resources: { | ||
| mode: ResourceAssignmentModeType.All, | ||
| }, | ||
| }, | ||
| }, | ||
| authToken: ownerToken, | ||
| }).then(r => r.expectNoGraphQLErrors()); | ||
|
|
||
| const read = await execute({ | ||
| document: AssignedResourcesSpec_ReadDefaultTest, | ||
| variables: { | ||
| organizationSlug: organization.slug, | ||
| }, | ||
| authToken: ownerToken, | ||
| }).then(r => r.expectNoGraphQLErrors()); | ||
|
|
||
| expect(read).toEqual({ | ||
| organization: { | ||
| id: expect.stringMatching('.+'), | ||
| oidcIntegration: { | ||
| defaultResourceAssignment: { | ||
| mode: 'ALL', | ||
| projects: null, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('permissions missing "organization:integrations"', () => { | ||
| test.concurrent('fail', async ({ expect }) => { | ||
| const { organization, ownerToken, oidcIntegrationId, createOrganizationAccessToken } = | ||
| await setup(); | ||
| const { privateAccessKey: readToken } = await createOrganizationAccessToken({ | ||
| permissions: ['organization:read'], | ||
| resources: { mode: ResourceAssignmentModeType.All }, | ||
| }); | ||
|
|
||
| await execute({ | ||
| document: AssignedResourcesSpec_UpdateDefaultMutation, | ||
| variables: { | ||
| input: { | ||
| oidcIntegrationId, | ||
| resources: { | ||
| mode: ResourceAssignmentModeType.All, | ||
| }, | ||
| }, | ||
| }, | ||
| authToken: ownerToken, | ||
| }).then(r => r.expectNoGraphQLErrors()); | ||
|
|
||
| await execute({ | ||
| document: AssignedResourcesSpec_ReadDefaultTest, | ||
| variables: { | ||
| organizationSlug: organization.slug, | ||
| }, | ||
| authToken: readToken, | ||
| }).then(r => r.expectGraphQLErrors()); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('update OIDC default assigned resources', () => { | ||
| describe('permissions="oidc:modify"', () => { | ||
| test.concurrent('success', async ({ expect }) => { | ||
| const { organization, ownerToken, oidcIntegrationId } = await setup(); | ||
|
|
||
| const update = await execute({ | ||
| document: AssignedResourcesSpec_UpdateDefaultMutation, | ||
| variables: { | ||
| input: { | ||
| oidcIntegrationId, | ||
| resources: { | ||
| mode: ResourceAssignmentModeType.All, | ||
| }, | ||
| }, | ||
| }, | ||
| authToken: ownerToken, | ||
| }).then(r => r.expectNoGraphQLErrors()); | ||
|
|
||
| expect(update).toEqual({ | ||
| updateOIDCDefaultResourceAssignment: { | ||
| error: null, | ||
| ok: { | ||
| updatedOIDCIntegration: { | ||
| defaultResourceAssignment: { | ||
| mode: 'ALL', | ||
| projects: null, | ||
| }, | ||
| id: expect.stringMatching('.+'), | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('permissions missing "oidc:modify"', () => { | ||
| test.concurrent('fails', async ({ expect }) => { | ||
| const { createOrganizationAccessToken, ownerToken, oidcIntegrationId } = await setup(); | ||
|
|
||
| const { privateAccessKey: accessToken } = await createOrganizationAccessToken({ | ||
| permissions: ['organization:read'], | ||
| resources: { | ||
| mode: ResourceAssignmentModeType.All, | ||
| }, | ||
| }); | ||
|
|
||
| const update = await execute({ | ||
| document: AssignedResourcesSpec_UpdateDefaultMutation, | ||
| variables: { | ||
| input: { | ||
| oidcIntegrationId, | ||
| resources: { | ||
| mode: ResourceAssignmentModeType.All, | ||
| }, | ||
| }, | ||
| }, | ||
| authToken: accessToken, | ||
| }).then(r => r.expectGraphQLErrors()); | ||
| }); | ||
| }); | ||
| }); |
10 changes: 10 additions & 0 deletions
10
packages/migrations/src/actions/2025.10.30T00-00-00.granular-oidc-role-permissions.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { type MigrationExecutor } from '../pg-migrator'; | ||
|
|
||
| export default { | ||
| name: '2025.10.30T00-00-00.granular-oidc-role-permissions.ts', | ||
| run: ({ sql }) => sql` | ||
| ALTER TABLE "oidc_integrations" | ||
| ADD COLUMN "default_assigned_resources" JSONB | ||
| ; | ||
| `, | ||
| } satisfies MigrationExecutor; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/services/api/src/modules/audit-logs/providers/audit-logs-types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
had to move because now storage uses the model and i didnt want to make services a dependency of storage.