in reply to How do I check if another user can access a file?
Sure, you could re-evaluate permission checks of your OS and emulate access before running the real application. But, you'll probably never get the tests 100% waterproof and will have to rely on your runtime checks.
The problem with the let it run and see approach is that some services can run a remarkably long time before a problem becomes visible, e.g. when an exceptional condition occurs that requires to save some evidence to a file and certainly - no permission. And there's also a chance that the application/system is left in an inconsistent state.
From my experience, it's better to have a clear and structured permission- and ownership-plan for a given set of directories and applications and to strictly adhere to this plan.
This concept is usually supported by catching exceptions at run-time (as you already do - but that is a second line of countermeasure) plus an automated mechanism (update-script) that enforces correct ownerships and permissions for file-types and - where necessary - individual files. It might be useful to let this script also create (empty) directory-trees.
Since your application-starter now can expect with confidence that the environment (permissions, ownerships) has a consistent and predictive state (remember update-script), things become easy for your application(-starter). It just has to check if the user belongs to a group (or set of groups) that is permitted to run a certain application (role: application). Sometimes you need another role for programs that update your files or need higher permissions (role: application-adm). If some of your programs are executed with root-permission - and you cannot avoid that - let those files be owned by root.
The whole concept can be scripted (update-script) and automated (e.g. cron). In extreme, the update-script is started before you run the application. This catches a lot of problems that can occur if e.g. someone has updated/installed files and forgot to set proper permissions/ownerships.
So, my advice is to separate permission/ownership-management (an administrative task)
from application-startup (an operational task).
YMMV, but I successfully run this (old school?) approach in one of our environments for years without any problems.
HTH
|
|---|