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

Custom audits #697

Merged
merged 115 commits into from
Aug 30, 2024
Merged

Custom audits #697

merged 115 commits into from
Aug 30, 2024

Conversation

amstilp
Copy link
Contributor

@amstilp amstilp commented Aug 19, 2024

  • Add custom auditing for UploadWorkspace sharing
  • Add custom auditing for UploadWorkspace auth domains

To enable some of these audits to be done programmatically, I added more tracking in ACM:

  • date_ready_for_compute for an UploadCycle indicates that the data model is finalized and compute can proceed in associated UploadWorkspaces
  • UploadWorkspaces now can tell if they are past, current, or future based on start and end dates
  • date_qc_completed field for UploadWorkspaces indicates if QC in that workspace is complete
  • date_completed field for ConsortiumCombinedDataWorkspaces indicates if the combined workspace is complete and ready to share

Still to do for UploadWorkspace sharing:

  • Add auditing for DCC writers
  • Add auditing for GREGOR_ALL
  • Add auditing for DCC admins
  • Add auditing for special anvil groups
  • Add auditing for unexpected groups
  • Add audit explanations and clean up template XXXs

To do for UploadWorkspace auth domain membership auditing:

  • Add auditing for DCC members
  • Add auditing for RC members
  • Add auditing for RC non-members
  • Add auditing for RC uploaders?
  • Add auditing for GREGOR_ALL
  • Add auditing for DCC admins
  • Add auditing for special anvil groups
  • Add auditing for unexpected groups

Other to dos:

  • Add all new fields to detail pages (and tables where appropriate)
  • Add ability to set an UploadCycle to is_ready_for_compute
  • Add ability to set date_qc_completed for UploadWorkspaces
  • Add ability to set date_completed for Combined workspaces
  • Link non-member groups to an RC
  • Add auth domain auditing for non-member groups
  • Write migration to automatically populate some of the new fields based on educated guesses
  • Combine new migrations into one (plus extra for populating fields)
  • Write a management command to run the audit from the command line
  • Run the management command nightly as a cron job

Closes #688

We'll be adding other audits, so it's clearer to have them in
separate source files in an audit-specific directory.
The logging level for "root" is DEBUG in base.py, which makes pytest
tests run with -s print out lots of unhelpful debug messages. Set
the logging level in test.py to be INFO instead of DEBUG.
They are far from complete.
This means that the writers group associated with the RC of the
workspace should be granted can_compute access. This indicator can
be used in the audit.
These are determined based on the start and end dates.
This makes it easier to test the audits - we don't have to figure
out the start and end dates for each upload cycle created in the
audit tests. We can just use a parameter to set them appropriately.
Instead of running a sub-method based on temporality of the upload
cycle, define sub-methods based on the group type. This will make
the logic clearer. Add the sub-method for auditing the RC member
group.
The field tracks the date when QC was completed. This will also be
used in audits.
Previously I had started with the RC member group, but an upload
workspace should never be shared directly with the member group;
that will happen via sharing with the auth domain. Also start redoing
tests such that the tests are split into different classes by
UploadWorkspace stage. This is a little clearer to program and test,
because different sharing is expected at different stages. The audits
themselves are still set up to run sub-methods by group type, though.
Note that this is before the combined workspace is shared; to add
those checks, we'll need to add a flag on the upload cycle.
This field tracks if the data in the combined workspace is completed
and ready to be shared with the consortium.
Copy link

codecov bot commented Aug 19, 2024

Codecov Report

Attention: Patch coverage is 99.88707% with 2 lines in your changes missing coverage. Please review.

Project coverage is 97.93%. Comparing base (9015742) to head (3dd2cb8).
Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
...egor_anvil/audit/upload_workspace_sharing_audit.py 99.17% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #697      +/-   ##
==========================================
+ Coverage   94.89%   97.93%   +3.03%     
==========================================
  Files         130      149      +19     
  Lines        6588    15900    +9312     
==========================================
+ Hits         6252    15572    +9320     
+ Misses        336      328       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

They should still have read access by being in the members group
in the auth domain.
This one is easy - it should always be "read" access.
This is also easy - DCC admins should always be an owner.
Any other group not covered in the audit should never have
direct access.
There are no tests for this view yet, since I'm not done writing
the audit class itself. However, we can use this to check the audit
against prod data.
The audit will just ignore these groups.
Add a foreign key in RC to the ManagedGroup model to link a
non-member group (similar to what we've done for member and uploader
groups). Show the non-member group on the detail page.
These tests call the "run_audit" method instead of the method that
audits a specific workspace and group. The run_audit flow handles
selecting the proper groups.
Right now this button is just a link to a page that resolves the
audit. Also add or make some modifications to templates (still not
final).
This is a better indicating that the access and role that are shown
are the current access/role, not the access/role that they should be.
Like the workspace sharing, create auth domain memberships such as
they would be at the previous step of the cycle.
Remove the previous migrations added into this branch and regenerate
them, with all changes in a single migration.
Instead of using the date for sharing with GREGOR_ALL, use the date
when the workspace was shared with its auth domain. This is how
we're actually sharing the workspace - GREGOR_ALL is part of the
auth domain and the workspace is then shared with its auth domain.
For groups that should only ever have read/write permission, change
the audit results to errors when the group has OWNER permission. This
is more sensible than having a "needs action" result, since this case
should never occur.
When run_upload_workspace_audit detects an error, it now prints out
a link to the page to audit sharing/auth domain membership for all
UploadWorkspaces.
@amstilp
Copy link
Contributor Author

amstilp commented Aug 28, 2024

We'll add the new management command as a cron job after testing the audits out for a bit.

Accidentally had an old data_access_audit in the template, so some
records were not getting rendered.
I accidentally put a test in the wrong class; move it to the
UploadCycleDetailTest class, and fix the code so that it creates
the object instead of relying on the test class to have it.
RC uploaders should not have access until the upload cycle starts,
and should lose access after QC is complete. Note that RC uploaders
typically will have access via being in the member group. This
commit likely breaks auditing for RC members groups, since we had to
split the notes into separate notes for members vs. uploaders due
to different access at different stages.
The RC members group should not be added to the auth domain
until after the upload cycle starts.
RC non-members should only have access to the workspace after an
upload cycle starts.
Mostly these affected the timing of the upload cycle and when to
grant writer access to RC uploaders.
2 weeks and 4 weeks, respectively, are more in line with approximate
timeframes for past upload cycles.
@amstilp amstilp merged commit 9a00389 into main Aug 30, 2024
10 checks passed
@amstilp amstilp deleted the feature/custom-audits branch August 30, 2024 16: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.

Add custom auditing for expected workspace sharing and auth domain group membership
1 participant