Skip to content

Conversation

@Kira-Pilot
Copy link
Member

@Kira-Pilot Kira-Pilot commented Dec 8, 2022

resolves #4736

Previously, we were logging audit entries for updates to the user table, but not to the user members table. This meant that if someone updated a group by adding or removing members, these changes weren't logged.

This PR adds member logging. We keep the diff for members under the Group resource as this is most intuitive for the auditor.

Screen Shot 2022-12-08 at 11 07 47 AM

NOTE: unsure why the TestAuthorizeAllEndpoints test is failing - any ideas?

@Kira-Pilot Kira-Pilot requested a review from sreya December 8, 2022 17:30
}
} else {
logger.Warn(logCtx, "marshal group member diff", slog.Error(err))
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a better way to log here so that I don't have to pass through logCtx and logger?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nah, it's on purpose though. The context can potentially hold fields that the logger can use.

HasGroupMemberChange: hasGroupMemberChange,
GroupMemberLists: wriBytes,
})

Copy link
Member Author

Choose a reason for hiding this comment

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

A pain point here is that if this request fails sometime before line 115, we won't get an audit log signifying the failure. I'm not sure how to get around this, given we want to pass some computational stuff in (GroupMemberLists).

Copy link
Contributor

Choose a reason for hiding this comment

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

What if instead of using database.Group here we instead made []database.GroupMember auditable? I think this might solve a lot of the jankiness of needing hardcoded stuff for group members.

Copy link
Contributor

Choose a reason for hiding this comment

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

This might take some work adding support for slices in the diff code.

Copy link
Member Author

Choose a reason for hiding this comment

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

@coadler I was trying to avoid having another auditable resource; however, I'm down to make the change because I agree - it would simplify a lot. In general, do you have any opinions about how many auditable resources we should have? I don't want to bloat the feature but maybe that's less of a concern than I think it is.

@Kira-Pilot Kira-Pilot requested a review from a team December 9, 2022 15:17
HasGroupMemberChange: hasGroupMemberChange,
GroupMemberLists: wriBytes,
})

Copy link
Contributor

Choose a reason for hiding this comment

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

What if instead of using database.Group here we instead made []database.GroupMember auditable? I think this might solve a lot of the jankiness of needing hardcoded stuff for group members.

}
} else {
logger.Warn(logCtx, "marshal group member diff", slog.Error(err))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nah, it's on purpose though. The context can potentially hold fields that the logger can use.


// Adds a 'members' key to Group resource diffs
// in order to capture the addition or removal of group members
func addGroupMemberDiff(logCtx context.Context, diff Map, groupMemberLists json.RawMessage, logger slog.Logger) Map {
Copy link
Contributor

Choose a reason for hiding this comment

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

The context should normally just be called ctx, and the context + logger should always be the first and second fields.

Suggested change
func addGroupMemberDiff(logCtx context.Context, diff Map, groupMemberLists json.RawMessage, logger slog.Logger) Map {
func addGroupMemberDiff(ctx context.Context, logger slog.Logger, diff Map, groupMemberLists json.RawMessage) Map {

@Kira-Pilot
Copy link
Member Author

Closing this for now as we discuss two other solutions:

  1. making []database.GroupMember auditable
  2. a solution arising from this discussion: Comprehensive side effect audit logging #5419

@Kira-Pilot Kira-Pilot closed this Jan 3, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 3, 2023
@Kira-Pilot Kira-Pilot deleted the audit-group-users/kira-pilot branch February 23, 2023 17:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

audit: updating users in a group should generate an audit log diff

3 participants