builtins.PermissionError: [Errno 1] Operation not permitted: '/var/lib/maas/.maas-proxy.conf.wwu2aw6z.tmp'

Bug #1883748 reported by Felipe Reyes
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MAAS
Fix Released
Medium
Felipe Reyes
2.7
Fix Committed
Medium
Felipe Reyes
2.8
Fix Released
Medium
Felipe Reyes

Bug Description

It was found an environment where there were about ~50 GB of files /var/lib/maas/.maas-proxy.conf.* , this was happening because /var/lib/maas/.maas-proxy.conf was owner by postgres:postgres , so maas was trying to apply the same permissions to the temporary file which failed since the process maas-regiond is running under the 'maas' user.

2020-06-16 15:34:46 maasserver.region_controller: [critical] Failed configuring proxy.
        Traceback (most recent call last):
          File "/usr/lib/python3.6/threading.py", line 864, in run
            self._target(*self._args, **self._kwargs)
          File "/usr/lib/python3/dist-packages/provisioningserver/utils/twisted.py", line 850, in worker
            return target()
          File "/usr/lib/python3/dist-packages/twisted/_threads/_threadworker.py", line 46, in work
            task()
          File "/usr/lib/python3/dist-packages/twisted/_threads/_team.py", line 190, in doWork
            task()
        --- <exception caught here> ---
          File "/usr/lib/python3/dist-packages/twisted/python/threadpool.py", line 250, in inContext
            result = inContext.theWork()
          File "/usr/lib/python3/dist-packages/twisted/python/threadpool.py", line 266, in <lambda>
            inContext.theWork = lambda: context.call(ctx, func, *args, **kw)
          File "/usr/lib/python3/dist-packages/twisted/python/context.py", line 122, in callWithContext
            return self.currentContext().callWithContext(ctx, func, *args, **kw)
          File "/usr/lib/python3/dist-packages/twisted/python/context.py", line 85, in callWithContext
            return func(*args,**kw)
          File "/usr/lib/python3/dist-packages/provisioningserver/utils/twisted.py", line 885, in callInContext
            return func(*args, **kwargs)
          File "/usr/lib/python3/dist-packages/provisioningserver/utils/twisted.py", line 217, in wrapper
            result = func(*args, **kwargs)
          File "/usr/lib/python3/dist-packages/maasserver/utils/orm.py", line 737, in call_within_transaction
            return func_outside_txn(*args, **kwargs)
          File "/usr/lib/python3/dist-packages/maasserver/utils/orm.py", line 540, in retrier
            return func(*args, **kwargs)
          File "/usr/lib/python3.6/contextlib.py", line 52, in inner
            return func(*args, **kwds)
          File "/usr/lib/python3/dist-packages/maasserver/proxyconfig.py", line 60, in _write_config
            write_config(cidrs, **kwargs)
          File "/usr/lib/python3/dist-packages/provisioningserver/utils/twisted.py", line 217, in wrapper
            result = func(*args, **kwargs)
          File "/usr/lib/python3/dist-packages/provisioningserver/proxy/config.py", line 85, in write_config
            atomic_write(content, target_path, overwrite=True, mode=0o644)
          File "/usr/lib/python3/dist-packages/provisioningserver/utils/fs.py", line 151, in atomic_write
            chown(temp_file, prev_stats.st_uid, prev_stats.st_gid)
        builtins.PermissionError: [Errno 1] Operation not permitted: '/var/lib/maas/.maas-proxy.conf.wwu2aw6z.tmp'

[Test case]

1. Install MAAS from deb packages (tested with 2.7 and 2.8).
2. sudo chown postgres:postgres /var/lib/maas/maas-proxy.conf
3. echo "# This shouldn't be here" | sudo tee -a /var/lib/maas/maas-proxy.conf
4. sudo systemctl restart maas-regiond
5. ls /var/lib/maas/.maas-proxy.*

Expected result:

The failure of chown() gets logged and the temporary file removed.

Actual result:

chown()'s PermissionError is not handled and leaving the temporary file behind.

Tags: sts

Related branches

Felipe Reyes (freyes)
Changed in maas:
assignee: nobody → Felipe Reyes (freyes)
Felipe Reyes (freyes)
Changed in maas:
status: New → In Progress
Changed in maas:
importance: Undecided → Medium
milestone: none → 2.9.0b1
Changed in maas:
status: In Progress → Fix Committed
Lee Trager (ltrager)
Changed in maas:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.