36 Commits

Author SHA1 Message Date
Dmitrii Kuvaiskii 31f08ab11c [GSC] Always use absolute paths inside the Docker container
Previously, some GSC templates and scripts that execute inside Docker
containers contained relative file paths. This led to failures if
a base Docker image contained WORKDIR different from root (`/`),
since all GSC scripts put Graphene-related files under root dir.

Signed-off-by: Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
2021-02-15 22:44:36 -08:00
Dmitrii Kuvaiskii 0a4d5ce0e5 [GSC] Refactor GSC and make it work again
Commit "Introduce one, central manifest, zero-config children and
constant MRENCLAVE" broke GSC. This commit fixes GSC (mainly adjusts
it the single-manifest change in that commit). Also, significant
internal refactoring is done (no user-visible changes). Also, scripts
now explicitly use UTF-8 when reading/writing the manifest files because
they are written in TOML which forces UTF-8.
2021-02-03 23:10:29 -08:00
Paweł Marczewski 17ab04db59 [Pal,LibOS] New logging system
Instead of 'loader.debug_type', introduce 'loader.log_level'
and 'loader.log_file', along with a set of definitions for
logging at a chosen level.

For now, the call sites keep using the legacy macros (SGX_DBG and
debug()), because converting them all will conflict with other
big changes in the code base. The existing LibOS calls are
assumed to be at 'info' level.
2021-01-20 17:27:29 +01:00
Michał Kowalczyk 3d31f2d18d Introduce one, central manifest, zero-config children and constant MRENCLAVE
This is the next part of the great loader rework, with a lot of breaking changes:

- Complete removal of the "trusted children" thing - now children
  processes can be spawned arbitrarily and from arbitrary mountpoint
  types, without any additional configuration needed.

- There's a new, required option in the manifest: `libos.entrypoint` - it
  specifies the URI to the entry binary in the first process. There's no
  need anymore to name the manifest and the first binary identically.

- On SGX, the main binary is not measured in MRENCLAVE anymore - only
  PAL, LibOS and the manifest are measured. This is enough to bind
  MRENCLAVE to a specific entrypoint user executable if wanted - it
  just has to be mounted as a trusted file.

- All Graphene SGX enclaves have now exactly the same MRENCLAVE. This is
  a hash of a "Graphene stub", which can "fork" into one of two states
  in runtime: initial process or child. The initial process creates a
  new "Graphene namespace" with a clean state, it can also be attested
  remotely (contrary to child processes). The initial process can spawn
  children processes by spawning a Graphene stub and directing it to
  start in the child mode. It then attests it locally, and if
  successful, establishes an encrypted pipe, "connects" to its own
  namespace and treats as trusted (including sending protected files
  key).

- Now, there's only one, central manifest describing the initial state
  of a Graphene instance which can be spawned from it (previously, each
  process required a separate manifest which could have different
  configuration - which wasn't actually supported and didn't make sense
  design-wise). One downside of central manifests is that all processes
  require the same enclave configuration (e.g. size), but that was
  already the case so far because of broken checkpointing code. Also,
  this is only a temporary problem, which will cease to exist after the
  introduction of EDMM.

- `sgx.static_address` was renamed to `sgx.nonpie_binary` and now has to
  be inserted manually by users (`sgx_sign` tools doesn't know about the
  binaries run inside, which can be even provided or generated in
  runtime by the user's workload).

- Caveat: the memory gap for non-PIE executables was removed because it
  requires adding a new option to the manifest to be cleanly
  implemented. This is left for some future loader rework PR.
2021-01-12 19:53:24 +01:00
Wojtek Porczyk 28e6c6e442 [GSC] Fix reliance on sgx-driver 2020-12-23 14:30:25 +01:00
Michał Kowalczyk d53729b201 [Pal] Rework manifest loading
This is a major refactor of the way manifests are loaded and handled,
which will be followed by a complete rework of the loader code (which
will include e.g. centralized config).

Changes/fixes:
- Huge part of manifest handling was refactored and untangled.
- Starting without a manifest is now disallowed. This was actually
  accidentally broken for some time and no one complained. It also makes
  little sense in practice and in Graphene's overall design, e.g. it
  conflicts with protected argv.
- Now we only allow starting by giving the executable, not manifest (the
  magic resolution logic was removed).
- Now manifests are sent over pipes between parent and children, instead
  of children finding and loading them on their own. This is a
  preparation for the upcoming centralized manifests change.
- Previously manifests were parsed 2 times on Linux and 3 times on
  Linux-SGX (by untrusted PAL, trusted PAL and LibOS). This is now
  fixed.
- The common `pal_main()` now requires that the backend-specific PAL
  loader loads the manifest before calling it. SGX code already has to
  do it (for proper initialization), so let's unify this interface for
  all PALs.
- Fix for a PAL crash when manifest size was divisible by page size
  (sic!). NULL termination was missing, but most of the time the padding
  to page size saved Graphene from crashing.
2020-12-05 01:46:03 +01:00
Anjo Vahldiek-Oberwagner 633cc239a2 [python] Fix GSC after python packaging 2020-11-27 16:55:06 +01:00
Paweł Marczewski 1d25612006 [CI] Enable pylint unconditionally, fix violations
Pylint output was filtered so that many files with existing pylint
violations were allowed to stay broken.

I made sure all files pass pylint, but whitelisted some rules that
we commonly disable:

* missing docstrings: most of the code is tests/internal anyway
* invalid-name: too many violations, and we commonly use one- or
  two-character names (like "a, b" or "t1, t2") which is
  disallowed by this rule; we could tweak it and then fix
  remaining violations such as camel-case or lowercase constants
* fixme: we leave TODOs as a matter of practice, same as in C
* high-level style rules like too-few-* and too-many-*,
  no-self-use

Hopefully that will make using pylint less annoying, while also
catching serious issues (such as unused variables or imports).
2020-11-17 13:45:09 -08:00
Dmitrii Kuvaiskii 8eee4a4742 [LibOS,Pal,Examples,GSC,Docs] Move manifest parsing to TOML
The manifest syntax stays exactly the same, including 0 and 1
integers to denote boolean values (this is done for ease of porting
and can be fixed in future commits). The only visible change is
surrounding strings in the manifest with quotes (requirement of
TOML). All manifests and Makefiles of our tests and example apps are
ported to the new TOML syntax. Documentation is updated.
2020-11-12 05:45:07 -08:00
Anjo Vahldiek-Oberwagner 56e6928deb [GSC] Fix test makefile to correctly use configuration file 2020-11-01 20:44:25 +01:00
Michał Kowalczyk e587869e13 [LibOS+Pal] manifest: Remove support for loader.exec and sgx.sigfile
Supporting these options complicates the design of Graphene and loading
logic significantly, providing little useful functionality:
- loader.exec:
    - the main user of it were our tests
    - worked only for the first process spawned inside Graphene, as it
      was a unidirectional manifest->binary mapping, so the child
      process didn't know about the corresponding manifest.
- sgx.sigfile:
    - probably all existing usages of it were completely redundant
    - was resolved relatively to CWD instead of the executable location,
      which made it mostly useless

From now on, the correct location of the files is:
- either place the manifest and sigfile next to the binary, with a
  matching name, or
- create a symlink to the binary in the folder where manifests are
  stored and launch it through this symlink
2020-10-23 00:06:46 +02:00
Michał Kowalczyk 47b130bc9a [GSC] Fix a bug in apploader's arguments testing 2020-10-22 17:46:28 +02:00
Dmitrii Kuvaiskii 3bcab01a0c [Pal/Linux-SGX] Remove "sgx.allow_file_creation" and always allow it
The manifest option "sgx.allow_file_creation" is useless (most
real-world apps will set it to "1" anyway). So this commit simply
removes this option and always allows to create files.
2020-10-06 00:20:22 -07:00
Anjo Vahldiek-Oberwagner 0432c1794a [GSC] Fix argument extraction from Docker image 2020-09-24 18:31:50 +02:00
Anjo Vahldiek-Oberwagner 81a18d6c8a [GSC] Fix LD_LIBRARY_PATH generation 2020-09-24 15:06:13 +02:00
Anjo Vahldiek-Oberwagner 1cbdf3225a [GSC] Add prebuilt image and documentation for AKS 2020-09-22 14:14:31 +02:00
Michał Kowalczyk fd15780628 [Pal] Rewrite GDB integration, part 1
For now only gdb-script and Python parts. This is mostly a clean-up of
both Linux and Linux-SGX integration which additionally removes some
annoying user prompts we had in the old scripts.
2020-09-22 00:47:46 +02:00
Anjo Vahldiek-Oberwagner 34b8eb1ec2 [GSC] Add an option to pre-build Graphene-only image
Previous iterations of GSC always built the Graphene runtime as part of
the `gsc build` command. This commit adds an option to extract the
compilation of the Graphene runtime from the GSC build command into a
separate command called `gsc build-graphene`. Using `gsc build-graphene`,
one can prepare a Docker image that includes the required runtime files
for a `gsc build` command.

The purpose of this separation is to publish Graphene Docker images for
special environments such as cloud environments. This simplifies the
configuration parameters for the user, since they only have to specify
the Graphene Docker image name instead of the Graphene repository and
Driver details.
2020-09-10 01:40:13 +02:00
Dmitrii Kuvaiskii ba6cd957bf [GSC] Exclude /graphene/signer/* from generated list of trusted files 2020-09-01 18:42:26 +00:00
Anjo Vahldiek-Oberwagner 67c23d74cf [GSC] Test GSC using Linux PAL and add a test for trusted arguments 2020-08-30 11:27:04 +02:00
Lu Ken 54bc4985bf [GSC] Support build-time variables via --build-arg
When building graphenized Docker image, some build-time variables
like http_proxy, https_proxy, no_proxy must be specified (for
private network behind proxy). This commit adds `--build-arg` via
GSC_BUILD_FLAGS.
2020-08-27 15:35:51 +00:00
Anjo Vahldiek-Oberwagner dec3cb85d8 [GSC] Rename loader.execname manifest option to loader.arg0_override 2020-08-10 20:13:42 -07:00
borysp 0f7a4e3fe5 Remove hardcoded paths to internal files
Graphene had some paths to internal files generated at compile time and
hardcoded into the output binary, which disallowed e.g. moving the
Graphene directory after compilation.
2020-08-03 20:19:28 +02:00
Michał Kowalczyk 049c79a4f1 [GSC] Fix build template to work with relative symlinks in Runtime/ 2020-07-31 22:09:32 +02:00
Michał Kowalczyk 5a765c0533 [GSC] Fix test Makefile to correctly set Graphene branch 2020-07-31 22:09:32 +02:00
Anjo Vahldiek-Oberwagner ac3dc5d6c2 [GSC] Change print behavior of tests to print intermediate results 2020-07-28 18:37:55 +00:00
Anjo Vahldiek-Oberwagner f51aafddf3 Graphene Shielded Containers v1 2020-07-08 10:51:09 -07:00
Michał Kowalczyk 7e3d9ac87e [Pal] Protect argv from untrusted world 2020-06-16 03:18:47 +02:00
Wojtek Porczyk c523740853 Remove GSC
This is unused, untested and in bad shape.
2020-01-14 02:20:56 +01:00
Jia Zhang 16ad03a94e [Tools] gsce: Use the last portion of the parsed app_name
A canonical image repo looks like "foo.com/hello-world:0.1". Thus the parsed
app_name should be the last portion of this string ("hello-world:0.1").
2019-09-12 11:34:31 -07:00
Li Lei 030a088892 [Tools] Multiple bug fixes of Graphene Secure Container (GSC) tool
- Forward container's LD_LIBRARY_PATH to the generated manifest
- Handle special library names when generating trusted files (libxxx-xxx.so)
- Add more standard files/directories to the generated manifest
2019-08-15 18:12:31 -07:00
Kush Garg 536f6a1e90 [Docs] Update GSC readme 2019-07-21 03:59:06 +02:00
Michał Kowalczyk 2bc2c04194 Remove trailing blanks 2019-05-07 16:32:16 +02:00
Zhang Chen 1c78c43c92 Tools/gsce: Clean up and optimize the integration of docker container and graphene-SGX
The dockerfile instruction RUN will create new layers
when it is executed, original codes will increase the size of
the final image and causes potential cache issues.
So we need to employ shell tricks to keep the layers as small as possible.

The detail:
https://docs.docker.com/v17.09/engine/userguide/eng-image/dockerfile_best-practices

Signed-off-by: Zhang Chen <chen.zhang@intel.com>
2019-02-26 13:19:53 -05:00
Michał Kowalczyk c9eb1d84e1 Fix Bash shebangs compatibility 2019-02-05 17:59:25 +01:00
Li Lei 2a98391d7b Graphene-SGX Secure Container: Seamless Integration of Docker Container and Graphene-SGX (#177)
* Adding scripts for building and running GSC (Graphene-SGX Secure Container)
* Describing GSC usage in Tools/README
2018-06-12 15:50:57 -07:00