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

Implement WAL rollback mechanism for Role Assignments #110

Merged

Conversation

davidadeleon
Copy link
Contributor

Overview

Implement a rollback mechanism for Role Assignments to handle a case where on dynamic SP creation we may encounter an error and have to rollback any changes. Currently the AppID will be deleted which also removes the SP, but any successful role assignments will be orphaned. This incurs a hit against the Role Assignment limit. There is no change to the user experience.

Design of Change

Create a separate WAL where the generated UUIDs of the role assignments can be stored, and referred to if needed for rollback. Added a TRACE level log for instances where a 204 response is returned from Azure. A 204 is returned when the Role Assignment ID has already been deleted or never existed.

Test Output

❯ go test -v -run TestRoleAssignmentWALRollback
=== RUN   TestRoleAssignmentWALRollback
=== RUN   TestRoleAssignmentWALRollback/service_principals
=== PAUSE TestRoleAssignmentWALRollback/service_principals
=== CONT  TestRoleAssignmentWALRollback/service_principals
2022-11-07T13:37:24.357-0500 [DEBUG] rolling back role assignments for SP: ID=9cf990ff-39cb-4f20-b373-9afa49c9f752
2022-11-07T13:37:25.505-0500 [TRACE] role assignment already deleted or does not exist: err="error unassigning role: authorization.RoleAssignmentsClient#DeleteByID: Failure responding to request: StatusCode=204 -- Original Error: autorest/azure: error response cannot be parsed: \"\" error: EOF"
--- PASS: TestRoleAssignmentWALRollback (0.00s)
    --- PASS: TestRoleAssignmentWALRollback/service_principals (19.11s)
PASS
ok      github.com/hashicorp/vault-plugin-secrets-azure 19.352s

wal.go Show resolved Hide resolved
wal.go Outdated Show resolved Hide resolved
@calvn calvn requested a review from a team November 7, 2022 20:43
Copy link
Member

@austingebauer austingebauer left a comment

Choose a reason for hiding this comment

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

Looking good! Left a few comments.

path_service_principal_test.go Outdated Show resolved Hide resolved
client.go Show resolved Hide resolved
path_service_principal_test.go Show resolved Hide resolved
wal.go Outdated Show resolved Hide resolved
wal.go Outdated Show resolved Hide resolved
wal.go Outdated Show resolved Hide resolved
…ize mismatch between number of roles and assignmentIDs, parameterize Resource Group in test
…ead of Errorf for AzureRoles and assignmentIDs check
wal.go Show resolved Hide resolved
Copy link
Member

@austingebauer austingebauer left a comment

Choose a reason for hiding this comment

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

LGTM!

client.go Outdated Show resolved Hide resolved
@davidadeleon davidadeleon merged commit f955aed into main Nov 9, 2022
@davidadeleon davidadeleon deleted the davidadeleon/implement-wal-rollback-for-roleassignments branch November 9, 2022 20:34
jasonodonnell pushed a commit that referenced this pull request Nov 22, 2022
* Implement Role Assignment WAL and rollback

* Improve error handling around unassignment of non-existent role assignment ID

* Better error handling in test, and guarding against nil or empty values

* Add clarity to rollback log message, and check if there were no Azure Roles associated with Role

* Further improve error handling, fix failing test, add guard against size mismatch between number of roles and assignmentIDs, parameterize Resource Group in test

* Fix rollback test, and clean up left over debug line

* Add missing error check for spRevoke during test, use errors.New instead of Errorf for AzureRoles and assignmentIDs check

* Add warning about resources potentially still existing if WAL has expired
jasonodonnell pushed a commit that referenced this pull request Nov 22, 2022
* Implement Role Assignment WAL and rollback

* Improve error handling around unassignment of non-existent role assignment ID

* Better error handling in test, and guarding against nil or empty values

* Add clarity to rollback log message, and check if there were no Azure Roles associated with Role

* Further improve error handling, fix failing test, add guard against size mismatch between number of roles and assignmentIDs, parameterize Resource Group in test

* Fix rollback test, and clean up left over debug line

* Add missing error check for spRevoke during test, use errors.New instead of Errorf for AzureRoles and assignmentIDs check

* Add warning about resources potentially still existing if WAL has expired
jasonodonnell pushed a commit that referenced this pull request Nov 22, 2022
* Implement Role Assignment WAL and rollback

* Improve error handling around unassignment of non-existent role assignment ID

* Better error handling in test, and guarding against nil or empty values

* Add clarity to rollback log message, and check if there were no Azure Roles associated with Role

* Further improve error handling, fix failing test, add guard against size mismatch between number of roles and assignmentIDs, parameterize Resource Group in test

* Fix rollback test, and clean up left over debug line

* Add missing error check for spRevoke during test, use errors.New instead of Errorf for AzureRoles and assignmentIDs check

* Add warning about resources potentially still existing if WAL has expired
jasonodonnell added a commit that referenced this pull request Nov 22, 2022
* Implement Role Assignment WAL and rollback

* Improve error handling around unassignment of non-existent role assignment ID

* Better error handling in test, and guarding against nil or empty values

* Add clarity to rollback log message, and check if there were no Azure Roles associated with Role

* Further improve error handling, fix failing test, add guard against size mismatch between number of roles and assignmentIDs, parameterize Resource Group in test

* Fix rollback test, and clean up left over debug line

* Add missing error check for spRevoke during test, use errors.New instead of Errorf for AzureRoles and assignmentIDs check

* Add warning about resources potentially still existing if WAL has expired

Co-authored-by: davidadeleon <56207066+davidadeleon@users.noreply.github.com>
jasonodonnell added a commit that referenced this pull request Nov 22, 2022
* Implement Role Assignment WAL and rollback

* Improve error handling around unassignment of non-existent role assignment ID

* Better error handling in test, and guarding against nil or empty values

* Add clarity to rollback log message, and check if there were no Azure Roles associated with Role

* Further improve error handling, fix failing test, add guard against size mismatch between number of roles and assignmentIDs, parameterize Resource Group in test

* Fix rollback test, and clean up left over debug line

* Add missing error check for spRevoke during test, use errors.New instead of Errorf for AzureRoles and assignmentIDs check

* Add warning about resources potentially still existing if WAL has expired

Co-authored-by: davidadeleon <56207066+davidadeleon@users.noreply.github.com>
jasonodonnell added a commit that referenced this pull request Nov 22, 2022
* Implement Role Assignment WAL and rollback

* Improve error handling around unassignment of non-existent role assignment ID

* Better error handling in test, and guarding against nil or empty values

* Add clarity to rollback log message, and check if there were no Azure Roles associated with Role

* Further improve error handling, fix failing test, add guard against size mismatch between number of roles and assignmentIDs, parameterize Resource Group in test

* Fix rollback test, and clean up left over debug line

* Add missing error check for spRevoke during test, use errors.New instead of Errorf for AzureRoles and assignmentIDs check

* Add warning about resources potentially still existing if WAL has expired

Co-authored-by: davidadeleon <56207066+davidadeleon@users.noreply.github.com>
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.

4 participants