Skip to content

Commit b0798b9

Browse files
committed
Add Corgid for new method of Inspector Integration
This binary does following: - This converts application inventory on the host to Cyclone Dx sbom - Send the Cyslone Dx sbom to the new telemetart API
1 parent e4a3a2d commit b0798b9

15 files changed

Lines changed: 3204 additions & 1 deletion

Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
ARG SDK_IMAGE
2+
FROM ${SDK_IMAGE} as rust-builder
3+
4+
ARG UNAME_ARCH
5+
USER root
6+
ENV CARGO_HOME=/src/.cargo
7+
8+
# Add sources
9+
ADD ./sources /src/
10+
11+
# Fetch dependencies
12+
RUN cargo fetch --locked --manifest-path /src/corgid/Cargo.toml
13+
14+
# Set bindgen clang arguments for musl compilation
15+
ENV BINDGEN_EXTRA_CLANG_ARGS="--target=${UNAME_ARCH}-bottlerocket-linux-musl --sysroot=/${UNAME_ARCH}-bottlerocket-linux-musl/sys-root"
16+
17+
# Build corgid statically linked with musl
18+
RUN cargo install --offline --locked --target ${UNAME_ARCH}-bottlerocket-linux-musl --path /src/corgid --root /output
19+
20+
# Gather licenses of dependencies
21+
RUN /usr/libexec/tools/bottlerocket-license-scan \
22+
--clarify /src/clarify.toml \
23+
--spdx-data /usr/libexec/tools/spdx-data \
24+
--out-dir /licenses \
25+
cargo --offline --locked /src/corgid/Cargo.toml
26+
127
FROM public.ecr.aws/amazonlinux/amazonlinux:2023 AS builder
228

329
RUN dnf install -y \
@@ -62,6 +88,10 @@ COPY --from=builder /root/build/util-linux/usr/share/licenses/util-linux/COPYING
6288
/usr/share/licenses/util-linux/
6389
RUN ln -s /opt/util-linux/bin/* /usr/bin
6490

91+
# Copy corgid binary and licenses
92+
COPY --from=rust-builder /output/bin/corgid /usr/sbin/corgid
93+
COPY --from=rust-builder /licenses /usr/share/licenses/corgid
94+
6595
# Validate amazon-ssm-agent binary
6696
RUN /usr/bin/amazon-ssm-agent -version
6797
# Validate lscpu binary

Makefile

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
TOP := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
2+
13
# IMAGE_NAME is the full name of the container image being built.
24
IMAGE_NAME ?= $(notdir $(shell pwd -P))$(IMAGE_ARCH_SUFFIX):$(IMAGE_VERSION)$(addprefix -,$(SHORT_SHA))
35
# IMAGE_VERSION is the semver version that's tagged on the image.
@@ -19,11 +21,37 @@ ARCH ?= $(lastword $(subst :, ,$(filter $(UNAME_ARCH):%,x86_64:amd64 aarch64:arm
1921
# SSM_AGENT_VERSION is the SSM Agent's distributed RPM Version to install.
2022
SSM_AGENT_VERSION ?= 3.3.3883.0
2123

22-
.PHONY: all build check check-ssm-agent download-ssm-agent update-ssm-agent
24+
# BOTTLEROCKET_SDK_VERSION is the SDK image used to build corgid.
25+
BOTTLEROCKET_SDK_VERSION ?= v0.73.0
26+
27+
.PHONY: all build check check-ssm-agent check-licenses fetch download-ssm-agent update-ssm-agent
2328

2429
# Run all build tasks for this container image.
2530
all: build check
2631

32+
# Fetches crates from upstream
33+
fetch:
34+
docker run --rm \
35+
--user "$(shell id -u):$(shell id -g)" \
36+
--security-opt label=disable \
37+
--env CARGO_HOME="/src/.cargo" \
38+
--volume "$(TOP)/sources:/src" \
39+
--workdir "/src/" \
40+
"public.ecr.aws/bottlerocket/bottlerocket-sdk:$(BOTTLEROCKET_SDK_VERSION)" \
41+
bash -c "cargo fetch --locked --manifest-path /src/corgid/Cargo.toml"
42+
43+
# Checks allowed/denied upstream licenses
44+
check-licenses: fetch
45+
docker run --rm \
46+
--network none \
47+
--user "$(shell id -u):$(shell id -g)" \
48+
--security-opt label=disable \
49+
--env CARGO_HOME="/src/.cargo" \
50+
--volume "$(TOP)/sources:/src" \
51+
--workdir "/src/" \
52+
"public.ecr.aws/bottlerocket/bottlerocket-sdk:$(BOTTLEROCKET_SDK_VERSION)" \
53+
bash -c "cargo deny --all-features check --disable-fetch --manifest-path /src/corgid/Cargo.toml licenses"
54+
2755
# Create a distribution container image tarball for release.
2856
dist: all
2957
@mkdir -p $(dir $(DISTFILE))
@@ -35,6 +63,8 @@ build:
3563
--tag $(IMAGE_NAME) \
3664
--build-arg IMAGE_VERSION="$(IMAGE_VERSION)" \
3765
--build-arg SSM_AGENT_VERSION="$(SSM_AGENT_VERSION)" \
66+
--build-arg UNAME_ARCH="$(UNAME_ARCH)" \
67+
--build-arg SDK_IMAGE="public.ecr.aws/bottlerocket/bottlerocket-sdk:$(BOTTLEROCKET_SDK_VERSION)" \
3868
-f Dockerfile . >&2
3969

4070
# Run checks against the container image.

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,42 @@ For example:
3838
# ex: echo '{"ssm":{"activation-id":"foo","activation-code":"bar","region":"us-west-2"}}' | base64
3939
user-data = "eyJzc20iOnsiYWN0aXZhdGlvbi1pZCI6ImZvbyIsImFjdGl2YXRpb24tY29kZSI6ImJhciIsInJlZ2lvbiI6InVzLXdlc3QtMiJ9fQo="
4040
```
41+
42+
## Inspector SBOM Upload (corgid)
43+
44+
This container includes `corgid`, a binary that collects the Bottlerocket package inventory, converts it to a [CycloneDX](https://cyclonedx.org/) SBOM, and sends it to the Amazon Inspector API for vulnerability scanning. It runs automatically in the background when the container starts.
45+
46+
### Disabling corgid
47+
48+
To disable Inspector SBOM upload, set `inspector-sbom-upload` to `"false"` in the control container's user data:
49+
50+
```json
51+
{
52+
"inspector": {
53+
"upload-sbom": false
54+
}
55+
}
56+
```
57+
58+
Base64-encode the JSON and set it in your instance user data:
59+
60+
```toml
61+
[settings.host-containers.control]
62+
# echo '{"inspector": {"upload-sbom": false}}' | base64
63+
user-data = "eyJpbnNwZWN0b3IiOiB7InVwbG9hZC1zYm9tIjogZmFsc2V9fQ=="
64+
```
65+
66+
This can be combined with SSM hybrid activation settings in the same JSON object:
67+
68+
```json
69+
{
70+
"ssm": {
71+
"activation-id": "foo",
72+
"activation-code": "bar",
73+
"region": "us-west-2"
74+
},
75+
"inspector": {
76+
"upload-sbom": false
77+
}
78+
}
79+
```

0 commit comments

Comments
 (0)