Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1877  / 1 Year ago, thu, december 22, 2022, 5:41:17

Situation:

Group A requires access to /path/to/dir/foo to upload files through ssh or ftp, but the directory in question: /path/to/dir/foo is owned by group B (if you'd like: /path is recursively owned by B), which should stay this way, for security reasons.





My attempt for a solution:

I create a symbolic link to /home/A, which A owns. Next, I grant permissions so A can access the symlink:



sudo ln -s /path/to/dir/foo /home/A/foo
sudo chown -h A:A /home/A/foo


I figured that /path/to/dir/foo should at least be owned by a group that A is part of:



sudo addgroup C
sudo useradd -G C A
sudo chown -R B:C /path/to/dir/foo
sudo chmod -R 774 /path/to/dir/foo


After doing all that, I connected through an FTPS client as user A and changed directory to: /home/A. To my surprise the symlink is not visible, which is odd, because the proFTPd is set up to show symlinks.



I also tried connecting through SFTP to the same directory. This time the symlink was visible, but when I tried to access it, I got the following prompt:




Cannot open remote file '/path/to/dir/foo'.



Permission denied.

Error code: 3

Error message from server: Permission denied




That leaves me with little to no alternatives, since this was the easiest solution I could think of.





Desperate attempt:

I granted global permissions to /path/to/dir/foo, but I still couldn't access the symlink foo in /home/A as user A. Meaning: ls -l /path/to/dir/foo would print -rwxrwxrwx.





Question:

How do I create a symlink /home/A/foo which points to /path/to/dir/foo. Which A can access, despite /path/to/dir/foo being mostly owned by user:group B (/path is owned by B) ?


More From » ssh

 Answers
7

If your directory is in an ext4 filesystem, you can use ACL. Best explained by example; my user is romano and the other user is default.



As romano:



[romano:~/tmp] % mkdir -p a/b/c/d
[romano:~/tmp] % cd !$
cd a/b/c/d
[romano:~/tmp/a/b/c/d] % touch f1
[romano:~/tmp/a/b/c/d] % ls -l
total 0
-rw-rw-r-- 1 romano romano 0 nov 27 17:15 f1


Obviously I can write to directory d, it's mine... but from default:



default@pern:/home/romano/tmp/a/b/c/d$ touch f2
touch: cannot touch ‘f2’: Permission denied


Yep. No symbolic link will change the fact that default can't write there.



Now, as romano, I grant additional access to group default:



[romano:~/tmp/a/b/c/d] % setfacl -m g:default:rwx .


(read as: add rwx permission to group default to the current . directory)



...And now, as default:



default@pern:/home/romano/tmp/a/b/c/d$ touch f2
default@pern:/home/romano/tmp/a/b/c/d$ ls -l
total 0
-rw-rw-r-- 1 romano romano 0 nov 27 17:15 f1
-rw-rw-r-- 1 default default 0 nov 27 17:17 f2


ACL syntax is a bit convouted, but it's a quite powerful tool. See man setfacl and man getfacl for a full info and more examples.



In your case if you have /path/to/dir/foo owned by A:A, and you want group B to have write access to foo you should:




  1. add +rx permission to each of the directory leading to it for group B:



     setfacl -m g:B:r-x /path
    setfacl -m g:B:r-x /path/to
    setfacl -m g:B:r-x /path/to/dir

  2. add +rwx permssion to group B to the directory:



     setfacl -m g:B:rwx /path7to7dir/foo



Notice however that seems we have a nasty bug around... See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8527. I am not sure about the consequences --- the simple case above worked ok, but please check it.


[#22260] Friday, December 23, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shionnky

Total Points: 276
Total Questions: 104
Total Answers: 108

Location: Montenegro
Member since Thu, Jun 16, 2022
2 Years ago
shionnky questions
;