Repository navigation
feat(oracle-epm): add guarded foundation #7469
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
Merged
Merged
Changes from all commits
Commits
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
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
66 changes: 66 additions & 0 deletions
66
apps/sim/lib/credentials/client-credential-accounts/minters/oracle-epm.test.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,66 @@ | ||
| /** @vitest-environment node */ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import { mintOracleEpmServiceAccountToken } from '@/lib/credentials/client-credential-accounts/minters/oracle-epm' | ||
| import { TokenServiceAccountValidationError } from '@/lib/credentials/token-service-accounts/errors' | ||
|
|
||
| describe('mintOracleEpmServiceAccountToken', () => { | ||
| it('mints Basic authentication locally and binds the normalized destination', async () => { | ||
| const fetchSpy = vi.spyOn(globalThis, 'fetch') | ||
| const result = await mintOracleEpmServiceAccountToken({ | ||
| orgId: ' https://EPM.example.com/gateway/ ', | ||
| clientId: 'integration.user@example.com', | ||
| clientSecret: 'password', | ||
| }) | ||
| expect(Buffer.from(result.accessToken, 'base64').toString()).toBe( | ||
| 'integration.user@example.com:password' | ||
| ) | ||
| expect(result).toMatchObject({ | ||
| expiresInSeconds: 600, | ||
| instanceUrl: 'https://epm.example.com/gateway', | ||
| identity: { | ||
| principal: null, | ||
| auditMetadata: { environmentUrl: 'https://epm.example.com/gateway' }, | ||
| storedMetadata: { environmentUrl: 'https://epm.example.com/gateway' }, | ||
| }, | ||
| }) | ||
| expect(JSON.stringify(result.identity)).not.toContain('password') | ||
| expect(JSON.stringify(result.identity)).not.toContain('integration.user') | ||
| expect(fetchSpy).not.toHaveBeenCalled() | ||
| fetchSpy.mockRestore() | ||
| }) | ||
|
|
||
| it.each([ | ||
| { clientId: 'user:name', clientSecret: 'password' }, | ||
| { clientId: 'user\nname', clientSecret: 'password' }, | ||
| { clientId: 'user', clientSecret: 'pass\nword' }, | ||
| { clientId: 'user\uD800', clientSecret: 'password' }, | ||
| { clientId: 'user', clientSecret: 'password\uDC00' }, | ||
| { clientId: '', clientSecret: 'password' }, | ||
| ])('rejects unsafe Basic credential text', async (credentials) => { | ||
| await expect( | ||
| mintOracleEpmServiceAccountToken({ | ||
| orgId: 'https://epm.example.com', | ||
| ...credentials, | ||
| }) | ||
| ).rejects.toBeInstanceOf(TokenServiceAccountValidationError) | ||
| }) | ||
|
|
||
| it('preserves valid surrogate pairs in Basic credential values', async () => { | ||
| const result = await mintOracleEpmServiceAccountToken({ | ||
| orgId: 'https://epm.example.com', | ||
| clientId: 'integration-😀', | ||
| clientSecret: 'password-🔒', | ||
| }) | ||
| expect(Buffer.from(result.accessToken, 'base64').toString()).toBe('integration-😀:password-🔒') | ||
| }) | ||
|
|
||
| it('does not reflect secrets in validation errors', async () => { | ||
| const secret = 'password-with-newline\n' | ||
| const error = await mintOracleEpmServiceAccountToken({ | ||
| orgId: 'https://epm.example.com', | ||
| clientId: 'user', | ||
| clientSecret: secret, | ||
| }).catch((value: unknown) => value) | ||
| expect(JSON.stringify(error)).not.toContain(secret) | ||
| }) | ||
| }) |
79 changes: 79 additions & 0 deletions
79
apps/sim/lib/credentials/client-credential-accounts/minters/oracle-epm.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,79 @@ | ||
| import type { | ||
| ClientCredentialAccountFields, | ||
| ClientCredentialAccountMintOptions, | ||
| ClientCredentialAccountMintResult, | ||
| } from '@/lib/credentials/client-credential-accounts/server' | ||
| import { | ||
| requireClientSecret, | ||
| TokenServiceAccountValidationError, | ||
| } from '@/lib/credentials/token-service-accounts/errors' | ||
| import { normalizeOracleEpmDestination } from '@/lib/internal/oracle-epm/destination' | ||
|
|
||
| const SYNTHETIC_TOKEN_TTL_SECONDS = 600 | ||
| const MAX_USERNAME_BYTES = 255 | ||
| const MAX_AUTH_VALUE_BYTES = 1_024 | ||
| const FORBIDDEN_CREDENTIAL_TEXT = /[\u0000-\u001f\u007f]/ | ||
| const MALFORMED_UTF16 = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/ | ||
|
|
||
| function invalidCredentials(reason: string): TokenServiceAccountValidationError { | ||
| return new TokenServiceAccountValidationError('invalid_credentials', 400, { | ||
| step: 'oracle_epm_basic_auth', | ||
| reason, | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * Builds credential-bound Basic authentication locally. Oracle EPM does not | ||
| * expose a token mint for this v1 flow, so connect performs no network probe. | ||
| */ | ||
| export async function mintOracleEpmServiceAccountToken( | ||
| fields: ClientCredentialAccountFields, | ||
| _options?: ClientCredentialAccountMintOptions | ||
| ): Promise<ClientCredentialAccountMintResult> { | ||
| let instanceUrl: string | ||
| try { | ||
| instanceUrl = normalizeOracleEpmDestination(fields.orgId) | ||
| } catch { | ||
| throw new TokenServiceAccountValidationError('site_not_found', 400, { | ||
| step: 'oracle_epm_destination_validation', | ||
| reason: 'environment URL must be a valid HTTPS Oracle EPM destination', | ||
| }) | ||
| } | ||
|
|
||
| const username = fields.clientId.trim() | ||
| const password = requireClientSecret( | ||
| fields.clientSecret, | ||
| 'oracle_epm_basic_auth', | ||
| 'Oracle EPM Cloud' | ||
| ) | ||
| if ( | ||
| !username || | ||
| username.includes(':') || | ||
| FORBIDDEN_CREDENTIAL_TEXT.test(username) || | ||
| MALFORMED_UTF16.test(username) || | ||
| Buffer.byteLength(username, 'utf8') > MAX_USERNAME_BYTES | ||
| ) { | ||
| throw invalidCredentials('integration username is invalid') | ||
| } | ||
| if ( | ||
| !password || | ||
| FORBIDDEN_CREDENTIAL_TEXT.test(password) || | ||
| MALFORMED_UTF16.test(password) || | ||
| Buffer.byteLength(password, 'utf8') > MAX_AUTH_VALUE_BYTES | ||
| ) { | ||
| throw invalidCredentials('password is invalid') | ||
| } | ||
|
|
||
| const hostname = new URL(instanceUrl).hostname | ||
| return { | ||
| accessToken: Buffer.from(`${username}:${password}`, 'utf8').toString('base64'), | ||
| expiresInSeconds: SYNTHETIC_TOKEN_TTL_SECONDS, | ||
| instanceUrl, | ||
| identity: { | ||
| displayName: `Oracle EPM ${hostname}`, | ||
| principal: null, | ||
| auditMetadata: { environmentUrl: instanceUrl }, | ||
| storedMetadata: { environmentUrl: instanceUrl }, | ||
| }, | ||
| } | ||
| } | ||
69 changes: 69 additions & 0 deletions
69
apps/sim/lib/credentials/client-credential-accounts/oracle-epm-password.test.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,69 @@ | ||
| import { encryptionMock, encryptionMockFns } from '@sim/testing/mocks/encryption.mock' | ||
| import { beforeEach, expect, it, vi } from 'vitest' | ||
| import { | ||
| createCredentialBodySchema, | ||
| updateCredentialByIdBodySchema, | ||
| } from '@/lib/api/contracts/credentials' | ||
| import { | ||
| v2CreateServiceAccountCredentialBodySchema, | ||
| v2UpdateCredentialBodySchema, | ||
| } from '@/lib/api/contracts/v2/credentials' | ||
| import { mintOracleEpmServiceAccountToken } from '@/lib/credentials/client-credential-accounts/minters/oracle-epm' | ||
| import { parseClientCredentialAccountSecretBlob } from '@/lib/credentials/client-credential-accounts/server' | ||
| import { verifyAndBuildServiceAccountSecret } from '@/lib/credentials/service-account-secret' | ||
|
|
||
| vi.mock('@/lib/core/security/encryption', () => encryptionMock) | ||
|
|
||
| const input = { | ||
| workspaceId: '11111111-1111-4111-8111-111111111111', | ||
| type: 'service_account' as const, | ||
| providerId: 'oracle-epm-service-account', | ||
| displayName: 'Oracle test', | ||
| orgId: 'https://epm.example.com/gateway', | ||
| clientId: 'integration-user', | ||
| clientSecret: ' password with spaces ', | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| encryptionMockFns.mockEncryptSecret.mockImplementation(async (value: string) => ({ | ||
| encrypted: value, | ||
| })) | ||
| }) | ||
|
|
||
| it.each([ | ||
| ['internal create', () => createCredentialBodySchema.parse(input)], | ||
| [ | ||
| 'internal reconnect', | ||
| () => updateCredentialByIdBodySchema.parse({ clientSecret: input.clientSecret }), | ||
| ], | ||
| [ | ||
| 'v2 create', | ||
| () => | ||
| v2CreateServiceAccountCredentialBodySchema.parse({ | ||
| workspaceId: input.workspaceId, | ||
| type: input.type, | ||
| providerId: input.providerId, | ||
| credentials: JSON.stringify({ | ||
| orgId: input.orgId, | ||
| clientId: input.clientId, | ||
| clientSecret: input.clientSecret, | ||
| }), | ||
| }).credentials, | ||
| ], | ||
| ['v2 reconnect', () => v2UpdateCredentialBodySchema.parse({ clientSecret: input.clientSecret })], | ||
| ['secret builder', () => input], | ||
| ] as const)( | ||
| 'preserves the password through %s, storage, and Basic authentication', | ||
| async (_surface, parse) => { | ||
| const fields = { ...input, ...parse() } | ||
| const result = await verifyAndBuildServiceAccountSecret(input.providerId, fields) | ||
| const stored = parseClientCredentialAccountSecretBlob( | ||
| result.encryptedServiceAccountKey, | ||
| input.providerId | ||
| ) | ||
| const credential = await mintOracleEpmServiceAccountToken(stored) | ||
| expect(Buffer.from(credential.accessToken, 'base64').toString('utf8')).toBe( | ||
| `integration-user:${input.clientSecret}` | ||
| ) | ||
| } | ||
| ) |
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.
Uh oh!
There was an error while loading. Please reload this page.