WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Directory in etc directory becomes owner root after reboot  (Read 1321 times)

Offline rhermsen

  • Wiki Author
  • Full Member
  • *****
  • Posts: 109
Directory in etc directory becomes owner root after reboot
« on: March 11, 2024, 07:57:09 PM »
As part of the extension I made the directory /usr/local/etc/frr owned by tc:staff

I expected this ownership to become default after each reboot.
But a reboot causes the directory to become owned by root.
This is also the case of any subdirectories.
Is this expected?

The files in this directory do stay owned by tc:staff.

Any advice to best change ownership e.g. using bootlocal.sh or better by the install script (tce.installed)?

# Below output shows the unsquashed extension has the intended ownership.
Code: [Select]
$ sudo unsquashfs frr.tcz
Parallel unsquashfs: Using 1 processor
99 inodes (4108 blocks) to write
[==============================================================================================/] 4207/4207 100%
created 89 files
created 15 directories
created 10 symlinks
created 0 devices
created 0 fifos
created 0 sockets
created 0 hardlinks
$ cd squashfs-root/usr/local/etc/
$ ls -la
total 0
drwxr-xr-x    3 root     root            60 Mar 11 14:07 ./
drwxr-xr-x    8 root     root           160 Mar 11 14:07 ../
drwxr-xr-x    2 tc       staff           60 Mar 11 14:07 frr/

# Below output after a reboot.
# The files are still owned by tc:staff, but the directories changed to root:root
Code: [Select]
$ ls -la /usr/local/etc/frr/
total 12
drwxr-xr-x    3 root     root           120 Mar 11 15:47 ./
drwxr-xr-x    8 root     root           320 Mar 11 15:47 ../
-rw-r--r--    1 tc       staff         4216 Mar 11 07:49 daemons
-rw-r--r--    1 tc       staff            0 Mar 11 07:49 frr.conf
drwxr-xr-x    2 root     root           100 Mar 11 15:47 ns-frr/
-rw-r--r--    1 tc       staff           58 Mar 11 07:49 vtysh.conf
$ ls -la /usr/local/etc/
total 4
drwxr-xr-x    8 root     root           320 Mar 11 15:47 ./
drwxr-xr-x   10 root     root           220 Mar 11 15:47 ../
drwxr-xr-x    2 root     root            60 Jan 25 22:42 X11/
-rw-r--r--    1 root     root           459 Dec 30  2022 bashrc
lrwxrwxrwx    1 root     root            45 Mar 11 15:47 ematch_map -> /tmp/tcloop/iproute2/usr/local/etc/ematch_map
drwxr-xr-x    3 root     root           100 Nov 10  2019 fonts/
drwxr-xr-x    3 root     root           120 Mar 11 15:47 frr/
lrwxrwxrwx    1 root     root            40 Mar 11 15:47 group -> /tmp/tcloop/iproute2/usr/local/etc/group
drwxr-xr-x    2 root     root            60 Dec  7 13:52 init.d/
lrwxrwxrwx    1 root     root            45 Mar 11 15:47 rt_dsfield -> /tmp/tcloop/iproute2/usr/local/etc/rt_dsfield
lrwxrwxrwx    1 root     root            44 Mar 11 15:47 rt_protos -> /tmp/tcloop/iproute2/usr/local/etc/rt_protos
lrwxrwxrwx    1 root     root            44 Mar 11 15:47 rt_realms -> /tmp/tcloop/iproute2/usr/local/etc/rt_realms
lrwxrwxrwx    1 root     root            44 Mar 11 15:47 rt_scopes -> /tmp/tcloop/iproute2/usr/local/etc/rt_scopes
lrwxrwxrwx    1 root     root            44 Mar 11 15:47 rt_tables -> /tmp/tcloop/iproute2/usr/local/etc/rt_tables
drwxr-xr-x    2 root     root           300 Mar 11 15:47 ssh/
drwxr-xr-x    7 root     root           280 Mar 11 15:47 ssl/


Offline rhermsen

  • Wiki Author
  • Full Member
  • *****
  • Posts: 109
Re: Directory in etc directory becomes owner root after reboot
« Reply #1 on: March 12, 2024, 12:08:34 PM »
I decided to change ownership via the install scrip (tce.installed).
Code: [Select]
if [ -d /usr/local/etc/frr ]; then
        chown -R tc:staff /usr/local/etc/frr
fi
/usr/local/etc/frr is now correctly owned by tc:staff.

But after a reboot /usr/local/etc/frr/ns-frr is still changed to root:root

The directory /usr/local/etc/frr/ns-frr is created once during bootup by the bootlocal.sh script.
Code: [Select]
[ ! -d "/usr/local/etc/frr/ns-frr" ] && sudo -u tc mkdir -p  /usr/local/etc/frr/ns-frr/
I unzipped the /mnt/vda1/tce/mydata.tgz in tmp and in this file the permissions are correct.

Code: [Select]
tc@testapps:/tmp/mydata$ tree -pug
.
|-- [drwxr-xr-x tc       staff   ]  etc
|   |-- [-rw-r--r-- tc       staff   ]  group
|   |-- [-rw-r----- tc       staff   ]  gshadow
|   |-- [-rw-r--r-- tc       staff   ]  inetd.conf
|   |-- [-rw-r--r-- tc       staff   ]  passwd
|   |-- [-rw-r--r-- tc       staff   ]  services
|   `-- [-rw-r----- tc       staff   ]  shadow
|-- [drwxr-xr-x tc       staff   ]  home
|   `-- [drwxr-x--- tc       staff   ]  tc
|-- [-rw-r--r-- tc       staff   ]  mydata.tar
|-- [drwxr-xr-x tc       staff   ]  opt
|   |-- [drwxr-xr-x tc       staff   ]  backgrounds
|   |-- [-rwxr-xr-x tc       staff   ]  bootlocal.sh
|   |-- [-rwxr-xr-x tc       staff   ]  bootsync.sh
|   |-- [-rwxr-xr-x tc       staff   ]  shutdown.sh
|   `-- [-rw-r--r-- tc       staff   ]  tcemirror
`-- [drwxr-xr-x tc       staff   ]  usr
    `-- [drwxr-xr-x tc       staff   ]  local
        `-- [drwxr-xr-x tc       staff   ]  etc
            |-- [drwxr-xr-x tc       staff   ]  frr
            |   |-- [-rw-r--r-- tc       staff   ]  daemons
            |   |-- [-rw-r--r-- tc       staff   ]  frr.conf
            |   |-- [drwxr-xr-x tc       staff   ]  ns-frr                       <<<<<< this directory becomes owned by root:root after reboot
            |   |   |-- [-rw-r--r-- tc       staff   ]  daemons
            |   |   |-- [-rw-r--r-- tc       staff   ]  frr.conf
            |   |   `-- [-rw-r--r-- tc       staff   ]  vtysh.conf
            |   `-- [-rw-r--r-- tc       staff   ]  vtysh.conf
            `-- [drwxr-xr-x tc       staff   ]  ssh
<snip>

11 directories, 30 files
tc@testapps:/tmp/mydata$

Offline rhermsen

  • Wiki Author
  • Full Member
  • *****
  • Posts: 109
Re: Directory in etc directory becomes owner root after reboot
« Reply #2 on: March 15, 2024, 02:20:01 PM »
See the exact same behavior with version 15.0 trying the x86_64 arch.

'/usr/local/etc/frr' becomes root:root after a reboot.
This I can counter with the following in '/usr/local/tce.installed'
Code: [Select]
if [ -d /usr/local/etc/frr ]; then
        chown -R tc:staff /usr/local/etc/frr
fi
But even with the 'Recurse' flag set the subdirectory '/usr/local/etc/frr/ns-frr' still becomes owned by root:root on reboot.

Only way to counter both is to also add next line in '/opt/bootlocal.sh'
Code: [Select]
[ -d "/usr/local/etc/frr/ns-frr" ] && chown -R tc:staff /usr/local/etc/frr

Offline rhermsen

  • Wiki Author
  • Full Member
  • *****
  • Posts: 109
[solved] Directory in etc directory becomes owner root after reboot
« Reply #3 on: March 16, 2024, 07:18:04 AM »
I found the reason. I missed to specify the directory in '/opt/.filetool.lst'. I only added the files...

If I explicitly specify the directory '/usr/local/etc/test' in '/opt/.filetool.lst' it does restore ownership correctly.
If I only specify the file(s) '/usr/local/etc/test/test.cfg' in '/opt/.filetool.lst' it does not restore ownership of '/usr/local/etc/test'.

From extracting '/mnt/vda1/tce/mydata.tgz' it appears to store also the ownership of '/usr/local/etc/test', but it doesn't...

Steps to reproduce the issue I ran into:
Code: [Select]
# Using TCL-14.0 x86 (expect same on x86_64 and also on TCL-15.0)
# verify logged in as tc (expect uid=tc, gid=staff)
id

sudo mkdir /usr/local/etc/test
sudo chown -R tc:staff /usr/local/etc/test
# verify directory created with owner tc:staff
ls -la /usr/local/etc/
touch /usr/local/etc/test/test.cfg
# verify file created with owner tc:staff
ls -la /usr/local/etc/test/
#echo usr/local/etc/test >> /opt/.filetool.lst
echo usr/local/etc/test/test.cfg >> /opt/.filetool.lst
filetool.sh -b
mkdir /tmp/test
tar xzf /mnt/vda1/tce/mydata.tgz -C /tmp/test
tce-load -wi tree
tree -pug /tmp/test
# confirm from the 'tree' output ownership of '/usr/local/etc/test' to be tc:staff

sudo reboot
ls -la /usr/local/etc/

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Directory in etc directory becomes owner root after reboot
« Reply #4 on: March 16, 2024, 11:12:42 AM »
Yeah, this is how tar behaves. Every now and then somebody runs into the same issue.
The only barriers that can stop you are the ones you create yourself.

Offline rhermsen

  • Wiki Author
  • Full Member
  • *****
  • Posts: 109
Re: Directory in etc directory becomes owner root after reboot
« Reply #5 on: March 16, 2024, 02:02:15 PM »
@curaga
I don't think it is tar because after 'tar xzf /mnt/vda1/tce/mydata.tgz -C /tmp/test' permissions are still as expected.
Still have to try some more to understand this behavior a bit better, but that is of later...
For now I use a workaround as part of the tce.installed script.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Directory in etc directory becomes owner root after reboot
« Reply #6 on: March 17, 2024, 03:39:45 AM »
If a directory is not included in the archive, it will be created with defaults. So ownership will depend on who runs it, permissions on the current umask, etc.
The only barriers that can stop you are the ones you create yourself.