Commit 4f66eefa authored by segfault's avatar segfault

Create mount points with GID and UID from the container

parent ffb40bac
......@@ -23,10 +23,15 @@ class DataFile(object, metaclass=ABCMeta):
def create(self):
logger.debug("Creating file %s", self.source)
with open_locked(self.source, 'w') as f:
os.fchown(f.fileno(), uid=getpwnam(self.owner).pw_uid, gid=getgrnam(self.group).gr_gid)
os.fchmod(f.fileno(), mode=self.mode)
f.write(self.default_content)
# Don't set the UID and GID if the file already exists, because it might be a mount point
# which uses UID and GID from the container
if not self.source.exists():
with open_locked(self.source, 'w') as f:
os.fchown(f.fileno(), uid=getpwnam(self.owner).pw_uid, gid=getgrnam(self.group).gr_gid)
os.fchmod(f.fileno(), mode=self.mode)
self.source.write_text(self.default_content)
def read(self) -> str:
return self.source.read_text()
......
from logging import getLogger
import os
from pathlib import Path
from pwd import getpwnam
from grp import getgrnam
logger = getLogger(__name__)
......@@ -43,10 +41,10 @@ class MountPoint(object):
if self.mode is None:
self.mode = 0o750 if self.is_dir else 0o640
def create(self):
def create(self, uid, gid):
logger.debug("Creating bind-mount %s", self.source)
if self.is_dir:
self.source.mkdir(mode=self.mode)
else:
self.source.touch(mode=self.mode)
os.chown(str(self.source), uid=getpwnam(self.owner).pw_uid, gid=getgrnam(self.group).gr_gid)
os.chown(str(self.source), uid=uid, gid=gid)
......@@ -513,7 +513,14 @@ class OnionService(DBusObject, metaclass=abc.ABCMeta):
def create_data_files(self):
logger.debug("Creating data files for %r", self.Name)
for f in self.data_files:
f.create()
# We have to use the UID and GID from the container if the file is a mount point
if isinstance(f, MountPoint):
uid = int(self.container.execute_command("id -u %s" % f.owner))
gid = int(self.container.execute_command("id -g %s" % f.group))
MountPoint.create(f, uid, gid)
if isinstance(f, DataFile):
# Create the data file (only writes the default content if the file was created as a mount point above)
f.create()
def expand_data_file_paths(self):
"""Expand the data file paths, which are relative to the service's state directory"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment