-
Notifications
You must be signed in to change notification settings - Fork 13.8k
feat(apps): Expose abacAttributes for apps
#40463
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
Show all changes
23 commits
Select commit
Hold shift + click to select a range
7c78fae
types
KevLehman 50f5266
type
KevLehman 185fb2e
clank
KevLehman 856c281
msgpack
KevLehman c2388d5
Update packages/apps/src/server/permissions/AppPermissions.ts
KevLehman c3f6ac4
Update packages/apps/src/server/runtime/deno/AppsEngineDenoRuntime.ts
KevLehman 8999a6c
Create pink-moons-cheer.md
KevLehman b622395
update leak
KevLehman 9526c68
lint
KevLehman 6b13d57
draft: secure fields example
d-gubert b45cdc8
missing apps codec change
d-gubert 34e4fc4
refactor: polish types
d-gubert f1e1e38
doug
KevLehman 96d524a
fixes
KevLehman b6d6c3d
fix: msgpack issues
d-gubert 9fb5256
fix: type definition
d-gubert 5b107dd
refactor: simplify validation
d-gubert 3760eab
test(apps): add secure fields and runtime message parsing tests
Copilot 0f19c6c
test(apps): add @@SecureFields integration tests to DenoRuntimeSubpro…
Copilot 4520998
tests: improve test cases for secure fields
d-gubert 4e5649e
timeouts
KevLehman b0d7c2d
i18n: add string for new permission
d-gubert b959f94
Merge branch 'develop' into feat/abac-attr-apps
KevLehman 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "@rocket.chat/meteor": minor | ||
| "@rocket.chat/apps-engine": minor | ||
| "@rocket.chat/apps": minor | ||
| --- | ||
|
|
||
| Allows apps with the right permission to read room's ABAC attributes. |
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
12 changes: 12 additions & 0 deletions
12
packages/apps-engine/src/definition/abac/AbacAttributes.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,12 @@ | ||
| export interface IAbacAttributeDefinition { | ||
| /** | ||
| * Validation expectation (NOT enforced here, must be enforced by caller): | ||
| * /^[A-Za-z0-9_-]+$/ | ||
| */ | ||
| key: string; | ||
|
|
||
| /** | ||
| * List of string values for this attribute key. | ||
| */ | ||
| values: string[]; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { kSecureFields, WithSecureFields } from '@rocket.chat/apps/dist/lib/SecureFields'; | ||
| import type { App } from '@rocket.chat/apps-engine/definition/App'; | ||
|
|
||
| import { AppObjectRegistry } from '../AppObjectRegistry.ts'; | ||
|
|
||
| export type { WithSecureFields } from '@rocket.chat/apps/dist/lib/SecureFields'; | ||
|
|
||
| export function applySecureFields(object: WithSecureFields<Record<string, unknown>>) { | ||
| const { [kSecureFields]: secureFields, ...rest } = object; | ||
|
|
||
| const app = AppObjectRegistry.get<App>('app'); | ||
|
|
||
| if (!app) { | ||
| throw new Error("App unavailable, can't parse object with secure fields"); | ||
| } | ||
|
|
||
| secureFields.forEach(({ permission, name, value }) => { | ||
| if (!app.getInfo().permissions?.find((p) => p.name === permission)) { | ||
| return; | ||
| } | ||
|
|
||
| rest[name] = value; | ||
| }); | ||
|
|
||
| return rest; | ||
| } | ||
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,59 @@ | ||
| import { assertEquals, assertThrows } from 'https://deno.land/std@0.203.0/assert/mod.ts'; | ||
| import { beforeEach, describe, it } from 'https://deno.land/std@0.203.0/testing/bdd.ts'; | ||
|
|
||
| import { AppObjectRegistry } from '../../AppObjectRegistry.ts'; | ||
| import { applySecureFields } from '../secureFields.ts'; | ||
|
|
||
| const SECURE_FIELDS_KEY = '@@SecureFields'; | ||
|
|
||
| describe('applySecureFields', () => { | ||
| beforeEach(() => { | ||
| AppObjectRegistry.clear(); | ||
| }); | ||
|
|
||
| it('throws when app is unavailable', () => { | ||
| assertThrows( | ||
| () => applySecureFields({ foo: 'bar', [SECURE_FIELDS_KEY]: [] } as any), | ||
| Error, | ||
| "App unavailable, can't parse object with secure fields", | ||
| ); | ||
| }); | ||
|
|
||
| it('applies only secure fields with matching permissions', () => { | ||
| AppObjectRegistry.set('app', { | ||
| getInfo: () => ({ | ||
| permissions: [{ name: 'abac.read' }], | ||
| }), | ||
| }); | ||
|
|
||
| const parsed = applySecureFields({ | ||
| foo: 'bar', | ||
| [SECURE_FIELDS_KEY]: [ | ||
| { permission: 'abac.read', name: 'abacAttributes', value: { department: 'support' } }, | ||
| { permission: 'api.read', name: 'apiToken', value: 'secret' }, | ||
| ], | ||
| } as any); | ||
|
|
||
| assertEquals(parsed, { | ||
| foo: 'bar', | ||
| abacAttributes: { department: 'support' }, | ||
| }); | ||
| }); | ||
|
|
||
| it('overwrites an existing field when permission is granted', () => { | ||
| AppObjectRegistry.set('app', { | ||
| getInfo: () => ({ | ||
| permissions: [{ name: 'abac.read' }], | ||
| }), | ||
| }); | ||
|
|
||
| const parsed = applySecureFields({ | ||
| abacAttributes: null, | ||
| [SECURE_FIELDS_KEY]: [{ permission: 'abac.read', name: 'abacAttributes', value: { tenant: 'alpha' } }], | ||
| } as any); | ||
|
|
||
| assertEquals(parsed, { | ||
| abacAttributes: { tenant: 'alpha' }, | ||
| }); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| export type SecureFieldDescriptor<T extends Record<string, unknown>, K extends keyof T> = { | ||
| permission: string; | ||
| name: K; | ||
| value: T[K]; | ||
| }; | ||
|
|
||
| export const kSecureFields = '@@SecureFields'; | ||
|
|
||
| export type WithSecureFields<T extends Record<string, unknown>> = T & { [kSecureFields]: SecureFieldDescriptor<T, keyof T>[] }; | ||
|
|
||
| export function secureFieldsMapper<T extends Record<string, unknown>>( | ||
| mapper: (object: T) => SecureFieldDescriptor<T, keyof T>[] | undefined, | ||
| ) { | ||
| return { [kSecureFields]: mapper }; | ||
| } | ||
|
|
||
| export function hasSecureFields(object: unknown): boolean { | ||
| return !!object?.[kSecureFields]; | ||
| } | ||
|
d-gubert marked this conversation as resolved.
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.