-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: add docker-compose and soft-tpm setup
Signed-off-by: Tuomo Tanskanen <[email protected]>
- Loading branch information
Showing
10 changed files
with
292 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
allowlist.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[agent] | ||
uuid = "d432fbb3-d2f1-4a97-9ef7-75bd81c00000" | ||
tpm_ownerpassword = "" | ||
tpm_version = "2" | ||
work_dir = "/var/lib/keylime/secure" | ||
secure_size = "1m" | ||
|
||
[cloud_agent] | ||
cloudagent_ip = "127.0.0.1" | ||
cloudagent_port = "9002" | ||
registrar_ip = "127.0.0.1" | ||
registrar_port = "8891" | ||
|
||
[tpm] | ||
tpm_ownerpassword = "" | ||
ek_handle = "0x81010000" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
services: | ||
tpm-simulator: | ||
build: | ||
context: ../soft-tpm | ||
dockerfile: ../soft-tpm/Dockerfile | ||
ports: | ||
- "2321:2321" | ||
- "2322:2322" | ||
volumes: | ||
- tpm-state:/var/lib/tpm | ||
# command: tpm_server -port 2321 -rm | ||
|
||
keylime-verifier: | ||
image: quay.io/keylime/keylime_verifier | ||
depends_on: | ||
- tpm-simulator | ||
environment: | ||
- TPM2TOOLS_TCTI=mssim:host=tpm-simulator,port=2321 | ||
- TCTI=mssim:host=tpm-simulator,port=2321 | ||
volumes: | ||
- cv_ca:/var/lib/keylime/cv_ca:rw | ||
ports: | ||
- "8881:8881" | ||
# just create delay so certs are there when it runs | ||
healthcheck: | ||
test: ["CMD-SHELL", "true"] | ||
interval: 5s | ||
timeout: 5s | ||
retries: 5 | ||
start_period: 10s | ||
command: keylime_verifier | ||
|
||
keylime-registrar: | ||
image: quay.io/keylime/keylime_registrar | ||
depends_on: | ||
- tpm-simulator | ||
- keylime-verifier | ||
environment: | ||
- TPM2TOOLS_TCTI=mssim:host=tpm-simulator,port=2321 | ||
- TCTI=mssim:host=tpm-simulator,port=2321 | ||
volumes: | ||
- cv_ca:/var/lib/keylime/cv_ca:ro | ||
ports: | ||
- "8891:8891" | ||
# just create delay so certs are there when it runs | ||
healthcheck: | ||
test: ["CMD-SHELL", "true"] | ||
interval: 5s | ||
timeout: 5s | ||
retries: 5 | ||
start_period: 10s | ||
command: keylime_registrar | ||
|
||
keylime-agent: | ||
image: quay.io/keylime/keylime_agent:master | ||
privileged: true | ||
depends_on: | ||
- tpm-simulator | ||
- keylime-verifier | ||
- keylime-registrar | ||
environment: | ||
- TPM2TOOLS_TCTI=mssim:host=tpm-simulator,port=2321 | ||
- TCTI=mssim:host=tpm-simulator,port=2321 | ||
- TPM_INTERFACE_TYPE=socsim | ||
# just create delay so certs are there when it runs | ||
healthcheck: | ||
test: ["CMD-SHELL", "true"] | ||
interval: 5s | ||
timeout: 5s | ||
retries: 5 | ||
start_period: 10s | ||
volumes: | ||
- /sys/kernel/security:/sys/kernel/security:ro | ||
- ./agent.conf:/etc/keylime/agent.conf:ro | ||
- agent_var_lib_keylime:/var/lib/keylime:rw | ||
- cv_ca:/var/lib/keylime/cv_ca:ro | ||
# command: keylime_agent | ||
|
||
volumes: | ||
tpm-state: | ||
cv_ca: | ||
agent_var_lib_keylime: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env bash | ||
# This is enabling IMA measurement temporarily | ||
# Need to set up grub/boottime parameters for permanent measurements | ||
# If it doesn't work, grub config for safe startup: | ||
# GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX ima=on integrity_audit=1 lsm=integrity,ima" | ||
|
||
# policy is auditing: change "audit" to "measure" | ||
|
||
# check requirements (tpm2-tools) | ||
set -e | ||
command -v tpm2_startup &>/dev/null | ||
|
||
# don't fail | ||
set -x | ||
set +e | ||
|
||
# Enable IMA measurement | ||
echo "1" | sudo tee /sys/kernel/security/ima/policy_update | ||
mkdir -p /etc/ima | ||
sudo tee /etc/ima/ima-policy << 'EOF' | ||
# Default IMA policy | ||
# Don't measure files opened with read-only permissions | ||
dont_measure obj_type=file mask=MAY_READ | ||
# Measure all executed files | ||
audit func=BPRM_CHECK mask=MAY_EXEC | ||
# Measure files mmap()ed for execute | ||
audit func=FILE_MMAP mask=MAY_EXEC | ||
# Measure files opened for write or append | ||
audit func=FILE_CHECK mask=MAY_WRITE uid=0 | ||
EOF | ||
|
||
# load the ima policy | ||
sudo cat /etc/ima/ima-policy | sudo tee /sys/kernel/security/ima/policy | ||
|
||
# Configure TPM PRC - this needs | ||
# setup tpm2-tools to access the tpmserver in docker | ||
export TPM2TOOLS_TCTI="mssim:host=localhost,port=2321" | ||
tpm2_startup -c | ||
|
||
# PCR 10 will store IMA measurements | ||
tpm2_pcrextend 10:sha256=0000000000000000000000000000000000000000000000000000000000000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
# Run docker-compose up -d first to have infra in place | ||
|
||
set -eu | ||
|
||
# Register agent with allowlist | ||
docker run --network host \ | ||
-e KEYLIME_TENANT_TLS_ENABLED=False \ | ||
-e KEYLIME_VERIFIER_TLS_ENABLED=False \ | ||
-e KEYLIME_REGISTRAR_TLS_ENABLED=False \ | ||
-e KEYLIME_TENANT_ENABLE_INSECURE_VERIFICATION=True \ | ||
-v "$(pwd)"/allowlist.txt:/tmp/allowlist.txt:ro \ | ||
quay.io/keylime/keylime_tenant \ | ||
-v 127.0.0.1 \ | ||
-t 127.0.0.1 \ | ||
-u d432fbb3-d2f1-4a97-9ef7-75bd81c00000 \ | ||
--uuid d432fbb3-d2f1-4a97-9ef7-75bd81c00000 \ | ||
--allowlist /tmp/allowlist.txt \ | ||
--exclude boot_aggregate \ | ||
--tpm_policy="1,3,7" \ | ||
-c add |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env bash | ||
# Script to generate file hashes for allowlist | ||
# redirect to target file "allowlist.txt" | ||
|
||
set -eu | ||
|
||
cat <<EOF | ||
# Allowlist format - use hashes of known good files | ||
exclude: !policy | ||
- boot_aggregate | ||
- ima-buf | ||
- ima-sig | ||
- ima-ng | ||
EOF | ||
|
||
echo "# Generated allowlist" | ||
echo "hashes:" | ||
|
||
# List of critical directories to measure | ||
DIRS_TO_MEASURE=( | ||
"/bin" | ||
"/sbin" | ||
"/usr/bin" | ||
"/usr/sbin" | ||
"/lib/systemd" | ||
"/usr/lib/systemd" | ||
) | ||
|
||
for dir in "${DIRS_TO_MEASURE[@]}"; do | ||
if [[ -d "${dir}" ]]; then | ||
find "${dir}" -type f -exec sha256sum {} \; | while read -r hash file; do | ||
echo " ${file}: ${hash}" | ||
done | ||
fi | ||
done | ||
echo | ||
|
||
# Read current IMA measurements | ||
echo "ima:" | ||
sudo cat /sys/kernel/security/ima/ascii_runtime_measurements | while read -r _ hash template file; do | ||
if [[ "${template}" == "ima-ng" ]]; then | ||
echo " ${file}:" | ||
echo " hash: ${hash}" | ||
echo " validation_mask: 0xd" | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Building this image: | ||
# docker build . -t tpmserver:tumi | ||
|
||
# Running this image: | ||
# docker run -d --name tpm-server -p 2321:2321 -p 2322:2322 tpmserver:tumi | ||
|
||
# Use a debian slim image as base | ||
FROM debian:bullseye-slim | ||
|
||
# Set working directory | ||
WORKDIR /tpm | ||
|
||
# Install dependencies | ||
RUN apt-get update && apt-get install -y \ | ||
build-essential \ | ||
autoconf \ | ||
libtool \ | ||
libssl-dev \ | ||
pkg-config \ | ||
git \ | ||
wget \ | ||
tpm2-tools \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Clone and build IBM's TPM2 simulator | ||
RUN git clone https://github.com/kgoldman/ibmswtpm2 \ | ||
&& cd ibmswtpm2/src \ | ||
&& make \ | ||
&& mv tpm_server /usr/local/bin/ \ | ||
&& cd / \ | ||
&& rm -rf /tpm/ibmswtpm2 | ||
|
||
COPY start.sh / | ||
|
||
# Create directory for TPM state | ||
RUN mkdir -p /var/lib/tpm | ||
|
||
# Set working directory for TPM state | ||
WORKDIR /var/lib/tpm | ||
|
||
# Expose TPM simulator ports | ||
EXPOSE 2321 2322 | ||
|
||
# Start TPM simulator | ||
CMD ["/start.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu | ||
|
||
# run tpmserver | ||
docker run -d --name tpm-server -p 2321:2321 -p 2322:2322 tpmserver:tumi | ||
sleep 10 | ||
|
||
# setup tpm2-tools to access the tpmserver in docker | ||
export TPM2TOOLS_TCTI="mssim:host=localhost,port=2321" | ||
|
||
# clear the tpm | ||
tpm2_startup -c | ||
|
||
# get random 16 hex from tpm to verify it works | ||
tpm2_getrandom --hex 16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Start IBM's TPM server in background | ||
nohup tpm_server & | ||
|
||
# Wait for simulator to be ready | ||
sleep 2 | ||
|
||
export TPM2TOOLS_TCTI="mssim:host=localhost,port=2321" | ||
tpm2_startup -c | ||
|
||
tail -f /dev/null |