gRPC Server Inside an Asylo Enclave

gRPC Server Inside an Asylo Enclave

09 October 2020

Let’s start with the introduction of gRPC, Enclave, Asylo…

gRPC

You must have heard about Remote Procedure Call (RPC). It is a request-response protocol.

gRPC is a one kind of RPC which is a free and open-source framework developed by Google. It allows you to define Request and Response for RPC (Remote Procedure Call).

gRPC server is modern, fast and efficient, built on top of HTTP/2, low latency, supports streaming, language-independent and makes authentication, load balancing, logging and monitoring super easy to plug into.

gRPC_Server_inside_Asylo_Enclave_01

An enclave

On traditional systems, the Operating System (OS) kernel has unlimited access to a machine’s hardware resources. OS kernel exposes most of its access permissions to a root user without any restrictions. As a result, if the hacker can execute code with root privileges, they can compromise every secret and bypass every security policy on the machine. For example, if the hacker obtaining root access on a machine that manages TLS keys, those keys may be compromised.

Enclaves are an emerging technology that changes this equation. An enclave is a special execution context in which code can run shielded from even the OS kernel, with the assurance that even a root privileged user can not extract the secrets of the enclave or undermine its integrity. This security is allowed by hardware-isolation technologies such as Intel SGX or ARM TrustZone, or even by additional software layers such as a hypervisor.

gRPC_Server_inside_Asylo_Enclave_02

Asylo

Asylo is an open source platform for developing enclave applications. It specifies an abstract model of the enclave that can be transparently mapped onto a variety of enclave technologies (i.e., enclave backends). Asylo provides a platform for software development that serves a growing variety of use cases. In a way, the backend of the enclave can be seen as a special purpose built-in computer running inside a traditional machine, with Asylo providing the necessary runtime for that embedded computer.

gRPC_Server_inside_Asylo_Enclave_03

Running gRPC Server Inside an Enclave

Let’s start our main objective of this blog i.e. running gRPC server inside an Enclave. This section explains how to run a gRPC server within an enclave and how to communicate with it from a client running in an untrusted environment.

The runtime of the Asylo enclave features rich POSIX support which allows full-featured gRPC servers to run within an enclave. Enclaves can then act as secure nodes in your cloud and distributed network.

You can use the Asylo Docker image and run the bazel commands below inside an interactive Docker terminal.

Defining the gRPC service:

Lets implement a simple translation service inside an enclave.

This is a simple example for request and response of a word to be translated.

gRPC_Server_inside_Asylo_Enclave_04

Setting up a server enclave:

To set up the server, the enclave must know the desired server address and the server must wait for the appropriate amount of time before shutting down the server. You can pass this information through the Initialize method which accepts an EnclaveConfig.

gRPC_Server_inside_Asylo_Enclave_05

This example maps the logic of configuring gRPC server to TrustedApplication’s virtual methods as follows:

  • The Initialize method constructs and launches the server using the information from the EnclaveConfig.
  • The Run method writes the server’s final port to an EnclaveOutput message extension, and returns an OK status. All our interaction with the enclave goes through gRPC, so Run doesn’t need to do any other work.
  • And the Finalize method shuts down the gRPC server.

Initializing the server:

To configure and start the server the Initialize method uses grpc::ServerBuilder. The server setup requires the server_address extension from the EnclaveConfig and the service member described above. The Initialize process logic ensures the server is initialized and started just once.

If the EnclaveConfig does not have an extension to server_address, or if the server does not start, then Initialize returns a non-OK status. Else, Initialize returns an OK Status:

gRPC_Server_inside_Asylo_Enclave_06

Running the server:

The Run method returns an OK status and an EnclaveOutput containing the gRPC server allocated port:

gRPC_Server_inside_Asylo_Enclave_07

Finalizing the server:

The Finalize approach shuts down the server for all remaining RPCs, with a 500 millisecond timeout. Finalize also tells the user that it is shutting down the server:

gRPC_Server_inside_Asylo_Enclave_08

gRPC_Server_inside_Asylo_Enclave_09

Request a quote