-
-
Notifications
You must be signed in to change notification settings - Fork 19
Backend agent table public permissions #1864
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
76 changes: 76 additions & 0 deletions
76
...src/microservices/sitenova-microservice/data-structures/sitenova-internal-responses.ds.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,76 @@ | ||
| import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; | ||
|
|
||
| // Decrypted connection credentials handed to the universal-backend service so it can open the | ||
| // customer database itself (with Knex). Serving this over the microservice-JWT channel keeps the | ||
| // core the sole owner of credential storage/decryption; the satellite never sees the core DB or | ||
| // the encryption keys. Same trust level as the existing write-capable raw-query edge. | ||
| export class SitenovaDecryptedConnectionRO { | ||
| @ApiProperty() | ||
| id: string; | ||
|
|
||
| @ApiProperty({ description: 'Connection engine type (e.g. postgres, mysql).' }) | ||
| type: string; | ||
|
|
||
| @ApiPropertyOptional() | ||
| host?: string | null; | ||
|
|
||
| @ApiPropertyOptional() | ||
| port?: number | null; | ||
|
|
||
| @ApiPropertyOptional() | ||
| username?: string | null; | ||
|
|
||
| @ApiPropertyOptional() | ||
| password?: string | null; | ||
|
|
||
| @ApiPropertyOptional() | ||
| database?: string | null; | ||
|
|
||
| @ApiPropertyOptional() | ||
| schema?: string | null; | ||
|
|
||
| @ApiPropertyOptional() | ||
| ssl?: boolean | null; | ||
|
|
||
| @ApiPropertyOptional() | ||
| cert?: string | null; | ||
|
|
||
| @ApiPropertyOptional({ description: 'True when the connection reaches the DB over an SSH tunnel.' }) | ||
| ssh?: boolean; | ||
|
|
||
| @ApiPropertyOptional() | ||
| azure_encryption?: boolean; | ||
|
|
||
| @ApiPropertyOptional() | ||
| sid?: string | null; | ||
|
|
||
| @ApiPropertyOptional() | ||
| authSource?: string | null; | ||
|
|
||
| @ApiPropertyOptional() | ||
| dataCenter?: string | null; | ||
| } | ||
|
|
||
| export class SitenovaConnectionForSiteRuntimeRO { | ||
| @ApiProperty({ type: SitenovaDecryptedConnectionRO }) | ||
| connection: SitenovaDecryptedConnectionRO; | ||
|
|
||
| @ApiProperty({ | ||
| description: | ||
| 'Per-connection HS256 key for generated-site end-user JWTs (created on first request). ' + | ||
| 'Lets the caller sign/verify the same tokens SitenovaEndUserAuthService does.', | ||
| }) | ||
| endUserJwtKey: string; | ||
| } | ||
|
|
||
| export class SitenovaPublicReadValidationRO { | ||
| @ApiProperty({ description: 'True when the connection public policy grants table:query on the table.' }) | ||
| allowed: boolean; | ||
|
|
||
| @ApiProperty({ | ||
| type: [String], | ||
| nullable: true, | ||
| description: 'Publicly readable subset of the submitted columnNames; null when columnNames was not submitted.', | ||
| }) | ||
| readableColumns: Array<string> | null; | ||
| } |
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
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
60 changes: 60 additions & 0 deletions
60
...end/src/microservices/sitenova-microservice/use-cases/sitenova-get-connection.use.case.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,60 @@ | ||
| import { BadRequestException, Inject, Injectable } from '@nestjs/common'; | ||
| import AbstractUseCase from '../../../common/abstract-use.case.js'; | ||
| import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js'; | ||
| import { BaseType } from '../../../common/data-injection.tokens.js'; | ||
| import { validateConnection } from '../../../entities/table/utils/validate-connection.util.js'; | ||
| import { isConnectionTypeAgent } from '../../../helpers/is-connection-entity-agent.js'; | ||
| import { SitenovaGetConnectionDs } from '../data-structures/sitenova.ds.js'; | ||
| import { SitenovaConnectionForSiteRuntimeRO } from '../data-structures/sitenova-internal-responses.ds.js'; | ||
| import { SitenovaEndUserAuthService } from '../services/sitenova-enduser-auth.service.js'; | ||
| import { ISitenovaGetConnection } from './sitenova-use-cases.interface.js'; | ||
|
|
||
| @Injectable() | ||
| export class SitenovaGetConnectionUseCase | ||
| extends AbstractUseCase<SitenovaGetConnectionDs, SitenovaConnectionForSiteRuntimeRO> | ||
| implements ISitenovaGetConnection | ||
| { | ||
| constructor( | ||
| @Inject(BaseType.GLOBAL_DB_CONTEXT) | ||
| protected _dbContext: IGlobalDatabaseContext, | ||
| private readonly endUserAuthService: SitenovaEndUserAuthService, | ||
| ) { | ||
| super(); | ||
| } | ||
|
|
||
| protected async implementation(inputData: SitenovaGetConnectionDs): Promise<SitenovaConnectionForSiteRuntimeRO> { | ||
| const { connectionId } = inputData; | ||
|
|
||
| const connection = await this._dbContext.connectionRepository.findAndDecryptConnection(connectionId, ''); | ||
| validateConnection(connection); | ||
|
|
||
| // Agent connections store no credentials on the core (queries run inside the customer | ||
| // network); the universal-backend service cannot open them with the returned config. | ||
| if (isConnectionTypeAgent(connection.type)) { | ||
| throw new BadRequestException('Agent connections have no stored credentials to hand out.'); | ||
| } | ||
|
|
||
| const endUserJwtKey = await this.endUserAuthService.getEndUserSigningKey(connectionId); | ||
|
|
||
| return { | ||
| connection: { | ||
| id: connection.id, | ||
| type: connection.type as string, | ||
| host: connection.host, | ||
| port: connection.port ?? null, | ||
| username: connection.username, | ||
| password: connection.password, | ||
| database: connection.database, | ||
| schema: connection.schema, | ||
| ssl: connection.ssl, | ||
| cert: connection.cert, | ||
| ssh: connection.ssh, | ||
| azure_encryption: connection.azure_encryption, | ||
| sid: connection.sid, | ||
| authSource: connection.authSource, | ||
| dataCenter: connection.dataCenter, | ||
| }, | ||
| endUserJwtKey, | ||
| }; | ||
| } | ||
| } |
24 changes: 23 additions & 1 deletion
24
backend/src/microservices/sitenova-microservice/use-cases/sitenova-use-cases.interface.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 |
|---|---|---|
| @@ -1,7 +1,29 @@ | ||
| import { InTransactionEnum } from '../../../enums/in-transaction.enum.js'; | ||
| import { SitenovaExecuteRawQueryDs } from '../data-structures/sitenova.ds.js'; | ||
| import { | ||
| SitenovaExecuteRawQueryDs, | ||
| SitenovaGetConnectionDs, | ||
| SitenovaValidatePublicReadDs, | ||
| } from '../data-structures/sitenova.ds.js'; | ||
| import { | ||
| SitenovaConnectionForSiteRuntimeRO, | ||
| SitenovaPublicReadValidationRO, | ||
| } from '../data-structures/sitenova-internal-responses.ds.js'; | ||
| import { SitenovaRawQueryResultRO } from '../data-structures/sitenova-responses.ds.js'; | ||
|
|
||
| export interface ISitenovaExecuteRawQuery { | ||
| execute(inputData: SitenovaExecuteRawQueryDs, inTransaction: InTransactionEnum): Promise<SitenovaRawQueryResultRO>; | ||
| } | ||
|
|
||
| export interface ISitenovaGetConnection { | ||
| execute( | ||
| inputData: SitenovaGetConnectionDs, | ||
| inTransaction: InTransactionEnum, | ||
| ): Promise<SitenovaConnectionForSiteRuntimeRO>; | ||
| } | ||
|
|
||
| export interface ISitenovaValidatePublicRead { | ||
| execute( | ||
| inputData: SitenovaValidatePublicReadDs, | ||
| inTransaction: InTransactionEnum, | ||
| ): Promise<SitenovaPublicReadValidationRO>; | ||
| } |
53 changes: 53 additions & 0 deletions
53
...c/microservices/sitenova-microservice/use-cases/sitenova-validate-public-read.use.case.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,53 @@ | ||
| import { Injectable } from '@nestjs/common'; | ||
| import AbstractUseCase from '../../../common/abstract-use.case.js'; | ||
| import { IDatabaseContext } from '../../../common/database-context.interface.js'; | ||
| import { CedarAction, PUBLIC_USER_ID } from '../../../entities/cedar-authorization/cedar-action-map.js'; | ||
| import { CedarAuthorizationService } from '../../../entities/cedar-authorization/cedar-authorization.service.js'; | ||
| import { CedarPermissionsService } from '../../../entities/cedar-authorization/cedar-permissions.service.js'; | ||
| import { SitenovaValidatePublicReadDs } from '../data-structures/sitenova.ds.js'; | ||
| import { SitenovaPublicReadValidationRO } from '../data-structures/sitenova-internal-responses.ds.js'; | ||
| import { ISitenovaValidatePublicRead } from './sitenova-use-cases.interface.js'; | ||
|
|
||
| // Bridges SitenovaPublicReadGuard's Cedar evaluation (allowed?) and the public readable-columns | ||
| // projection to the universal-backend service, which runs the actual query itself but must apply | ||
| // the exact same public-read policy the core applies on its own /sitenova data routes. | ||
| @Injectable() | ||
| export class SitenovaValidatePublicReadUseCase | ||
| extends AbstractUseCase<SitenovaValidatePublicReadDs, SitenovaPublicReadValidationRO> | ||
| implements ISitenovaValidatePublicRead | ||
| { | ||
| protected _dbContext: IDatabaseContext | null = null; | ||
|
|
||
| constructor( | ||
| private readonly cedarAuthService: CedarAuthorizationService, | ||
| private readonly cedarPermissions: CedarPermissionsService, | ||
| ) { | ||
| super(); | ||
| } | ||
|
Comment on lines
+1
to
+26
|
||
|
|
||
| protected async implementation(inputData: SitenovaValidatePublicReadDs): Promise<SitenovaPublicReadValidationRO> { | ||
| const { connectionId, tableName, columnNames } = inputData; | ||
|
|
||
| const publicEnabled = await this.cedarAuthService.isPublicAccessEnabled(connectionId); | ||
| if (!publicEnabled) { | ||
| return { allowed: false, readableColumns: null }; | ||
| } | ||
| const allowed = await this.cedarAuthService.validate({ | ||
| userId: PUBLIC_USER_ID, | ||
| action: CedarAction.TableQuery, | ||
| connectionId, | ||
| tableName, | ||
| publicAccess: true, | ||
| }); | ||
| if (!allowed) { | ||
| return { allowed: false, readableColumns: null }; | ||
| } | ||
|
|
||
| let readableColumns: Array<string> | null = null; | ||
| if (columnNames && columnNames.length > 0) { | ||
| const readable = await this.cedarPermissions.getReadableColumnsForPublic(connectionId, tableName, columnNames); | ||
| readableColumns = columnNames.filter((columnName) => readable.has(columnName)); | ||
| } | ||
| return { allowed: true, readableColumns }; | ||
| } | ||
| } | ||
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.
🔒 Security & Privacy | 🔴 Critical | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: rocket-admin/rocketadmin
Length of output: 50381
🏁 Script executed:
Repository: rocket-admin/rocketadmin
Length of output: 18051
🏁 Script executed:
Repository: rocket-admin/rocketadmin
Length of output: 50380
IDOR (CWE-639): Authorization Bypass Through User-Controlled Key (IDOR)
Reachability: External
Reachability path
Add connection-level authorization to the SitNova connection-credentials endpoint.
SaaSAuthMiddlewareonly checks the microservice JWT and acceptsrequest_id; it does not scope the request to a connection or tenant.getConnection()passes the caller-controlledconnectionIddirectly tofindAndDecryptConnection(), then returns decrypted credentials and the HS256 signing key. Require an explicitconnections[*]/service authorization claim or a matching connection guard before returning connection secrets.🤖 Prompt for AI Agents