LoginSignup
0
0

MongoDBの公開鍵更新

Last updated at Posted at 2023-05-23

aptで使用されるMongoDBの公開鍵の更新を行ったので、その際の手順についてご紹介します。

環境

  • Debian 10 (Buster)
  • MongoDB 4.2

起きたこと

Debianサーバーのセキュリティーアップデートをかけようとした際、次のような警告が出ました。

$ sudo apt update
...
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 Release: The following signatures were invalid: EXPKEYSIG 4B7C549A058F8B6B MongoDB 4.2 Release Signing Key <packaging@mongodb.com>
W: Failed to fetch http://repo.mongodb.org/apt/debian/dists/buster/mongodb-org/4.2/Release.gpg  The following signatures were invalid: EXPKEYSIG 4B7C549A058F8B6B MongoDB 4.2 Release Signing Key <packaging@mongodb.com>
W: Some index files failed to download. They have been ignored, or old ones used instead.

どうやらMongoDBのリポジトリの認証が通らずフェッチに失敗し、MongoDBパッケージの更新ができなくなっているようです。

公開鍵の確認

MongoDBはDebianの公式パッケージリストに含まれていないため、リポジトリの情報と公開鍵をパッケージ管理システムに登録して、パッケージをインストールしています。

登録されている公開鍵の状態を確認します。

# apt-keyコマンドを使うためにgnupgをインストール
$ sudo apt install gnupg

# 登録済みの公開鍵リストを表示
$ apt-key list
/etc/apt/trusted.gpg
--------------------
pub   rsa4096 2018-04-18 [SC] [expired: 2023-04-17]
      E162 F504 A20C DF15 827F  718D 4B7C 549A 058F 8B6B
uid           [ expired] MongoDB 4.2 Release Signing Key <packaging@mongodb.com>

…

「[expired: 2023-04-17]」とあるように、有効期限切れのようです。

公開鍵の更新

最新の公開鍵をダウンロードして、登録済みの公開鍵と差し替えます。

# 最新の公開鍵をダウンロード
$ curl -O https://pgp.mongodb.com/server-4.2.asc
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1674  100  1674    0     0   2532      0 --:--:-- --:--:-- --:--:--  2532

# 登録済みの公開鍵を削除(冒頭の警告文中「EXPKEYSIG 4B7C549A058F8B6B」を指定)
$ sudo apt-key del 4B7C549A058F8B6B
OK

# ダウンロードした公開鍵を登録
$ sudo apt-key add server-4.2.asc
OK

# 確認
$ apt-key list
/etc/apt/trusted.gpg
--------------------
pub   rsa4096 2018-04-18 [SC] [expires: 2025-04-16]
      E162 F504 A20C DF15 827F  718D 4B7C 549A 058F 8B6B
uid           [ unknown] MongoDB 4.2 Release Signing Key <packaging@mongodb.com>

…

有効期限が「[expires: 2025-04-16]」に更新されました。
sudo apt updateを実行しても警告は出ず、パッケージの更新ができるようになりました。

さいごに

今回、Debian 10 (Buster)環境においてapt-keyコマンドを使用しましたが、apt-keyコマンドは既に非推奨となっているため、最新のDebianでは使えなくなっているようです。

代替コマンドとしてgpgコマンドを使った方法が提示されているようなので、お使いのバージョンに合わせてどちらのコマンドを使うかご検討ください。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0