• Stars
    star
    112
  • Rank 311,092 (Top 7 %)
  • Language
    Rust
  • License
    MIT License
  • Created almost 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

cargo-sandbox

cargo-sandbox intends to be a drop-in replacement for cargo, with the added benefit of isolating those commands from other parts of your system - that is, it runs cargo commands in a "sandbox".

For example, instead of running: cargo check

You can run: cargo-sandbox check

Threat Model

cargo-sandbox intends to protect against a specific attacker with specific goals.

The attacker can execute code on your host but only as part of a cargo command. This can be accomplished through malicious build scripts, procedural macros, and possibly other methods.

cargo-sandbox does aim to prevent this attacker from:

  1. Reading or writing files outside of the project's appropriate context
  2. Gaining access to sensitive environment variables, such as tokens or passwords
  3. Gaining access to your crates.io login token

cargo-sandbox does not aim to prevent this attacker from:

  1. Patching your code such that it executes malicious code at runtime

Implementation

Currently the isolation provided by cargo-sandbox is achieved by running the cargo commands in various docker containers via the docker unix domain socket (currently hardcoded at "/var/run/docker.sock").

Every "project" has its own set of containers. Within a project there are two containers:

  1. Build - used for cargo build, cargo check, cargo fmt, etc.
  2. Publish - user for cargo publish

No data is shared across the Build and Publish containers within a project, no data is shared across projects at all. In the future, for optimization purposes, there may be some tightly controlled sharing.

In order to make native dependencies easier to handle the current plan is to leverage riff. See: https://determinate.systems/posts/riff-rust-maintainers

Current State

Currently, cargo-sandbox is in a very early stage of development. The management of containers is error prone and somewhat inefficient. Please see the issue tracker for more details, but here's the quicknotes version based on what I want to get done short term:

  • Partial support for build, check, publish
  • Improved handling of native dependencies with riff
  • Support for fmt, clippy
  • Support for run, test, bench
  • Support for custom policies, including more restrictions

FAQ

Does cargo-sandbox work on $OS?

Currently cargo-sandbox only works on Linux but that is not a fundamental limitation. While the project is still in its early stages I'd prefer to focus on getting the design right, not on portability.

That said, ensuring a path to broad OS support is a goal of the project.

If the attacker can just patch code and execute in production, what's the point?

To briefly address this concern:

  1. There are already tons of tools and techniques for protecting arbitrary production programs. While I would not call the problem "solved", the ability to constrain a program at runtime is far more mature.
  2. Surprisingly, given (1), a dev environment can be even more privileged than a service in production! Consider that some developers will have code commit rights, browser session cookies, SSH keys, and other sensitive data.

Indeed I suspect that many attackers are far more comfortable landing on a developer's laptop than in some random production service that may not even have external networking capabilities. Further, one tool does not need to solve all problems - in the future cargo-sandbox may expand its threat model.

At minimum I hope to (in the future) improve the ability to audit for such attacks, even if they are not prevented.

I thought that containers weren't security boundaries? Is this adding any value?

You may have heard "containers are not a security boundary". That has not really been true for a long time, especially if we're talking about Docker containers.

Let's define a security boundary as "a limitation of an attacker's capabilities that requires an explicit vulnerability to bypass"; that is to say, if I can just "ask" to get out of a sandbox it is not a boundary, but if I need to exploit a vulnerability that will eventually be patched then it is a boundary.

So... is a Docker Container a security boundary? It is - trivially so. There is no native means by which a process in a Docker Container can escape - any such attack would be considered a Docker vulnerability.

Beyond that, Docker containers leverage a number of powerful security features:

  1. Namespaces: Docker containers run in isolated namespaces. Namespaces are a feature of the Linux kernel that allow processes to have their own view of the system. For example, a process in a Docker container can have its own view of the filesystem, network, users, and process tree.

  2. Apparmor/SELinux: Docker containers can (and will by default) run with support for Linux's powerful Mandatory Access Control (MAC) systems. These systems allow processes to be restricted from accessing certain resources, such as files or network ports.

  3. Seccomp: Docker containers run with a seccomp profile by default, restricting which system calls processes can make. While the default profile may not be ideal, cargo-sandbox intends to provide a more restrictive profile with time.

More Repositories

1

aktors

Rust actor library with a bit of inspiration from Akka/Pykka
Rust
46
star
2

derive_aktor

A macro to generate Rust actors
Rust
42
star
3

autobox

A set of tools and libraries for automatically generating and initiating sandboxes for Rust programs
Rust
16
star
4

typed-imap

A rust library for a Type Safe IMAP protocol
Rust
13
star
5

sandbox

Easy sandboxing for rust
Rust
10
star
6

gsblookup-rs

Rust interface to Google Safe Browsing Lookup API
Rust
7
star
7

SyslogParser

A system log parser designed to aid in generating apparmor and iptables rules.
C++
6
star
8

shannon-entropy

A rust library to calculate the shannon entropy of a string.
Rust
4
star
9

PlayRustClassifier

A system for classifying specific reddit posts on the rust subreddit.
Rust
4
star
10

Cricket

Cricket is a fuzzing harness written in Rust
Rust
4
star
11

queue-delay-app

A service for facilitating AWS SNS Topic Delays
Rust
3
star
12

dlfile

For dl the file
Rust
3
star
13

sysmon

Type definitions and deserialization support for Sysmon events in Rust
Rust
2
star
14

dgraph-rs

A DGraph client for Rust
Rust
2
star
15

sqs-service-helper

A helper library for creating rust services that consume messages from SQS
Rust
2
star
16

void-ship

Remove your vDSO And vvar mappings to restrict clock access
Rust
2
star
17

grapl-analyzer-deployer

A deployment service that plugs into Grapl
Python
2
star
18

dedup_by

A helper function for removing consecutive duplicates from a vector of complex types
Rust
1
star
19

grapl-graph-descriptions-py

A libray for working with Grapl's undetlying graph data structures via Python
Python
1
star
20

Vector

An implementation of the vector data structure.
C++
1
star
21

grapl-graph-descriptions

Crate for working with Grapl graphs
Rust
1
star
22

haveibeenpwnd

A client for the Have I Been Pwned? API v2 for Rust
Rust
1
star
23

ThreadPool

A threadpool with lock and lock-free functions
C++
1
star
24

splunk-cim

Rust type definitions for the Splunk Common Information Model
Rust
1
star
25

ProjEuler

This is just going to be my repository for doing Project Euler (https://projecteuler.net) challenges. I do them in my spare time, and it's much easier for me to program when I have a GIT repo to pull from. I haven't been doing them very long, but they're great to keep me in practice. Sometimes I change up the challenges myself, since it's more fun to do things certain ways.
C
1
star