-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[antlir2][rpms] improved gpg key handling
Summary: I discovered some pretty nasty bugs where dnf's gpg key checking actually depends on what is installed in the build appliance image. When trying to minimize the size of the BA, I removed some unused rpms from `fb-runtime`, then suddenly I was no longer able to build any images that installed rpms from `fb-runtime`! Even more confusing, `dnf` sometimes does not import all the keys used in a repo - if there are multiple public keys in a single file, dnf will only import the first one, causing weird package installation failures later on. This diff moves more GPG key behavior directly into antlir2: All GPG keys for a repo are now imported. Unsigned packages are blocked if the repo they belong to has one or more GPG keys. Test Plan: ``` ❯ buck2 test fbcode//antlir/antlir2/test_images/rpms/sig: Buck UI: https://www.internalfb.com/buck2/ab7a8eb4-53b3-430a-b471-eab2d8a40ce7 Test UI: https://www.internalfb.com/intern/testinfra/testrun/11540474050704033 Network: Up: 1.1MiB Down: 0B (reSessionID-a315b0d4-baef-484b-9f21-b434a172669b) Jobs completed: 147. Time elapsed: 21.5s. Cache hits: 0%. Commands: 87 (cached: 0, remote: 0, local: 87) Tests finished: Pass 14. Fail 0. Fatal 0. Skip 0. Build failure 0 ``` Failing images: ``` ❯ buck2 test -c antlir2.rpm_sig_broken_images=1 fbcode//antlir/antlir2/test_images/rpms/sig: Buck UI: https://www.internalfb.com/buck2/1c58eaf5-226a-48b2-9113-dd4cf4608c0e Test UI: https://www.internalfb.com/intern/testinfra/testrun/7318349583684467 ... 2023-10-09T19:55:34.845020Z TRACE compile:rpms: rpm: dnf-driver: GpgError { package: Package { name: "unsigned", epoch: 0, version: "0", release: "0", arch: "noarch" }, error: "RPM is not signed" } ... ... 2023-10-09T19:55:34.901547Z TRACE compile:rpms: rpm: dnf-driver: GpgError { package: Package { name: "signed-with-wrong-key", epoch: 0, version: "0", release: "0", arch: "noarch" }, error: "public key not available" } ... Failed to build 'fbcode//antlir/antlir2/test_images/rpms/sig:install-unsigned (ovr_config//platform/linux:x86_64-fbcode-platform010-clang15#fdd3fedc5f835a2f)' Failed to build 'fbcode//antlir/antlir2/test_images/rpms/sig:install-signed-with-wrong-key (ovr_config//platform/linux:x86_64-fbcode-platform010-clang15#fdd3fedc5f835a2f)' ``` Reviewed By: epilatow Differential Revision: D50094060 fbshipit-source-id: a710ae5f1a8cecd0d0d63acfa0fea641fba5eaf8
- Loading branch information
1 parent
034cefb
commit 9fcec20
Showing
6 changed files
with
392 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
antlir/antlir2/test_images/rpms/sig/test_install_signed_imported_keys.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
use std::collections::HashSet; | ||
use std::process::Command; | ||
|
||
#[test] | ||
fn installed_keys() { | ||
let out = Command::new("rpm") | ||
.arg("--root") | ||
.arg("/layer") | ||
.arg("-q") | ||
.arg("gpg-pubkey") | ||
.output() | ||
.expect("failed to run cmd"); | ||
let stdout = String::from_utf8(out.stdout).expect("cmd output not utf8"); | ||
assert!(!stdout.is_empty()); | ||
let keys: HashSet<_> = stdout.lines().map(|l| l.trim()).collect(); | ||
assert_eq!( | ||
keys, | ||
HashSet::from([ | ||
// key that 'signed' is signed with | ||
"gpg-pubkey-bf8dba69-6524319d", | ||
// 'unused' key that is also set as trusted for the test repo | ||
"gpg-pubkey-22b685ee-652452bf", | ||
// unused key prepended to key.pub but not used to sign any packages | ||
"gpg-pubkey-efb03108-6524638a", | ||
]) | ||
); | ||
} |
Oops, something went wrong.