tempfile.mkstemp: add mode=0o600 parameter
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- python
- Lĩnh vực
- operating-systems
Hướng nghiên cứu
Bắt đầu với tempfile.mkstemp và tempfile._mkstemp_inner, sau đó xem lại các cuộc thảo luận và bản sửa lỗi Borg được liên kết để nắm bối cảnh trước đó. Xác minh cách chế độ hiện được hardcode được áp dụng, cách một tham số chế độ sẽ đi qua cả hai điểm vào và cách hành vi mặc định cũng như hành vi của umask cần được giữ nguyên. Được xem là hoàn tất khi chế độ được yêu cầu được hỗ trợ mà không thay đổi mặc định an toàn.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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?
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Merge trung bình
- 1 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 558
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python/cpython
-
docs pending
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
stdlib type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
stdlib type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
build type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
stdlib topic-email type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Tất cả issue của python/cpython
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
bancolombia/sentinel#23 ·
-
test md Đang mởCI
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100