Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ export class CedarAuthorizationService implements ICedarAuthorizationService, On
resourceType = CedarResourceType.Table;
resourceId = `${connectionId}/${tableName}`;
break;
case 'dashboard':
case 'dashboard': {
resourceType = CedarResourceType.Dashboard;
resourceId = `${connectionId}/${dashboardId}`;
break;
const needsSentinel = action === CedarAction.DashboardCreate || !dashboardId;
const effectiveDashboardId = needsSentinel ? '__new__' : dashboardId;
resourceId = `${connectionId}/${effectiveDashboardId}`;
return this.evaluate(userId, connectionId, action, resourceType, resourceId, tableName, effectiveDashboardId);
}
default:
return false;
}
Expand Down Expand Up @@ -155,8 +158,16 @@ export class CedarAuthorizationService implements ICedarAuthorizationService, On
entities: [],
schema: schema,
};
cedarWasm.isAuthorized(testCall as Parameters<typeof cedarWasm.isAuthorized>[0]);
const result = cedarWasm.isAuthorized(testCall as Parameters<typeof cedarWasm.isAuthorized>[0]);
if (result.type !== 'success') {
const errors = (result as unknown as { type: string; errors: string[] }).errors ?? [];
throw new HttpException(
{ message: `Invalid cedar schema: ${errors.join('; ') || 'unknown validation error'}` },
Comment on lines +163 to +165
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors.join('; ') assumes result.errors is a string[], but elsewhere (evaluate) the code treats result.errors as a structured value and logs it via JSON.stringify. If errors is an array of objects (common for wasm error diagnostics), this will produce unhelpful output like [object Object]. Consider extracting a readable message (e.g., map each error to error.message when present, otherwise JSON.stringify(error)), and avoid the unsafe cast by narrowing on 'errors' in result or using the cedar-wasm result types.

Suggested change
const errors = (result as unknown as { type: string; errors: string[] }).errors ?? [];
throw new HttpException(
{ message: `Invalid cedar schema: ${errors.join('; ') || 'unknown validation error'}` },
const rawErrors =
'errors' in result && Array.isArray((result as any).errors)
? (result as any).errors
: [];
const errorMessages = rawErrors.map((err: unknown) => {
if (typeof err === 'string') {
return err;
}
if (err && typeof err === 'object' && 'message' in err && typeof (err as any).message === 'string') {
return (err as any).message;
}
try {
return JSON.stringify(err);
} catch {
return String(err);
}
});
throw new HttpException(
{
message: `Invalid cedar schema: ${
errorMessages.length > 0 ? errorMessages.join('; ') : 'unknown validation error'
}`,
},

Copilot uses AI. Check for mistakes.
HttpStatus.BAD_REQUEST,
);
}
} catch (e) {
if (e instanceof HttpException) throw e;
throw new HttpException({ message: `Invalid cedar schema: ${e.message}` }, HttpStatus.BAD_REQUEST);
}
}
Expand Down
18 changes: 15 additions & 3 deletions backend/src/entities/cedar-authorization/cedar-policy-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,20 @@ export function generateCedarPolicyForGroup(
}

if (permissions.dashboards) {
let hasCreatePermission = false;
let hasReadPermission = false;
for (const dashboard of permissions.dashboards) {
const dashboardRef = `RocketAdmin::Dashboard::"${connectionId}/${dashboard.dashboardId}"`;
const access = dashboard.accessLevel;

if (access.read) {
hasReadPermission = true;
policies.push(
`permit(\n principal in ${groupRef},\n action == RocketAdmin::Action::"dashboard:read",\n resource == ${dashboardRef}\n);`,
);
}
if (access.create) {
policies.push(
`permit(\n principal in ${groupRef},\n action == RocketAdmin::Action::"dashboard:create",\n resource == ${dashboardRef}\n);`,
);
hasCreatePermission = true;
}
if (access.edit) {
policies.push(
Expand All @@ -75,6 +76,17 @@ export function generateCedarPolicyForGroup(
);
}
}
const newDashboardRef = `RocketAdmin::Dashboard::"${connectionId}/__new__"`;
if (hasReadPermission) {
policies.push(
`permit(\n principal in ${groupRef},\n action == RocketAdmin::Action::"dashboard:read",\n resource == ${newDashboardRef}\n);`,
);
}
if (hasCreatePermission) {
policies.push(
`permit(\n principal in ${groupRef},\n action == RocketAdmin::Action::"dashboard:create",\n resource == ${newDashboardRef}\n);`,
);
}
}

for (const table of permissions.tables) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ test('dashboard with read=true generates only dashboard:read', (t) => {
t.false(result.includes('dashboard:edit'));
t.false(result.includes('dashboard:delete'));
const permits = result.match(/permit\(/g);
t.is(permits.length, 1);
t.is(permits.length, 2); // dash-1 read + __new__ read
});

test('dashboard with all flags true generates dashboard:read + dashboard:create + dashboard:edit + dashboard:delete', (t) => {
Expand All @@ -253,7 +253,7 @@ test('dashboard with all flags true generates dashboard:read + dashboard:create
t.true(result.includes('dashboard:edit'));
t.true(result.includes('dashboard:delete'));
const permits = result.match(/permit\(/g);
t.is(permits.length, 4);
t.is(permits.length, 5); // dash-1: read + edit + delete, __new__: read + create
});

test('dashboard with all flags false generates no policies for that dashboard', (t) => {
Expand Down
5 changes: 2 additions & 3 deletions backend/test/ava-tests/saas-tests/connection-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,9 @@ test.serial(`${currentTest} should return all connection users from different gr
const foundUsersRO = JSON.parse(findAllUsersResponse.text);
t.is(foundUsersRO.length, 2);

// t.is(foundUsersRO[0].isActive, false);
t.is(foundUsersRO[1].isActive, true);
t.is(Object.hasOwn(foundUsersRO[1], 'email'), true);
t.true(foundUsersRO.some((u: { isActive: boolean }) => u.isActive === true));
t.is(Object.hasOwn(foundUsersRO[0], 'email'), true);
t.is(Object.hasOwn(foundUsersRO[1], 'email'), true);
t.is(Object.hasOwn(foundUsersRO[0], 'createdAt'), true);
t.is(Object.hasOwn(foundUsersRO[1], 'createdAt'), true);

Expand Down
Loading