PEP 551 discussion #1004
PEP 551 discussion #1004
Comments
|
Awesome! Glad to have you on board here :) Probably the most important thing to check right now is whether the additional limits people may want to apply are possible with PEP 578 as it is, or do we need additional API (additional events can come later, they're not all meant to be in the initial PEP). Also, this doc isn't meant to be defining spython, just providing guidance for those who will. So the places where it "should" or "shouldn't" do something really ought to be phrased as "consider this" or "avoid that". |
|
@tiran Thanks for your comments! A couple of thoughts:
I think this is already considered in the original spec as part of the alternate entry point that removes interactive modes.
This is a good idea, but it may do too much to hinder the real-world usability of Python with larger code bases with (internal or external) library dependencies in complex deployment environments. There are definitely environments in which this is a good idea. However, how much flexibility should an
In a code-signing environment,
I like this as an idea. Designate some file system location where any dynamically-evaluated code must reside for later auditing. Since these mechanisms are used for dynamically generated code, and it may not be possible to sign this code, if you're enforcing code-signing, then I think this idea would only generate auditing artefacts. That said, the complexity of finding a reliable place to write these files may also prove difficult. I think that the audit logging mechanism may be a better approach—generate an audit log message on every
This is an interesting technique. It's definitely possible to create security holes using What kind of attacks do you see this addressing that wouldn't be handled by the script itself?
I believe this is covered with a two-pronged approach:
|
An interesting mitigation to consider is whitelisted code-paths. Certain potentially "unsafe" behavior occurs in the standard library as you note. It might be possible to identify these fixed code paths and restrict certain "unsafe" operations only if they occur within that code path. This may have a performance penalty, but there may be techniques to significantly minimize that penalty. |
To be honest, I completely forgot about PEP 551 and was confused when you started to talk about three PEPs...
Yeah, I don't mind the exact wording. |
OK, it wasn't obvious to me ,because I don't consider piping a script from stdin as interactive. It's probably my Unix mentality. :) May I suggest to extend the wording to make it obvious for everybody?
https://docs.python.org/3/using/cmdline.html?highlight=isolated
Could you give me an example why you consider the local directory useful?
It's certainly possible to extend the PYC format to allow a user-specific section after the header. Also it would be possible to store the code signing information in an NTFS ADS or Linux xattr. For example IMA Appraisal uses an xattr.
Let me think about this for a bit.
I'm referring to "The spython entry point requires a script file be passed as the first argument, and does not allow any options to precede it.". It sounds to me that argument passing is not allowed with spython. However this would make spython unusable for command line scripts. If we want to harden Linux, then we need a way to only have spython on board.
SGTM! |
I was thinking more about replacing namedtuple's exec with a specialized helper in C. WARNING experimental hack with a bunch of reference leaks:
|
|
This is where tracing exec is so much more preferable to trying to figure out whether to block it or not. Once you start reviewing logs you'll see the namedtuple calls stick out and can easily mark them as uninteresting, while still treating other exec's as anomalies. And then if someone comes up with a clever exploit via namedtuple you haven't lost the traced code. Similarly for ignoring .pyc files - yes, you can sign them, but you can't get a transcript of the code that was actually executed. When you hit the point where you discover you've been breached and are trying to figure out who/why/how, having access to their source code is much more useful. This is one of the biggest things that Powershell added for the same reasons. |
"Precede" means you can't pass interpreter arguments (e.g. no |
It's a little bit more than just the wording, it's the whole intent of the PEP :) We don't have to design something that will work for any given scenarios here. All we're doing is outlining recommendations and possibly specific details to help people make their own decisions and implementations. So We can provide sample code (examples) but are not trying to provide a ready-to-use implementation. (Maybe each of us personally will end up doing one for our respective employers anyway? But that's wearing the MSFT/RH hats rather than our python-dev hats, and this PEP is wearing our python-dev hats.) |
Critically, I believe that if you want to be able to sign |
We could definitely look into replacing I suspect most developers of Python code that will run on an SPython will be developing and testing against CPython, and I suspect that the secure environments in which SPython runs are likely to also be "high-reliability" environments. Many of the mitigations discussed in the PEPs try to be very surgical in nature to try to avoid surface area for subtle bugs specific to SPython to creep in. Additionally, I assume that many code bases that run on SPython may make use of common third-party libraries, so we should also evaluate how frequently Another possible approach might be to find a way to move dynamic code generation to the build system. A library using |
There is a related Linux-specific mitigation that has not been considered: shell redirection techniques like This logic (plus any code signing mechanisms) would probably be included in a |
Excellent point!
|
That's correct. The build system needs access to the private key in order to sign files. It's easily possible to build, sign, and ship .pyc files together .py files. On RPM systems (Centos, Fedora, RHEL) .pyc files are created on package built time and shipped in RPM package. That makes it possible to verify all code files and detect files that have been tampered with. (There are also other models where the system is booted in signature generation mode and then switched into another policy that makes the signatures read-only (simply speaking).) |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

@zooba, I'm using this issue as a to be discussed list for PEP 551. Some are just crazy ideas that I wanted to dump into text form before I forget them again.
curl https://example.com/script.py | spythonopen_for_importlikeO_MAYEXECandW^X(Python file must not be owned or writeable by current effective uid/gid unless it's root).# spython: argumentson the second line of the script? Or only allow arguments from scripts in well-known directories like/bin:/sbin:...?pdb,cmd,code)exec()of imports in*.pthfiles?exec()completely?__new__function. The function generator could be implemented astuple._make_new()or so.SPYTHONLOGbreaks with tradition to have all Python env vars prefixed withPYTHON.The text was updated successfully, but these errors were encountered: