pub struct Capabilities { /* private fields */ }
Expand description
Capabilities are used to limit what a user can do to the system.
Capabilities are split into 4 categories:
- Scripting: Whether or not the user can execute scripts
- Guest access: Whether or not a non-authenticated user can execute queries on the system when authentication is enabled.
- Functions: Whether or not the user can execute certain functions
- Network: Whether or not the user can access certain network addresses
Capabilities are configured globally. By default, capabilities are configured as:
- Scripting: false
- Guest access: false
- Functions: All functions are allowed
- Network: No network address is allowed nor denied, hence all network addresses are denied unless explicitly allowed
The capabilities are defined using allow/deny lists for fine-grained control.
§Filtering functions and net-targets.
The filtering of net targets and functions is done with an allow/deny list. These list can either match everything, nothing or a given list.
By default every function and net-target is disallowed. For a function or net target to be allowed it must match the allow-list and not match the deny-list. This means that if for example a function is both in the allow-list and in the deny-list it will be disallowed.
With the combination of both these lists you can filter subgroups. For example:
Capabilities::none()
.with_allow_function("http::*")?
.with_deny_function("http::post")?
Will allow all and only all http::*
functions except the function http::post
.
Examples:
- Allow all functions:
--allow-funcs
- Allow all functions except
http.*
:--allow-funcs --deny-funcs 'http.*'
- Allow all network addresses except AWS metadata endpoint:
--allow-net --deny-net='169.254.169.254'
§Examples
Create a new instance, and allow all capabilities
let capabilities = Capabilities::all();
let config = Config::default().capabilities(capabilities);
let db = Surreal::new::<File>(("temp.db", config)).await?;
Create a new instance, and allow certain functions
let capabilities = Capabilities::default()
.with_deny_function("http::*")?;
let config = Config::default().capabilities(capabilities);
let db = Surreal::new::<File>(("temp.db", config)).await?;
Implementations§
Source§impl Capabilities
impl Capabilities
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a builder with default capabilities enabled.
Default capabilities enables live query notifications and all (non-scripting) functions.
Sourcepub fn with_scripting(self, enabled: bool) -> Self
pub fn with_scripting(self, enabled: bool) -> Self
Set whether to enable the embedded javascript scripting runtime.
Sourcepub fn with_guest_access(self, enabled: bool) -> Self
pub fn with_guest_access(self, enabled: bool) -> Self
Set whether to allow non-authenticated users to execute queries when authentication is enabled.
Sourcepub fn with_live_query_notifications(self, enabled: bool) -> Self
pub fn with_live_query_notifications(self, enabled: bool) -> Self
Set wether to enable live query notifications.
Sourcepub fn allow_all_functions(&mut self) -> &mut Self
pub fn allow_all_functions(&mut self) -> &mut Self
Set the allow list to allow all functions
Sourcepub fn with_allow_all_functions(self) -> Self
pub fn with_allow_all_functions(self) -> Self
Set the allow list to allow all functions
Sourcepub fn deny_all_functions(&mut self) -> &mut Self
pub fn deny_all_functions(&mut self) -> &mut Self
Set the deny list to deny all functions
Sourcepub fn with_deny_all_function(self) -> Self
pub fn with_deny_all_function(self) -> Self
Set the deny list to deny all functions
Sourcepub fn allow_none_functions(&mut self) -> &mut Self
pub fn allow_none_functions(&mut self) -> &mut Self
Set the allow list to allow no function
Sourcepub fn with_allow_none_functions(self) -> Self
pub fn with_allow_none_functions(self) -> Self
Set the allow list to allow no function
Sourcepub fn deny_none_functions(&mut self) -> &mut Self
pub fn deny_none_functions(&mut self) -> &mut Self
Set the deny list to deny no function
Sourcepub fn with_deny_none_function(self) -> Self
pub fn with_deny_none_function(self) -> Self
Set the deny list to deny no function
Sourcepub fn allow_function<S: AsRef<str>>(
&mut self,
func: S,
) -> Result<&mut Self, ParseFuncTargetError>
pub fn allow_function<S: AsRef<str>>( &mut self, func: S, ) -> Result<&mut Self, ParseFuncTargetError>
Add a function to the allow lists
Adding a function to the allow list overwrites previously set allow-all or allow-none filters.
Sourcepub fn with_allow_function<S: AsRef<str>>(
self,
func: S,
) -> Result<Self, ParseFuncTargetError>
pub fn with_allow_function<S: AsRef<str>>( self, func: S, ) -> Result<Self, ParseFuncTargetError>
Add a function to the allow lists
Adding a function to the allow list overwrites previously set allow-all or allow-none filters.
Sourcepub fn deny_function<S: AsRef<str>>(
&mut self,
func: S,
) -> Result<&mut Self, ParseFuncTargetError>
pub fn deny_function<S: AsRef<str>>( &mut self, func: S, ) -> Result<&mut Self, ParseFuncTargetError>
Add a function to the deny lists
Adding a function to the deny list overwrites previously set deny-all or deny-none filters.
Sourcepub fn with_deny_function<S: AsRef<str>>(
self,
func: S,
) -> Result<Self, ParseFuncTargetError>
pub fn with_deny_function<S: AsRef<str>>( self, func: S, ) -> Result<Self, ParseFuncTargetError>
Add a function to the deny lists
Adding a function to the deny list overwrites previously set deny-all or deny-none filters.
Sourcepub fn allow_all_net_targets(&mut self) -> &mut Self
pub fn allow_all_net_targets(&mut self) -> &mut Self
Set the allow list to allow all net targets
Sourcepub fn with_allow_all_net_targets(self) -> Self
pub fn with_allow_all_net_targets(self) -> Self
Set the allow list to allow all net targets
Sourcepub fn deny_all_net_targets(&mut self) -> &mut Self
pub fn deny_all_net_targets(&mut self) -> &mut Self
Set the deny list to deny all net targets
Sourcepub fn with_deny_all_net_target(self) -> Self
pub fn with_deny_all_net_target(self) -> Self
Set the deny list to deny all net targets
Sourcepub fn allow_none_net_targets(&mut self) -> &mut Self
pub fn allow_none_net_targets(&mut self) -> &mut Self
Set the allow list to allow no net targets
Sourcepub fn with_allow_none_net_targets(self) -> Self
pub fn with_allow_none_net_targets(self) -> Self
Set the allow list to allow no net targets
Sourcepub fn deny_none_net_targets(&mut self) -> &mut Self
pub fn deny_none_net_targets(&mut self) -> &mut Self
Set the deny list to deny no net targets
Sourcepub fn with_deny_none_net_target(self) -> Self
pub fn with_deny_none_net_target(self) -> Self
Set the deny list to deny no net targets
Sourcepub fn allow_net_target<S: AsRef<str>>(
&mut self,
func: S,
) -> Result<&mut Self, ParseNetTargetError>
pub fn allow_net_target<S: AsRef<str>>( &mut self, func: S, ) -> Result<&mut Self, ParseNetTargetError>
Add a net target to the allow lists
Adding a net target to the allow list overwrites previously set allow-all or allow-none filters.
Sourcepub fn with_allow_net_target<S: AsRef<str>>(
self,
func: S,
) -> Result<Self, ParseNetTargetError>
pub fn with_allow_net_target<S: AsRef<str>>( self, func: S, ) -> Result<Self, ParseNetTargetError>
Add a net target to the allow lists
Adding a net target to the allow list overwrites previously set allow-all or allow-none filters.
Sourcepub fn deny_net_target<S: AsRef<str>>(
&mut self,
func: S,
) -> Result<&mut Self, ParseNetTargetError>
pub fn deny_net_target<S: AsRef<str>>( &mut self, func: S, ) -> Result<&mut Self, ParseNetTargetError>
Add a net target to the deny lists
Adding a net target to the deny list overwrites previously set deny-all or deny-none filters.
Sourcepub fn with_deny_net_target<S: AsRef<str>>(
self,
func: S,
) -> Result<Self, ParseNetTargetError>
pub fn with_deny_net_target<S: AsRef<str>>( self, func: S, ) -> Result<Self, ParseNetTargetError>
Add a net target to the deny lists
Adding a net target to the deny list overwrites previously set deny-all or deny-none filters.
Trait Implementations§
Source§impl Clone for Capabilities
impl Clone for Capabilities
Source§fn clone(&self) -> Capabilities
fn clone(&self) -> Capabilities
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more