Track created_by and updated_by in Node and Revisions#1255
Track created_by and updated_by in Node and Revisions#1255jmaruland wants to merge 23 commits intobluesky:mainfrom
Conversation
0f4e558 to
1ce3bdc
Compare
ee06f6d to
505796b
Compare
|
Closes #1076 |
danielballan
left a comment
There was a problem hiding this comment.
Nice to see this coming together! I have a couple questions in line.
Also, this needs a database migration to add the new columns to existing databases.
tiled/server/router.py
Outdated
| data_sources=body.data_sources, | ||
| access_blob=access_blob, | ||
| created_by=( | ||
| principal.identities[0].id if len(principal.identities) > 0 else "" |
There was a problem hiding this comment.
This design consideration deserves some thought:
- What should we put here when the principal has no identities? Service Principals have no identities. Should we put
service:{principal.uuid}? Or nothing? - Should the fallback value be
""orNone/NULL?
There was a problem hiding this comment.
I actually had to add this conditional because test_access_control.py::test_service_principal_access_control was failing here. It seems like, at some point during the handshake with the server, principal.identities is passed as an empty list.
|
Suggestions for various scenarios:
To test a service principal: # Log in as admin. Then...
# Create a new Service Principal. It is identified by its UUID. It has no "identities"; it cannot log in with a password.
sp = admin_client.context.admin.create_service_principal()
# Create an API key for this Service Principal.
key_info = admin_client.context.admin.create_api_key(sp["uuid"])
# Then to log in as the principal, you can do this...
admin_client.logout()
sp_client.context.api_key = key_info["secret"]
# For clarity use a new variable name.
sp_client = admin_client
del admin_client |
|
Run a command line this to generate a template for a database migration. See other similar files in this directory for examples. Finally, add the unique ID for this migration (the first part of the filename, and it also appears in the file) to this list: Lines 7 to 26 in 2cf4c80 |
|
@danielballan I ran the command for the database migration but I have pre-commit a bit a bit mad because of flake8 This is an auto-generated file. Should I ignore these messages? |
|
Is it ok if I add an inline comment with |
|
False alarm. I understand what the next step us with the |
… database migration
tiled/catalog/migrations/versions/8fd6ac88f2ec_add_created_by_and_updated_by.py
Show resolved
Hide resolved
| def get_current_user(principal: Principal) -> Optional[str]: | ||
| username = None | ||
| if principal is not None: | ||
| if len(principal.identities) > 0: | ||
| username = principal.identities[0].id | ||
| else: | ||
| username = f"service:{principal.uuid}" | ||
| return username |
There was a problem hiding this comment.
I'd like broader input on whether this passes the smell test as a pragmatic approach.
This PR is about adding created_by and updated_by columns to some tables in the catalog database. This will not no bearing on access policy (that uses access_blob exclusively) but could be useful for forensics. Once a node is "tagged", we don't currently retain information about who created it. That seems useful to retain, internally.
Background:
- Tiled supports multiple identity providers (akin to Globus' "linked identities" or "Log in with GitHub OR Google OR ....")
- For a while, I've wondered if we should simplify this to just one. I am not aware of any deployments today that use more than one IdP (identity provider).
- But the recent "American Science Cloud" goal of providing an IdP that works across Labs means we might soon have a reason to support both a BNL OIDC and an "American Science Cloud" OIDC. It would be shame to rip this out and find out 3 months later than we want it back.
- It would be clean/pure to store Principal UUIDs in access tags, like
{"user": "66f1e964-5ea4-4cde-b304-1c93231e45dc"}but{"user": "dallan"}is a lot easier to read, and I went with "easy to read" since I foresaw "multiple identity" providers as rare or maybe soon-to-be-dropped. - But the above feels a bit messy....What if identities changes, etc.
Should we switch to storing principal UUIDs here? Or "Just use the first identity in the list," acceptable? There are obvious problems if identities change...
attn @gwbischof @nmaytan @genematx
Checklist
This PR introduces created_by and updated_by columns in the database for forensic purposes.