tempfile.mkstemp: add mode=0o600 parameter
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- python
調査の方向性
tempfile.mkstemp と tempfile._mkstemp_inner から始め、過去のコンテキストを確認するために、リンクされた Borg の議論と修正を確認してください。現在ハードコードされているモードがどのように適用されているか、モードパラメーターが両方のエントリーポイントを通じてどのように渡されるか、またデフォルトと umask の動作をどのように変更せず維持すべきかを検証してください。要求されたモードが、セキュアなデフォルトを変更せずにサポートされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Enhancement
Currently the file mode for the temp file is hardcoded to be 0o600. While this might be a good default for real temporary files for security reasons, I propose it should offer flexibility if the use case is slightly different.
It can and should still default to 0o600, but should not be hardcoded.
Besides having "real" temp files that just get thrown away, a popular use case for temp files is also this:
- create a temp file in a specific parent directory (same as parent dir of final file)
- write data to the temp file (e.g. a new configuration file)
- close the file, sync data and metadata to disk
- atomically rename the temp file over the previous version of the file (must be on same fs for this, see step 1)
- sync again
That way, the file has always valid contents (either the old version or the new version) and you never get 0-bytes files or otherwise corrupted files.
The problem with the hardcoded 0o600 mode in such an application is that the file you end up with (and which is not temporary any more, but your final file (e.g. config file)) will also have that 0o600 mode, which is unexpected if your umask usually would create files with e.g. 0o660 mode.
Trying to "fix" the file mode has pitfalls:
- to get the umask, you have to set it (and potentially re-set it again to the returned value), which is awkward
os.chmodis not supported on all filesystems and might throw an exception. this issue might go unnoticed until someone uses the code with e.g.cifs(samba share).- even if the chmod works, posix ACLs might still behave in unexpected ways (see link in "previous discussion")
The root cause of this issue is the 0o600 mode. If one uses 0o666, everything behaves as normal, umask works, final mode is correct, ACLs don't get modified. Note that when giving mode=0o666, the umask will still get applied afterwards, so one might well end up with a 0o660 or 0o640 mode on the file.
Pitch
tempfile.mkstemp(..., mode=0o600)
tempfile._mkstemp_inner(..., mode)
So it is as secure as now by default and still usable for the above popular use case without people having to do dirty stuff.
Previous discussion
- 1st issue: https://github.com/borgbackup/borg/issues/6400
- 1st fix: https://github.com/borgbackup/borg/pull/6403
- 2nd issue https://github.com/borgbackup/borg/issues/6786
- 2nd fix: https://github.com/borgbackup/borg/pull/6787
- 3rd issue: https://github.com/borgbackup/borg/issues/6933
- 3rd fix: https://github.com/borgbackup/borg/pull/6936
- to be continued?
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 558
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
docs pending
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
build type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
stdlib topic-email type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
zostera/django-bootstrap4#894 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
use-agent-os/agent-os#3276 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
NousResearch/hermes-agent#117848 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
zilliztech/memsearch#759 ·