eBPF-based security platform
status: report a pending or unverifiable config instead of refusing
Daniel Borkmann88c0df334cea
diff --git a/Documentation/architecture.rst b/Documentation/architecture.rstindex 1e67c267..33ee7ee3 100644--- a/Documentation/architecture.rst+++ b/Documentation/architecture.rst@@ -702,8 +702,8 @@ eventlog replay and its anchor, the on-disk assets, and withand ``--include-modules`` the corresponding detail. The register isalways read: a status that did not ask the TPM would be a status thetarget wrote about itself. The overall-``status`` is ``ok``, ``degraded``, ``init-pending``, ``lsm-off`` or-``tampered``. ``--json`` emits the same as one document; ``--otel``+``status`` is ``ok``, ``degraded``, ``reboot-pending``,+``init-pending``, ``lsm-off`` or ``tampered``. ``--json`` emits the same as one document; ``--otel``pushes it as a keepalive log record. ``status`` is the target's ownaccount of itself; ``shirudo attest`` (section 7) is the account theTPM signs.diff --git a/Documentation/operations.rst b/Documentation/operations.rstindex c5192960..ed1bc1e0 100644--- a/Documentation/operations.rst+++ b/Documentation/operations.rst@@ -103,7 +103,7 @@ machine-readable one. The fields that matter day to day:means ``initrd``.Conditions- Four, each ``OK``, ``WARN`` or ``ALERT`` with a detail:+ Five, each ``OK``, ``WARN`` or ``ALERT`` with a detail:.. list-table:::header-rows: 1@@ -126,6 +126,21 @@ Conditions* - ``TpmMeasured``- ``WARN`` when no register is bound this boot(``degraded``) or no TPM answers; the detail says which.+ * - ``ConfigActive``+ - ``WARN`` while a config activation is pending until the next+ reboot (``reboot-pending``); ``ALERT`` when the config PCR,+ the activation records and the mounted config disagree, or+ the records belong to another TPM boot (``tampered``).++``config``+ The selected or pending config's ``root_hash``, whether its+ ``activation_pending`` and, when its records cannot vouch for it,+ the ``error``. Every other target command refuses in those states;+ ``status`` runs in them so that the keepalive reports them. It then+ uses the pending config's export settings only when that is the+ config mounted, and otherwise only the runtime image's settings and+ the environment, so a keepalive needs ``OTEL_EXPORTER_OTLP_ENDPOINT``+ in ``map-export.env`` to reach a collector in such a state.``keyring_serial`` and ``keyring_serial_pinned``The live keyring and the one frozen at ``init``; they match on a@@ -431,7 +446,8 @@ TPM reset and restart counts, event sequence and pending state. Ordinary targethold the config operation lock and use one held config directory for theoperation; a command waits up to 30 seconds for another one to releaseit. They refuse a pending activation or PCR/history inconsistency;-attestation follows the same rule.+attestation follows the same rule. ``status`` alone runs in those states+and reports them (section 2).Activate a complete locally staged bundle or pull it by HTTPS prefix::diff --git a/Documentation/telemetry.rst b/Documentation/telemetry.rstindex 1f292746..91df42bc 100644--- a/Documentation/telemetry.rst+++ b/Documentation/telemetry.rst@@ -221,7 +221,8 @@ Keepalive, one log record from ``shirudo status --otel``::eventName shirudo.keepaliveseverityNumber/Text 9 / INFO status ok- 13 / WARN degraded, init-pending+ 13 / WARN degraded, init-pending,+ reboot-pending17 / ERROR lsm-off, tamperedbody the status --json document as a key-valuelist (schema, status, conditions, tpm,diff --git a/Documentation/threat-model.rst b/Documentation/threat-model.rstindex 25fc75ad..554c3b0c 100644--- a/Documentation/threat-model.rst+++ b/Documentation/threat-model.rst@@ -437,7 +437,10 @@ T12 Interrupted image activationAn interruption after it, including an ambiguous TPM response, requiresmanual reboot. The node keeps running; Shirudo does not initiate thatreboot. Further state changes and config attestation refuse; no same-boot- recovery or extension retry is attempted. Trusted startup re-verifies the+ recovery or extension retry is attempted. ``status`` still runs and+ reports the activation as ``reboot-pending``; it uses the pending+ config's export settings only when that config is the one mounted,+ since the record vouches for no other. Trusted startup re-verifies theselected image, reads its entire verified mapping, emits a fresh BOOTevent and applies revocations before restoring upatches. Completion isrecorded only after startup succeeds. Missing or invalid selected imagesdiff --git a/builtin-status.c b/builtin-status.cindex 44899dd3..b71e77a2 100644--- a/builtin-status.c+++ b/builtin-status.c@@ -41,6 +41,7 @@#include "util/json.h"#include "util/macros.h"#include "util/identity.h"+#include "util/image_runtime.h"#include "util/keyring.h"#include "util/keys.h"#include "util/log.h"@@ -539,6 +540,9 @@ int cmd_status(int argc, const char **argv)int n_ups, i, fd, ret = 0;const char *otel_status = NULL;bool otel_endpoint_configured = false;+ char config_root_hex[65] = "";+ __u8 config_root[32];+ int config_state;for (i = 1; i < argc; i++) {if (strcmp(argv[i], "--json") == 0) {@@ -653,6 +657,9 @@ int cmd_status(int argc, const char **argv)gather_assets(&assets);tamper_rc = tamper_read(&tamper);+ config_state = shirudo_image_config_state(config_root);+ if (config_state != -ENODEV)+ hex_encode(config_root, sizeof(config_root), config_root_hex);{if (strsprintf(nv_index, sizeof(nv_index), "0x%08X",@@ -743,6 +750,9 @@ int cmd_status(int argc, const char **argv)cst.tpm, chain_rc == 0,match == 1, match >= 0,nv_index);+ cin.config_seen = config_state != -ENODEV;+ cin.config_state = config_state;+ cin.config_root = config_root_hex;otel_status = status_verdict(&cin);json_kv_string(&e, "status",otel_status);@@ -846,6 +856,20 @@ int cmd_status(int argc, const char **argv)} else {json_kv_null(&e, "tamper_attempts");}+ if (config_state != -ENODEV) {+ json_obj_open_key(&e, "config");+ json_kv_string(&e, "root_hash", config_root_hex);+ json_kv_bool(&e, "activation_pending",+ config_state == -EINPROGRESS);+ if (config_state && config_state != -EINPROGRESS)+ json_kv_string(&e, "error",+ strerror(-config_state));+ else+ json_kv_null(&e, "error");+ json_obj_close(&e);+ } else {+ json_kv_null(&e, "config");+ }if (include_system)sysinfo_emit_json(&e, &sysi);{@@ -1009,6 +1033,11 @@ int cmd_status(int argc, const char **argv)ret = 1;}}+ if (otel && !otel_endpoint_configured && config_state &&+ config_state != -ENODEV)+ pr_warn("status: no keepalive is sent: with the config activation %s, no export endpoint is known, since a config image is used only when its activation record vouches for it; OTEL_EXPORTER_OTLP_ENDPOINT in /etc/shirudo/map-export.env still names one",+ config_state == -EINPROGRESS ?+ "pending" : "unverifiable");if (json_stdout)printf("%s\n", json_buf);}@@ -1033,6 +1062,9 @@ int cmd_status(int argc, const char **argv)cst.tpm, chain_rc == 0,match == 1, match >= 0,nv_index);+ cin.config_seen = config_state != -ENODEV;+ cin.config_state = config_state;+ cin.config_root = config_root_hex;verdict = status_verdict(&cin);status_reason(&cin, reason, sizeof(reason));nc = conditions(&cin, conds, ARRAY_SIZE(conds));diff --git a/testing/helper/test-conditions.c b/testing/helper/test-conditions.cindex 9b3a162f..f63e1caf 100644--- a/testing/helper/test-conditions.c+++ b/testing/helper/test-conditions.c@@ -14,7 +14,9 @@*/#include <stdint.h>+#include <errno.h>#include <stdio.h>+#include <stdlib.h>#include <string.h>#include <shirudo/string.h>@@ -32,8 +34,8 @@ int main(int argc, char **argv)struct shirudo_condition conds[SHIRUDO_CONDITIONS_MAX];struct shirudo_conditions_input in = {};__s64 lsm, serial, pinned;+ const char *mode, *config;char reason[160];- const char *mode;size_t n, i;if (argc != 6 || arg_s64(argv[1], &lsm) || arg_s64(argv[3], &serial) ||@@ -60,6 +62,13 @@ int main(int argc, char **argv)in.cm_seen = in.chain_seen;in.chain_matches = !strcmp(argv[5], "match");in.nv_index = "0x01818E00";+ config = getenv("SHIRUDO_TEST_CONFIG_STATE");+ in.config_seen = !config || strcmp(config, "none");+ in.config_state = !config ? 0 :+ !strcmp(config, "pending") ? -EINPROGRESS :+ !strcmp(config, "untrusted") ? -EUCLEAN :+ !strcmp(config, "stale") ? -ESTALE : 0;+ in.config_root = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";status_reason(&in, reason, sizeof(reason));printf("status=%s\n", status_verdict(&in));diff --git a/testing/otel/t0018-status-otel.sh b/testing/otel/t0018-status-otel.shindex 424aea95..2e07fc70 100644--- a/testing/otel/t0018-status-otel.sh+++ b/testing/otel/t0018-status-otel.sh@@ -44,6 +44,7 @@ severity = {"ok": (9, "INFO"),"degraded": (13, "WARN"),"init-pending": (13, "WARN"),+ "reboot-pending": (13, "WARN"),"lsm-off": (17, "ERROR"),"tampered": (17, "ERROR"),}[status]@@ -56,7 +57,7 @@ PYtest_expect_success 'keepalive status severities and structured body are deterministic' 'work=$(mktemp -d) || return 1- for status in ok degraded init-pending lsm-off tampered+ for status in ok degraded init-pending reboot-pending lsm-off tampereddopython3 ../helper/otel-mock.py success "$work/port" "$work/body" \"$work/meta" &@@ -75,7 +76,8 @@ import json, sysstatus = sys.argv[1]record = json.load(open(sys.argv[2]))["resourceLogs"][0]["scopeLogs"][0]["logRecords"][0]expected = {"ok": (9, "INFO"), "degraded": (13, "WARN"),- "init-pending": (13, "WARN"), "lsm-off": (17, "ERROR"),+ "init-pending": (13, "WARN"), "reboot-pending": (13, "WARN"),+ "lsm-off": (17, "ERROR"),"tampered": (17, "ERROR")}[status]assert (record["severityNumber"], record["severityText"]) == expectedassert record["eventName"] == "shirudo.keepalive"diff --git a/testing/t0050-conditions.sh b/testing/t0050-conditions.shindex aa0a9940..44a0f28c 100755--- a/testing/t0050-conditions.sh+++ b/testing/t0050-conditions.sh@@ -6,6 +6,8 @@# of keyring the anchor is in, a keyring other than the one init froze,# or none where it froze one, makes the status tampered, and the register# conditions tell a TPM that does not answer from one with no register.+# A pending config activation is reboot-pending, and a config its records+# cannot vouch for is tampered.cd "$(dirname "$0")". ./test-lib.sh@@ -67,4 +69,31 @@ test_expect_success 'a bound register is measured' 'grep -qx "TpmMeasured OK NV index 0x01818E00 readable"'+test_expect_success 'an active config is OK' '+ ./$H 1 bpf 100 100 match |+ grep -qx "ConfigActive OK config 0123456789ab.. is active"+'++test_expect_success 'a pending activation is reboot-pending' '+ out=$(SHIRUDO_TEST_CONFIG_STATE=pending ./$H 1 bpf 100 100 match) &&+ echo "$out" | grep -qx "status=reboot-pending" &&+ echo "$out" | grep -qx "reason=a config activation is pending until the next reboot" &&+ echo "$out" | grep -qx "ConfigActive WARN the activation of config 0123456789ab.. is pending until the next reboot"+'++test_expect_success 'a config its records cannot vouch for is tampered' '+ for state in untrusted stale+ do+ out=$(SHIRUDO_TEST_CONFIG_STATE=$state ./$H 1 bpf 100 100 match) &&+ echo "$out" | grep -qx "status=tampered" &&+ echo "$out" | grep -qx "reason=the selected config cannot be verified against its records" &&+ echo "$out" | grep -q "^ConfigActive ALERT .*(tamper?)$" || return 1+ done+'++test_expect_success 'a pending activation does not hide a register mismatch' '+ SHIRUDO_TEST_CONFIG_STATE=pending ./$H 1 bpf 100 100 mismatch |+ grep -qx "status=tampered"+'+test_donediff --git a/util/conditions.c b/util/conditions.cindex 7fabe37b..a6a70b88 100644--- a/util/conditions.c+++ b/util/conditions.c@@ -5,6 +5,7 @@* Shared local security conditions block + status verdict.*/+#include <errno.h>#include <stdio.h>#include <string.h>@@ -13,6 +14,21 @@#include "conditions.h"+static bool config_untrusted(const struct shirudo_conditions_input *in)+{+ return in->config_seen && in->config_state &&+ in->config_state != -EINPROGRESS;+}++static const char *config_untrusted_detail(int state)+{+ if (state == -ESTALE)+ return "the config activation record does not belong to this TPM boot (tamper?)";+ if (state == -EKEYREJECTED)+ return "the mounted config does not match the selected root (tamper?)";+ return "the config PCR, activation records and mounted config disagree (tamper?)";+}+size_t conditions(const struct shirudo_conditions_input *in,struct shirudo_condition *c, size_t cap){@@ -104,6 +120,31 @@ size_t conditions(const struct shirudo_conditions_input *in,}n++;}+ if (n < cap) {+ const char *root = in->config_root ? in->config_root : "?";++ c[n].type = "ConfigActive";+ c[n].status = "OK";+ if (!in->config_seen) {+ c[n].status = "WARN";+ strscpy(c[n].detail, "no config activation state (init not run?)",+ sizeof(c[n].detail));+ } else if (in->config_state == -EINPROGRESS) {+ c[n].status = "WARN";+ if (strsprintf(c[n].detail, sizeof(c[n].detail),+ "the activation of config %.12s.. is pending until the next reboot",+ root) < 0)+ strscpy(c[n].detail, "?", sizeof(c[n].detail));+ } else if (config_untrusted(in)) {+ c[n].status = "ALERT";+ strscpy(c[n].detail, config_untrusted_detail(in->config_state),+ sizeof(c[n].detail));+ } else if (strsprintf(c[n].detail, sizeof(c[n].detail),+ "config %.12s.. is active", root) < 0) {+ strscpy(c[n].detail, "?", sizeof(c[n].detail));+ }+ n++;+ }return n;}@@ -126,12 +167,14 @@ const char *status_verdict(const struct shirudo_conditions_input *in)return "unparseable";if ((in->cm_seen && !in->chain_matches) ||(in->ksm_seen && !in->keyring_serial_matches) ||- (in->ksp_seen && !in->keyring_present))+ (in->ksp_seen && !in->keyring_present) || config_untrusted(in))return "tampered";if (!in->lsm_attached)return "lsm-off";if (!in->keyring_present)return "init-pending";+ if (in->config_seen && in->config_state == -EINPROGRESS)+ return "reboot-pending";if (!in->chain_seen)return "degraded";return "ok";@@ -151,6 +194,9 @@ void status_reason(const struct shirudo_conditions_input *in,} else if (strcmp(v, "tampered") == 0) {if (in->cm_seen && !in->chain_matches)strscpy(buf, "live register != eventlog replay", cap);+ else if (config_untrusted(in))+ strscpy(buf, "the selected config cannot be verified against its records",+ cap);else if (!in->keyring_present)strscpy(buf, "the keyring init froze is gone", cap);else@@ -159,6 +205,9 @@ void status_reason(const struct shirudo_conditions_input *in,strscpy(buf, "LSM not attached -- enforcement OFF", cap);} else if (strcmp(v, "init-pending") == 0) {strscpy(buf, "target hasn't been `shirudo init`'d", cap);+ } else if (strcmp(v, "reboot-pending") == 0) {+ strscpy(buf, "a config activation is pending until the next reboot",+ cap);} else if (strcmp(v, "degraded") == 0) {strscpy(buf, in->tpm_reachable ?"no register bound this boot" : "no TPM answered", cap);diff --git a/util/conditions.h b/util/conditions.hindex 86a83686..6aa1c72a 100644--- a/util/conditions.h+++ b/util/conditions.h@@ -35,6 +35,9 @@ struct shirudo_conditions_input {int chain_matches; /* 0/1 if cm_seen */int cm_seen;const char *nv_index;+ int config_seen;+ int config_state; /* shirudo_image_config_state() */+ const char *config_root; /* hex, when config_seen */};struct shirudo_condition {@@ -45,10 +48,10 @@ struct shirudo_condition {/** Maximum number of conditions returned today (LsmAttached,- * KeyringSealed, ChainIntact, TpmMeasured); callers can size their- * stack array off this.+ * KeyringSealed, ChainIntact, TpmMeasured, ConfigActive); callers can+ * size their stack array off this.*/-#define SHIRUDO_CONDITIONS_MAX 4+#define SHIRUDO_CONDITIONS_MAX 5size_t conditions(const struct shirudo_conditions_input *in,struct shirudo_condition *out, size_t cap);@@ -58,7 +61,7 @@ void conditions_print(const struct shirudo_condition *c, size_t n);/** Single-word aggregate verdict (severity worst -> best):* unreachable -> unparseable -> tampered -> lsm-off ->- * init-pending -> degraded -> ok+ * init-pending -> reboot-pending -> degraded -> ok* Used by the `Status:` line in `shirudo status` and its JSON output.*/const char *status_verdict(const struct shirudo_conditions_input *in);diff --git a/util/image_runtime.c b/util/image_runtime.cindex cc626f8d..44f5a1ae 100644--- a/util/image_runtime.c+++ b/util/image_runtime.c@@ -59,6 +59,7 @@ struct image_context {struct shirudo_tpm *tpm;int candidate_fd;int certificate_fd;+ int config_state; /* what current_config() refused status with */bool loaded;bool boot_keys_open;bool boot_target_valid;@@ -933,6 +934,23 @@ static int current_config(void)return rc ? rc : config_mount_check(&record);}+/*+ * status is how a fleet sees these states, so it runs in them while every+ * other command refuses: with the pending config's settings when that is+ * the config mounted, and with the runtime image's alone otherwise, since+ * a config the record cannot vouch for names no export destination.+ */+static int status_config(int state)+{+ struct shirudo_config_update_record record;++ image.config_state = state;+ if (state == -EINPROGRESS &&+ !shirudo_config_update_read(&image.update, &record))+ (void)config_mount_check(&record);+ return 0;+}+int shirudo_image_enter(const char *command, int argc, const char **argv){struct shirudo_identity identity;@@ -971,7 +989,25 @@ int shirudo_image_enter(const char *command, int argc, const char **argv)}if (!strcmp(command, "image"))return open_update();- return current_config();+ rc = current_config();+ if (!strcmp(command, "status") &&+ (rc == -EINPROGRESS || rc == -EUCLEAN || rc == -ESTALE ||+ rc == -EKEYREJECTED))+ return status_config(rc);+ return rc;+}++int shirudo_image_config_state(__u8 root[32])+{+ struct shirudo_config_update_record record;++ if (image.update.lock_fd < 0)+ return -ENODEV;+ if (shirudo_config_update_read(&image.update, &record))+ memset(root, 0, 32);+ else+ memcpy(root, record.target.root_hash, 32);+ return image.config_state;}int shirudo_image_status(void)diff --git a/util/image_runtime.h b/util/image_runtime.hindex 5e33b8cc..511b1da2 100644--- a/util/image_runtime.h+++ b/util/image_runtime.h@@ -24,4 +24,12 @@ void shirudo_image_leave(void);int shirudo_image_update(const char *prefix);int shirudo_image_status(void);+/*+ * The config state status reports: 0 with the selected config active,+ * -EINPROGRESS while an activation is pending, or the integrity error the+ * other commands refuse on; -ENODEV without activation state. root is the+ * selected or pending config's, zero when unknown.+ */+int shirudo_image_config_state(__u8 root[32]);+#endif /* SHIRUDO_IMAGE_RUNTIME_H */diff --git a/util/upatch_maps_otel.c b/util/upatch_maps_otel.cindex 11b2821c..2049d334 100644--- a/util/upatch_maps_otel.c+++ b/util/upatch_maps_otel.c@@ -1607,7 +1607,8 @@ int shirudo_status_otel_severity(const char *status, const char **text)return 9;}if (strcmp(status, "degraded") == 0 ||- strcmp(status, "init-pending") == 0) {+ strcmp(status, "init-pending") == 0 ||+ strcmp(status, "reboot-pending") == 0) {*text = "WARN";return 13;}