you try to install this module
pip install pyseccomp
import pyseccomp
Answer from top talent on Stack Overflowlinux - How can you security-harden a Python program? - Stack Overflow
Python security hardening - Information Security Stack Exchange
ssh - Custom Python Server - how to secure it? - Information Security Stack Exchange
Basic Server Hardening Steps
Videos
You could turn your python scripts into windows executables using py2exe. That way it would be treated the same way you restrict other system binary. Be aware that it is possible to reverse-engineer by "uncompiling" it, showing the script functions and all. But as your question in only about enforcing execution authorization, i think that it will fulfill your need.
How about the use of PyPy with its sandboxing mode?
I'm afraid I'm not that familiar so I'm uncertain that it would be fully secure but certainly worth a look.
As far as I can see, your only options are:
- PyPy sandboxing
- A Python to executable compiler
- Giving users a Virtual Machine which allows Python
- Using a PC sandboxing solution to isolate Python and the file system.
I recently leased a VPS to host a few services, and took the first steps towards locking down the server (Ubuntu Server 20.04).
What I have done so far:
-
Update & Upgrade the system
-
Install / enable unattended-upgrades & apt-listchanges (automatically install important updates daily, and monitor/list changes automatically)
-
Create a non-root user, add to sudoers
-
Lock down SSH
-
Change to a nonstandard port
-
Create & configure key based SSH login (key protected with password)
-
Disable root login via SSH
-
Disable password login via SSH
-
-
Configure Firewall
-
Create rule to allow but limit SSH in on new port
-
Create rules to allow in, on other necessary ports (for me just 80 and 443)
-
Set default deny for everything else.
-
Rule to drop ping requests
-
Enable firewall
-
-
Setup fail2ban for SSH
-
Rather relaxed 15/15/15 rule (15 failed logins, in 15 minutes = 15 minute ban)
-
-
Check to make sure apparmor is enabled and in enforcement mode
On the to-do / research list are (1) setting up mail so important system mail is sent (or forwarded from 'root') to my actual e-mail address (2) figuring out backups of some sort
What additional steps would you take?
What have I left out / forgotten / got wrong?