OCDocker.Toolbox.Security module¶
Security helpers for operations that cross trust boundaries.
Usage:
import OCDocker.Toolbox.Security as ocsec
- OCDocker.Toolbox.Security.allow_unsafe_runtime(*, deserialization=True, script_exec=True)[source]¶
Allow unsafe runtime operations in the current process.
This function sets opt-in environment flags used by security gates in OCDocker. Intended for trusted internal scripts/workflows.
- Parameters:
deserialization (bool, optional) – If True, enables pickle/joblib/torch deserialization gates. Default is True.
script_exec (bool, optional) – If True, enables dynamic script execution gate. Default is True.
- Return type:
None
- OCDocker.Toolbox.Security.env_flag_enabled(env_var)[source]¶
Check whether an environment variable is set to a truthy value.
- Parameters:
env_var (str) – Name of the environment variable to inspect.
- Returns:
True when environment variable is set to one of: 1, true, yes, y, on (case-insensitive).
- Return type:
bool
- OCDocker.Toolbox.Security.require_trusted_input(*, trusted, operation, env_var, source=None)[source]¶
Enforce explicit trust for high-risk operations.
- Parameters:
trusted (bool) – Explicit opt-in from caller that input is trusted.
operation (str) – Human-readable operation description (e.g., “pickle deserialization”).
env_var (str) – Environment variable that can globally opt in.
source (str, optional) – Optional input source path shown in diagnostic message.
- Raises:
PermissionError – If neither explicit trust nor environment opt-in is set.
- Return type:
None