Running snapcraft 7 locally as regular user fails due to apt-get permissions

Being able to test snapcraft builds locally before submitting to a CI builder is a huge time-saver for me. Since I already do this in a dedicated VM, I use SNAPCRAFT_BUILD_ENVIRONMENT=host in order to avoid creating unnecessary layers of abstraction/resource use.

However, since updating to snapcraft 7, trying to run this is a regular user leads to a permission error:

$ snapcraft
Executed: pull <some-part>                                                                                                                                                                 
Failed to refresh package list: failed to run apt update.                                                                                                
Full execution log: '/<...>/log/snapcraft-20220718-170429.544282.log'

The above error is fairly self explanatory: the log file confirms that snapcraft tries to run apt-get update and fails, which makes sense since it’s running under a regular user without permissions to the relevant system files. I’m not sure how this worked previously, but this was definitely not an issue with older versions of snapcraft.

Am I trying to do something that is no longer supported? Should I be running snapcraft with sudo?

Snapcraft 6 and earlier ran sudo internally for some calls, but this was changed in 7.x because snapcraft already runs as root inside of its managed build environment. To replicate this in your own dedicated build VM you’ll need to run snapcraft with the appropriate permissions (as root or using sudo).

Ok perfect, thanks for confirming this @cmatsuoka! The new behavior does indeed make more sense.

1 Like