[Bug 2039217] Re: python apt Cache(memonly=True) does not behave as if memonly.

Julian Andres Klode 2039217 at bugs.launchpad.net
Wed Oct 25 07:49:43 UTC 2023


The behavior here is correct, the memonly attribute constructs the cache
in memory, but you still need the directories where the lists files are
in so you can read them, and you can still update lists files, download
packages, etc pp.

Without the var/lib/apt/lists directory at least, the cache would just
fail to build as it can't open the directory to iterate it.

Generally speaking you'll be better off using apt_pkg directly instead
of the apt package with its hidden magic. It stands to reason nobody
should be using apt because it generally leads to headscratchingly slow
code that you're not going to understand.

** Changed in: python-apt (Ubuntu)
       Status: New => Won't Fix

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to python-apt in Ubuntu.
https://bugs.launchpad.net/bugs/2039217

Title:
  python apt Cache(memonly=True) does not behave as if memonly.

Status in python-apt package in Ubuntu:
  Won't Fix

Bug description:
  When I use the python constructor for apt.Cache with a
  rootdir=/mnt/host (which is mounted read-only) and memonly=True, it
  isn't behaving as if it's memonly. It's trying to create directories
  on the mounted system.

  Here's my stack: (note, python click module takes up a bit of the top
  of the stack)

  ```
  Collecting apt-based metrics...
  Traceback (most recent call last):
    File "./restart_check.py", line 165, in <module>
      _main()
    File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1157, in __call__
      return self.main(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1078, in main
      rv = self.invoke(ctx)
    File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1434, in invoke
      return ctx.invoke(self.callback, **ctx.params)
    File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 783, in invoke
      return __callback(*args, **kwargs)
    File "./restart_check.py", line 139, in _main
      cache = apt.cache.Cache(rootdir=root_dir, memonly=True)
    File "/usr/lib/python3/dist-packages/apt/cache.py", line 161, in __init__
      self._check_and_create_required_dirs(rootdir)
    File "/usr/lib/python3/dist-packages/apt/cache.py", line 201, in _check_and_create_required_dirs
      os.makedirs(rootdir + d)
    File "/usr/lib/python3.8/os.py", line 213, in makedirs
      makedirs(head, exist_ok=exist_ok)
    File "/usr/lib/python3.8/os.py", line 213, in makedirs
      makedirs(head, exist_ok=exist_ok)
    File "/usr/lib/python3.8/os.py", line 223, in makedirs
      mkdir(name, mode)
  OSError: [Errno 30] Read-only file system: '/mnt/host/var'
  ```

  Why are those create-dir calls not protected from the memonly flag?
  Are they truly needed to be able to set up the cache?

  Ya know what, this could be a security vulnerability, making writes to
  a system that was supposed to be treated as read-only, particularly
  for those that mounted to a disk in a non-read-only way. memonly is
  not as advertised.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/python-apt/+bug/2039217/+subscriptions




More information about the foundations-bugs mailing list