Skip to content

Commit 5ed8cdb

Browse files
committed
RBAC plugin: authenticateAuthorize* accepts array resources
Widen check.resource on the convenience methods to RbacResource | RbacResource[] so they match RbacAbility.can. Previously the interface declared only RbacResource on these methods, which left an inconsistency — anyone wanting to pass an array of resources had to call authenticateBearer + ability.can manually instead of using the convenience method. Surfaced when reviewing the cloud enterprise controller (TRI-8720), which had unilaterally widened its implementation to RbacResource[] and would have failed type-check if any caller routed an array through the typed interface. Updated: - packages/plugins/src/rbac.ts — RoleBaseAccessController interface. - internal-packages/rbac/src/fallback.ts — RoleBaseAccessFallback matches. - LazyController already uses Parameters<...> and tracks the interface, so it picks up the change automatically. @trigger.dev/plugins gets a minor bump (changeset added). Verification: - pnpm run typecheck across @trigger.dev/plugins, @trigger.dev/rbac, webapp — clean. - pnpm run test --filter @internal/rbac — 31 unit tests pass. - e2e suite unaffected (no signature change at runtime — pure type widening).
1 parent a9cb0e7 commit 5ed8cdb

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/plugins": minor
3+
---
4+
5+
RBAC plugin: `RoleBaseAccessController.authenticateAuthorizeBearer` and `authenticateAuthorizeSession` now accept `RbacResource | RbacResource[]` for `check.resource`, matching `RbacAbility.can`. This was an inconsistency — abilities accepted arrays but the convenience methods didn't, so callers wanting the array form had to call `authenticateBearer` + `ability.can` manually.

internal-packages/rbac/src/fallback.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class RoleBaseAccessFallbackController implements RoleBaseAccessController {
131131

132132
async authenticateAuthorizeBearer(
133133
request: Request,
134-
check: { action: string; resource: RbacResource },
134+
check: { action: string; resource: RbacResource | RbacResource[] },
135135
options?: { allowJWT?: boolean }
136136
): Promise<BearerAuthResult> {
137137
const auth = await this.authenticateBearer(request, options);
@@ -145,7 +145,7 @@ class RoleBaseAccessFallbackController implements RoleBaseAccessController {
145145
async authenticateAuthorizeSession(
146146
request: Request,
147147
context: { organizationId?: string; projectId?: string },
148-
check: { action: string; resource: RbacResource }
148+
check: { action: string; resource: RbacResource | RbacResource[] }
149149
): Promise<SessionAuthResult> {
150150
const auth = await this.authenticateSession(request, context);
151151
if (!auth.ok) return auth;

packages/plugins/src/rbac.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,19 @@ export interface RoleBaseAccessController {
7979
context: { organizationId?: string; projectId?: string }
8080
): Promise<SessionAuthResult>;
8181

82-
// Convenience: authenticate + ability.can() check in one call; returns ok:false if check fails
82+
// Convenience: authenticate + ability.can() check in one call; returns ok:false if check fails.
83+
// resource accepts the same single-or-array shape as RbacAbility.can — array form means
84+
// "grant access if any element passes".
8385
authenticateAuthorizeBearer(
8486
request: Request,
85-
check: { action: string; resource: RbacResource },
87+
check: { action: string; resource: RbacResource | RbacResource[] },
8688
options?: { allowJWT?: boolean }
8789
): Promise<BearerAuthResult>;
8890

8991
authenticateAuthorizeSession(
9092
request: Request,
9193
context: { organizationId?: string; projectId?: string },
92-
check: { action: string; resource: RbacResource }
94+
check: { action: string; resource: RbacResource | RbacResource[] }
9395
): Promise<SessionAuthResult>;
9496

9597
// Role introspection (enterprise: DB-backed; OSS: returns [])

0 commit comments

Comments
 (0)