Skip to content

Commit

Permalink
command line for url permission check in http request.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joinhack committed Jan 21, 2025
1 parent a7acba4 commit f06f6d2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bls-runtime/src/cli_clap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,14 @@ const ALLOW_READ_ALL_HELP: &str = "Allow the app to all read permissions.";

const ALLOW_WRITE_HELP: &str = "Allow the app to write permissions.";

const ALLOW_NET_HELP: &str = "Allow the app to net accessing permissions.";

const DENY_READ_HELP: &str = "Deny the app to read permissions.";

const DENY_WRITE_HELP: &str = "Deny the app to write permissions.";

const DENY_NET_HELP: &str = "Deny the app to net accessing permissions.";

const ALLOW_WRITE_ALL_HELP: &str = "Allow the app to all write permissions.";

fn parse_envs(envs: &str) -> Result<(String, String)> {
Expand Down Expand Up @@ -235,12 +239,20 @@ pub struct PermissionFlags {
#[clap(long = "allow-write", id="allow-write", num_args=(0..) , value_name = "PATH[,]", help = ALLOW_WRITE_HELP, value_parser = parser_allow)]
pub allow_write: Option<PermissionGrant>,

#[clap(long = "allow-net", id="allow-net", num_args=(0..) , value_name = "PATH[,]", help = ALLOW_NET_HELP, value_parser = parser_allow)]
pub allow_net: Option<PermissionGrant>,

#[clap(long = "deny-read", id="deny-read", num_args=(0..) , value_name = "PATH[,]", help = DENY_READ_HELP, value_parser = parser_allow)]
pub deny_read: Option<PermissionGrant>,

#[clap(long = "deny-write", id="deny-write", num_args=(0..) , value_name = "PATH[,]", help = DENY_WRITE_HELP, value_parser = parser_allow)]
pub deny_write: Option<PermissionGrant>,

#[clap(long = "deny-net", id="deny-net", num_args=(0..) , value_name = "URL[,]", help = DENY_NET_HELP, value_parser = parser_allow)]
pub deny_net: Option<PermissionGrant>,



#[clap(long = "allow-all", id = "allow-all", help = "Allow all permissions.")]
pub allow_all: bool,
}
Expand All @@ -252,6 +264,8 @@ impl Into<PermissionsConfig> for PermissionFlags {
deny_read: self.deny_read,
allow_write: self.allow_write,
deny_write: self.deny_write,
deny_net: self.deny_net,
allow_net: self.allow_net,
allow_all: self.allow_all,
};
permissions
Expand Down
2 changes: 2 additions & 0 deletions bls-runtime/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ fn parse_args() -> CliCommandOpts {
set_perm_grant!("allow-write", o.permission_flags.allow_write);
set_perm_grant!("deny-read", o.permission_flags.deny_read);
set_perm_grant!("deny-write", o.permission_flags.deny_write);
set_perm_grant!("allow-net", o.permission_flags.allow_net);
set_perm_grant!("deny-net", o.permission_flags.deny_net);
o
}
Err(_) => {
Expand Down
6 changes: 6 additions & 0 deletions crates/wasi-common/src/blockless/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ pub struct PermissionsConfig {
pub allow_write: Option<PermissionGrant>,
pub deny_read: Option<PermissionGrant>,
pub deny_write: Option<PermissionGrant>,
pub allow_net: Option<PermissionGrant>,
pub deny_net: Option<PermissionGrant>,
pub allow_all: bool,
}

Expand All @@ -526,6 +528,8 @@ impl Into<PermissionsOptions> for &PermissionsConfig {
set_perm!(&self.allow_write, options.allow_write);
set_perm!(&self.deny_read, options.deny_read);
set_perm!(&self.deny_write, options.deny_write);
set_perm!(&self.allow_net, options.allow_net);
set_perm!(&self.deny_net, options.deny_net);
options.prompt = true;
options.allow_all = self.allow_all;
options
Expand All @@ -537,8 +541,10 @@ impl Default for PermissionsConfig {
PermissionsConfig {
allow_read: None,
allow_write: None,
allow_net: None,
deny_read: None,
deny_write: None,
deny_net: None,
allow_all: false,
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/wasi-common/src/blockless/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@ impl BlsRuntimePermissionsContainer {
if let Some(PermissionGrant::All) = config.deny_write {
permissions.write.flag_denied_global = true;
}
if let Some(PermissionGrant::All) = config.deny_net {
permissions.net.flag_denied_global = true;
}
if let Some(PermissionGrant::All) = config.allow_read {
permissions.read.granted_global = true;
}
if let Some(PermissionGrant::All) = config.allow_write {
permissions.write.granted_global = true;
}
if let Some(PermissionGrant::All) = config.allow_net {
permissions.net.granted_global = true;
}
*self.inner.lock() = permissions;
Ok(())
}
Expand Down

0 comments on commit f06f6d2

Please sign in to comment.