-
Notifications
You must be signed in to change notification settings - Fork 11k
fix(core) disable command_might_be_dangerous when unsandboxed #15036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,10 @@ fn unrestricted_file_system_sandbox_policy() -> FileSystemSandboxPolicy { | |
| FileSystemSandboxPolicy::unrestricted() | ||
| } | ||
|
|
||
| fn external_file_system_sandbox_policy() -> FileSystemSandboxPolicy { | ||
| FileSystemSandboxPolicy::external_sandbox() | ||
| } | ||
|
|
||
| async fn test_config() -> (TempDir, Config) { | ||
| let home = TempDir::new().expect("create temp dir"); | ||
| let config = ConfigBuilder::default() | ||
|
|
@@ -1686,3 +1690,100 @@ async fn verify_approval_requirement_for_unsafe_powershell_command() { | |
| (unless AskForApproval::Never is specified)."# | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn dangerous_command_allowed_when_sandbox_is_explicitly_disabled() { | ||
| let command = vec_str(&["rm", "-rf", "/tmp/nonexistent"]); | ||
| assert_exec_approval_requirement_for_command( | ||
| ExecApprovalRequirementScenario { | ||
| policy_src: None, | ||
| command, | ||
| approval_policy: AskForApproval::Never, | ||
| sandbox_policy: SandboxPolicy::ExternalSandbox { | ||
| network_access: Default::default(), | ||
| }, | ||
| file_system_sandbox_policy: external_file_system_sandbox_policy(), | ||
| sandbox_permissions: SandboxPermissions::UseDefault, | ||
| prefix_rule: None, | ||
| }, | ||
| ExecApprovalRequirement::Skip { | ||
| bypass_sandbox: false, | ||
| proposed_execpolicy_amendment: Some(ExecPolicyAmendment { | ||
| command: vec_str(&["rm", "-rf", "/tmp/nonexistent"]), | ||
| }), | ||
| }, | ||
| ) | ||
| .await; | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn dangerous_command_forbidden_in_external_sandbox_when_policy_matches() { | ||
| let command = vec_str(&["rm", "-rf", "/tmp/nonexistent"]); | ||
| assert_exec_approval_requirement_for_command( | ||
| ExecApprovalRequirementScenario { | ||
| policy_src: Some("prefix_rule(pattern=['rm'], decision='prompt')".to_string()), | ||
| command, | ||
| approval_policy: AskForApproval::Never, | ||
| sandbox_policy: SandboxPolicy::ExternalSandbox { | ||
| network_access: Default::default(), | ||
| }, | ||
| file_system_sandbox_policy: external_file_system_sandbox_policy(), | ||
| sandbox_permissions: SandboxPermissions::UseDefault, | ||
| prefix_rule: None, | ||
| }, | ||
| ExecApprovalRequirement::Forbidden { | ||
| reason: "approval required by policy, but AskForApproval is set to Never".to_string(), | ||
| }, | ||
| ) | ||
| .await; | ||
| } | ||
|
|
||
| struct ExecApprovalRequirementScenario { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find this a bit confusing since most of the fields are "inputs" to the assertion whereas What about dropping async fn assert_exec_approval_requirement_for_command(
scenario: ExecApprovalRequirementScenario,
expected_requirement: ExecApprovalRequirement,
) {I think that makes it clearer from the call site what is being asserted. Or even have
dylan-hurd-oai marked this conversation as resolved.
|
||
| /// Source for the Starlark `.rules` file. | ||
| policy_src: Option<String>, | ||
|
dylan-hurd-oai marked this conversation as resolved.
|
||
| command: Vec<String>, | ||
| approval_policy: AskForApproval, | ||
| sandbox_policy: SandboxPolicy, | ||
| file_system_sandbox_policy: FileSystemSandboxPolicy, | ||
| sandbox_permissions: SandboxPermissions, | ||
| prefix_rule: Option<Vec<String>>, | ||
| } | ||
|
|
||
| async fn assert_exec_approval_requirement_for_command( | ||
| test: ExecApprovalRequirementScenario, | ||
| expected_requirement: ExecApprovalRequirement, | ||
| ) { | ||
| let ExecApprovalRequirementScenario { | ||
| policy_src, | ||
| command, | ||
| approval_policy, | ||
| sandbox_policy, | ||
| file_system_sandbox_policy, | ||
| sandbox_permissions, | ||
| prefix_rule, | ||
| } = test; | ||
|
|
||
| let policy = match policy_src { | ||
| Some(src) => { | ||
| let mut parser = PolicyParser::new(); | ||
| parser | ||
| .parse("test.rules", src.as_str()) | ||
| .expect("parse policy"); | ||
| Arc::new(parser.build()) | ||
| } | ||
| None => Arc::new(Policy::empty()), | ||
| }; | ||
|
|
||
| let requirement = ExecPolicyManager::new(policy) | ||
| .create_exec_approval_requirement_for_command(ExecApprovalRequest { | ||
| command: &command, | ||
| approval_policy, | ||
| sandbox_policy: &sandbox_policy, | ||
| file_system_sandbox_policy: &file_system_sandbox_policy, | ||
| sandbox_permissions, | ||
| prefix_rule, | ||
| }) | ||
| .await; | ||
|
|
||
| assert_eq!(requirement, expected_requirement); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could also be because no sandbox is available, like for Windows users who have not installed our sandbox?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I might be misunderstanding the intent of
FileSystemSandboxKind. Should we instead use the following logic?I've updated to switch to this instead