Chrootbuild does not use the keys from the user keyring

From a previous conversation: in Buildpkg: how to provide public keys - #3 by Yochanan

Please use chrootbuild instead. It will automatically import your user keyring.

This does not seem to work.

Probably, sudo chrootbuild -p package -c does indeed chreate a chroot where the user keyring is copied in. But then every time you build the package, on build the keyring is wiped out and re-populated using /etc/chrootbuild/build.sh which tries to receive the keys from keyservers.

So, even if you have the keys in your keyring and/or the package itself has the keys in keys/pgp the build will fail if a key is needed that is not on the default keyserver.

For instance, try:
sudo chrootbuild -b stable -c -p kquickimageeditor taking the kquickimageeditor source package from the arch source package repo (https://gitlab.archlinux.org/archlinux/packaging/packages/kquickimageeditor).

Is chrootbuild buggy?

A more careful analysis:

During create_chroot(), chrootbuild explicitly creates /build/.gnupg and copies either ~/.gnupg/pubring.kbx or pubring.gpg from the invoking user’s home:

$install -d "$1"/{build,build/.gnupg,...}

for x in .gnupg/pubring.{kbx,gpg}; do
    [[ -r ${USER_HOME}/$x ]] || continue
    $install -m 644 "${USER_HOME}/$x" "$1/build/$x"
done

And USER_HOME is deliberately set to /home/${SUDO_USER} when run as root via sudo, so this is indeed your normal user’s GPG keyring.

Then, before every package build, build_pkg() does:

build_dir=${CHROOT_DIR}/build
rm -rf ${build_dir}/.[!.]*

.gnupg matches .[!.]*, so that deletes:

/var/lib/chrootbuild/build/.gnupg

including the pubring.kbx that create_chroot() copied.

My impression is that current upstream chrootbuild intentionally depends on gpg --recv-keys for PKGBUILD source-signature keys. The user-keyring-copy code looks like a leftover from the pre-2021 design.

Changing /etc/chrootbuild/build.sh into:

#!/bin/bash

export LC_ALL=en_US.UTF-8;
. /etc/profile;
cd /build/$1
. PKGBUILD
echo "validating keys: ${validpgpkeys[@]}"

# ===== BEGIN LOCAL MODIFICATION =====

# Import bundled package keys first, if present.
if compgen -G 'keys/pgp/*' > /dev/null; then
    gpg --import keys/pgp/*
fi

# Fetch from the keyserver only keys that are still missing.
missing_keys=()
for key in "${validpgpkeys[@]}"; do
    gpg --list-keys "$key" &>/dev/null || missing_keys+=("$key")
done

if (( ${#missing_keys[@]} )); then
    gpg --recv-keys "${missing_keys[@]}"
fi

# ===== END LOCAL MODIFICATION =====

makepkg -$2 --noconfirm

works around the issue by letting one use the keys in the package itself.


Moderator edit: Merged consecutive replies

The -c means a clean chroot - that means a complete reset of the root.

Yes, -c means recreate the chroot from zero. I think it was suggested in Buildpkg: how to provide public keys - #3 by Yochanan because the code copies the user keyring into the chroot when the chroot is re-created.

However, as mentioned, this is not useful anymore, since the keyring is wiped and recreated before the build actually starts.

As I recall the chrootbuild script is adapted from Arch Linux chrootbuild.

I do not know if there has been any changes to the upstream version which Manjaro has not implemented…

I think this is an issue with the package in question.

If you look into the keys folder - you will find these keys

07:07:23 ± [fh@tiger] ~/.../keys/pgp
[main] $ ls -l
total 12
-rw-r--r-- 1 fh fh 2257  3 okt 06:57 39FFA93CAE9C6AFC212AD00202325448204E452A.asc
-rw-r--r-- 1 fh fh  734  3 okt 06:57 931703E04546328CEE35B5A51F7428FFC412A679.asc
-rw-r--r-- 1 fh fh 3898  3 okt 06:57 B3ED0BAE371BEDA00717921D18F4795C1CE7042B.asc

Do note the key

-rw-r--r-- 1 fh fh  734  3 okt 06:57 931703E04546328CEE35B5A51F7428FFC412A679.asc

Which contains the public key you are missing in the pacman keyring

==> Verifying source file signatures with gpg...
    kquickimageeditor-0.7.0.1.tar.xz ... FAILED (unknown public key 1F7428FFC412A679)
==> ERROR: One or more PGP signatures could not be verified!
==> ERROR: Building package [kquickimageeditor] failed.
      Cleaning up.

This makes me think the key is no longer in the Arch Linux keyring… or it has not yet propagated to the stable branch

I have verified the issue and I have tested your changes to the build.sh script.

I think you are correct that the reason is related to the changes in upstream packaging with relation to the key management.

I think it would be good if @philm or @Yochanan looked at this…

That is an upstream developer key and would never be in the Arch Linux keyring.

In a case like that, one needs to import the key to their user keyring, then chrootbuild will pick it up. In this case, that key is neither available via the Ubuntu nor OpenPGP keyserver, so it would need to be imported manually.

@callegar Nothing has changed since the topic you referenced and chrootbuild is working as intended.

In a case like that, one needs to import the key to their user keyring, then chrootbuild will pick it up

What I am trying to say is that chrootbuild won’t pick up user keyrings, contrarily to what it is being said. Looking at the code, it picks it up keys from the user keyring when building the chroot, but then it deletes them right after before it can use them. Is this really intended?

I don’t really grasp where the problem is - to my knowledge the chrootbuild work as it is expected.

I reckon that using an Arch Linux native PKGBUILD is outside the scope of the Manjaro version of chrootbuild.

It is possible to work around the issue you have described, but as the build.sh script is not marked as a backup file, it is going to be replaced on package updates.

The problem that I am encountering is that it is written almost everywhere, including in this thread that chrootbuild should import the keys from the user keyring into the chroot when the chroot is created, with sudo chrootbuild -c -p <somepackage>.

However, this does not work. If you look at the code it is because chrootbuild does in fact create the chroot with the keys imported into it, but then immediately deletes the keyring before starting to build any package, so the imported keys cannot be used.

  • The fact that a feature is reported to exist, but in fact not working is IMHO a bit problematic in itself, because this ends up being confusing and pushes users of the tool into time consuming debugging sessions. If copying the keys from the user keyring is something that cannot be relied upon, it would be better to have it clearly stated;
  • If the copying of the keys from the user keyring is something that ultimately doesn’t let the keys to be used, then it seems unnecessary to copy them at all. Probably in chrootbuild there is some old code that should have been removed and it is its existance that still makes everyone say that the keys from the user keyring are imported and used by chrootbuild.
  • In fact, being able to copy and use keys from the user keyrings would be useful when dealing with "foreign packages* as in my case (e.g. when trying to fix a package that is broken but coming directly from arch). So another possibility would be to make that work.

It could be… I don’t know enough about the design choices made so long ago.

When I joined the Manjaro Team many years ago, it used the be the buildpkg script which were used to build packages. I have used the chrootbuild to build single AUR packages with no issues. I also used the same script to build packages which has AUR dependencies and that can also be done - suffice you build in the correct order and install the dependency into the chroot.

But your example appears to be about the upstream developer keys which are provided by the keys folder provided by the PKGBUILD repository.

Those keys may or may not be available using gpg --recv-keys which makes them a bit dangerous to blindly trust.

I just tested building kquickimageeditor and it seems we have a unique case here. It seems to be an issue with one of the keys, not chrootbuild itself.

==> Verifying source file signatures with gpg...
    kquickimageeditor-0.7.0.1.tar.xz ... FAILED (unknown public key 1F7428FFC412A679)
==> ERROR: One or more PGP signatures could not be verified!
❯ gpg --import keys/pgp/*
gpg: key 02325448204E452A: public key "Carl Schwan <carl@carlschwan.eu>" imported
gpg: key 1F7428FFC412A679: public key "Noah Davis <noahadvs@gmail.com>" imported
gpg: key 18F4795C1CE7042B: public key "Carl Schwan <carl@carlschwan.eu>" imported
gpg: Total number processed: 3
gpg:               imported: 3

Carl Schwan’s keys are on the keyserver, however the RSA key is different. The fingerprint matches the one listed in the PKGBUILD.

❯ gpg --search-keys --keyserver=hkps://keyserver.ubuntu.com carl@carlschwan.eu
gpg: data source: https://185.125.188.27:443
(1)	Carl Schwan <carl@carlschwan.eu>
	Carl Schwan <carlschwan@kde.org>
	  2048 bit RSA key 02325448204E452A, created: 2022-09-27
(2)	Carl Schwan <carl@carlschwan.eu>
	  4096 bit RSA key 18F4795C1CE7042B, created: 2019-03-01
❯ gpg --fingerprint 02325448204E452A
pub   rsa2048 2022-09-27 [SC]
      39FF A93C AE9C 6AFC 212A  D002 0232 5448 204E 452A
uid           [ unknown] Carl Schwan <carl@carlschwan.eu>
uid           [ unknown] Carl Schwan <carlschwan@kde.org>
sub   rsa2048 2022-09-27 [E]
      3F16 00DF 6822 51AB 08CA  8B82 189C 3BD7 B5AE 6D1D

Notice chrootbuild imports the current 02325448204E452A RSA key:

:: Update chroot file system
:: Synchronizing package databases...
 core is up to date
 extra is up to date
 multilib is up to date
:: Starting full system upgrade...
 there is nothing to do
validating keys: 39FFA93CAE9C6AFC212AD00202325448204E452A 931703E04546328CEE35B5A51F7428FFC412A679
gpg: directory '/build/.gnupg' created
gpg: /build/.gnupg/trustdb.gpg: trustdb created
gpg: key 02325448204E452A: public key "Carl Schwan <carl@carlschwan.eu>" imported
gpg: Total number processed: 1
gpg:               imported: 1
==> Making package: kquickimageeditor 0.7.0.1-1 (Mon 05 Oct 2026 02:38:25 PM UTC)

However, it still failed as it’s still trying to validate 1F7428FFC412A679.

The !. specifies to ignore anything matching .; therefore it’s not removing the .gnupg folder. Keep /var/lib/chrootbuild/build/.gnupg/ open in your file manager and you’ll see it is not removed when checking the PGP keys.

What does that mean, exactly? What’s the “pre-2021 design”? :thinking:

That’s actually helpful, I’ll add it.

EDIT: Added with manjaro-chrootbuild r328.5f32c15-1.

1 Like

Indeed - which I pointed out earlier

And I repeated this - in other words

1 Like

Thanks for looking into it. Just a little background. There is an issue with the current QML compiler in Qt that prevents this package from operating correctly, which in turn causes applications depending on it to misbehave, kscanpage being a notable example. This is why I am trying to rebuild the package to see if tweaking the build process to change the way in which the QML compiler operates with it can temporarily work around the issue (good news, it does).

I’ll check again if I came to hasty to the conclusion that the keyring in the chroot is removed before the build. For sure, importing the 1F7428FFC412A679 in the user keyring, and invoking chrootbuild so that the chroot is recreated (so that the user keys should get in the chroot keyring) is not enough to have the 1F7428FFC412A679 key correctly used in the build, so there is probably something wrong.

Apparently, from the commit history, some code that regards key management in chrootbuild got significant changes about 2021, so I suspected some corner case didn’t get tested there.

Thanks for considering it.

Indeed. However, you should be able to import that key in your user keyring, then use chrootbuild with the -c flag so that the chroot is recreated and the keys from your user keyring are imported in the chroot keyring and have the key used in the build process. Unfortunately, this fails. So this package is likely hitting a corner case where chrootbuild does not fully work as advertised. It may be useful to look into why (even if the last commit from @Yochanan in r328.5f32c15-1 already helps).