pub struct Capabilities { /* private fields */ }
Expand description
Capabilities are used to limit what users are allowed to do using queries.
Capabilities are split into categories:
- Scripting: Whether or not users can execute scripts
- Guest access: Whether or not unauthenticated users can execute queries
- Functions: Whether or not users can execute certain functions
- Network: Whether or not users can connect to 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, all are impliticly denied
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_functions(self) -> Self
pub fn with_deny_all_functions(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_targets(self) -> Self
pub fn with_deny_all_net_targets(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 moreSource§impl Debug for Capabilities
impl Debug for Capabilities
Auto Trait Implementations§
impl Freeze for Capabilities
impl RefUnwindSafe for Capabilities
impl Send for Capabilities
impl Sync for Capabilities
impl Unpin for Capabilities
impl UnwindSafe for Capabilities
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more