-
-
Notifications
You must be signed in to change notification settings - Fork 18
migrate permissions to Cedar during application bootstrap #1653
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ export async function migratePermissionsToCedar(dataSource: DataSource): Promise | |
| .leftJoinAndSelect('group.connection', 'connection') | ||
| .leftJoinAndSelect('group.permissions', 'permission') | ||
| .where('connection.id = :connectionId', { connectionId: connection.id }) | ||
| .andWhere('(group.cedarPolicy IS NULL OR group.cedarPolicy = :empty)', { empty: '' }) | ||
| .getMany(); | ||
|
|
||
| for (const group of groups) { | ||
|
|
@@ -61,5 +62,5 @@ export async function migratePermissionsToCedar(dataSource: DataSource): Promise | |
| } | ||
| } | ||
|
|
||
| console.log(`Migrated Cedar policies for ${migratedCount} groups`); | ||
| console.log(`Migrated Cedar policies for ${migratedCount} groups (skipped groups with existing policies)`); | ||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,9 @@ import bodyParser from 'body-parser'; | |||||||||
| import { ValidationError } from 'class-validator'; | ||||||||||
| import cookieParser from 'cookie-parser'; | ||||||||||
| import helmet from 'helmet'; | ||||||||||
| import { DataSource } from 'typeorm'; | ||||||||||
| import { ApplicationModule } from './app.module.js'; | ||||||||||
| import { migratePermissionsToCedar } from './entities/cedar-authorization/scripts/migrate-permissions-to-cedar.js'; | ||||||||||
| import { WinstonLogger } from './entities/logging/winston-logger.js'; | ||||||||||
| import { AllExceptionsFilter } from './exceptions/all-exceptions.filter.js'; | ||||||||||
| import { ValidationException } from './exceptions/custom-exceptions/validation-exception.js'; | ||||||||||
|
|
@@ -82,6 +84,9 @@ async function bootstrap() { | |||||||||
| }), | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| const dataSource = app.get(DataSource); | ||||||||||
| await migratePermissionsToCedar(dataSource); | ||||||||||
|
||||||||||
| await migratePermissionsToCedar(dataSource); | |
| if (process.env.CEDAR_MIGRATION_ON_BOOT !== 'false') { | |
| await migratePermissionsToCedar(dataSource); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that this script runs during normal bootstrap, the migration approach can become a startup bottleneck: it loads groups per connection and then persists each group one-by-one. Consider reducing round-trips (e.g., query all groups needing migration in one pass, batch updates, and prefer
updateoncedarPolicyrather thansaveon fully loaded entities) to keep startup time predictable for large datasets.