enforce protection of OriginalFile.repo property via database triggers#5273
enforce protection of OriginalFile.repo property via database triggers#5273
Conversation
repo field is too short
|
It's an interesting solution. One minor and one longer term point:
|
|
Thank you: I shall see if I can make sense of the node table! |
|
Does the loop over nodes cause a performance hit? |
|
Good question, I'm measuring performance of other stuff on another branch at the moment. 😃 My |
select count(*) from node;
select count(*) from node where down is null; |
|
Nightshade's |
Spring can resolve by type but out-of-order needlessly confuses
|
Useful in testing: INSERT INTO node (id, conn, permissions, up, down, uuid)
VALUES (nextval('seq_node'), 'fake', -52, now(), now(), CAST(random() AS TEXT)); |
|
Regarding #5273 (comment) performance testing is looking good to me locally with a couple of hundred nodes with a couple of them up. |
|
So I think the multi-VM issue potentially persists (i.e. if two nodes are running), though perhaps only if the nodes whose secret is being used goes down (?). Not saying that should block this PR, but something we should think about down the road. Otherwise, I'm interested to hear if you think this is now stable enough or if we will need to come back to review this solution. (i.e. is it still a hack?) Regardless, the changes now look nicely smaller. |
|
I think it should work okay with multiple nodes? Unless I messed up the logic in the triggers somehow. I think stable enough for 5.4 anyway, not saying we might not want to come back to in in the longer term if we have a nicer idea. |
What this PR does
Now that
OriginalFile.repois mapped in the OMERO model (see ome/omero-documentation#1623) we prevent this property being easily mutated because there are security implications that would otherwise require careful analysis. The repository DAO does have to be able to set the property when registering an original file in the repository. Initially I was having it drop to SQL to effect this but making a direct database change then re-merging that change into theOriginalFileHibernate proxy impacted performance, slowing plate import.Experimenting with
BasicACLVoter.allowCreationandOmeroInterceptormethods likeonFlushDirtyandonSavefailed to find any useful combination of calls that would allow me to detect if therepoproperty had been changed in a situation where I could also be reassured that the setter was trusted.This PR introduces a hackish solution that has the twin virtues of actually working and being faster. Maybe we can find a better way but that can wait: I am putting time and behavior ahead of loveliness. The solution is: establish a secret key when the server starts up, tell it to the database then, when we try to set the
originalfile.repocolumn, have a database trigger look for that secret key prefixingoriginalfile.name: if that prefix is there, then remove it and allow the change. Outside users, such as clients using the update service, have no way to access the secret key.Testing this PR
CI should show no regressions and
testFileRepoProperty*()in https://10.0.51.154:8443/job/OMERO-test-integration/lastCompletedBuild/testngreports/integration/UpdateServiceTest/ should pass. Comparing import times should reveal a small speedup, especially with significantly less time spent increateOriginalFile. Profiling the new triggers also suggests little time spent in those.Related reading
https://trello.com/c/l4SERvRy