Skip to content
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

tools: genpolicy static checks #8814

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-kata-static-tarball-amd64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
- cloud-hypervisor
- cloud-hypervisor-glibc
- firecracker
- genpolicy
- kata-ctl
- kernel
- kernel-confidential
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/static-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
- kata-ctl
- runk
- trace-forwarder
- genpolicy
command:
- "make vendor"
- "make check"
Expand Down Expand Up @@ -75,6 +76,8 @@ jobs:
install-libseccomp: yes
- component: runk
install-libseccomp: yes
- component: genpolicy
component-path: src/tools/genpolicy
steps:
- name: Checkout the code
uses: actions/checkout@v4
Expand Down
10 changes: 0 additions & 10 deletions src/tools/genpolicy/Cargo.lock

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

9 changes: 7 additions & 2 deletions src/tools/genpolicy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Copyright (c) 2024 Microsoft Corporation
#
# SPDX-License-Identifier: Apache-2.0
#

[package]
name = "genpolicy"
version = "0.1.0"
Expand Down Expand Up @@ -35,7 +40,7 @@ async-trait = "0.1.68"
docker_credential = "1.2.0"
flate2 = { version = "1.0.26", features = ["zlib-ng"], default-features = false }
oci-distribution = { version = "0.10.0" }
openssl = { version = "0.10.54", features = ["vendored"] }
openssl = { version = "0.10.54" }
serde_ignored = "0.1.7"
serde_json = "1.0.39"
serde-transcode = "1.1.1"
Expand All @@ -44,7 +49,7 @@ tokio = {version = "1.33.0", features = ["rt-multi-thread"]}
# OCI container specs.
oci = { path = "../../libs/oci" }

# Kata Agent prototol.
# Kata Agent protocol.
protocols = { path = "../../libs/protocols", features = ["with-serde"] }
protobuf = "3.2.0"

Expand Down
28 changes: 4 additions & 24 deletions src/tools/genpolicy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,12 @@ The Policy auto-generated by `genpolicy` is typically used for implementing conf

# Building `genpolicy` from source code

## Install build dependencies
Build in docker container:

Example for Ubuntu 22.04.3:

```bash
$ sudo apt-get update
$ sudo apt-get install -y build-essential cmake curl git musl-dev musl-tools
$ curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh
$ source "$HOME/.cargo/env"
$ arch=$(uname -m)
$ rustup target add "${arch}-unknown-linux-musl"
```

# Build `genpolicy`

```bash
```sh
$ git clone https://github.com/kata-containers/kata-containers.git
$ cd kata-containers/src/tools/genpolicy
$ source "$HOME/.cargo/env"
$ make && make install
```

If you want to use `LIBC=gnu` instead of the default `LIBC=musl`, change the last step above to:

```bash
$ LIBC=gnu make && LIBC=gnu make install
$ cd kata-containers
$ tools/packaging/kata-deploy/local-build/kata-deploy-binaries.sh --build=genpolicy
danmihai1 marked this conversation as resolved.
Show resolved Hide resolved
```

# Executing `genpolicy`
Expand Down
7 changes: 2 additions & 5 deletions src/tools/genpolicy/src/verity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ impl<T: Digest + Clone> Verity<T> {
count
};

let mut data = Vec::new();
data.resize(hash_block_size, 0);

let data = vec![0; hash_block_size];
let mut levels = Vec::new();
levels.resize(
level_count,
Expand Down Expand Up @@ -209,8 +207,7 @@ pub fn traverse_file<T: Digest + Clone>(
mut verity: Verity<T>,
writer: &mut impl FnMut(&mut File, &[u8], u64) -> io::Result<()>,
) -> io::Result<GenericArray<u8, T::OutputSize>> {
let mut buf = Vec::new();
buf.resize(verity.data_block_size, 0);
let mut buf = vec![0; verity.data_block_size];
while verity.more_blocks() {
file.seek(SeekFrom::Start(read_offset))?;
file.read_exact(&mut buf)?;
Expand Down
3 changes: 3 additions & 0 deletions tools/packaging/kata-deploy/local-build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ cloud-hypervisor-glibc-tarball:
firecracker-tarball:
${MAKE} $@-build

genpolicy-tarball:
${MAKE} $@-build

kata-ctl-tarball:
${MAKE} $@-build

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ options:
cloud-hypervisor
cloud-hypervisor-glibc
firecracker
genpolicy
kata-ctl
kernel
kernel-confidential
Expand Down Expand Up @@ -713,6 +714,10 @@ install_agent_ctl() {
install_tools_helper "agent-ctl"
}

install_genpolicy() {
install_tools_helper "genpolicy"
}

install_kata_ctl() {
install_tools_helper "kata-ctl"
}
Expand Down Expand Up @@ -787,6 +792,8 @@ handle_build() {

firecracker) install_firecracker ;;

genpolicy) install_genpolicy ;;

kata-ctl) install_kata_ctl ;;

kernel) install_kernel ;;
Expand Down Expand Up @@ -893,6 +900,7 @@ main() {
agent-ctl
cloud-hypervisor
firecracker
genpolicy
kata-ctl
kernel
kernel-experimental
Expand Down
3 changes: 3 additions & 0 deletions tools/packaging/static-build/tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ ARG RUST_TOOLCHAIN
SHELL ["/bin/ash", "-o", "pipefail", "-c"]
RUN apk --no-cache add \
bash \
cmake \
curl \
gcc \
git \
libcap-ng-static \
libseccomp-static \
openssl-dev \
openssl-libs-static \
make \
musl-dev \
protoc && \
Expand Down