要求が多すぎると、gpg-agentがキーパスワードを「忘れてしまう」

要求が多すぎると、gpg-agentがキーパスワードを「忘れてしまう」

Regolith経由でUbuntuを実行してログインすると、gpgキーのロックが解除されます。複数の復号化タスクを並列に実行していますが、7を超えると、gpg-agentキーがロック解除されたことを「忘れて」pinentryを求めるメッセージが表示されます。

❯ gpg --version
gpg (GnuPG) 2.2.27
libgcrypt 1.10.1

私はこれをPythonとして示すために最小限の作業例を作成しました。

復号化するテストファイルを作成します。 。パスワードを要求せずにecho "something" | gpg --encrypt -o test.gpgシェルで実行します。gpg --decrypt test.gpg

以下のスクリプトを使用してWORKERNUM8未満に設定すると(マイコンピュータでは1に設定すると、すべてのコンピュータで動作するようです)、スクリプトはパスワードを要求せずにパスワードを復号化します。しかし、8以上に増やすと、すべてのプロセスから出るわけではなく、一部のプロセスから出てくるようですが、パスワードの要求を受け始めます。プロセスの実行も明らかに中断され始めます(待機中であると仮定しますgpg-agent)。

import subprocess
import multiprocessing as mp
import time



the_queue = mp.Queue()
WORKERNUM = 7

def worker_main(queue):
    while True:
        msg = queue.get(True)
        print(time.time(), msg)
        out = subprocess.run(["gpg", "--decrypt", "test.gpg"], capture_output=True)
        print(msg, time.time(), out.stdout)


the_pool = mp.Pool(WORKERNUM, worker_main, (the_queue,))

counter = 0
while True:
    counter += 1
    the_queue.put(counter)
    print(the_queue.qsize())
    while the_queue.qsize() > 10:
        time.sleep(0.1)

--batchdecryptコマンドを渡そうとしましたが、何も変更されませんでした。これに関連する言及があるかどうかをgpg調べるためにマニュアルページを見てみましたが、gpg-agent何も見つかりません。 2つの質問があります。

a)なぜこれが起こるのか、b)これを防ぐために、処理プールの最大サイズを把握する必要がなく、代わりにgpgそれを処理してpinentryを取得しないように設定できますか?

ベストアンサー1

慎重に観察した最後にjournalctl見つけた実際エラーはですCannot allocate memory。に基づいてこの議論gpg-agent複数のスレッドがセキュアメモリにアクセスしようとすると、セキュアメモリが使い果たされる可能性があります。設定すると問題が解決auto-expand-secmem 100します。~/.gnupg/gpg-agent.conf

       --auto-expand-secmem n                                                                                                                                  Allow Libgcrypt to expand its secure memory area as required. The optional
value n is a non-negative integer with a suggested size in bytes of each
additionally allocated secure memory area. The value is rounded up to the next
32 KiB; usual C style prefixes are allowed. For an heavy loaded gpg-agent with
many concurrent connection this option avoids sign or decrypt errors due to out
of secure memory error returns.

おすすめ記事