-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
swtpm: Abstract NVRAM interface for pluggable state store #490
Conversation
Pull Request Test Coverage Report for Build 3357
💛 - Coveralls |
It definitely looks manageable.
(sorry, didn't mean to close it. got on wrong button) |
Thanks for the comment. I'll add entries in man pages and an extension to |
e441c70
to
cb8a82b
Compare
tests/test_commandline
Outdated
PID=$! | ||
|
||
if wait_port_open $PORT $PID 4; then | ||
echo "Test 1 failed: TPM did not open port $PORT" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Test 4' ... here and below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, thanks.
src/swtpm/common.c
Outdated
} | ||
} else { | ||
logprintf(STDERR_FILENO, | ||
"The file parameter is required for the tpmstate option.\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not the file parameter but the directory or backend+backenduri parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll fix the error message.
Can you please also rebase this on the latest master? |
cb8a82b
to
567d01a
Compare
Sure, rebased. |
tests/test_commandline
Outdated
|
||
${SWTPM_BIOS} &>/dev/null | ||
if [ $? -ne 0 ]; then | ||
echo "Test 4 failed: tpm_bios did not work" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tpm_bios -> swtpm_bios
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or rather ${SWTPM_BIOS}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll fix that and also "Test 1" as well.
567d01a
to
b1c7ede
Compare
src/swtpm/swtpm_nvstore_file.c
Outdated
|
||
state_directory/tpm_number.name | ||
|
||
A temporary filename used to write to may be created. It shold be rename()'d to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shold -> should
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
man/man8/swtpm.pod
Outdated
@@ -317,6 +323,10 @@ The I<--key> option supports the I<fd=> parameter. | |||
|
|||
The I<--key> option supports the I<pwdfd=> parameter. | |||
|
|||
=item B<nvram-backend-file> | |||
|
|||
The I<--tpmstate> option supports the I<backend=file> option. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... supports the I<backend=file> and I<backend_uri=uri> parameters.
I hope that everything that's needed by the backends can be encoded into the backend_uri parameter...
Looks good to me now. We'll need similar extensions for the swtpm_setup tool as well to choose the backend ... |
b1c7ede
to
6593d61
Compare
Yes, we need similar extensions in swtpm_setup as well. Implementing the extension as it is (i.e. adding abstraction layer to swtpm_setup) may not be a good idea because it will bring a lot of copy-and-paste codes or we have to libraries common codes. Instead, let me propose another approach.
For 1. we can use temporal directory (using mkdtemp(3)) or a directory specified by user using new For 2. we can introduce new CMD to communicate with swtpm for example CMD_HAS_STATE for check_state_overwride(). Another idea is to introduce If we go this way, we can also reduce the swtpm_setup dependencies on swtpm implementation details (TPM state file names). Any comments are appreciated. |
Now that you introduce a URI, I a wondering whether we should work with URIs like the iscsi:// you showed and now we would use a URI file:// or actually as mentioned in PR #513 maybe this should be the directory backend, rather than file, with a dir:// URI since this will want to own the whole directory due to the lock. Just to be consistent. |
Thanks, I like that idea. Will update this PR. |
That should then obsolete the
This assumes of course that every type of backend can be expressed via a URI, but as far as the current backend and the iscsi backends are concerned that should be sufficient. |
@Etsukata You will have to rebase this branch again. Also, if we don't end up merging it by Friday it will likely have to wait another 2 weeks or so since I will be out for a while. |
6593d61
to
34011a8
Compare
Hi @stefanberger, thanks for the notice. |
man/man8/swtpm.pod
Outdated
@@ -150,14 +150,18 @@ The following options are support by all interfaces: | |||
|
|||
=over 4 | |||
|
|||
=item B<--tpmstate dir=E<lt>dirE<gt>[,mode=E<lt>0...E<gt>]> | |||
=item B<--tpmstate dir=E<lt>dirE<gt>[,mode=E<lt>0...E<gt>]|backend_uri=E<lt>uriE<gt>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully last change. Please change this to backend-uri
to be consistent with other option parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The help screens in swtpm.c, swtpm_chardev.c, and cuse_tpm also need to be extended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll update them.
man/man8/swtpm.pod
Outdated
The default value is 0640. | ||
|
||
If I<backend_uri> is specified, the TPM state data will be stored to the URI. | ||
Currently I<backend_uri=dir://<path_to_dir>> is the only one available. In this case, | ||
URI should specify the path to the directory where files are stored. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I<path_to_dir> starts with a '/' then the path is interpreted as an absolute path, otherwise it is a path relative to the current directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I will append the sentence to the man pod.
34011a8
to
2de9980
Compare
@Etsukata I think it's ready to be merged... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks much for this, looks good to me.
Related GH issue: stefanberger#461 This patch adds an abstraction layer to NVRAM state store implementation for pluggable storage backends. No functional changes are intended in this change. The default state store backend ("dir backend") keeps current behavior. To make swtpm ready for pluggable store, this patch moves file related operations to the seperate file (swtpm_nvstore_dir.c) and defined the interface for plugins (nvram_backend_ops in swtpm_nvstore.h). The interface can be used by each plugin which will be added later. With the interface, each plugin can access its "backend_uri" which points to the location of the backend storage, for example S3 bucket URL or iSCSI URL, and decide how it stores TPM state data. Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
Add an options to specify pluggable backend URI. Ex: --tpmstate backend-uri=dir://<path_to_dir> Backend URI is specific to each backend plugin which points to the location of the NVRAM files. Currently, "dir" is the only one available backend. In this case backend-uri should be a path to the directory where files are stored. This option is designed to compatible with existing "dir" option. If "dir" is specified, swtpm prioritize "dir" ignoring "backend-uri". Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
Append "nvram-backend-dir" to --print-capabilities output. Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2de9980
to
628b862
Compare
Hi @stefanberger, thanks for the comment.
|
For swtpm_setup, I'll create several PRs separately. I appreciate if you could take a look at them once you get back, thanks. |
Looks good to me @Etsukata. |
Related GH issue: #461
This is RFC PR to add an abstraction layer to NVRAM state store
implementation for pluggable storage backends. No functional changes are
intended in this change. The default state store backend ("file backend")
keeps current behavior.
To make swtpm ready for pluggable store, this patch moves file related
operations to the separate file (swtpm_nvstore_file.c) and defined the
interface for plugins (nvram_backend_ops in swtpm_nvstore.h). The
interface can be used by each plugin which will be added later.
With the interface, each plugin can access its "backend_uri" which
points to the location of the backend storage, for example S3 bucket
URL or iSCSI URL, and decide how it stores TPM state data.
The second commit adds two options to specify pluggable backend type and
backend URI.
Ex:
--tpmstate backend=...,backend_uri=...
Backend URI is specific to each backend plugin which points to the
location of the NVRAM files.
Currently, "file" is the only one available backend. In this case
backend_uri should be a path to the directory where files are stored.
This option is designed to compatible with existing "dir" option.
If "dir" is specified, swtpm prioritize "dir" ignoring "backend".