pingtoo wrote:Hu wrote:pingtoo wrote:I believe it is documented in Gentoo handbook in *User administration* section suggest daily user to be place in *portage* group to *Be able to access portage restricted resources.*
Do you have a citation for this?
Yes, as it is documented in
Gentoo handbook in
User administration/Adding a user for daily use.
That section documents various important groups. It does not suggest that the user should be a member of all, or even most, of them.
pingtoo wrote:I understand from security point of view making a directory permission open wide is not a good practice. However my suggestion is direct point for using *sudo* which change effect UID to *root* and therefor the directory must allow *root* to create new file in order for the sudo method to work. And without going through how the exact environment was setup, it would be much quicker to use a command to illustrate the setup to allow root write access. I would think for security concern using *sudo* to perform this task is inappropriate in the first place, would you agree?
Your phrasing is confusing, but no, I don't think I agree here.
pingtoo wrote:However I hold a different opinion in compare open directory wide vs use root execution. In this case in particular I ask the user open a directory very deep in a directory tree, not at some arbitrated top level directory where other might accidentally travail into.
The root user normally has CAP_DAC_OVERRIDE and CAP_DAC_READ_SEARCH, which would allow it to completely ignore traditional Unix permissions.
Code: Select all
# mkdir -m0 abc
# touch abc/def
# ls -la abc
total 0
d--------- 2 root root 60 ./
drwx------ 7 root root 160 ../
-rw-r----- 1 root root 0 def
If a process gets
Permission denied, then either:
- The process lacks CAP_DAC_OVERRIDE+CAP_DAC_READ_SEARCH.
- There is an active layered security module which can confine even users with those capabilities.
If the process lacks CAP_DAC_OVERRIDE+CAP_DAC_READ_SEARCH then either it isn't actually root, or it dropped those capabilities. Either way, that suggests it needs a permission grant along the entire tree. Setting an inner directory to mode 777 is useless if a parent directory lacks search permission for the caller. This comes back to my earlier point: changing the permissions on one directory, without understanding why the existing permissions do not work, is not the right solution. At best, it will happen to allow the user to work, and probably teach the user a bad habit. At worst, it will do nothing, and the user will have opened permissions for nothing - and possibly learned the bad habit anyway. Faced with a permissions problem, the right course of action is to understand why the existing grants are insufficient. This is
especially true when the existing grant appears to be
root.
pingtoo wrote:So I cannot accept saying me suggest "Changing permission to mode 777 is almost always the wrong solution".
You are welcome to ignore the advice. That does not mean you will not get called on it again later.
pingtoo wrote:Whereas use root execution might post even greater risk to entire system due to intention or mistake in script.
Yes, of course irresponsible or uninformed use of root is dangerous. Your junior administrator was clearly both irresponsible and uninformed. Irresponsible for putting a dangerously broad cleanup job into service without better testing. Uninformed for not knowing of, and using, some simple sanity checks that could have mitigated its damage.
pingtoo wrote:Allow me share my previous work experience, One of my junior system admin try to clean up a temporary file location, he created cron job under root eventually wipe out entire system. According to his explanation, He first tried use his own id to create the cron job calling sudo to delete everything in the temporary file location failed due to sudo in cron asking for input.
He should have known better than to think calling
sudo from a cronjob would work.
pingtoo wrote:After I restore the system and check his crontab script I found he perform a cd tmpdir then rm *, however some other system tidy script remove the tmpdir due to it is a empty directory, so the next day the crob job kick in, the cd tmpdir failed due to the tmpdir not exist and the rm * performed at / and that wipe out the entire system.
I've lost count of how many times I've heard variations of this story. It's shockingly common for people to assume
cd never fails. Although the damage was not quite as impressive, I have a very similar story from a few years back. A novice user chained together
cd place ; rm *, and proceeded to delete most of his home directory when
place didn't exist.
As pietinger says, a simple use of
&& could have saved your junior administrator. Personally, I would use the more comprehensive
set -eu. Of course, if at all possible, I wouldn't use
rm * even if I
was sure I was in the right directory. There are other ways of performing a wild delete, some of which can do a much better job of failing safely. The first that comes to mind here would be
find tmpdir -mindepth 1 -delete, with some tweaks if recursion is needed.
pingtoo wrote:Hu wrote:I suspect that in this case, the failing process wasn't really running as root, and so was falling victim to restrictive search permissions on a parent directory.
@Hu, if you review the post by the OP you will see OP posted a
Code: Select all
sudo ebuild sc-im-0.8.2.ebuild manifest
with error message which in particular stated that
Code: Select all
/usr/lib/portage/python3.9/ebuild.sh: line 645: /home/ari/Ari/coding/resources_/dinolay/app-office/sc-im/sc-im-0.8.2.ebuild: Permission denied
. I happen to run into this error before and that is why I suggest chmod 777 will fix this error.
As I said, I think the process wasn't running as root. Yes, the user ran
sudo, but the called process could easily change itself to a non-root uid.
pingtoo wrote:But if one need to bring out a solution for this problem would have been ask why Gentoo require use root in order to develop.
Does it? I would expect that with the right environment, to avoid trying to write to root-only resources, one could write an ebuild and digest it without root. Running it will likely require root, but Portage's sandbox features do a pretty good job of keeping people out of trouble - assuming the user is not actively trying to circumvent them.