-
Notifications
You must be signed in to change notification settings - Fork 70
App group lifecycle plugin #351
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
Open
barborico
wants to merge
16
commits into
main
Choose a base branch
from
brynna/app_group_lifecycle_plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
506dc80
Update data model to support app group lifecycle plugins.
barborico f6d906a
Add app group lifecycle plugin spec, with unit tests.
barborico a25a214
Validate app group lifecycle plugins on Flask app startup.
barborico 7abde14
Invoke plugin hooks for group lifecycle and membership changes, prese…
barborico 73e2b61
Add new Flask CLI command to invoke periodic app group membership syn…
barborico aa09a0e
Add API support for modifying plugin config on apps and app groups, w…
barborico 0639abc
Add API endpoints to expose information about registered app group li…
barborico cc55701
Make the frontend aware of the new plugin API endpoints.
barborico 39a0144
Add frontend component to edit plugin configuration.
barborico ed1180f
Add frontend component to view plugin configuration and status.
barborico 561e469
Create example app group lifecycle plugin.
barborico 709881d
Misc cleanup: Make it easy to disable echoing of SQL queries in local…
barborico 0fa7023
Misc cleanup: Remove old print statements.
barborico 3d8926d
Misc cleanup: Fix a typo.
barborico 2ec000e
Misc cleanup: Fix typo.
barborico 00a0b8b
CI checks: Fix typo in Slack notification plugin path name, add tests…
barborico 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
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 |
|---|---|---|
|
|
@@ -10,15 +10,15 @@ | |
| OKTA_API_TOKEN = os.getenv("OKTA_API_TOKEN") | ||
| # The Group Owners API is only available to Okta plans with IGA enabled | ||
| # Disable by default, but allow opt-in to sync group owners to Okta if desired | ||
| OKTA_USE_GROUP_OWNERS_API = os.getenv("OKTA_USE_GROUP_OWNERS_API", "False") == "True" | ||
| OKTA_USE_GROUP_OWNERS_API = os.getenv("OKTA_USE_GROUP_OWNERS_API", "false").lower() == "true" | ||
| CURRENT_OKTA_USER_EMAIL = os.getenv("CURRENT_OKTA_USER_EMAIL", "[email protected]") | ||
|
|
||
| # Optional env var to set a custom Okta Group Profile attribute for Access management inclusion/exclusion | ||
| OKTA_GROUP_PROFILE_CUSTOM_ATTR = os.getenv("OKTA_GROUP_PROFILE_CUSTOM_ATTR") | ||
|
|
||
| SQLALCHEMY_DATABASE_URI = os.getenv("DATABASE_URI") | ||
| SQLALCHEMY_TRACK_MODIFICATIONS = False | ||
| SQLALCHEMY_ECHO = ENV == "development" # or ENV == "test" | ||
| SQLALCHEMY_ECHO = os.getenv("SQLALCHEMY_ECHO", str(ENV == "development")).lower() == "true" | ||
|
|
||
| # Attributes to display in the user page | ||
| USER_DISPLAY_CUSTOM_ATTRIBUTES = os.getenv("USER_DISPLAY_CUSTOM_ATTRIBUTES", "Title,Manager") | ||
|
|
@@ -79,7 +79,7 @@ def default_user_search() -> list[str]: | |
| DATABASE_USER = os.getenv("DATABASE_USER", "root") | ||
| DATABASE_PASSWORD = os.getenv("DATABASE_PASSWORD", "") | ||
| DATABASE_NAME = os.getenv("DATABASE_NAME", "access") | ||
| DATABASE_USES_PUBLIC_IP = os.getenv("DATABASE_USES_PUBLIC_IP", "False") == "True" | ||
| DATABASE_USES_PUBLIC_IP = os.getenv("DATABASE_USES_PUBLIC_IP", "false").lower() == "true" | ||
|
|
||
| FLASK_SENTRY_DSN = os.getenv("FLASK_SENTRY_DSN") | ||
| REACT_SENTRY_DSN = os.getenv("REACT_SENTRY_DSN") | ||
|
|
||
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
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 |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| from api.models.tag import coalesce_ended_at | ||
| from api.operations.constraints import CheckForReason, CheckForSelfAdd | ||
| from api.plugins import get_notification_hook | ||
| from api.plugins.app_group_lifecycle import get_app_group_lifecycle_hook, get_app_group_lifecycle_plugin_to_invoke | ||
| from api.services import okta | ||
| from api.views.schemas import AuditLogSchema, EventType | ||
|
|
||
|
|
@@ -369,8 +370,25 @@ async def _execute(self) -> OktaGroup: | |
| ) | ||
| ) | ||
|
|
||
| # Commit all changes so far | ||
| db.session.commit() | ||
| db.session.commit() | ||
|
|
||
| # Invoke app group lifecycle plugin hooks for removed members | ||
| plugin_id = get_app_group_lifecycle_plugin_to_invoke(self.group) | ||
| if plugin_id is not None and len(self.members_to_remove) > 0: | ||
| try: | ||
| hook = get_app_group_lifecycle_hook() | ||
| hook.group_members_removed( | ||
| session=db.session, group=self.group, members=self.members_to_remove, plugin_id=plugin_id | ||
| ) | ||
| db.session.commit() | ||
| except Exception: | ||
| current_app.logger.exception( | ||
| f"Failed to invoke group_members_removed hook for group {self.group.id} with plugin '{plugin_id}'" | ||
| ) | ||
| db.session.rollback() | ||
| else: | ||
| # Commit all changes so far | ||
| db.session.commit() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This session commit probably doesn't need to be in an else clause, but either way is fine for now. |
||
|
|
||
| # Mark relevant OktaUserGroupMembers as 'Should expire' | ||
| # Only relevant for the expiring groups page so not adding checks for this field anywhere else since OK if marked to expire | ||
|
|
@@ -505,6 +523,21 @@ async def _execute(self) -> OktaGroup: | |
| # Commit changes so far, so we can reference OktaUserGroupMember in approved AccessRequests | ||
| db.session.commit() | ||
|
|
||
| # Invoke app group lifecycle plugin hooks for added members | ||
| plugin_id = get_app_group_lifecycle_plugin_to_invoke(self.group) | ||
| if plugin_id is not None and len(self.members_to_add) > 0: | ||
| try: | ||
| hook = get_app_group_lifecycle_hook() | ||
| hook.group_members_added( | ||
| session=db.session, group=self.group, members=self.members_to_add, plugin_id=plugin_id | ||
| ) | ||
| db.session.commit() | ||
| except Exception: | ||
| current_app.logger.exception( | ||
| f"Failed to invoke group_members_added hook for group {self.group.id} with plugin '{plugin_id}'" | ||
| ) | ||
| db.session.rollback() | ||
|
|
||
| # Approve any pending access requests for access granted by this operation | ||
| pending_requests_query = ( | ||
| AccessRequest.query.options(joinedload(AccessRequest.requested_group)) | ||
|
|
||
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.
This needs to handle the case where members are added/removed from a role group and there's an app group associated with that role group that has an app group plugin which should be notified of changes.