[小ネタ]CodeBuild(Ubuntuベース)でYarn PackagingのGPG errorが発生した場合の一時回避方法

2021.02.03

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

AWS事業本部 福岡オフィスの梶原です。

CI/CDしてますか?

CodeBuildをよく使用しているのですが、CodeBuild内でapt-get updateを実施した際に、下記エラー(The following signatures were invalid: EXPKEYSIG)がでてしまい、一時回避したので共有します。

事象

CodeBuildにビルドの際に、エラーが発生し、ビルドがエラーを検知し途中で停止してしまいます。

CodeBuildのオペレーティングシステム(Ubuntu)の環境イメージ

aws/codebuild/standard:5.0-21.01.08

エラーログ

[Container] 2021/02/03 07:50:14 Running command apt-get update
Get:1 https://dl.yarnpkg.com/debian stable InRelease [17.1 kB]
Get:2 https://apt.corretto.aws stable InRelease [10.7 kB]
Get:3 http://dl.google.com/linux/chrome/deb stable InRelease [1811 B]
Get:10 https://dl.bintray.com/sbt/debian  Release.gpg [821 B]
Err:1 https://dl.yarnpkg.com/debian stable InRelease
  The following signatures were invalid: EXPKEYSIG XXXXXXXXXXXXX Yarn Packaging <yarn@dan.cx>

<中略>

Reading package lists...
W: GPG error: https://dl.yarnpkg.com/debian stable InRelease: The following signatures were invalid: EXPKEYSIG XXXXXXXXXXXXX Yarn Packaging <yarn@dan.cx>
E: The repository 'https://dl.yarnpkg.com/debian stable InRelease' is not signed.
[Container] 2021/02/03 08:01:02 Command did not exit successfully apt-get update exit status 100
[Container] 2021/02/03 08:01:02 Phase complete: INSTALL State: FAILED
[Container] 2021/02/03 08:01:02 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: apt-get update. Reason: exit status 100

回避方法

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -

をapt-get update前に実施します。 Issueの参考URLではsudo apt-key add - となっていますが、apt-key add - で実施します

Buildspec.yml

version: 0.2
phases:
  install:
    commands:
      # 公開鍵の最新化
      - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
      - apt-get update
  build:
    commands:
       - 省略

対応後

[Container] 2021/02/03 08:22:56 Running command curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
Warning: apt-key output should not be parsed (stdout is not a terminal)
OK

省略
Get:1 https://apt.corretto.aws stable InRelease [10.7 kB]
Get:2 https://dl.yarnpkg.com/debian stable InRelease [17.1 kB]

[Container] 2021/02/03 08:23:06 Phase complete: INSTALL State: SUCCEEDED

要因

Yarn Debian key expiry date updated (EXPKEYSIG 23E7166788B63E1E) ほぼ、こちらのIssueeに書いてありますが公開鍵の不一致が原因とのことで、最新化すれば回避できるようです

恒久対応

恒久対応としては、環境イメージのバージョンを固定せずに最新のイメージを使用していれば、イメージが更新されたタイミングでエラーがでなくなる状況かと思いますので 一時的に回避策を使用し、イメージの更新がされ、対応後は該当の処理は削除してよいかと思います。

参考

【Tips】aptから入れたUbuntuのyarnが正しくupdateできないときの対応 https://qiita.com/GandT/items/763c48f0aadbfff1e638

Yarn Debian key expiry date updated (EXPKEYSIG 23E7166788B63E1E) https://github.com/yarnpkg/yarn/issues/7866