-
Notifications
You must be signed in to change notification settings - Fork 13.8k
feat: classification banners for ABAC rooms #41307
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
43 commits
Select commit
Hold shift + click to select a range
e0cfef1
feat: add ABAC classification banner engine
KevLehman 189dd75
feat: add ABAC classification banner settings, endpoint and schema docs
KevLehman f60109a
feat: render classification banner in ABAC rooms
KevLehman 7228534
feat: add classification banner config builder page
KevLehman 6062f07
chore: add changeset for ABAC classification banners
KevLehman c20d819
feat: move classification banner settings into their own ABAC accordion
KevLehman 7c24288
feat: improve classification banner builder UX
KevLehman 1deeb28
feat: dark mode for classification banner builder
KevLehman af44b0b
feat: align banner builder palettes with Fuselage theme tokens
KevLehman 0020520
refactor: remove banner position option, banner always renders above …
KevLehman 505f814
chore: sync banner builder with position removal
KevLehman 4066893
chore: sync banner builder UX fixes
KevLehman bcd31d4
refactor!: rank banner values most restrictive first (index 0 = highest)
KevLehman b50d10a
chore: sync banner builder validation panel move
KevLehman f13e6ee
chore: sync banner builder persistence and copy button change
KevLehman 647e597
chore: sync banner builder confirm modal
KevLehman d412646
chore: sync banner builder dialog centering fix
KevLehman 300c0b4
refactor: make banner config a public setting and build the banner cl…
KevLehman 1c00163
chore: sync banner builder collapsible attributes
KevLehman d54e8c2
chore: fix prettier formatting in banner engine spec
KevLehman 7a8b90a
refactor: simplify banner engine surface and reuse ABAC room hooks
KevLehman 3ba2353
refactor: style classification banner with css-in-js instead of inlin…
KevLehman a6e55a5
refactor: rename RoomLayout banner slot to classificationBanner
KevLehman 26f27a0
chore: sync banner builder engine parity
KevLehman c28c070
docs: state id/source uniqueness in the banner config schema
KevLehman b056f1c
refactor: move banner docs into the builder docs modal
KevLehman 9b094e4
refactor: extract config shape guard and fallback constants, inline r…
KevLehman 93ddf92
refactor: move banner engine into the client and drop the vendored bu…
KevLehman 7580128
refactor: trust the saved config, parse-only guard on the client
KevLehman e4607a0
style: prefer falsy length checks in banner engine
KevLehman 32f52c6
refactor: require all config fields per schema, extract documented co…
KevLehman 9b0d698
test: lock the banner config schema as the enforcement contract
KevLehman e28f700
test: document why schema spec clones via JSON round-trip
KevLehman a4ee987
test: validate banner schema with the shared rest-typings ajv instance
KevLehman 3f66514
test: express schema rejection cases as plain object literals
KevLehman 789daf1
refactor: collapse resolveColor into a single ordered find
KevLehman 4ad9c52
feat: render unmapped values of configured attributes as raw text in …
KevLehman ba115cf
order
KevLehman 0ec0412
feat: validate the classification banners config against its JSON sch…
KevLehman 20dc820
fix: address review feedback on banner contrast, keys, and test hygiene
KevLehman ba380a8
fix: ui review
dougfabris 8671417
chore: remove style values from classification schema
dougfabris 1455f76
test: match banner locator to region role and static aria-label
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,5 @@ | ||
| --- | ||
| '@rocket.chat/meteor': minor | ||
| --- | ||
|
|
||
| Adds classification banners to ABAC-managed rooms: admins can describe US-Government-style classification markings (levels, special access programs, releasability, colors) in a new JSON setting, and matching rooms display a colored classification banner above the room header for all members. |
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
146 changes: 146 additions & 0 deletions
146
apps/meteor/client/views/room/ClassificationBanner/ClassificationBanner.stories.tsx
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,146 @@ | ||
| import type { IRoom, RoomType } from '@rocket.chat/core-typings'; | ||
| import { mockAppRoot } from '@rocket.chat/mock-providers'; | ||
| import type { Meta, StoryObj } from '@storybook/react'; | ||
|
|
||
| import ClassificationBanner from './ClassificationBanner'; | ||
| import type { ClassificationBannersConfig } from './lib/types'; | ||
| import FakeRoomProvider from '../../../../tests/mocks/client/FakeRoomProvider'; | ||
| import { createFakeLicenseInfo } from '../../../../tests/mocks/data'; | ||
|
|
||
| const config: ClassificationBannersConfig = { | ||
| version: 1, | ||
| enabled: true, | ||
| banner: { | ||
| style: 'classic', | ||
| uppercase: true, | ||
| monospace: false, | ||
| delimiter: ' // ', | ||
| colorMode: 'highest', | ||
| fallbackText: 'NO CLASSIFICATION DATA', | ||
| fallbackColor: '#6C727A', | ||
| }, | ||
| attributes: [ | ||
| { | ||
| id: 'classification', | ||
| source: 'clearance.level', | ||
| label: 'Classification level', | ||
| showInBanner: true, | ||
| showLabel: false, | ||
| bannerLabel: '', | ||
| labelSeparator: '', | ||
| valueSeparator: '/', | ||
| sortAlpha: false, | ||
| groupThreshold: 0, | ||
| multipleLabel: '', | ||
| drivesColor: true, | ||
| values: [ | ||
| { source: 'TS-SCI', label: 'TOP SECRET//SCI', color: '#fce100' }, | ||
| { source: 'TS', label: 'TOP SECRET', color: '#ff8c00' }, | ||
| { source: 'S', label: 'SECRET', color: '#c8102e' }, | ||
| { source: 'C', label: 'CONFIDENTIAL', color: '#0033a0' }, | ||
| { source: 'CUI', label: 'CUI', color: '#502b85' }, | ||
| { source: 'U', label: 'UNCLASSIFIED', color: '#007a33' }, | ||
| ], | ||
| }, | ||
| { | ||
| id: 'sar', | ||
| source: 'access.programs', | ||
| label: 'Special access programs', | ||
| showInBanner: true, | ||
| showLabel: true, | ||
| bannerLabel: 'SAR', | ||
| labelSeparator: '-', | ||
| valueSeparator: '/', | ||
| sortAlpha: true, | ||
| groupThreshold: 4, | ||
| multipleLabel: 'MULTIPLE PROGRAMS', | ||
| drivesColor: false, | ||
| values: [ | ||
| { source: 'SAP-1042', label: 'APPLES', color: '#c8102e' }, | ||
| { source: 'SAP-2271', label: 'BANANAS', color: '#ff8c00' }, | ||
| { source: 'SAP-3380', label: 'ORANGES', color: '#0033a0' }, | ||
| { source: 'SAP-4419', label: 'PEACHES', color: '#007a33' }, | ||
| { source: 'SAP-5567', label: 'GRAPES', color: '#502b85' }, | ||
| ], | ||
| }, | ||
| { | ||
| id: 'relto', | ||
| source: 'dissem.relto', | ||
| label: 'Releasable to', | ||
| showInBanner: true, | ||
| showLabel: true, | ||
| bannerLabel: 'RELTO', | ||
| labelSeparator: ' ', | ||
| valueSeparator: '/', | ||
| sortAlpha: false, | ||
| groupThreshold: 0, | ||
| multipleLabel: '', | ||
| drivesColor: false, | ||
| values: [ | ||
| { source: 'USA', label: 'USA', color: '#0033a0' }, | ||
| { source: 'FVEY', label: 'FVEY', color: '#007a33' }, | ||
| { source: 'NATO', label: 'NATO', color: '#502b85' }, | ||
| ], | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const roomAttributes = [ | ||
| { key: 'clearance.level', values: ['TS'] }, | ||
| { key: 'access.programs', values: ['SAP-1042', 'SAP-2271', 'SAP-3380'] }, | ||
| { key: 'dissem.relto', values: ['USA'] }, | ||
| ]; | ||
|
|
||
| const roomArgs: Partial<IRoom> = { | ||
| _id: 'classifiedRoom', | ||
| t: 'p' as RoomType, | ||
| name: 'operation-nightingale', | ||
| fname: 'operation-nightingale', | ||
| abacAttributes: roomAttributes, | ||
| }; | ||
|
|
||
| const withBanner = (bannerConfig: ClassificationBannersConfig, room: Partial<IRoom> = roomArgs) => | ||
| mockAppRoot() | ||
| .withJohnDoe() | ||
| .withSetting('ABAC_Enabled', true) | ||
| .withSetting('ABAC_Classification_Banners_Enabled', true) | ||
| .withSetting('ABAC_Classification_Banners_Config', JSON.stringify(bannerConfig)) | ||
| .withEndpoint('GET', '/v1/licenses.info', () => ({ | ||
| license: createFakeLicenseInfo({ activeModules: ['abac'] }), | ||
| })) | ||
| .wrap((children) => <FakeRoomProvider roomOverrides={room}>{children}</FakeRoomProvider>) | ||
| .buildStoryDecorator(); | ||
|
|
||
| export default { | ||
| component: ClassificationBanner, | ||
| parameters: { | ||
| layout: 'fullscreen', | ||
| }, | ||
| decorators: [withBanner(config)], | ||
| } satisfies Meta<typeof ClassificationBanner>; | ||
|
|
||
| export const Classic: StoryObj<typeof ClassificationBanner> = {}; | ||
|
|
||
| export const TopSecret: StoryObj<typeof ClassificationBanner> = { | ||
| decorators: [withBanner(config, { ...roomArgs, abacAttributes: [{ key: 'clearance.level', values: ['TS-SCI'] }] })], | ||
| }; | ||
|
|
||
| export const Unclassified: StoryObj<typeof ClassificationBanner> = { | ||
| decorators: [withBanner(config, { ...roomArgs, abacAttributes: [{ key: 'clearance.level', values: ['U'] }] })], | ||
| }; | ||
|
|
||
| export const GroupedPrograms: StoryObj<typeof ClassificationBanner> = { | ||
| decorators: [ | ||
| withBanner(config, { | ||
| ...roomArgs, | ||
| abacAttributes: [ | ||
| { key: 'clearance.level', values: ['S'] }, | ||
| { key: 'access.programs', values: ['SAP-1042', 'SAP-2271', 'SAP-3380', 'SAP-4419', 'SAP-5567'] }, | ||
| ], | ||
| }), | ||
| ], | ||
| }; | ||
|
|
||
| export const Fallback: StoryObj<typeof ClassificationBanner> = { | ||
| decorators: [withBanner(config, { ...roomArgs, abacAttributes: [{ key: 'unmapped.attribute', values: ['whatever'] }] })], | ||
| }; |
53 changes: 53 additions & 0 deletions
53
apps/meteor/client/views/room/ClassificationBanner/ClassificationBanner.tsx
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 { Box } from '@rocket.chat/fuselage'; | ||
| import { useSetting } from '@rocket.chat/ui-contexts'; | ||
| import { useMemo } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| import { buildClassificationBanner, parseClassificationBannersConfig } from './lib/engine'; | ||
| import { useIsABACManagedRoom } from '../../admin/ABAC/hooks/useIsABACManagedRoom'; | ||
| import { useRoom } from '../contexts/RoomContext'; | ||
|
|
||
| const ClassificationBanner = () => { | ||
| const { t } = useTranslation(); | ||
| const room = useRoom(); | ||
| const isABACRoom = useIsABACManagedRoom(room); | ||
| const bannersEnabled = useSetting('ABAC_Classification_Banners_Enabled', false); | ||
| const rawConfig = useSetting('ABAC_Classification_Banners_Config', ''); | ||
| const enabled = bannersEnabled && isABACRoom; | ||
|
|
||
| const banner = useMemo(() => { | ||
| if (!enabled) { | ||
| return null; | ||
| } | ||
|
|
||
| const config = parseClassificationBannersConfig(rawConfig); | ||
| return config?.enabled ? buildClassificationBanner(config, room.abacAttributes ?? []) : null; | ||
| }, [enabled, rawConfig, room.abacAttributes]); | ||
|
|
||
| if (!banner) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <Box | ||
| role='region' | ||
| aria-live='polite' | ||
| aria-label={t('ABAC_Room_Attributes')} | ||
| {...(banner.monospace && { fontFamily: 'mono' })} | ||
| backgroundColor={banner.backgroundColor} | ||
| color={banner.color} | ||
| textTransform={banner.uppercase ? 'uppercase' : 'none'} | ||
| fontScale='c2' | ||
| height='x20' | ||
| display='flex' | ||
| alignItems='center' | ||
| justifyContent='center' | ||
| > | ||
| <Box is='span' withTruncatedText> | ||
| {banner.text} | ||
| </Box> | ||
| </Box> | ||
| ); | ||
| }; | ||
|
|
||
| export default ClassificationBanner; | ||
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 @@ | ||
| export { default } from './ClassificationBanner'; |
23 changes: 23 additions & 0 deletions
23
apps/meteor/client/views/room/ClassificationBanner/lib/colors.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,23 @@ | ||
| /** | ||
| * Picks a readable text color for a solid background fill. | ||
| * | ||
| * Computes each candidate's WCAG contrast ratio against the background (sRGB channels are | ||
| * gamma-decoded to linear light, then weighted by how strongly the eye perceives each: 21% red, | ||
| * 72% green, 7% blue) and keeps the higher-contrast one — so admins can pick any banner color | ||
| * and the label stays legible. | ||
| */ | ||
| export const readableTextColor = (hex: string): '#1F2329' | '#FFFFFF' => { | ||
|
KevLehman marked this conversation as resolved.
|
||
| const luminanceOf = (color: string): number => { | ||
| const [r, g, b] = [0, 2, 4].map((offset) => parseInt(color.replace('#', '').slice(offset, offset + 2), 16) / 255); | ||
| const linearize = (channel: number): number => (channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4); | ||
| return 0.2126 * linearize(r) + 0.7152 * linearize(g) + 0.0722 * linearize(b); | ||
| }; | ||
|
|
||
| const background = luminanceOf(hex); | ||
| const contrastWith = (ink: string): number => { | ||
| const text = luminanceOf(ink); | ||
| return (Math.max(background, text) + 0.05) / (Math.min(background, text) + 0.05); | ||
| }; | ||
|
|
||
| return contrastWith('#1F2329') >= contrastWith('#FFFFFF') ? '#1F2329' : '#FFFFFF'; | ||
| }; | ||
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.