-
Notifications
You must be signed in to change notification settings - Fork 60
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
Log when User/SA/Roles is added to a group #1205
base: master
Are you sure you want to change the base?
Conversation
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.
nice job 👍 I have few comments
rbac/management/group/view.py
Outdated
group=group, tenant=tenant, type="service-account", service_account_id__in=service_accounts | ||
group=group, | ||
tenant=tenant, | ||
type="service-account", |
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.
Let's use TYPE_SERVICE_ACCOUNT for this, I have a PR ongoing to replace these random type names with enums. So I can remember replacing this in my PR too
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.
LGTM
rbac/management/audit_log/model.py
Outdated
@@ -138,3 +153,17 @@ def log_edit(self, request, resource, object): | |||
self.action = AuditLog.EDIT | |||
self.tenant_id = self.get_tenant_id(request) | |||
super(AuditLog, self).save() | |||
|
|||
def log_add(self, request, resource, object, type_dict, user_type): |
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.
maybe better name ? it is not visible difference between log_add
and log_create
.
something like "log_role_or_user_added_to_group" or log_group_membership
or log_group_assigment
.
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.
Oh! There's another task to add permissions to a role, so I was thinking of having this log_add
function do that as well! I just have it for now grouped this way to split the prs. Do you think that's alright...?
yes it is merged now but into #1198, this PR also contains migration. I am not sure what it is the best approach here. if we will merge this, we would need to solve conflicts in #1198 and also change names of migrations. |
f9465f2
to
a2b27d7
Compare
rbac/management/audit_log/model.py
Outdated
"""Create list of principals/roles/service accounts for description.""" | ||
names_list = [] | ||
if user_type == "user" or user_type == "User": | ||
for i in type_dict: |
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.
Nit: can we use a more meaningful name to replace these "i" here?
Such as principal_data, role_data, etc.
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.
LGTM
But we need to solve the related bug below to have the best behavior of the audit logs and the process to add a non-existent role to a group.
/retest |
@@ -771,6 +785,27 @@ def principals(self, request: Request, uuid: Optional[UUID] = None): | |||
# Serialize the group... | |||
output = GroupSerializer(group) | |||
response = Response(status=status.HTTP_200_OK, data=output.data) | |||
|
|||
if status.is_success(response.status_code): | |||
if len(principals) > 0: |
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 should be part of transaction block which start on 715.
you can put audit log creation under those related conditions (len(service_accounts|principals) > 0
).
if operation fails, transaction is rolled back and record into audit log is not created.
@@ -138,3 +153,17 @@ def log_edit(self, request, resource, object): | |||
self.action = AuditLog.EDIT | |||
self.tenant_id = self.get_tenant_id(request) | |||
super(AuditLog, self).save() | |||
|
|||
def log_group_assignment(self, request, resource, object, type_dict, user_type): |
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.
resource and object names are confusing
it looks that resource is rather resource_type
and then object can be resource
:)
Does it make sense ?
@@ -138,3 +153,17 @@ def log_edit(self, request, resource, object): | |||
self.action = AuditLog.EDIT | |||
self.tenant_id = self.get_tenant_id(request) | |||
super(AuditLog, self).save() | |||
|
|||
def log_group_assignment(self, request, resource, object, type_dict, user_type): |
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.
user_type
could be user, service or role. What about name target_resource_type
or assigned_resource_type
? or something like that
request, | ||
AuditLog.GROUP, | ||
object=group, | ||
type_dict=response_data.data, |
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.
what about to pass just values for description ? Something like:
[response_data.data["uuid"] for role in response_data.data]
then type_dict could be renamed to something like values_for_description
and it will allow to remove method self.find_specific_list_of_users
and it is possible to join(",") in log assignment method.
Link(s) to Jira
Description of Intent of Change(s)
The what, why and how.
Log when a user/principal, service account, or role is added to a group
Local Testing
How can the feature be exercised?
How can the bug be exploited and fix confirmed?
Is any special local setup required?
Checklist
Secure Coding Practices Checklist Link
Secure Coding Practices Checklist