Snapcraft clean fails on root-owned files
Metadata
Current evaluation
Root-owned LXD build files broke snapcraft clean; fixed by merged PR snapcore/snapcraft#1904 (commit 6bd4c9e59), correcting raw.idmap ownership handling.
Resolution: closed resolved
Reason: PR #1904 was merged as commit 6bd4c9e59, titled "lxd: raw.idmap expects host and container id respectively." The maintainer linked it as the fix for the permissions regression introduced by PR #1847.
Evaluated by: mr-cal-bot
No scores available.
Issue body
I am building a snap using SNAPCRAFT_CONTAINER_BUILDS to 1.
I have a couple of parts in a snap, and because of bug 1741752 I have to run snapcraft clean frequently. When I do, the clean fails for what seems like a permission issue.
lan@hal:~/tmp/dolphin-emu⟫ snapcraft clean
"grade" property not specified: defaulting to "stable"
Deleting local:snapcraft-dolphin-emu
Cleaning up priming area
Cleaning up staging area
Cleaning up parts directory
Traceback (most recent call last):
File "/snap/snapcraft/1021/bin/snapcraft", line 11, in <module>
load_entry_point('snapcraft==2.38', 'console_scripts', 'snapcraft')()
File "/snap/snapcraft/1021/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 565, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/snap/snapcraft/1021/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2631, in load_entry_point
return ep.load()
File "/snap/snapcraft/1021/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2291, in load
return self.resolve()
File "/snap/snapcraft/1021/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2297, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/snap/snapcraft/1021/lib/python3.6/site-packages/snapcraft/cli/__main__.py", line 19, in <module>
run(prog_name='snapcraft')
File "/snap/snapcraft/1021/lib/python3.6/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/snap/snapcraft/1021/lib/python3.6/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/snap/snapcraft/1021/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/snap/snapcraft/1021/lib/python3.6/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/snap/snapcraft/1021/lib/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/snap/snapcraft/1021/lib/python3.6/site-packages/snapcraft/cli/lifecycle.py", line 184, in clean
metadata=config.get_metadata()).clean(parts, step)
File "/snap/snapcraft/1021/lib/python3.6/site-packages/snapcraft/internal/lxd/_project.py", line 182, in clean
lifecycle.clean(self._project_options, parts, step)
File "/snap/snapcraft/1021/lib/python3.6/site-packages/snapcraft/internal/lifecycle/_clean.py", line 174, in clean
_cleanup_common_directories_for_step(step, project_options)
File "/snap/snapcraft/1021/lib/python3.6/site-packages/snapcraft/internal/lifecycle/_clean.py", line 131, in _cleanup_common_directories_for_step
parts)
File "/snap/snapcraft/1021/lib/python3.6/site-packages/snapcraft/internal/lifecycle/_clean.py", line 154, in _cleanup_parts_dir
shutil.rmtree(path)
File "/snap/snapcraft/1021/usr/lib/python3.6/shutil.py", line 474, in rmtree
_rmtree_safe_fd(fd, path, onerror)
File "/snap/snapcraft/1021/usr/lib/python3.6/shutil.py", line 412, in _rmtree_safe_fd
_rmtree_safe_fd(dirfd, fullname, onerror)
File "/snap/snapcraft/1021/usr/lib/python3.6/shutil.py", line 412, in _rmtree_safe_fd
_rmtree_safe_fd(dirfd, fullname, onerror)
File "/snap/snapcraft/1021/usr/lib/python3.6/shutil.py", line 432, in _rmtree_safe_fd
onerror(os.unlink, fullname, sys.exc_info())
File "/snap/snapcraft/1021/usr/lib/python3.6/shutil.py", line 430, in _rmtree_safe_fd
os.unlink(name, dir_fd=topfd)
PermissionError: [Errno 13] Permission denied: 'mbedtls.doxyfile'
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Root-owned LXD build files broke snapcraft clean; fixed by merged PR snapcore/snapcraft#1904 (commit 6bd4c9e59), correcting raw.idmap ownership handling. | |
| stealth/space-bunny-alpha | — | closed resolved | Root-owned part files came from incorrect LXD raw.idmap UID mapping introduced by #1847; merged PR #1904 (commit 6bd4c9e59) fixed the host-to-container ID mapping. | |
| stealth/space-bunny-alpha | — | closed stale | Closed without a recorded fix or explanation after `snapcraft clean` hit PermissionError on root-owned files created with container builds. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed without resolution. snapcraft clean failed with a PermissionError when removing root-owned files from the build directory. No fix or discussion was provided. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed without resolution or comments. The snapcraft clean permission error on root-owned files was not addressed and appears abandoned or resolved in a later release. |
Update history
| Date | Change |
|---|---|
| created |
Related work
-
Likely Fixed By:
snapcore/snapcraft#1904
(confidence 99%)
Merged as commit 6bd4c9e59 to correct LXD ID mapping and resulting file ownership.
-
Caused By:
snapcore/snapcraft#1847
(confidence 95%)
The maintainer identified this PR as the source of the clean-permissions regression.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #1666735 snapcraft cleanbuild does not work with lxd installed via snap | snapcraft (launchpad) | closed | Fixed by merged canonical/snapcraft#1199 (commit 417989880), making cleanbuild LXD detection packaging-independent instead of relying on apt package metadata. | |
| #1791977 rerun snapcraft as root if on managed-host | snapcraft (launchpad) | closed | Fixed managed-host builds by re-executing Snapcraft as root; PR snapcore/snapcraft#2281 merged as d6ec1d24e. | |
| #1822372 Snapcraft cleanbuild on Arch Linux with LXD - AppArmor permission error | snapcraft (launchpad) | closed | LP #1822372 closed as not-a-bug/stale: reporter resolved the AppArmor error with an LXD profile workaround (security.nesting/privileged, raw.lxc cgroup lines); maintainer later closed it noting cleanbuild was removed as builds are clean by default. | |
| #1741082 sshfs breaks with serving user files to root in LXD | snapcraft (launchpad) | closed | Fixed by merged PR canonical/snapcraft#1847 (commit e7d73a365), creating a matching user for remote LXD sshfs builds so project files are not left root-owned. | |
| #1992213 Snapcraft crashes when the APT unprivileged user owns the host's source list file instead of root | snapcraft (launchpad) | open | Snapcraft 8187 crashed opening a 0600 _apt-owned APT metadata file. The legacy LXD path was removed, but equivalent current apt-cache checks still need review. | |
| #1746612 Snapcraft cleanbuild doesn't work if you're not using the LXD snap | snapcraft (launchpad) | closed | Closed after the missing hostfs behavior was fixed upstream in lxc/lxd#4183. Snapcraft PR #1912 offered a workaround but was not merged. | |
| #1719996 Wrong permission on resources when on SNAPCRAFT_CONTAINER_BUILDS=1 | snapcraft (launchpad) | closed | Fixed by snapcore/snapcraft PR #1588, which corrected UID handling for SNAPCRAFT_CONTAINER_BUILDS=1 and resolved root ownership of generated build directories. | |
| #1703344 snapcraft cleanbuild exits with a traceback when lxd is not installed | snapcraft (launchpad) | closed | Fixed cleanbuild’s traceback when LXD is absent by handling the missing lxc executable and reporting a clear error. Merged in snapcraft#1400. |