Skip to content

Enhance dashboard resource handling and improve cedar schema validati…#1659

Merged
Artuomka merged 4 commits intomainfrom
backend_extend_cedar_permissions
Mar 11, 2026
Merged

Enhance dashboard resource handling and improve cedar schema validati…#1659
Artuomka merged 4 commits intomainfrom
backend_extend_cedar_permissions

Conversation

@Artuomka
Copy link
Collaborator

…on error reporting

Copilot AI review requested due to automatic review settings March 11, 2026 12:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates Cedar authorization behavior around dashboard resources and improves Cedar schema validation error reporting in the backend authorization service.

Changes:

  • Adjusts how the Cedar resource type/id is derived for dashboard:* actions, with special handling for dashboard:create.
  • Enhances Cedar schema validation by checking the cedar-wasm isAuthorized result and surfacing validation errors as a 400 Bad Request.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +67 to +72
if (action === CedarAction.DashboardCreate) {
resourceType = CedarResourceType.Connection;
resourceId = connectionId;
} else {
if (!dashboardId) return false;
resourceType = CedarResourceType.Dashboard;
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.

For dashboard:create, this maps the resource to CedarResourceType.Connection, but the Cedar schema currently declares dashboard:create applies to resourceTypes: ['Dashboard'] (see cedar-schema.ts around the dashboard:create action). With Cedar enabled, isAuthorized will treat this as a schema mismatch and evaluate() will return false, causing dashboard creation to be forbidden (no legacy fallback in DashboardCreateGuard). Align the resource type/id mapping with the schema (either keep Dashboard here, or update the schema/action definition and any related entity-building/policies to make dashboard:create a Connection-scoped action).

Suggested change
if (action === CedarAction.DashboardCreate) {
resourceType = CedarResourceType.Connection;
resourceId = connectionId;
} else {
if (!dashboardId) return false;
resourceType = CedarResourceType.Dashboard;
resourceType = CedarResourceType.Dashboard;
if (action === CedarAction.DashboardCreate) {
resourceId = connectionId;
} else {
if (!dashboardId) return false;

Copilot uses AI. Check for mistakes.
Comment on lines +166 to +168
const errors = (result as unknown as { type: string; errors: string[] }).errors ?? [];
throw new HttpException(
{ message: `Invalid cedar schema: ${errors.join('; ') || 'unknown validation error'}` },
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.
@Artuomka Artuomka disabled auto-merge March 11, 2026 12:58
@Artuomka Artuomka enabled auto-merge March 11, 2026 15:06
@Artuomka Artuomka merged commit 772a995 into main Mar 11, 2026
17 of 19 checks passed
@Artuomka Artuomka deleted the backend_extend_cedar_permissions branch March 11, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants