-
Notifications
You must be signed in to change notification settings - Fork 174
ROX-13326: Use UUID columns for roles, permissionsets and simpleaccessscopes (PermissionSet and SimpleAccessScope identifiers) in postgres mode. #3725
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
Merged
rhybrillou
merged 10 commits into
yann/ROX-13326-use_uuids_for_role_internals
from
yann/ROX-13326-role_ids_as_uuids
Nov 17, 2022
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d9abd0a
ROX-13326: Use UUID columns for roles, permissionsets and simpleacces…
dashrews78 53ded04
Add full migration test
rhybrillou ae6397c
Style fixes
rhybrillou c8d861e
Extend test to validate UUID access scope and permission set identifi…
rhybrillou 85c6d50
Fix migrator build issues
rhybrillou 1b76b83
Refine migrator test
rhybrillou 49588ae
Type management fixes
rhybrillou 1d580ea
Fix test
rhybrillou a4c6ba5
ROX-13326: Access control UUID support in the UI (#3818)
rhybrillou 78f731f
Address review comment
rhybrillou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| package role | ||
|
|
||
| // postgres ID for default sccess scopes | ||
| // Postgres IDs for access scopes | ||
| // The values are UUIDs taken in descending order from ffffffff-ffff-fff4-f5ff-ffffffffffff | ||
| // Next ID: ffffffff-ffff-fff4-f5ff-fffffffffffd | ||
| const ( | ||
| denyAllAccessScopeID = "ffffffff-ffff-fff4-f5ff-fffffffffffe" | ||
| unrestrictedAccessScopeID = "ffffffff-ffff-fff4-f5ff-ffffffffffff" | ||
| denyAllAccessScopeID = "ffffffff-ffff-fff4-f5ff-fffffffffffe" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| package postgres | ||
|
|
||
| //go:generate pg-table-bindings-wrapper --type=storage.PermissionSet --migration-seq 37 --migrate-from rocksdb | ||
| //go:generate pg-table-bindings-wrapper --type=storage.PermissionSet | ||
| // To regenerate migration, add: | ||
| // --migration-seq 37 --migrate-from rocksdb | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| package rocksdb | ||
|
|
||
| //go:generate rocksdb-bindings-wrapper --type=PermissionSet --bucket=permission_sets --cache --uniq-key-func GetName() --migration-seq 37 --migrate-to permission_sets | ||
| //go:generate rocksdb-bindings-wrapper --type=PermissionSet --bucket=permission_sets --cache --uniq-key-func GetName() | ||
| // To regenerate migration, add: | ||
| // --migration-seq 37 --migrate-to permission_sets |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| package postgres | ||
|
|
||
| //go:generate pg-table-bindings-wrapper --type=storage.Role --migration-seq 46 --migrate-from rocksdb | ||
| //go:generate pg-table-bindings-wrapper --type=storage.Role | ||
| // To regenerate migration, add: | ||
| // --migration-seq 46 --migrate-from rocksdb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| package rocksdb | ||
|
|
||
| //go:generate rocksdb-bindings-wrapper --type=Role --bucket=roles --cache --key-func GetName() --migration-seq 46 --migrate-to roles | ||
| //go:generate rocksdb-bindings-wrapper --type=Role --bucket=roles --cache --key-func GetName() | ||
| // To regenerate migration, add: | ||
| // --migration-seq 46 --migrate-to roles |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| package postgres | ||
|
|
||
| //go:generate pg-table-bindings-wrapper --type=storage.SimpleAccessScope --migration-seq 52 --migrate-from rocksdb | ||
| //go:generate pg-table-bindings-wrapper --type=storage.SimpleAccessScope | ||
| // To regenerate migration, add: | ||
| // --migration-seq 52 --migrate-from rocksdb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| package rocksdb | ||
|
|
||
| //go:generate rocksdb-bindings-wrapper --type=SimpleAccessScope --bucket=simple_access_scopes --cache --uniq-key-func GetName() --migration-seq 52 --migrate-to simple_access_scopes | ||
| //go:generate rocksdb-bindings-wrapper --type=SimpleAccessScope --bucket=simple_access_scopes --cache --uniq-key-func GetName() | ||
| // To regenerate migration, add: | ||
| // --migration-seq 52 --migrate-to simple_access_scopes |
60 changes: 6 additions & 54 deletions
60
migrator/migrations/n_37_to_n_38_postgres_permission_sets/migration.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,76 +1,28 @@ | ||
| // Code generated by pg-bindings generator. DO NOT EDIT. | ||
rhybrillou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| package n37ton38 | ||
|
|
||
| import ( | ||
| "context" | ||
| // Code generation from pg-bindings generator disabled. To re-enable, check the gen.go file in | ||
| // central/role/store/permissionset/postgres | ||
|
|
||
| "github.com/jackc/pgx/v4/pgxpool" | ||
| "github.com/pkg/errors" | ||
| import ( | ||
| "github.com/stackrox/rox/generated/storage" | ||
| "github.com/stackrox/rox/migrator/migrations" | ||
| "github.com/stackrox/rox/migrator/migrations/loghelper" | ||
| legacy "github.com/stackrox/rox/migrator/migrations/n_37_to_n_38_postgres_permission_sets/legacy" | ||
| pgStore "github.com/stackrox/rox/migrator/migrations/n_37_to_n_38_postgres_permission_sets/postgres" | ||
| "github.com/stackrox/rox/migrator/types" | ||
| pkgMigrations "github.com/stackrox/rox/pkg/migrations" | ||
| pkgSchema "github.com/stackrox/rox/pkg/postgres/schema" | ||
| "github.com/stackrox/rox/pkg/sac" | ||
| "gorm.io/gorm" | ||
| ) | ||
|
|
||
| var ( | ||
| migration = types.Migration{ | ||
| StartingSeqNum: pkgMigrations.CurrentDBVersionSeqNumWithoutPostgres() + 37, | ||
| VersionAfter: &storage.Version{SeqNum: int32(pkgMigrations.CurrentDBVersionSeqNumWithoutPostgres()) + 38}, | ||
| Run: func(databases *types.Databases) error { | ||
| legacyStore, err := legacy.New(databases.PkgRocksDB) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if err := move(databases.GormDB, databases.PostgresDB, legacyStore); err != nil { | ||
| return errors.Wrap(err, | ||
| "moving permission_sets from rocksdb to postgres") | ||
| } | ||
| // The data migration code was moved to the simpleaccessscope migrator. | ||
| // The goal is to be able to convert the IDs that do not parse as UUIDs to proper UUID values, | ||
| // and still be able to convert the references in the roles table. | ||
| return nil | ||
| }, | ||
| } | ||
| batchSize = 10000 | ||
| schema = pkgSchema.PermissionSetsSchema | ||
| log = loghelper.LogWrapper{} | ||
| ) | ||
|
|
||
| func move(gormDB *gorm.DB, postgresDB *pgxpool.Pool, legacyStore legacy.Store) error { | ||
| ctx := sac.WithAllAccess(context.Background()) | ||
| store := pgStore.New(postgresDB) | ||
| pkgSchema.ApplySchemaForTable(context.Background(), gormDB, schema.Table) | ||
| var permissionSets []*storage.PermissionSet | ||
| err := walk(ctx, legacyStore, func(obj *storage.PermissionSet) error { | ||
| permissionSets = append(permissionSets, obj) | ||
| if len(permissionSets) == batchSize { | ||
| if err := store.UpsertMany(ctx, permissionSets); err != nil { | ||
| log.WriteToStderrf("failed to persist permission_sets to store %v", err) | ||
| return err | ||
| } | ||
| permissionSets = permissionSets[:0] | ||
| } | ||
| return nil | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if len(permissionSets) > 0 { | ||
| if err = store.UpsertMany(ctx, permissionSets); err != nil { | ||
| log.WriteToStderrf("failed to persist permission_sets to store %v", err) | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func walk(ctx context.Context, s legacy.Store, fn func(obj *storage.PermissionSet) error) error { | ||
| return s.Walk(ctx, fn) | ||
| } | ||
|
|
||
| func init() { | ||
| migrations.MustRegisterMigration(migration) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't understand what this change will do. Can you explain it to me?
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.
the
--migration-seqcommand line parameter allows the generation of then_...data migration files.As the migration requires to process
permissionset,roleandsimpleaccessscopetogether in order to reconcile the non-uuid identifiers, the current migration code generation cannot be used.As an example, the
Adminrole uses theadminpermission set and theunrestrictedaccess scope. The migration will have to replaceadminwith the same permission set identifier value in bothpermission_setsand therolestables, as well as theunrestrictedwith the same access scope identifier value in bothsimple_access_scopesandrolestables.The generated code for
permissionsetandroleis moved to thesimpleaccessscopesmigration file.