Skip to content

Commit f0885e0

Browse files
committed
Add additional vTPM fields to the config to be able to run runtime in the container
Signed-off-by: Efim Verzakov <efimverzakov@gmail.com>
1 parent 151a011 commit f0885e0

File tree

5 files changed

+45
-10
lines changed

5 files changed

+45
-10
lines changed

config-linux.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,13 +592,19 @@ The following parameters can be specified to set up the controller:
592592
Each entry has the following structure:
593593

594594
* **`statePath`** *(string, REQUIRED)* - Unique path where vTPM writes its state into.
595-
* **`statePathIsManaged`** *(string, OPTIONAL)* - Whether runc is allowed to delete the TPM's state path upon destroying the TPM, defaults to false.
596-
* **`vtpmVersion`** *(string, OPTIONAL)* - The version of TPM to emulate, either 1.2 or 2, defaults to 1.2.
595+
* **`statePathIsManaged`** *(boolean, OPTIONAL)* - Whether runtime is not allowed to delete the TPM's state path upon destroying the TPM, e.g. if we do not want to recreate vTPM with the previous state. Defaults to false.
596+
* **`vtpmVersion`** *(string, OPTIONAL)* - The version of TPM to emulate, either 1.2 or 2, defaults to 2.
597597
* **`createCerts`** *(boolean, OPTIONAL)* - If true then create certificates for the vTPM, defaults to false.
598-
* **`runAs`** *(string, OPTIONAL)* - Under which user to run the vTPM, e.g. 'tss'.
598+
* **`runAs`** *(string, OPTIONAL)* - Under which user to run the vTPM, e.g. 'tss'.
599599
* **`pcrBanks`** *(string, OPTIONAL)* - Comma-separated list of PCR banks to activate, default depends on `swtpm`.
600600
* **`encryptionPassword`** *(string, OPTIONAL)* - Write state encrypted with a key derived from the password, defaults to not encrypted.
601+
* **`vtpmName`** *(string, REQUIRED)* - The name of vTPM device to emulate in the container. The devpath will have the format `/dev/tpm` + `vtpmName`. `vtpmName` should be unique among the container's `vtpms` devices.
601602

603+
Note that some runtimes can use different commands to pass device in the container (e.g. bind if the container will be running in the non-default user namespace and mknod otherwise). Runtime can adopt a device path to the format `/dev/generated-host-path` + `vtpmName`. This can be essential if we want to create different containers with non-shared VTPM devices under the same device path.
604+
* **`vtpmMajor`** *(int64, OPTIONAL) - The major of vTPM device to emulate in the container. This is required when runtime is running in the container and tmpfs is mounted on `/dev` path.
605+
* **`vtpmMinor`** *(int64, OPTIONAL) - The minor of vTPM device to emulate in the container. This is required when runtime is running in the container and tmpfs is mounted on `/dev` path.
606+
607+
Note that a vTPM device should be precreated with Endorsement Key Pair. Another main commands e.g. TakeOwnership for TPM 1.2 can be called in the createContainer hooks.
602608
#### Example
603609

604610
```json
@@ -610,7 +616,10 @@ Each entry has the following structure:
610616
"createCerts": false,
611617
"runAs": "tss",
612618
"pcrBanks": "sha1,sha512",
613-
"encryptionPassword": "mysecret"
619+
"encryptionPassword": "mysecret",
620+
"vtpmName": "tpm0",
621+
"vtpmMajor": 100,
622+
"vtpmMinor": 1
614623
}
615624
]
616625
```

config.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,10 @@ Here is a full example `config.json` for reference.
10831083
"vtpmVersion": "2",
10841084
"createCerts": false,
10851085
"runAs": "tss",
1086-
"pcrBanks": "sha1,sha512"
1086+
"pcrBanks": "sha1,sha512",
1087+
"vtpmName": "tpm0",
1088+
"vtpmMajor": 100,
1089+
"vtpmMinor": 1
10871090
}
10881091
]
10891092
},

schema/defs-linux.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,20 @@
280280
},
281281
"encryptionPassword": {
282282
"type": "string"
283+
},
284+
"vtpmName": {
285+
"type": "string"
286+
},
287+
"vtpmMajor": {
288+
"$ref": "#/definitions/Major"
289+
},
290+
"vtpmMinor": {
291+
"$ref": "#/definitions/Minor"
283292
}
284293
},
285294
"required": [
286-
"statePath"
295+
"statePath",
296+
"vtpmName"
287297
]
288298
},
289299
"DeviceCgroup": {

schema/test/config/good/spec-example.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,11 @@
352352
"vtpmVersion": "2",
353353
"createCerts": false,
354354
"runAs": "tss",
355-
"pcrBanks": "sha1,sha512"
355+
"pcrBanks": "sha1,sha512",
356+
"encryptionPassword": "mysecret",
357+
"vtpmName": "tpm0",
358+
"vtpmMajor": 100,
359+
"vtpmMinor": 1
356360
},
357361
{
358362
"statePath": "/var/lib/runc/myvtpm2",
@@ -361,7 +365,10 @@
361365
"createCerts": true,
362366
"runAs": "root",
363367
"pcrBanks": "sha1,sha512",
364-
"encryptionPassword": "mysecret"
368+
"encryptionPassword": "mysecret",
369+
"vtpmName": "tpm1",
370+
"vtpmMajor": 101,
371+
"vtpmMinor": 1
365372
}
366373
]
367374
},

specs-go/config.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ type LinuxVTPM struct {
460460
// Whether runc is allowed to delete the 'Statepath' once the TPM is destroyed
461461
StatePathIsManaged bool `json:"statePathIsManaged,omitempty"`
462462
// Version of the TPM that is emulated
463-
TPMVersion string `json:"vtpmVersion,omitempty"`
463+
VTPMVersion string `json:"vtpmVersion,omitempty"`
464464
// Whether to create certificates upon first start of vTPM
465465
CreateCertificates bool `json:"createCerts,omitempty"`
466466
// The PCR banks to enable
@@ -469,6 +469,12 @@ type LinuxVTPM struct {
469469
RunAs string `json:"runAs,omitempty"`
470470
// The password to derive the encryption key from
471471
EncryptionPassword string `json:"encryptionPassword,omitempty"`
472+
// Name of the vtpm
473+
VTPMName string `json:"vtpmName,omitempty"`
474+
// Device's major to be created
475+
VTPMMajor int64 `json:"vtpmMajor,omitempty"`
476+
// Device's minor to be created
477+
VTPMMinor int64 `json:"vtpmMinor,omitempty"`
472478
}
473479

474480
// LinuxResources has container runtime resource constraints
@@ -493,7 +499,7 @@ type LinuxResources struct {
493499
Rdma map[string]LinuxRdma `json:"rdma,omitempty"`
494500
// Unified resources.
495501
Unified map[string]string `json:"unified,omitempty"`
496-
// VTPM configuration
502+
// Linux VTPM configuration
497503
VTPMs []LinuxVTPM `json:"vtpms,omitempty"`
498504
}
499505

0 commit comments

Comments
 (0)