Skip to content
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

Align sync pattern between users/groups #414

Merged
merged 2 commits into from
Oct 12, 2021
Merged

Align sync pattern between users/groups #414

merged 2 commits into from
Oct 12, 2021

Conversation

BruceMacD
Copy link
Collaborator

@BruceMacD BruceMacD commented Oct 7, 2021

Closes:
#363 Align user/group sync patterns
#389 primary key required error no longer occurs when there are no inactive groups
#417 general supportability refactoring

Partially addresses:
#241 User/group mappings are built incrementally at runtime after an initial clear on config import

This change brings users/groups into the same pattern which does not create the entity until it is found at the source, then a config import finds the relevant role bindings.

Changes:

  • remove direct group assignment to users in config
  • only create group when it is active at the source
  • reimport config on group creation
  • update tests
  • clear role, users, and groups on first config application
  • wrap sync errors with context
  • make sync its own function
  • time sync events

@BruceMacD BruceMacD requested a review from ssoroka October 7, 2021 19:12
@@ -61,10 +61,6 @@ groups:
- name: cluster-CCC

users:
- email: woz@example.com
groups:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Assigning groups declared in config directly to users is confusing. This was an artifact of adding groups functions before the feature of synchronizing them from the source, removing this functionality.

@@ -174,29 +176,7 @@ func ApplyUserMapping(db *gorm.DB, users []ConfigUserMapping) error {
return usrReadErr
}

// add the user to groups, these declarations can be overridden by external group syncing
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This allowed for adding users declared in config to groups, this feature doesnt make sense anymore

@@ -248,14 +205,36 @@ func ImportConfig(db *gorm.DB, bs []byte) error {
initialConfig = config

return db.Transaction(func(tx *gorm.DB) error {
// gorm blocks global delete by default: https://gorm.io/docs/delete.html#Block-Global-Delete
if err := tx.Where("1 = 1").Delete(&Role{}).Error; err != nil {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried the drop/create table method here instead, but it didn't re-create the relational tables. This only runs on initial config import.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be deleting all rows here vs selectively adding/removing rows? (some of the thinking behind #241)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I could switch to that for sure. My opinion here was that it is less complex to just clear configuration on import (which only happens on start-up) where we want the state to exactly match the config anyway. I can see that building the database back on initial sync is a bit of a pain though.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see what protects it from running multiple times in the registry.go Run()

@@ -209,43 +185,6 @@ func TestExistingSourceIsOverridden(t *testing.T) {
assert.Equal(t, fakeOktaSource.Domain, importedOkta.Domain)
}

func containsUserRoleForDestination(db *gorm.DB, user User, destinationId string, roleName string) (bool, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

just moved this to the end of the file

- remove direct group assignment to users in config
- only create group when it is active at the source
- reimport config on group creation
- update tests
- clear role, users, and groups on first config application
- wrap sync errors with context
- make sync its own function
- time sync events
@@ -248,14 +205,36 @@ func ImportConfig(db *gorm.DB, bs []byte) error {
initialConfig = config

return db.Transaction(func(tx *gorm.DB) error {
// gorm blocks global delete by default: https://gorm.io/docs/delete.html#Block-Global-Delete
if err := tx.Where("1 = 1").Delete(&Role{}).Error; err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see what protects it from running multiple times in the registry.go Run()

if err != nil {
return err

if err := tx.Model(&group).Association("Users").Replace(users); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

this needs a len() check and a clear for the zero case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, I tested this one with an empty list and it's ok in this case

@BruceMacD
Copy link
Collaborator Author

BruceMacD commented Oct 10, 2021

@ssoroka
For some reason I can't reply to your comment about ImportConfig being called multiple times in registry.go. Are you thinking that someone could run infra registry and the tables being dropped would cause some issues?

Edit: I get what you mean now, I'm going to leave #241 open and address incrementally building configuration for that ticket. That way this function would be safe to call anywhere.

@BruceMacD BruceMacD merged commit 13e1407 into main Oct 12, 2021
@BruceMacD BruceMacD deleted the align-sync-pattern branch October 12, 2021 14:10
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.

3 participants