Skip to main content
This tutorial uses V3 attestation, which is in beta. Inline configs also require config deployments to be enabled for your organization; contact support@tinfoil.sh to turn them on.
A Bunker runs an image that Tinfoil builds and publishes. To run your own image in an enclave instead, deploy it as a container from a config you write, then verify the result yourself: that the hardware attests to your image, and that the config it runs has the shape you expect. This tutorial does both from one Go program. It creates the container with the Admin API Go SDK and verifies it with the Tinfoil Go SDK.

Prerequisites

  • An admin API key with containers.create and containers.read, exported as TINFOIL_ADMIN_KEY.
  • Your image pinned by @sha256: digest. For a private image, set registry credentials first.
  • Go 1.27.4 or later.

Set up a module

Write the config

Save this as tinfoil-config.yml next to your program, with your image in place of the demo image:
tinfoil-config.yml
An inline config pins cvm-version to the SHA-256 of the runtime manifest, which you can compute yourself:
PUBLIC_KEY parameterizes the image with your public key; replace the demo key with your own. Anyone can run the same image digest with a different key, so the key in the config is what makes the container yours. include-config-in-attestation puts the config itself into the attestation so the client can read it. Without it, the config stays out of the attestation and a client can only check it against bytes it already holds. See the configuration reference for the other fields.

Deploy and verify

main.go
Run it:
The program does three things:
  1. Deploy. deploy sends the config inline (source: local) and polls the container until it is running. Tinfoil stores the config in its canonical JSON form, which is the form the enclave measures.
  2. Verify the attestation. tinfoil.NewEnclaveHTTPClient fetches a fresh attestation from the container’s domain and checks the hardware report, the runtime that cvm-version pins, and that the config in the attestation is the one that was measured. AuthorizedBy hands that config to your function instead of requiring a registry endorsement.
  3. Check the shape. requireShape rejects the enclave unless its config runs only your image, by digest, with your public key as its only environment variable and no administrator access through cvm_admin or direct admin SSH. The key must be a literal in env, not a name filled in at deploy time or a secret, since neither is in the attestation. Add checks for anything else you rely on, such as networks.
If any check fails, NewEnclaveHTTPClient returns an error and the program sends nothing. On success, enclave is an *http.Client whose requests reach only the verified enclave, and it verifies again when its verification expires.