eBPF-based security platform
quote-check: build a static OpenSSL where the distribution has none
John Fastabend89cee52c74c7
diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.ymlindex 26066f7c..cf369a10 100644--- a/.github/workflows/packages.yml+++ b/.github/workflows/packages.yml@@ -320,23 +320,33 @@ jobs:rpm-operator:needs: rpm-targetruns-on: ubuntu-latest- timeout-minutes: 10+ timeout-minutes: 25container:image: fedora:45options: --ulimit memlock=-1:-1steps:+ # Fedora ships no static libcrypto, so make builds a static OpenSSL+ # for shirudo-quote-check, with perl, and links it with glibc-static.- name: Install the build dependenciesrun: |dnf -q install -y gcc make pkgconf-pkg-config git python3 rpm-build \cryptsetup openssl openssl-devel libcurl-devel tpm2-tss-devel \- elfutils-libelf-devel zlib-ng-compat-devel luajit-devel jq+ elfutils-libelf-devel zlib-ng-compat-devel luajit-devel jq \+ glibc-static perl- name: Check out repositoryuses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1with:fetch-depth: 0+ - name: Restore the quote checker's static OpenSSL+ id: quote-check-openssl+ uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0+ with:+ path: build/quote-check-openssl+ key: quote-check-openssl-fedora45-${{ runner.arch }}-${{ hashFiles('Makefile.target-deps') }}+- name: Install clang 23run: sh .github/scripts/install-clang.sh@@ -366,6 +376,13 @@ jobs:rpm -qp --requires shirudo-operator-*.rpm | grep -qx 'clang >= 23'.github/scripts/gen-sbom.sh shirudo-operator-*.rpm+ - name: Save the quote checker's static OpenSSL+ if: always() && steps.quote-check-openssl.outputs.cache-hit != 'true' && hashFiles('build/quote-check-openssl/lib/libcrypto.a') != ''+ uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0+ with:+ path: build/quote-check-openssl+ key: ${{ steps.quote-check-openssl.outputs.cache-primary-key }}+- name: Install, exercise and remove both packagesrun: |set -euxdiff --git a/Documentation/contribute/code/developer-guide.rst b/Documentation/contribute/code/developer-guide.rstindex c656b5eb..ef949feb 100644--- a/Documentation/contribute/code/developer-guide.rst+++ b/Documentation/contribute/code/developer-guide.rst@@ -321,9 +321,18 @@ Other make targets``libzstd-dev`` and ``libjitterentropy3-dev`` beside``libssl-dev`` and ``zlib1g-dev``. CI installs them with:src:`.github/scripts/install-static-libcrypto-deps.sh`, which- reads that list. A ``SANITIZE=`` build links it- against the shared libraries, because the sanitizer runtimes do- not link statically. See :doc:`/reference/cli/quote-check`.+ reads that list. Where the distribution ships no+ ``libcrypto.a``, as Fedora does not, ``make quote-check`` and+ ``make install-operator`` first build a static OpenSSL into+ ``build/quote-check-openssl`` with :src:`Makefile.target-deps`,+ which needs ``perl``, and compile the checker's objects against+ its headers under ``build/quote-check/``; the link then needs+ ``glibc-static``. ``QUOTE_CHECK_OPENSSL=<prefix>`` names another+ static OpenSSL. ``shirudo`` and ``shirudo-build`` still link the+ distribution's OpenSSL. ``make distclean`` removes that build. A+ ``SANITIZE=`` build links the checker against the shared+ libraries, because the sanitizer runtimes do not link+ statically. See :doc:`/reference/cli/quote-check`.* - ``make install-operator``- Installs the operator binary, the helper under``$(libexecdir)/shirudo``, ``shirudo-quote-check``, the imagediff --git a/Documentation/start/install.rst b/Documentation/start/install.rstindex 9728f3cf..2e5c9415 100644--- a/Documentation/start/install.rst+++ b/Documentation/start/install.rst@@ -96,7 +96,10 @@ Build the packages$ make -C packaging bindeb-pkg PKG_ROLES=operator- ``PKG_ROLES=target`` builds only the target package.+ ``PKG_ROLES=target`` builds only the target package. On Fedora,+ which ships no static ``libcrypto``, the operator build also+ downloads and builds a static OpenSSL for ``shirudo-quote-check``+ and needs ``perl`` and ``glibc-static`` for it.Install the operator package----------------------------diff --git a/Makefile b/Makefileindex e00e9ec6..6c642f68 100644--- a/Makefile+++ b/Makefile@@ -51,7 +51,7 @@ export prefix exec_prefix bindir libexecdir sharedir libdir mandir completionsdisystemdunitdir udevrulesdir dracutmodulesdir SHIRUDO_TARGET_PKG_CONFIG_PATH \SHIRUDO_TARGET_STATIC_LIBDIR-.PHONY: all help target target-deps target-deps-clean shirudo-target target-config shirudo-build quote-check docs bpf-deps install install-target install-operator clean distclean config tests proofs proofs-cbmc proofs-lean4 sparse tags cscope+.PHONY: all help target target-deps target-deps-clean shirudo-target target-config shirudo-build quote-check quote-check-deps docs bpf-deps install install-target install-operator clean distclean config tests proofs proofs-cbmc proofs-lean4 sparse tags cscopeall: config+$(Q)$(MAKE) -f Makefile.shirudo PROFILE=operator CONFIG_MK=config.mk all@@ -102,8 +102,25 @@ help:shirudo-build:+$(Q)$(MAKE) -C tools/shirudo-build-quote-check:- +$(Q)$(MAKE) -C tools/quote-check+# shirudo-quote-check is a static PIE. Where the distribution ships no+# libcrypto.a, as Fedora does not, it links a static OpenSSL built once+# into QUOTE_CHECK_OPENSSL_PREFIX instead.+QUOTE_CHECK_OPENSSL_PREFIX ?= $(CURDIR)/build/quote-check-openssl+QUOTE_CHECK_SYSTEM_LIBCRYPTO_A := $(wildcard $(shell pkg-config \+ --variable=libdir libcrypto 2>/dev/null)/libcrypto.a)+QUOTE_CHECK_OPENSSL ?= $(if $(SANITIZE)$(QUOTE_CHECK_SYSTEM_LIBCRYPTO_A),, \+ $(QUOTE_CHECK_OPENSSL_PREFIX))++quote-check-deps:+ifneq ($(strip $(QUOTE_CHECK_OPENSSL)),)+ +$(Q)$(MAKE) -f Makefile.target-deps \+ TARGET_DEPS_DIR="$(CURDIR)/build/quote-check-deps" \+ TARGET_OPENSSL_PREFIX="$(strip $(QUOTE_CHECK_OPENSSL))" openssl+endif++quote-check: quote-check-deps+ +$(Q)$(MAKE) -C tools/quote-check \+ QUOTE_CHECK_OPENSSL="$(strip $(QUOTE_CHECK_OPENSSL))"sparse: config+$(Q)$(MAKE) -f Makefile.shirudo PROFILE=operator CONFIG_MK=config.mk sparse@@ -157,8 +174,9 @@ install-target: all+$(Q)$(MAKE) target-config+$(Q)$(MAKE) -f Makefile.shirudo PROFILE=target CONFIG_MK=config-target.mk install-target-install-operator: all- +$(Q)$(MAKE) -f Makefile.shirudo install-operator+install-operator: all quote-check-deps+ +$(Q)$(MAKE) -f Makefile.shirudo install-operator \+ QUOTE_CHECK_OPENSSL="$(strip $(QUOTE_CHECK_OPENSSL))"clean:+$(Q)$(MAKE) -C Documentation clean@@ -170,6 +188,7 @@ distclean: clean$(Q)rm -f config.mk$(Q)rm -f tags cscope.files cscope.out cscope.in.out cscope.po.out+$(Q)$(MAKE) -f Makefile.target-deps TARGET_DEPS_DIR="$(TARGET_DEPS_DIR)" clean+ $(Q)rm -rf build/quote-check-deps "$(QUOTE_CHECK_OPENSSL_PREFIX)"$(Q)$(MAKE) -f Makefile.shirudo distclean.PHONY: vm vm-console vm-ssh vm-stop vm-clean oci telemetry stack-up stack-downdiff --git a/Makefile.shirudo b/Makefile.shirudoindex 32e21928..c3742604 100644--- a/Makefile.shirudo+++ b/Makefile.shirudo@@ -517,18 +517,43 @@ tools/shirudo-build/shirudo-build: $(BUILD_OBJS) util/sign.o util/config_image.o# a function inside a database container for one, so it is a static PIE# whatever the profile. The sanitizer runtimes do not link statically.PKG_CONFIG ?= pkg-config+QUOTE_CHECK_UTIL_SRCS := util/tpm_wire.c util/crypto_openssl.c util/hex.c \+ util/json.c util/io.c util/seal.c util/log.c \+ util/malloc.c util/string.c++# A distribution without a static libcrypto, Fedora for one, gets the+# prefix of a static OpenSSL here. The checker's objects then compile+# against its headers, apart from those of shirudo, whose OpenSSL may be+# another major version.+QUOTE_CHECK_OPENSSL ?=+ifneq ($(SANITIZE),)+override QUOTE_CHECK_OPENSSL :=+endif+ifeq ($(QUOTE_CHECK_OPENSSL),)+QUOTE_CHECK_LINK_OBJS := $(QUOTE_CHECK_OBJS) $(QUOTE_CHECK_UTIL_SRCS:.c=.o)+QUOTE_CHECK_PKG_CONFIG := $(PKG_CONFIG)+else+QUOTE_CHECK_LINK_OBJS := $(addprefix build/quote-check/, \+ $(QUOTE_CHECK_SRCS:.c=.o) $(QUOTE_CHECK_UTIL_SRCS:.c=.o))+QUOTE_CHECK_PKG_CONFIG := PKG_CONFIG_PATH= \+ PKG_CONFIG_LIBDIR=$(QUOTE_CHECK_OPENSSL)/lib/pkgconfig $(PKG_CONFIG)+-include $(QUOTE_CHECK_LINK_OBJS:.o=.d)+endif+ifeq ($(SANITIZE),)QUOTE_CHECK_LDFLAGS := $(HARDEN_STATIC_PIE_LDFLAGS) -static-pie -static-libgcc-QUOTE_CHECK_LIBS := $(shell $(PKG_CONFIG) --static --libs libcrypto 2>/dev/null)+QUOTE_CHECK_LIBS := $(shell $(QUOTE_CHECK_PKG_CONFIG) --static --libs libcrypto 2>/dev/null)elseQUOTE_CHECK_LDFLAGS := $(HARDEN_LDFLAGS)QUOTE_CHECK_LIBS := $(LIBCRYPTO_LIBS)endif-tools/quote-check/shirudo-quote-check: $(QUOTE_CHECK_OBJS) util/tpm_wire.o \- util/crypto_openssl.o util/hex.o \- util/json.o util/io.o util/seal.o \- util/log.o util/malloc.o util/string.o+build/quote-check/%.o: %.c Makefile.shirudo $(CONFIG_MK_DEP)+ @printf ' CC $@\n'+ $(Q)mkdir -p $(dir $@)+ $(Q)$(CC) -I$(QUOTE_CHECK_OPENSSL)/include $(CFLAGS) -MMD -MP -c $< -o $@++tools/quote-check/shirudo-quote-check: $(QUOTE_CHECK_LINK_OBJS)@printf ' LD $@\n'$(Q)$(LD) $(CFLAGS) $(QUOTE_CHECK_LDFLAGS) $(LDFLAGS) -o $@ $^ \$(QUOTE_CHECK_LIBS)@@ -1202,7 +1227,7 @@ clean:$(Q)rm -f tools/quote-check/shirudo-quote-check$(Q)rm -f $(MAIN_OBJ) $(BUILTIN_OBJS) $(UTIL_OBJS) \$(BUILD_OBJS) $(QUOTE_CHECK_OBJS) $(VERSION_OBJ) util/version_id.c- $(Q)rm -rf build/target build/unit+ $(Q)rm -rf build/target build/unit build/quote-check$(Q)rm -f $(DEPS) testing/helper/*.d$(Q)rm -f $(BPF_OBJS) $(VMLINUX_H) systemd/shirudo.service \systemd/shirudo-initrd.service \diff --git a/Makefile.target-deps b/Makefile.target-depsindex 436cc803..3f2a18c9 100644--- a/Makefile.target-deps+++ b/Makefile.target-deps@@ -11,6 +11,12 @@SHELL := /bin/sh+# The packaging build passes shirudo's install paths (prefix, libdir,+# DESTDIR) on the command line, and make hands those to every sub-make,+# where they override what each dependency's own configure chose: OpenSSL+# would install into the system libdir. The dependencies' makes get none.+MAKEOVERRIDES :=+TARGET_DEPS_DIR ?= build/target-depsTARGET_STATIC_LIBDIR ?= $(TARGET_DEPS_DIR)/libTARGET_OPENSSL_PREFIX ?= $(TARGET_DEPS_DIR)/openssl@@ -90,12 +96,16 @@ TSS_ARCHIVES := \libtss2-sys.a \libtss2-mu.a-.PHONY: all clean check-system-archives+.PHONY: all openssl clean check-system-archivesall: $(OPENSSL_STAMP) $(CURL_STAMP) $(TSS_STAMP) $(STATIC_ARCHIVES_STAMP) $(ENV_FILE)@printf 'shirudo: target dependencies ready\n'@printf 'shirudo: run make target (or source %s)\n' '$(ENV_FILE)'+# The static OpenSSL alone, for shirudo-quote-check where the+# distribution ships no libcrypto.a.+openssl: $(OPENSSL_STAMP)+# Static-only, no shared objects or loadable modules: the target binary# must not pick up a provider or engine from the host filesystem. The# OPENSSLDIR is the Debian-family system location so default trust