eBPF-based security platform
docs: describe both ways to enroll a target's TPM
John Fastabend20f0e39e6e86
diff --git a/Documentation/images/internals-attest-evidence.svg b/Documentation/images/internals-attest-evidence.svgnew file mode 100644index 00000000..1d3106dc--- /dev/null+++ b/Documentation/images/internals-attest-evidence.svg@@ -0,0 +1,65 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 580" width="900" height="580" font-family="sans-serif" role="img" aria-labelledby="t">+ <title id="t">Collecting evidence: the operator predicts the register and sends a nonce, with a credential challenge at enrollment; the target has the TPM create the attestation key, activate the credential, quote the PCRs and certify the register with the nonce, and returns an evidence document that the operator verifies</title>+ <style>@media (prefers-color-scheme: dark) { [fill="#5d6675"] { fill: #b4bcc7; } }</style>+ <defs>+ <marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">+ <path d="M0,0 L10,5 L0,10 z" fill="#8a93a0"/>+ </marker>+ </defs>+ <g stroke="#8a93a0" stroke-width="1" stroke-dasharray="3 4">+ <line x1="130" y1="54" x2="130" y2="74"/>+ <line x1="130" y1="118" x2="130" y2="534"/>+ <line x1="450" y1="54" x2="450" y2="462"/>+ <line x1="450" y1="498" x2="450" y2="570"/>+ <line x1="770" y1="54" x2="770" y2="570"/>+ </g>+ <g fill="#8a93a0" fill-opacity="0.08" stroke="#8a93a0" stroke-width="1.5">+ <rect x="50" y="10" width="160" height="44" rx="6"/>+ <rect x="370" y="10" width="160" height="44" rx="6"/>+ <rect x="690" y="10" width="160" height="44" rx="6"/>+ <rect x="30" y="74" width="200" height="44" rx="6"/>+ <rect x="320" y="462" width="260" height="36" rx="6"/>+ <rect x="30" y="534" width="200" height="34" rx="6"/>+ </g>+ <g fill="none" stroke="#8a93a0" stroke-width="1.5" marker-end="url(#arrow)">+ <line x1="130" y1="150" x2="448" y2="150"/>+ <line x1="450" y1="205" x2="768" y2="205"/>+ <line x1="450" y1="260" x2="768" y2="260"/>+ <line x1="770" y1="280" x2="452" y2="280" stroke-dasharray="5 4"/>+ <line x1="450" y1="335" x2="768" y2="335"/>+ <line x1="770" y1="355" x2="452" y2="355" stroke-dasharray="5 4"/>+ <line x1="450" y1="410" x2="768" y2="410"/>+ <line x1="770" y1="430" x2="452" y2="430" stroke-dasharray="5 4"/>+ <line x1="450" y1="522" x2="132" y2="522"/>+ </g>+ <g fill="#5d6675" font-size="12" text-anchor="middle">+ <text x="130" y="30" font-weight="bold" font-size="13">Operator</text>+ <text x="130" y="46" font-size="11">no TPM</text>+ <text x="450" y="30" font-weight="bold" font-size="13">Target</text>+ <text x="450" y="46" font-size="11" font-family="monospace">shirudo attest</text>+ <text x="770" y="37" font-weight="bold" font-size="13">TPM</text>++ <text x="130" y="93" font-family="monospace">attest predict</text>+ <text x="130" y="109" font-size="11">certificates, artifacts, tree root</text>++ <text x="290" y="142">nonce, and a challenge at enrollment</text>+ <text x="290" y="168" font-size="11">attest challenge, bound to the AK name</text>++ <text x="610" y="197">CreatePrimary: AK</text>+ <text x="610" y="223" font-size="11">fixed template, endorsement hierarchy</text>++ <text x="610" y="252">ActivateCredential, with a challenge</text>+ <text x="610" y="296" font-size="11">the credential, only for that AK</text>++ <text x="610" y="327" font-family="monospace">Quote(PCRs; nonce)</text>+ <text x="610" y="371" font-size="11">signed PCR digest</text>++ <text x="610" y="402" font-family="monospace">NV_Certify(register; nonce)</text>+ <text x="610" y="446" font-size="11">signed register value and name</text>++ <text x="450" y="485" font-size="11">with this boot's eventlog, the EK, logs</text>++ <text x="290" y="514">evidence document</text>+ <text x="130" y="556" font-family="monospace">attest verify</text>+ </g>+</svg>diff --git a/Documentation/images/internals-attest-names.svg b/Documentation/images/internals-attest-names.svgnew file mode 100644index 00000000..ac3e55a4--- /dev/null+++ b/Documentation/images/internals-attest-names.svg@@ -0,0 +1,58 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 520" width="900" height="520" font-family="sans-serif" role="img" aria-labelledby="t">+ <title id="t">Two ways to learn the attestation key's name: through credential activation, where the TPM releases the operator's credential only to that key under an endorsement key the operator trusts, or from a builder that created both keys in the TPM before handing it over; both end in the names every later verify pins</title>+ <style>@media (prefers-color-scheme: dark) { [fill="#5d6675"] { fill: #b4bcc7; } }</style>+ <defs>+ <marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">+ <path d="M0,0 L10,5 L0,10 z" fill="#8a93a0"/>+ </marker>+ </defs>+ <line x1="450" y1="10" x2="450" y2="350" stroke="#8a93a0" stroke-width="1" stroke-dasharray="3 4"/>+ <g fill="#8a93a0" fill-opacity="0.08" stroke="#8a93a0" stroke-width="1.5">+ <rect x="60" y="52" width="330" height="50" rx="6"/>+ <rect x="60" y="132" width="330" height="50" rx="6"/>+ <rect x="60" y="212" width="330" height="50" rx="6"/>+ <rect x="60" y="292" width="330" height="50" rx="6"/>+ <rect x="510" y="52" width="330" height="50" rx="6"/>+ <rect x="510" y="132" width="330" height="50" rx="6"/>+ <rect x="510" y="212" width="330" height="50" rx="6"/>+ <rect x="250" y="384" width="400" height="44" rx="6"/>+ <rect x="230" y="458" width="440" height="50" rx="6"/>+ </g>+ <g fill="none" stroke="#8a93a0" stroke-width="1.5" marker-end="url(#arrow)">+ <line x1="225" y1="102" x2="225" y2="130"/>+ <line x1="225" y1="182" x2="225" y2="210"/>+ <line x1="225" y1="262" x2="225" y2="290"/>+ <line x1="675" y1="102" x2="675" y2="130"/>+ <line x1="675" y1="182" x2="675" y2="210"/>+ <polyline points="225,342 225,362 380,362 380,382"/>+ <polyline points="675,262 675,362 520,362 520,382"/>+ <line x1="450" y1="428" x2="450" y2="456"/>+ </g>+ <g fill="#5d6675" font-size="12" text-anchor="middle">+ <text x="225" y="22" font-weight="bold" font-size="13">Credential activation</text>+ <text x="225" y="40" font-size="11">trust rests on the endorsement key</text>+ <text x="675" y="22" font-weight="bold" font-size="13">Builder-recorded names</text>+ <text x="675" y="40" font-size="11">trust rests on the builder, and for a virtual TPM its host</text>++ <text x="225" y="73" font-family="monospace">target: attest --nonce</text>+ <text x="225" y="91" font-size="11">AK name, EK public area, EK certificate</text>+ <text x="225" y="153" font-family="monospace">attest challenge</text>+ <text x="225" y="171" font-size="11">EK vouched for by --ek-ca or --ek-name</text>+ <text x="225" y="233" font-family="monospace">target: attest --challenge</text>+ <text x="225" y="251" font-size="11">the TPM releases the credential only to that AK</text>+ <text x="225" y="313" font-family="monospace">attest verify --expect-credential</text>+ <text x="225" y="331" font-size="11">once, at enrollment</text>++ <text x="675" y="73">The builder controls the TPM</text>+ <text x="675" y="91" font-size="11">a hypervisor's virtual TPM, or provisioning before deployment</text>+ <text x="675" y="153" font-family="monospace">CreatePrimary: AK, EK</text>+ <text x="675" y="171" font-size="11">attest's templates, endorsement hierarchy</text>+ <text x="675" y="233">The builder records the names</text>+ <text x="675" y="251" font-size="11">before the TPM is handed to the target</text>++ <text x="450" y="403" font-family="monospace">inventory: ak-name, ek-name</text>+ <text x="450" y="420" font-size="11">on the operator host, one pair per target</text>+ <text x="450" y="479" font-family="monospace">attest verify --ak-name --ek-name</text>+ <text x="450" y="497" font-size="11">every later verification, the same on both paths</text>+ </g>+</svg>diff --git a/Documentation/images/internals-attest-verify.svg b/Documentation/images/internals-attest-verify.svgnew file mode 100644index 00000000..8005f894--- /dev/null+++ b/Documentation/images/internals-attest-verify.svg@@ -0,0 +1,66 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 450" width="900" height="450" font-family="sans-serif" role="img" aria-labelledby="t">+ <title id="t">Four comparisons in attest verify: the eventlog replay must equal the certified register value; the name computed from the init record must equal the certified name; pcr_before extended by the anchor must equal the quoted PCR 9; the init event must equal the one attest predict computes</title>+ <style>@media (prefers-color-scheme: dark) { [fill="#5d6675"] { fill: #b4bcc7; } }</style>+ <defs>+ <marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">+ <path d="M0,0 L10,5 L0,10 z" fill="#8a93a0"/>+ </marker>+ </defs>+ <g fill="#8a93a0" fill-opacity="0.08" stroke="#8a93a0" stroke-width="1.5">+ <rect x="20" y="40" width="280" height="60" rx="6"/>+ <rect x="600" y="40" width="280" height="60" rx="6"/>+ <rect x="20" y="140" width="280" height="60" rx="6"/>+ <rect x="600" y="140" width="280" height="60" rx="6"/>+ <rect x="20" y="240" width="280" height="60" rx="6"/>+ <rect x="600" y="240" width="280" height="60" rx="6"/>+ <rect x="20" y="340" width="280" height="60" rx="6"/>+ <rect x="600" y="340" width="280" height="60" rx="6"/>+ </g>+ <g fill="none" stroke="#8a93a0" stroke-width="1.5">+ <rect x="390" y="52" width="120" height="36" rx="18"/>+ <rect x="390" y="152" width="120" height="36" rx="18"/>+ <rect x="390" y="252" width="120" height="36" rx="18"/>+ <rect x="390" y="352" width="120" height="36" rx="18"/>+ </g>+ <g fill="none" stroke="#8a93a0" stroke-width="1.5" marker-end="url(#arrow)">+ <line x1="300" y1="70" x2="388" y2="70"/>+ <line x1="600" y1="70" x2="512" y2="70"/>+ <line x1="300" y1="170" x2="388" y2="170"/>+ <line x1="600" y1="170" x2="512" y2="170"/>+ <line x1="300" y1="270" x2="388" y2="270"/>+ <line x1="600" y1="270" x2="512" y2="270"/>+ <line x1="300" y1="370" x2="388" y2="370"/>+ <line x1="600" y1="370" x2="512" y2="370"/>+ </g>+ <g fill="#5d6675" font-size="11">+ <text x="20" y="24">Signed by the TPM or computed by the operator</text>+ <text x="880" y="24" text-anchor="end">Written by the target</text>+ </g>+ <g fill="#5d6675" font-size="13" font-weight="bold">+ <text x="34" y="64">NV_Certify: value</text>+ <text x="614" y="64">This boot's eventlog</text>+ <text x="34" y="164">NV_Certify: name</text>+ <text x="614" y="164">init record</text>+ <text x="34" y="264">Quote: PCR 9</text>+ <text x="614" y="264">init record</text>+ <text x="34" y="364">attest predict: init event</text>+ <text x="614" y="364">init event</text>+ </g>+ <g fill="#5d6675" font-size="11">+ <text x="34" y="86">the register's 32 bytes</text>+ <text x="614" y="86">every digest folded from 32 zero bytes</text>+ <text x="34" y="186">the index's attributes and write policy</text>+ <text x="614" y="186">name from pcr_before, phase_before, writer key</text>+ <text x="34" y="286">quoted with the nonce</text>+ <text x="614" y="286">pcr_before extended by the anchor digest</text>+ <text x="34" y="386">--cert, --upatch, --tree-root</text>+ <text x="614" y="386">cert_sha256, set_digest, tree_root</text>+ <text x="450" y="432" text-anchor="middle">A mismatch in any row fails verify. Events after init are judged by --expect-chain or --allow-runtime-events.</text>+ </g>+ <g fill="#5d6675" font-size="13" font-weight="bold" text-anchor="middle">+ <text x="450" y="75">replay</text>+ <text x="450" y="175">binding</text>+ <text x="450" y="275">anchor</text>+ <text x="450" y="375">expected</text>+ </g>+</svg>diff --git a/Documentation/images/internals-register-events.svg b/Documentation/images/internals-register-events.svgnew file mode 100644index 00000000..91f12a4d--- /dev/null+++ b/Documentation/images/internals-register-events.svg@@ -0,0 +1,53 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 400" width="900" height="400" font-family="sans-serif" role="img" aria-labelledby="t">+ <title id="t">Building the register: in the initrd init defines the NV index under a policy on PCRs 9 and 11, extends the init event, extends PCR 9 with the anchor and writes the init record; every later command extends a tagged event digest and then appends its record to the eventlog</title>+ <style>@media (prefers-color-scheme: dark) { [fill="#5d6675"] { fill: #b4bcc7; } }</style>+ <defs>+ <marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">+ <path d="M0,0 L10,5 L0,10 z" fill="#8a93a0"/>+ </marker>+ </defs>+ <g fill="#8a93a0" fill-opacity="0.08" stroke="#8a93a0" stroke-width="1.5">+ <rect x="90" y="10" width="140" height="44" rx="6"/>+ <rect x="350" y="10" width="140" height="44" rx="6"/>+ <rect x="570" y="10" width="140" height="44" rx="6"/>+ <rect x="750" y="10" width="140" height="44" rx="6"/>+ </g>+ <g stroke="#8a93a0" stroke-width="1" stroke-dasharray="3 4">+ <line x1="160" y1="54" x2="160" y2="365"/>+ <line x1="420" y1="54" x2="420" y2="365"/>+ <line x1="640" y1="54" x2="640" y2="365"/>+ <line x1="820" y1="54" x2="820" y2="365"/>+ <line x1="10" y1="262" x2="890" y2="262"/>+ </g>+ <g fill="none" stroke="#8a93a0" stroke-width="1.5" marker-end="url(#arrow)">+ <line x1="160" y1="100" x2="638" y2="100"/>+ <line x1="160" y1="145" x2="638" y2="145"/>+ <line x1="160" y1="190" x2="818" y2="190"/>+ <line x1="160" y1="235" x2="418" y2="235"/>+ <line x1="160" y1="305" x2="638" y2="305"/>+ <line x1="160" y1="350" x2="418" y2="350"/>+ </g>+ <g fill="#5d6675" font-size="12" text-anchor="middle">+ <text x="160" y="37" font-weight="bold" font-size="13">shirudo</text>+ <text x="420" y="30" font-weight="bold" font-size="13">eventlog</text>+ <text x="420" y="46" font-size="11" font-family="monospace">/var/lib/shirudo</text>+ <text x="640" y="30" font-weight="bold" font-size="13">TPM NV index</text>+ <text x="640" y="46" font-size="11">the register</text>+ <text x="820" y="37" font-weight="bold" font-size="13">TPM PCR 9</text>++ <text x="400" y="92">NV_DefineSpace, write policy on PCRs 9 and 11</text>+ <text x="400" y="137" font-family="monospace">NV_Extend(init)</text>+ <text x="490" y="182">PCR_Extend(SHA-256(anchor)), the anchor names the index</text>+ <text x="290" y="227">init record, to eventlog.pending</text>++ <text x="400" y="297" font-family="monospace">NV_Extend(SHA-256(tag || fields))</text>+ <text x="290" y="342">append the record</text>+ </g>+ <g fill="#5d6675" font-size="11">+ <text x="10" y="88">initrd, once</text>+ <text x="10" y="103">per TPM boot</text>+ <text x="10" y="290">every later</text>+ <text x="10" y="305">command</text>+ <text x="160" y="388">upatch_load, upatch_unload, tree_op, key_revoke: extend, then append, under eventlog.lock</text>+ </g>+</svg>diff --git a/Documentation/images/operate-attest-activation.svg b/Documentation/images/operate-attest-activation.svgnew file mode 100644index 00000000..ed77939d--- /dev/null+++ b/Documentation/images/operate-attest-activation.svg@@ -0,0 +1,60 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 540" width="900" height="540" font-family="sans-serif" role="img" aria-labelledby="t">+ <title id="t">Enrolling through credential activation: the target answers a nonce with enroll.json, carrying the attestation key's name and the endorsement key; the operator makes a challenge for an endorsement key it vouches for; the target answers it with a second nonce, and the TPM releases the credential only to that attestation key under that endorsement key; the operator verifies the credential and records both names</title>+ <style>@media (prefers-color-scheme: dark) { [fill="#5d6675"] { fill: #b4bcc7; } }</style>+ <defs>+ <marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">+ <path d="M0,0 L10,5 L0,10 z" fill="#8a93a0"/>+ </marker>+ </defs>+ <g stroke="#8a93a0" stroke-width="1" stroke-dasharray="3 4">+ <line x1="160" y1="54" x2="160" y2="208"/>+ <line x1="160" y1="254" x2="160" y2="416"/>+ <line x1="470" y1="54" x2="470" y2="530"/>+ <line x1="770" y1="54" x2="770" y2="530"/>+ </g>+ <g fill="#8a93a0" fill-opacity="0.08" stroke="#8a93a0" stroke-width="1.5">+ <rect x="85" y="10" width="150" height="44" rx="6"/>+ <rect x="395" y="10" width="150" height="44" rx="6"/>+ <rect x="695" y="10" width="150" height="44" rx="6"/>+ <rect x="30" y="208" width="260" height="46" rx="6"/>+ <rect x="30" y="416" width="260" height="46" rx="6"/>+ <rect x="30" y="486" width="260" height="44" rx="6"/>+ </g>+ <g fill="none" stroke="#8a93a0" stroke-width="1.5" marker-end="url(#arrow)">+ <line x1="160" y1="96" x2="468" y2="96"/>+ <line x1="470" y1="132" x2="768" y2="132"/>+ <line x1="770" y1="150" x2="472" y2="150" stroke-dasharray="5 4"/>+ <line x1="470" y1="186" x2="162" y2="186"/>+ <line x1="160" y1="292" x2="468" y2="292"/>+ <line x1="470" y1="330" x2="768" y2="330"/>+ <line x1="770" y1="348" x2="472" y2="348" stroke-dasharray="5 4"/>+ <line x1="470" y1="394" x2="162" y2="394"/>+ <line x1="160" y1="462" x2="160" y2="484"/>+ </g>+ <g fill="#5d6675" font-size="12" text-anchor="middle">+ <text x="160" y="30" font-weight="bold" font-size="13">Operator</text>+ <text x="160" y="46" font-size="11">inventory, no TPM</text>+ <text x="470" y="30" font-weight="bold" font-size="13">Target</text>+ <text x="470" y="46" font-size="11" font-family="monospace">shirudo attest</text>+ <text x="770" y="30" font-weight="bold" font-size="13">TPM</text>+ <text x="770" y="46" font-size="11">physical or virtual</text>++ <text x="315" y="88">nonce</text>+ <text x="620" y="124">CreatePrimary: AK, EK</text>+ <text x="620" y="166" font-size="11">public areas, names, EK certificate</text>+ <text x="315" y="178" font-family="monospace">enroll.json</text>++ <text x="160" y="228" font-family="monospace">attest challenge</text>+ <text x="160" y="245" font-size="11">EK vouched for by --ek-ca or --ek-name</text>++ <text x="315" y="284" font-family="monospace">challenge.json, nonce-2</text>+ <text x="620" y="322">ActivateCredential</text>+ <text x="620" y="364" font-size="11">the credential, only to that AK under that EK</text>+ <text x="315" y="386" font-family="monospace">answer.json</text>++ <text x="160" y="436" font-family="monospace">verify --expect-credential</text>+ <text x="160" y="453" font-size="11">with --ak-name and --ek-name</text>+ <text x="160" y="505" font-family="monospace">inventory: ak-name, ek-name</text>+ <text x="160" y="521" font-size="11">every later verify pins them</text>+ </g>+</svg>diff --git a/Documentation/images/operate-attest-builder.svg b/Documentation/images/operate-attest-builder.svgnew file mode 100644index 00000000..1198d6f2--- /dev/null+++ b/Documentation/images/operate-attest-builder.svg@@ -0,0 +1,65 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 500" width="900" height="500" font-family="sans-serif" role="img" aria-labelledby="t">+ <title id="t">Enrolling from a builder's records: while it controls the TPM, the builder creates the attestation key and the endorsement key from attest's templates and gives their names to the operator's inventory; every attestation after that is a nonce, the target having the TPM create the same attestation key, quote the PCRs and certify the register, and a verify that pins the builder's names, with no credential challenge</title>+ <style>@media (prefers-color-scheme: dark) { [fill="#5d6675"] { fill: #b4bcc7; } }</style>+ <defs>+ <marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">+ <path d="M0,0 L10,5 L0,10 z" fill="#8a93a0"/>+ </marker>+ </defs>+ <g stroke="#8a93a0" stroke-width="1" stroke-dasharray="3 4">+ <line x1="120" y1="54" x2="120" y2="206"/>+ <line x1="340" y1="54" x2="340" y2="452"/>+ <line x1="570" y1="54" x2="570" y2="490"/>+ <line x1="790" y1="54" x2="790" y2="490"/>+ <line x1="10" y1="206" x2="890" y2="206"/>+ </g>+ <g fill="#8a93a0" fill-opacity="0.08" stroke="#8a93a0" stroke-width="1.5">+ <rect x="45" y="10" width="150" height="44" rx="6" stroke-dasharray="5 4"/>+ <rect x="265" y="10" width="150" height="44" rx="6"/>+ <rect x="495" y="10" width="150" height="44" rx="6"/>+ <rect x="715" y="10" width="150" height="44" rx="6"/>+ <rect x="220" y="452" width="240" height="36" rx="6"/>+ </g>+ <g fill="none" stroke="#8a93a0" stroke-width="1.5" marker-end="url(#arrow)">+ <line x1="120" y1="104" x2="788" y2="104"/>+ <line x1="790" y1="124" x2="122" y2="124" stroke-dasharray="5 4"/>+ <line x1="120" y1="172" x2="338" y2="172"/>+ <line x1="340" y1="244" x2="568" y2="244"/>+ <line x1="570" y1="282" x2="788" y2="282"/>+ <line x1="570" y1="332" x2="788" y2="332"/>+ <line x1="790" y1="348" x2="572" y2="348" stroke-dasharray="5 4"/>+ <line x1="570" y1="388" x2="788" y2="388"/>+ <line x1="790" y1="404" x2="572" y2="404" stroke-dasharray="5 4"/>+ <line x1="570" y1="436" x2="342" y2="436"/>+ </g>+ <g fill="#5d6675" font-size="12" text-anchor="middle">+ <text x="120" y="30" font-weight="bold" font-size="13">Builder</text>+ <text x="120" y="46" font-size="11">hypervisor or provisioner</text>+ <text x="340" y="30" font-weight="bold" font-size="13">Operator</text>+ <text x="340" y="46" font-size="11">inventory, no TPM</text>+ <text x="570" y="30" font-weight="bold" font-size="13">Target</text>+ <text x="570" y="46" font-size="11" font-family="monospace">shirudo attest</text>+ <text x="790" y="30" font-weight="bold" font-size="13">TPM</text>+ <text x="790" y="46" font-size="11">physical or virtual</text>++ <text x="455" y="96" font-family="monospace">CreatePrimary: AK, EK (attest's templates)</text>+ <text x="455" y="140" font-size="11">their names</text>+ <text x="230" y="164">ak-name, ek-name</text>+ <text x="230" y="190" font-size="11">into the inventory</text>++ <text x="455" y="236">nonce</text>++ <text x="680" y="274">CreatePrimary: AK</text>+ <text x="680" y="298" font-size="11">the name the builder recorded</text>++ <text x="680" y="324" font-family="monospace">Quote(PCRs; nonce)</text>+ <text x="680" y="380" font-family="monospace">NV_Certify(register; nonce)</text>++ <text x="455" y="428">evidence document</text>+ <text x="340" y="475" font-family="monospace">verify --ak-name --ek-name</text>+ </g>+ <g fill="#5d6675" font-size="11">+ <text x="128" y="76">before handover, once</text>+ <text x="128" y="226">every attestation</text>+ </g>+</svg>diff --git a/Documentation/internals/measurement-register.rst b/Documentation/internals/measurement-register.rstindex 5c852594..5ed7c2d3 100644--- a/Documentation/internals/measurement-register.rst+++ b/Documentation/internals/measurement-register.rst@@ -139,7 +139,20 @@ Binding at boot---------------``init`` binds the register once per TPM boot, normally from the initrd,-after it has restored the archived upatches (:doc:`boot-flow`):+after it has restored the archived upatches (:doc:`boot-flow`). Figure 1+shows the binding and the extensions that follow it.++.. figure:: /images/internals-register-events.svg+ :alt: In the initrd, init defines the NV index under a write policy+ on PCRs 9 and 11, extends it with the init event, extends PCR 9+ with the anchor digest and writes the init record to+ eventlog.pending. Every later command extends the index with a+ tagged event digest and then appends its record to the+ eventlog, under eventlog.lock.++ Figure 1. Binding the register at boot and extending it later.++The binding takes these steps:#. Open a salted session using the EK whose name ``init`` froze in theidentity map. The session authenticates the TPM's successful replies.@@ -332,7 +345,20 @@ Evidence``shirudo attest`` asks the TPM for two signed statements and collectswhat a verifier needs to check them. It needs no enrollment state on the-target and leaves none.+target and leaves none. Figure 2 shows one run, with the credential+activation that enrollment adds.++.. figure:: /images/internals-attest-evidence.svg+ :alt: The operator runs attest predict and sends a nonce, with a+ credential challenge at enrollment. The target has the TPM create+ the attestation key from its fixed template, activate the+ credential when there is a challenge, quote the PCRs and certify+ the register with the nonce. It returns an evidence document with+ this boot's eventlog, and the operator runs attest verify.++ Figure 2. Collecting evidence. The operator holds no TPM; the nonce,+ the challenge and the document travel by whatever channel the operator+ uses to reach the target.The attestation key is a primary under the endorsement hierarchy with afixed template: ECC NIST P-256, ECDSA with SHA-256, ``restricted`` and@@ -376,12 +402,53 @@ the attestation key it loaded has the name the challenge was made for.with the signature checks, this shows that the key that signed is arestricted key in the TPM that holds the endorsement key.+Builder-recorded names+~~~~~~~~~~~~~~~~~~~~~~++Activation is one way to learn the attestation key's name. The other is+to take it from a builder that controlled the TPM before the target got+it, a hypervisor creating a virtual TPM or a provisioning step: the+builder creates both keys from the templates ``attest`` uses+(:doc:`/reference/cli/attest`) and records their names. Figure 3 sets the+two side by side. Both end in the same pinned names, and ``verify``+checks evidence the same way after either.++.. figure:: /images/internals-attest-names.svg+ :alt: Credential activation: the target sends evidence, the operator+ makes a challenge for an endorsement key it vouches for, the TPM+ releases the credential only to that attestation key, and verify+ checks it once. Builder-recorded names: the builder creates both+ keys in the TPM before handover and records their names. Both+ paths end in the inventory every later verify pins.++ Figure 3. Two ways to learn the attestation key's name.++On the builder path the name is trusted because the builder saw the key+created, not because the TPM proved anything to the operator. The+builder, and for a virtual TPM its host, joins the trusted base, and the+endorsement key in the evidence is the target's word: no challenge ties+it to the attestation key. The two paths combine. An endorsement key+name the builder recorded can vouch for the endorsement key in+``attest challenge --ek-name``, in place of a certificate chain.+What verify and predict compute-------------------------------``shirudo attest verify`` and ``shirudo attest predict`` run on theoperator and touch no TPM. ``verify`` prints one line per check and a-verdict. It checks, in this order:+verdict. Figure 4 shows the four comparisons that tie what the target+wrote about itself to what the TPM signed or the operator computed.++.. figure:: /images/internals-attest-verify.svg+ :alt: The eventlog replay must equal the certified register value; the+ name computed from the init record must equal the certified name;+ pcr_before extended by the anchor digest must equal the quoted+ PCR 9; the init event must equal the one attest predict computes.++ Figure 4. What ``verify`` compares. Once the replay matches, the+ ``init`` record's fields are the ones the TPM measured.++It checks, in this order:#. the nonce;#. the attestation key: a restricted signing key with the requireddiff --git a/Documentation/operate/run/attest.rst b/Documentation/operate/run/attest.rstindex 0ff7ac1f..dde41564 100644--- a/Documentation/operate/run/attest.rst+++ b/Documentation/operate/run/attest.rst@@ -15,9 +15,21 @@ PCRs for a nonce you chose, and you check the signature and the valueson the operator host against what you installed.This page enrolls a target once, then collects and verifies evidence.-The checks only mean something when you pin the values the target-reports about itself, so the verification step lists the options you-must pass.+Enrollment records the names of the TPM's attestation key and+endorsement key, and there are two ways to trust them:++- `Enroll from a target activation`_: the target answers a credential+ challenge, which the TPM can only answer when the attestation key is in+ the TPM that holds an endorsement key you vouch for. Use it when the+ TPM has a manufacturer's endorsement certificate or you hold its+ endorsement key name.+- `Enroll from a builder's records`_: the hypervisor or provisioning step+ that created the TPM's keys records their names before handover, with+ no exchange with the target. Use it when you trust that builder.++Either way, every later verification pins those names. The checks only+mean something when you pin the values the target reports about itself,+so the verification step lists the options you must pass.Before you begin----------------@@ -90,12 +102,27 @@ document passes, as `A verify that pins nothing`_ shows.- Nothing was extended into PCR 9 after the register's anchor.Without it, verify notes further measurements and passes.-Enroll a target----------------+Enroll from a target activation+-------------------------------Enroll a target once per TPM. You record the name of its attestationkey and prove that the key sits in the same TPM as an endorsement key-you trust.+you trust. When a builder you trust created the TPM's keys, its records+can take the place of these steps (`Enroll from a builder's records`_).+Figure 1 shows the steps: two runs of ``attest``, each with its own+nonce, and a challenge in between.++.. figure:: /images/operate-attest-activation.svg+ :alt: The operator sends a nonce; the target has the TPM create the+ attestation key and the endorsement key and returns enroll.json.+ The operator makes a challenge for an endorsement key it vouches+ for and sends it with a second nonce. The TPM releases the+ credential only to that attestation key under that endorsement+ key, and the target returns answer.json. The operator verifies+ the credential and records both names in its inventory.++ Figure 1. Enrolling through credential activation. The TPM proves to+ the operator that the attestation key is in it.1. Choose a nonce on the operator host:@@ -165,6 +192,145 @@ you trust.7. Record ``<ak-name>`` and ``<ek-name>`` for this target in yourinventory. Every later verification pins them.+8. If you run the keepalive backend, mark the key as enrolled, so that+ the node reads ``enrolled`` rather than ``untrusted``+ (:doc:`/operate/integrations/backend`):++ .. code-block:: console++ operator$ clickhouse-client --query "INSERT INTO shirudo.nodes \+ (ak_name, trust) VALUES ('<ak-name>', 'enrolled')"++Enroll from a builder's records+-------------------------------++Credential activation lets you learn from the target that its+attestation key is in a TPM you trust. When a builder you trust controls+the TPM before the target gets it, such as the hypervisor that creates a+virtual TPM or a provisioning step before deployment, the builder can+record the names itself, and enrollment needs no challenge.++The builder then becomes part of what you trust, and for a virtual TPM+so does the host that runs it. The attestation key's name is trusted+because the builder saw the key created in that TPM, and the key is fixed+to it, so no other TPM can sign with it. Nothing in the evidence ties the+endorsement key to the attestation key on this path: ``--ek-name`` checks+only the endorsement key the target reports.++Figure 2 shows the path: the builder records the names once, before+handover, and every attestation after that is a nonce, the evidence and a+verify that pins them.++.. figure:: /images/operate-attest-builder.svg+ :alt: Before handover, the builder has the TPM create the attestation+ key and the endorsement key from attest's templates and gives+ their names to the operator's inventory. For every attestation,+ the operator sends a nonce, the target has the TPM create the+ same attestation key, quote the PCRs and certify the register+ with the nonce, and returns the evidence document, which the+ operator verifies with the recorded names. There is no+ credential challenge.++ Figure 2. Enrolling from a builder's records. The builder, not the+ TPM, vouches for the names.++The steps below are for a virtual TPM run by swtpm, before the guest's+first boot. They need swtpm and tpm2-tools on the builder host.+``<state-dir>`` is the directory that holds the guest's TPM state, the+one QEMU's or libvirt's swtpm will use.++1. Create the TPM state, unless the guest already has some:++ .. code-block:: console++ builder$ swtpm_setup --tpm2 --tpmstate <state-dir> --createek++2. Run swtpm on that state, with the guest stopped:++ .. code-block:: console++ builder$ swtpm socket --tpm2 --tpmstate dir=<state-dir> \+ --server type=tcp,port=2321 --ctrl type=tcp,port=2322 \+ --flags not-need-init,startup-clear --pid file=swtpm.pid --daemon+ builder$ export TPM2TOOLS_TCTI=swtpm:port=2321++3. Create the attestation key from the template ``attest`` uses, and save+ its public area:++ .. code-block:: console++ builder$ tpm2_createprimary -C e -g sha256 -G ecc256:ecdsa-sha256:null \+ -a 'fixedtpm|fixedparent|sensitivedataorigin|userwithauth|restricted|sign' \+ -c ak.ctx+ builder$ tpm2_readpublic -c ak.ctx -o ak.pub+ builder$ tpm2_flushcontext -t++4. Create the endorsement key from the TCG default template, and save its+ public area:++ .. code-block:: console++ builder$ tpm2_createek -c - -G ecc -u ek.pub++ The evidence carries the ECC endorsement key unless the TPM's only+ endorsement certificate is RSA; use ``-G rsa`` for such a TPM.++5. Compute the two names, ``000b`` and the SHA-256 of each public area:++ .. code-block:: console++ builder$ echo 000b$(tail -c +3 ak.pub | sha256sum | cut -c1-64)+ builder$ echo 000b$(tail -c +3 ek.pub | sha256sum | cut -c1-64)++ The first line is ``<ak-name>``, the second ``<ek-name>``.++6. Shut the TPM down in order and stop swtpm, which saves the state.+ swtpm releases ``<state-dir>`` only when its process exits, so wait+ for that before the guest's swtpm opens it, then start the guest:++ .. code-block:: console++ builder$ tpm2_shutdown+ builder$ pid=$(cat swtpm.pid)+ builder$ swtpm_ioctl --tcp :2322 -s+ builder$ while kill -0 "$pid" 2>/dev/null; do sleep 0.1; done++7. Record both names for this target in your inventory. Take them from+ the builder, never from the target.++8. If you run the keepalive backend, mark the key as enrolled. The row+ can go in before the target first boots; its first keepalive joins+ it:++ .. code-block:: console++ operator$ clickhouse-client --query "INSERT INTO shirudo.nodes \+ (ak_name, trust) VALUES ('<ak-name>', 'enrolled')"++9. Verify every evidence document with the recorded names, as+ `Verify evidence`_ shows. There is no credential to expect:++ .. code-block:: console++ operator$ shirudo attest verify --evidence=ev.json --nonce=<nonce> \+ --ak-name=<ak-name> --ek-name=<ek-name> \+ --expect-bind-pcr=9=<pcr9> --expect-bind-pcr=11=<pcr11> \+ --require-initrd --expect-chain=<register> \+ --expect-config-root=<config-root> --expect-config-pcr=<config-pcr>++For a physical TPM a provisioning step controls, skip steps 1, 2 and 6+and leave ``TPM2TOOLS_TCTI`` unset, so that tpm2-tools uses the TPM+device. The names are the TPM's own and stay with it.++A virtual TPM cloned with its state presents the original's keys, so give+each clone fresh state and record its own names. A migration that keeps+the state keeps the names, and ``TPM2_Clear`` changes neither.++A builder that records only the endorsement key's name still saves the+endorsement certificate check: pass that name as ``--ek-name`` in step 4+of `Enroll from a target activation`_, and the challenge proves that the+attestation key is in that TPM.+Predict the register--------------------diff --git a/Documentation/reference/cli/attest.rst b/Documentation/reference/cli/attest.rstindex 9fff8c9a..dccfb428 100644--- a/Documentation/reference/cli/attest.rst+++ b/Documentation/reference/cli/attest.rst@@ -50,6 +50,52 @@ hierarchy. With ``--challenge``, ``attest`` activates the credential theoperator made for that key and includes it, which proves that the keylives in the same TPM as the endorsement key (:doc:`attest-challenge`).+Both keys are primaries under the endorsement hierarchy, created from the+templates below, so one TPM always yields the same keys and names. A+builder that creates them from the same templates in the same TPM reads+the names the evidence will carry. The endorsement key is the ECC one,+or the RSA one when the TPM holds only an RSA endorsement certificate.++.. list-table::+ :header-rows: 1+ :widths: 20 36 44++ * - Field+ - Attestation key+ - Endorsement key+ * - Type+ - ECC+ - ECC, or RSA+ * - Name algorithm+ - SHA-256+ - SHA-256+ * - Attributes+ - ``0x00050072``: ``fixedTPM``, ``fixedParent``,+ ``sensitiveDataOrigin``, ``userWithAuth``, ``restricted``,+ ``sign``+ - ``0x000300B2``: ``fixedTPM``, ``fixedParent``,+ ``sensitiveDataOrigin``, ``adminWithPolicy``, ``restricted``,+ ``decrypt``+ * - Authorization policy+ - Empty+ - ``837197674484b3f81a90cc8d46a5d724fd52d76e06520b64f2a1da1b331469aa``,+ ``PolicySecret`` on the endorsement hierarchy+ * - Symmetric+ - Null+ - AES-128 in CFB mode+ * - Scheme+ - ECDSA with SHA-256+ - Null+ * - Key+ - NIST P-256, KDF null+ - NIST P-256, KDF null; or RSA-2048, exponent 0 (65537)+ * - ``unique``+ - Empty+ - 32 zero bytes each for x and y; 256 zero bytes for RSA++The endorsement key templates are the TCG EK Credential Profile's+default low-range templates, L-2 for ECC and L-1 for RSA.+Without ``--nonce``, ``attest`` warns that the evidence proves nofreshness.