Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom signing key for images does not work gnupg 2.4 / flatcar beta #1471

Closed
juliantaylor opened this issue Jun 14, 2024 · 3 comments · Fixed by flatcar/init#123
Closed
Labels
kind/bug Something isn't working

Comments

@juliantaylor
Copy link

juliantaylor commented Jun 14, 2024

Description

since 3913.1.0 in the beta channel gnupg 2.4 is used, this seems to break usage of custom signing keys due to dirmngr not being present in the installer image and the installer using hardcoded key in the --trusted-key argument despite running flatcar-install -k customkey

Impact

self signed images cannot be installed

Environment and steps to reproduce

gnupg 2.4 on flatcar 3941.1.0

# gpg --version
gpg (GnuPG) 2.4.4
libgcrypt 1.10.3-unknown
Copyright (C) 2024 g10 Code GmbH

gpg --import Flatcar_Image_Signing_Key.asc 
gpg: directory '/root/.gnupg' created
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key C99502A9B080DAF6: public key "testt" imported
gpg: Total number processed: 1
gpg:               imported: 1

# some arbitrary trusted key that does not exist locally (hardcoded in flatcar installer)
# gpg --dirmngr-program /doesnotexist --batch --trusted-key 06B7853EF0C91158 --verify flatcar_production_image.bin.bz2.sig flatcar_production_image.bin.bz2 && echo SUCCESS
gpg: Signature made Fri Jun 14 13:58:05 2024 UTC
gpg:                using RSA key 6B7853EF0C91158A4A9401B8C99502A9B080DAF6
gpg: error running '/doesnotexist': probably not installed
gpg: failed to start dirmngr '/doesnotexist': Configuration error
gpg: can't connect to the dirmngr: Configuration error
gpg: key 06B7853EF0C91158: no public key for trusted key - skipped
gpg: key 06B7853EF0C91158 marked as ultimately trusted
gpg: Good signature from "testt" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 6B78 53EF 0C91 158A 4A94  01B8 C995 02A9 B080 DAF6

verification failed here despite gpg: Good signature from "testt" [unknown], it exited with code 2

in comparison on flatcar 3874.1.0:

# gpg --version
gpg (GnuPG) 2.2.35
libgcrypt 1.10.2-unknown

# gpg --import Flatcar_Image_Signing_Key.asc
gpg: keybox '/root/.gnupg/pubring.kbx' created
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key C99502A9B080DAF6: public key "testt" imported
gpg: Total number processed: 1
gpg:               imported: 1

# gpg --dirmngr-program /doesnotexist --batch --trusted-key 06B7853EF0C91158 --verify flatcar_production_image.bin.bz2.sig flatcar_production_image.bin.bz2 && echo SUCCESS
gpg: Signature made Fri Jun 14 13:58:05 2024 UTC
gpg:                using RSA key 6B7853EF0C91158A4A9401B8C99502A9B080DAF6
gpg: key 06B7853EF0C91158: no public key for trusted key - skipped
gpg: key 06B7853EF0C91158 marked as ultimately trusted
gpg: Good signature from "testt" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 6B78 53EF 0C91 158A 4A94  01B8 C995 02A9 B080 DAF6
SUCCESS

verification succeeded

Expected behavior

self signed images can be installed with verification

If we could override the --trusted-key in the flatcar installer gnugpg would not try to invoke dirmngr and it would work but the trusted key is hardcoded in the installer.

@juliantaylor juliantaylor added the kind/bug Something isn't working label Jun 14, 2024
@juliantaylor juliantaylor changed the title custom signing key for images does not work gnupg 2.4 custom signing key for images does not work gnupg 2.4 / flatcar beta Jun 14, 2024
@chewi
Copy link
Contributor

chewi commented Jun 17, 2024

I can't comment on overriding the trusted key, but dirmngr is missing because gnupg has been built with USE="-ssl" due to the ssl flag being masked against this package. The reason given in the package.use.mask file is that Flatcar doesn't ship with gnutls by default, but I don't think that's true anymore. I can see libgnutls.so on my test VM.

@juliantaylor
Copy link
Author

thanks, removing the masking of ssl in sdk_container/src/third_party/coreos-overlay/profiles/coreos/base/package.use.mask and thus having dirmngr installed allows self signed images to install again.

@chewi
Copy link
Contributor

chewi commented Jun 19, 2024

I may make that change, but it's not the proper fix here. I understand the issue now and am discussing the solution. We probably want --assert-signer rather than --trusted-key and it obviously needs to be adjusted for custom keys.

chewi added a commit to flatcar/init that referenced this issue Jun 21, 2024
Using a custom key was recently broken by a GnuPG update. The Flatcar
key is not imported when a custom key is given, but we still reference
the Flatcar key with --trusted-key regardless, causing gpg to attempt to
download the key from a keyserver. This fails because we no longer ship
the necessary dirmngr binary, which is now only built when GnuPG has
GnuTLS support enabled.

Enabling GnuTLS support works around the problem, but it is not the
proper fix. --trusted-key causes gpg to trust the given key, even though
there is no secret key present. This is unnecessary, as the key would be
trusted anyway, albeit with a warning. --assert-signer makes more sense,
as this ensures the file was signed specifically by the given key rather
than some other key you happen to have in your keyring.

--assert-signer only accepts the long key ID, not the key file. There is
no way to discover the key ID of a key that has just been imported, but
you can get it from the original key file in a stable manner.

Closes: flatcar/Flatcar#1471
Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
Development

Successfully merging a pull request may close this issue.

2 participants