-
Notifications
You must be signed in to change notification settings - Fork 45
Description
What is missing in SGX signing flows, what is needed for "plugins/templates" in GSC?
The context are these PRs and discussions:
- RFC: Add sgx-sign plugins gramine#1118
- Rewrite SGX signing in cryptography.io gramine#1197
- Enable
--templateoption to use withsign-image(for use with HSMs, for example) #112 - Change positional args
manifestandkeyto optional args #118 - Add SGX enclave signing with OpenSSL engine contrib#19
- Add AKV Dockerfile templates for signing with gsc contrib#20
Woju's opinion
[the text is combined from Woju's messages in the chat]
The missing part is to fix Intel's idea about how to extend the signing Dockerfile with custom snippets.
The signing plugins (PR 1118 proper) are more or less ready, but they're only part of the solution. In real life you might need to install some dependencies (which are not necessarily packaged as pip/python packages) and even run random commands (like login/logout to HSM API, cf. azure example, PR #20). And it's not clear to me how this should be done to be both elastic enough to cater to real-world use cases and rigid enough to prevent users shooting themselves in the feet. What's clear to me is that the original proposal in #112 is a footgun; I've talked about this in the meeting and written in the thread of #112.
So this probably needs a rethink, how GSC's jinja templates are organised (directory hierarchy in templates/ and filenames) to enable template inheritance that would be conductive to overriding relevant parts while still relatively strict to keep the necessary parts like the FROM device which drops the private key, see:
gsc/templates/Dockerfile.common.sign.template
Lines 14 to 16 in 77b1f70
| # This trick removes all temporary files from the previous commands (including gsc-signer-key.pem | |
| # and passphrase) | |
| FROM {{image}} |
#1118 is also relevant to one other PR in GSC (#118) that makes the --key argument optional-but-not-really.
It's true that this argument is flow-specific, i.e. applicable only to the single signing schema, with private key. This also needs to be re-thought and reworked.
So the parsing of arguments to GSC signing command is either plugin-specific or some other way. There's a question of packaging: can we package #1118 plugins and GSC plugins together? It would be convenient to do so, and while devising the proper plugin API we need at least to think about how to do it. Like another python's entrypoint that would return something? Another directory with overriding templates? Some way of parsing cli arguments?
One way of doing general parsing of cli arguments was discussed in one of the calls, and could be a generic -D, --define key=value argument very similar to gramine-manifest. That would dispense of general CLI parsing in GSC plugins, but there still will be need for templates/ overrides. This can be done relatively easy, because Jinja supports multiple template loaders and loads just the first found template, so we can insert this other template directory before the default.
Also, #1118 signing plugins will be general, while GSC problems with stuff in templates and inserting custom commands right in the middle of arbitrary dockerfiles are more-or-less GSC-specific. So I don't mind a GSC-only solution to such GSC-only problems.
So my idea how to do it: add --template-dir (or sth like that, the exact name TBD) instead of --template like proposed in #112. This is because Jinja likes loaders more than one-off templates. Somewhere in the comments in those PR's reviews is a snippet of how I would reconfigure jinja loaders when encountering this option to make it possible to inherit from template that's named the same. Then, rewrite relevant templates with {% block %}s to allow replacing respective sections and/or appending to them. This way we'll have option to later package this as python/pip packages, by adding entrypoint which will return a path to directory with templates, this directory being shipped as part of the plugin python package. Possibly even the same package as signing plugin.
As a side effect, this will expose GSC template names and block names as public APIs (plugin writers will need to override specific, named templates, and specific, named blocks inside those templates). Therefore this is a good opportunity to rewrite template names, move them between directories, etc.
Last point: #1118 is probably mergable as-is, possibly ironing out orthography in documentation. If you need to validate is against something, https://github.com/woju/gramine-sgx-otk is written to use this template API
https://github.com/woju/gramine-sgx-otk/blob/6f75511ca8e9ca1e2c39c9dd5ff73d97cf298b49/setup.py#L16.
What to do about all this?
- Come up with a design and a plan to incorporate all of the above.