Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
samteb committed Feb 16, 2024
1 parent 1613593 commit a9d1ada
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 61 deletions.
63 changes: 63 additions & 0 deletions apps/authz/src/opa/template/meta-permissions.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Action, EntityType, UserRole } from '@narval/authz-shared'
import { Criterion, Policy, Then } from '../../shared/types/policy.type'

const metaPermissions = [
Action.CREATE_ORGANIZATION,
Action.CREATE_USER,
Action.UPDATE_USER,
Action.CREATE_CREDENTIAL,
Action.ASSIGN_USER_GROUP,
Action.ASSIGN_WALLET_GROUP,
Action.ASSIGN_USER_WALLET,
Action.DELETE_USER,
Action.REGISTER_WALLET,
Action.CREATE_ADDRESS_BOOK_ACCOUNT,
Action.EDIT_WALLET,
Action.UNASSIGN_WALLET,
Action.REGISTER_TOKENS,
Action.EDIT_USER_GROUP,
Action.DELETE_USER_GROUP,
Action.CREATE_WALLET_GROUP,
Action.DELETE_WALLET_GROUP
]

export const permitMetaPermission: Policy = {
name: 'permitMetaPermission',
when: [
{
criterion: Criterion.CHECK_ACTION,
args: metaPermissions
},
{
criterion: Criterion.CHECK_PRINCIPAL_ROLE,
args: [UserRole.ADMIN]
},
{
criterion: Criterion.CHECK_APPROVALS,
args: [
{
approvalCount: 2,
countPrincipal: false,
approvalEntityType: EntityType.UserRole,
entityIds: [UserRole.ADMIN, UserRole.ROOT]
}
]
}
],
then: Then.PERMIT
}

export const forbidMetaPermission: Policy = {
name: 'forbidMetaPermission',
when: [
{
criterion: Criterion.CHECK_ACTION,
args: metaPermissions
},
{
criterion: Criterion.CHECK_PRINCIPAL_ROLE,
args: [UserRole.ADMIN]
}
],
then: Then.FORBID
}
61 changes: 0 additions & 61 deletions apps/authz/src/opa/template/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,64 +114,3 @@ export const exampleForbidPolicy: Policy = {
export const policies = {
policies: [examplePermitPolicy, exampleForbidPolicy]
}

const metaPermissions = [
Action.CREATE_ORGANIZATION,
Action.CREATE_USER,
Action.UPDATE_USER,
Action.CREATE_CREDENTIAL,
Action.ASSIGN_USER_GROUP,
Action.ASSIGN_WALLET_GROUP,
Action.ASSIGN_USER_WALLET,
Action.DELETE_USER,
Action.REGISTER_WALLET,
Action.CREATE_ADDRESS_BOOK_ACCOUNT,
Action.EDIT_WALLET,
Action.UNASSIGN_WALLET,
Action.REGISTER_TOKENS,
Action.EDIT_USER_GROUP,
Action.DELETE_USER_GROUP,
Action.CREATE_WALLET_GROUP,
Action.DELETE_WALLET_GROUP
]

export const permitMetaPermission: Policy = {
name: 'permitMetaPermission',
when: [
{
criterion: Criterion.CHECK_ACTION,
args: metaPermissions
},
{
criterion: Criterion.CHECK_PRINCIPAL_ROLE,
args: [UserRole.ADMIN]
},
{
criterion: Criterion.CHECK_APPROVALS,
args: [
{
approvalCount: 2,
countPrincipal: false,
approvalEntityType: EntityType.UserRole,
entityIds: [UserRole.ADMIN, UserRole.ROOT]
}
]
}
],
then: Then.PERMIT
}

export const forbidMetaPermission: Policy = {
name: 'forbidMetaPermission',
when: [
{
criterion: Criterion.CHECK_ACTION,
args: metaPermissions
},
{
criterion: Criterion.CHECK_PRINCIPAL_ROLE,
args: [UserRole.ADMIN]
}
],
then: Then.FORBID
}

0 comments on commit a9d1ada

Please sign in to comment.