背景
apt updateでwarningがでるようになた- いつの間にかapt-keyのやり方が変わっていたらしい
- 昔入れたdockerの入れ方によって発生していた
- 結構前からそうだったらしいが、2026年に気がついた
発生したwarning
1
2
3
| apt update
...
W: https://download.docker.com/linux/ubuntu/dists/noble/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
|
原因
古いdockerのインストールコマンドで入れた鍵の入れ方が原因だった。
1
2
3
4
5
6
7
8
9
10
11
12
13
| #!/bin/bash
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt install docker-ce docker-ce-cli containerd.io -y
sudo apt install docker-compose-plugin -y
sudo usermod -aG docker $USER
newgrp docker
docker ps
# reboot
|
どうやら、apt-key add - は今では非推奨らしい。
1
2
3
| sudo apt-key list
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
...
|
対応
以下で対応した。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| # まず中身確認
cat /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_ubuntu-noble.list
# Docker公式GPG鍵を新しい場所に配置
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# 新形式の docker.sources を作る
sudo tee /etc/apt/sources.list.d/docker.sources > /dev/null <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: noble
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF
# 古い Docker repo 定義を削除
sudo rm /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_ubuntu-noble.list
# 古い鍵の削除
sudo apt-key del 0EBFCD88
# 確認
sudo apt update
|
add key -と、ファイルを作る方式の違い
鍵の信頼範が違う。
sudo apt-key add -は全体の信頼済みの鍵になる。
置き場は、/etc/apt/trusted.gpgに置かれる。
他方、新しいものは、dockerリポジトリの中でのみ使う想定となる。
1
2
| sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
|
つまり、/etc/apt/trusted.gpgが非推奨になったということ。
検証方法の違い
もともとの検証方法:
1
2
3
4
5
6
7
8
9
| apt update
↓
sources.list / sources.list.d/ を読む
↓
各リポジトリから InRelease / Release.gpg を取る
↓
公開鍵(/etc/apt/trusted.gpg、/etc/apt/trusted.gpg.d/*.gpg)で署名を検証する
↓
OKなら、そのリポジトリのパッケージ一覧を信用してDL
|
新しい検証方法(dockerの場合):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| apt update
↓
/etc/apt/sources.list.d/docker.sources を読む
↓
URIs: https://download.docker.com/linux/ubuntu
Signed-By: /etc/apt/keyrings/docker.asc
↓
https://download.docker.com/linux/ubuntu から InRelease / Release.gpg を取得
↓
/etc/apt/keyrings/docker.asc の公開鍵で署名を検証
↓
署名OK
↓
Docker repo の Packages 一覧を信用
↓
docker-ce / docker-ce-cli / containerd.io などをDL・インストール可能にする
|
まとめ
- 今後は鍵は、個別に設置して、aptで設定するのがいい感じ
- サードパーティリポジトリの鍵を
/etc/apt/trusted.gpg に入れる方式は避ける - 今後は
/etc/apt/keyrings/ に鍵ファイルを置き、.sources または .list 側で Signed-By を指定する - これにより、鍵の信頼範囲を特定のリポジトリに限定できる
参考文献