pub struct SafetyContext { /* private fields */ }Expand description
A struct representing a set of rules to be loaded into a seccomp filter and applied to the current thread, or all threads in the current process.
Create with new(). Add RuleSets with enable(), and then use apply_to_current_thread()
to apply the filters to the current thread, or apply_to_all_threads() to apply the filter to
all threads in the process.
Implementations§
Source§impl SafetyContext
impl SafetyContext
Sourcepub fn new() -> SafetyContext
pub fn new() -> SafetyContext
Create a new SafetyContext. The seccomp filters will not be loaded until either
apply_to_current_thread or
apply_to_all_threads is called.
Sourcepub fn with_errno(self, errno: u32) -> SafetyContext
pub fn with_errno(self, errno: u32) -> SafetyContext
Set the errno to the provided value when a syscall does not match one of the seccomp rules
in this SafetyContext.
Sourcepub fn enable<R: RuleSet>(
self,
policy: R,
) -> Result<SafetyContext, ExtraSafeError>
pub fn enable<R: RuleSet>( self, policy: R, ) -> Result<SafetyContext, ExtraSafeError>
Enable the simple and conditional rules provided by the RuleSet.
§Errors
Will return ExtraSafeError::ConditionalNoEffectError if a conditional rule is enabled at
the same time as a simple rule for a syscall, which would override the conditional rule.
Sourcepub fn apply_to_current_thread(self) -> Result<(), ExtraSafeError>
pub fn apply_to_current_thread(self) -> Result<(), ExtraSafeError>
Load the SafetyContext’s rules into a seccomp filter and apply the filter to the current
thread.
If the landlock feature is enabled but no landlock rules are applied, landlock is not
enabled, unless landlock_only() is called. To enable landlock but allow no file access,
you can first apply a landlock_only() SafetyContext, and then apply a separate
SafetyContext with your seccomp rules.
§Errors
May return an ExtraSafeError.
If no rulesets are enabled, returns an ExtraSafeError::NoRulesEnabled error. If you
really want to enable “nothing”, try enabling the builtins::BasicCapabilities default
ruleset manually, or create your own with e.g. just the exit syscall.
Sourcepub fn apply_to_all_threads(self) -> Result<(), ExtraSafeError>
pub fn apply_to_all_threads(self) -> Result<(), ExtraSafeError>
Load the SafetyContext’s rules into a seccomp filter and apply the filter to all threads in
this process.
If the landlock feature is enabled but no landlock rules are applied, landlock is not
enabled, unless landlock_only() is called. To enable landlock but allow no file access,
you can first apply a landlock_only() SafetyContext, and then apply a separate
SafetyContext with your seccomp rules.
§Errors
May return an ExtraSafeError.
If no rulesets are enabled, returns an ExtraSafeError::NoRulesEnabled error. If you
really want to enable “nothing”, try enabling the builtins::BasicCapabilities default
ruleset manually, or create your own with e.g. just the exit syscall.