Skip to content

Commit

Permalink
kbs: switch to Regorus for resource policy
Browse files Browse the repository at this point in the history
Switch from Go-based policy engine to rust-based Regorus
Switch from Anyhow to thiserror for resource policy
Add several unit tests and test policies

Signed-off-by: Tobin Feldman-Fitzthum <[email protected]>
  • Loading branch information
fitzthum committed Apr 16, 2024
1 parent 47d7a23 commit 3d0b11d
Show file tree
Hide file tree
Showing 16 changed files with 484 additions and 105 deletions.
165 changes: 163 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ kbs-types = "0.5.3"
jsonwebtoken = { version = "9", default-features = false }
log = "0.4.17"
prost = "0.11.0"
regorus = { version = "0.1.2", default-features = false, features = ["regex", "base64", "time"] }
rstest = "0.18.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.89"
Expand Down
3 changes: 2 additions & 1 deletion kbs/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ RUN apt-get update && \
apt-get install -y --no-install-recommends \
curl \
gpg \
gnupg-agent
gnupg-agent \
git

RUN curl -fsSL https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | \
gpg --dearmor --output /usr/share/keyrings/intel-sgx.gpg && \
Expand Down
2 changes: 1 addition & 1 deletion kbs/docker/Dockerfile.coco-as-grpc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM rust:latest as builder
WORKDIR /usr/src/kbs
COPY . .

RUN apt-get update && apt install -y protobuf-compiler wget
RUN apt-get update && apt install -y protobuf-compiler wget git

RUN wget https://go.dev/dl/go1.20.1.linux-amd64.tar.gz
RUN tar -C /usr/local -xzf go1.20.1.linux-amd64.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion kbs/docker/Dockerfile.intel-trust-authority
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM rust:latest as builder
WORKDIR /usr/src/kbs
COPY . .

RUN apt-get update && apt install -y wget
RUN apt-get update && apt install -y wget git

RUN wget https://go.dev/dl/go1.20.1.linux-amd64.tar.gz
RUN tar -C /usr/local -xzf go1.20.1.linux-amd64.tar.gz
Expand Down
4 changes: 3 additions & 1 deletion kbs/sample_policies/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
This directory contains sample policy files to configure the policy engine
of the KBS. You can use these files to write your own policies.

There are also several example policies used [for testing](../test/data).

| File | Description |
| --- | --- |
|[allow_all.rego](./allow_all.rego)|Equivalent to turning off the policy engine. Release resources unconditionally|
|[deny_all.rego](./deny_all.rego)|Deny all resources release|
|[deny_all.rego](./deny_all.rego)|Deny all resources release|
1 change: 1 addition & 0 deletions kbs/src/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ log.workspace = true
mobc = { version = "0.8.3", optional = true }
prost = { version = "0.11", optional = true }
rand = "0.8.5"
regorus.workspace = true
reqwest = { version = "0.11", features = ["json"], optional = true }
rsa = { version = "0.9.2", optional = true, features = ["sha2"] }
rustls = { version = "0.20.8", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion kbs/src/api/src/http/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub(crate) async fn get_resource(
resource_description.resource_type,
resource_description.resource_tag
);
let (resource_allowed, _extra_policy_output) = policy_engine
let resource_allowed = policy_engine
.0
.lock()
.await
Expand Down
Loading

0 comments on commit 3d0b11d

Please sign in to comment.