Discourse コンテナは unattended-upgrades を使用しますか?

Discourse の Docker コンテナは、Debian ベースの Docker コンテナ内の OS パッケージを最新の状態に保つために unattended-upgrades を使用していますか?

INSTALL-cloud.md ガイドでは、Docker ホストマシンに unattended-upgrades をインストールすることが推奨されているため、Docker コンテナ内部の OS パッケージの状態が気になりました。GitHub 上の discourse および discourse_docker リポジトリを検索しましたが、unattended-upgrades への言及が見つかったのは、同じインストールドキュメントのみでした。

では、Discourse の Docker コンテナ自体はどうでしょうか? それunattended-upgrades を使用していますか?

さらに調査を進めた結果、Discourse の Docker コンテナでは unattended-upgradesインストールされているが、実行されていないことが判明しました

おそらく意図的に無効になっているのでしょう。何か問題を引き起こす可能性があるためです。画像自体は、深刻なセキュリティ問題が発見された際に更新されます。

必要であれば有効にできます。コンテナにアクセスするだけです。

実は、Discourse の Docker イメージが runit を使用するように設定されていることに気づきました。Discourse の Docker コンテナには systemd がインストールされているのでしょうか?

私の推測では、systemd がインストールされていないことが unattended-upgrades の失敗の原因ではないかと考えられます。

その通りですね。systemdが好きな人ばかりではありません。そのため、その基盤となるコンテナを、それを利用する大規模な専門チームが定期的に更新してくれると信頼するか、あるいは自分で別の方法で更新し、何かを壊さないことを祈るかのどちらかを選ぶことができます。

いいえ、使用していませんし、今後使用させる予定もありません。推奨される方法は、ホスト OS を最新のセキュリティパッチで更新し続けることです。

念のため言っておきますが、実際には更新されています。

参考までに、Discourse Docker コンテナでは systemd が動作しないため実際には実行されない unattended-upgrades のインストール不具合を、cron ジョブを介して実行をトリガーすることで修正しました。

必要な cron ジョブを作成するために、以下の YAML テンプレートファイルを /var/discourse/templates/ ディレクトリに作成しました(Debian ベースの Discourse Docker イメージに同梱されている cron のバグ修正 コマンドも含まれています):

cat << EOF > /var/discourse/templates/unattended-upgrades.template.yml
run:
  - file:
     path: /etc/cron.d/unattended-upgrades
     contents: |+
        ################################################################################
        # File:    /etc/cron.d/unattended-upgrades
        # Version: 0.2
        # Purpose: run unattended-upgrades in lieu of systemd. For more info see
        #           * https://wiki.opensourceecology.org/wiki/Discourse
        #           * https://meta.discourse.org/t/does-discourse-container-use-unattended-upgrades/136296/3
        # Author:  Michael Altfield <michael@opensourceecology.org>
        # Created: 2020-03-23
        # Updated: 2020-04-23
        ################################################################################
        20 04 * * * root /usr/bin/nice /usr/bin/unattended-upgrades --debug
        

  - exec: /bin/echo -e "\n" >> /etc/cron.d/unattended-upgrades
  # fix the Docker cron bug https://stackoverflow.com/questions/43323754/cannot-make-remove-an-entry-for-the-specified-session-cron
  - exec: /bin/sed --in-place=.\`date "+%Y%m%d_%H%M%S"\` 's%^\([^#]*\)\(session\s\+required\s\+pam_loginuid\.so\)$%\1#\2%' /etc/pam.d/cron
EOF

上記のテンプレートファイルを有効にするには、アプリの YAML ファイル内の templates リストに追加する必要があります。例を以下に示します:

[root@osestaging1 discourse]# head -n20 /var/discourse/containers/app.yml
## this is the all-in-one, standalone Discourse Docker container template
##
## After making changes to this file, you MUST rebuild
## /var/discourse/launcher rebuild app
##
## BE *VERY* CAREFUL WHEN EDITING!
## YAML FILES ARE SUPER SUPER SENSITIVE TO MISTAKES IN WHITESPACE OR ALIGNMENT!
## visit http://www.yamllint.com/ to validate this file as needed

templates:
  - "templates/unattended-upgrades.template.yml"
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
#  - "templates/web.socketed.template.yml"
  - "templates/web.modsecurity.template.yml"
  - "templates/web.ratelimited.template.yml"
## Uncomment these two lines if you wish to add Lets Encrypt (https)
  #- "templates/web.ssl.template.yml"
  #- "templates/web.letsencrypt.ssl.template.yml"
[root@osestaging1 discourse]# 

新しい Discourse の Docker イメージ(Debian 10 実行中)では、これが有効になっているようです。これは runit → cron → /etc/cron.daily/apt-compat → /usr/lib/apt/apt.systemd.daily を介して起動されます。

また、1 年前の Ubuntu 16 ベースの Docker イメージ(discourse/base:2.0.20190321-0122 ベース)でも動作していました。カスタマイズは行っていないと確信しています。

[quote=“tormod, post:10, topic:136296”]
runit → cron → /etc/cron.daily/apt-compat → /usr/lib/apt/apt.systemd.daily の順で起動されます。[/quote]

systemd がインストールされていないため、実際には実行されません。