Secure enclaves
How to protect code and data even from whoever controls the machine.
The problem
Normally, whoever runs the computer sees everything. The operating system can read the memory of any process, the hypervisor can read the memory of any virtual machine, and whoever administers the server (or the cloud) can read all of it together.
That is a problem when you want to process something sensitive, such as a private key, medical data or another company's model, on a machine that is not yours or that you do not fully trust.
Who you trust
The enclave flips the trust stack. Instead of trusting every software layer below your program, you trust only the processor and the code inside the enclave. This minimal set of trusted things is called the TCB (Trusted Computing Base).
The four pieces
1. Memory isolation
The processor reserves a memory region for the enclave and blocks any access coming from outside it, including from the kernel. If the operating system tries to read those addresses, it gets garbage or an error.
This isolation comes in different sizes. Some technologies protect only a piece of a process; others protect a whole virtual machine:
2. Encrypted memory
Inside the processor the data is in plaintext, because that is where the code works on it. When it leaves the chip for RAM, an encryption engine encrypts everything automatically with a key that never leaves the processor. On the way back, it decrypts. So even someone with physical access to the memory sticks sees only scrambled bytes.
3. Remote attestation
How do you know the code running in there is really what you expect, and that it is in a real enclave and not a simulator? The processor computes a hash (the measurement) of the code loaded into the enclave and signs it with a key that only a genuine chip has. You check the signature, compare the hash with the code you audited, and only then send your secrets.
4. Sealing
The enclave needs to keep things across reboots, but the disk is controlled by the operating system. The solution is to encrypt the data with a key derived from two ingredients: a secret key burned into the chip and the measurement of the enclave itself.
The life of an enclave
- Create. The application asks the processor for a protected memory region.
- Load and measure. The enclave code is copied in, page by page, and the processor keeps hashing everything that goes in.
- Initialize. The measurement is frozen. From here on nobody outside can change the code.
- Attest. Whoever needs to trust the enclave asks for the signed report and checks the measurement.
- Run. The application calls enclave functions, which process the secrets inside.
- Destroy. The processor wipes the region. Only what was sealed survives.
While running, code crosses the enclave boundary through well-defined gates. Entering the enclave is an ECALL; when the enclave needs something only the operating system does, such as reading a file or using the network, it goes out through an OCALL.
A concrete example
Imagine a transaction signing service that keeps a private key on a rented server:
- The service starts the enclave with the signing code, which is open source.
- The key owner asks for attestation, checks that the hash matches the published version of the code, and only then sends the private key, encrypted for the enclave.
- The enclave seals the key and stores the blob on disk.
- The regular application sends transactions through an ECALL; the enclave returns signatures.
- If the server reboots, the enclave opens the sealed blob and carries on. The key never shows up in plaintext outside it, not even to the server's administrator.
Implementations you will run into
| Technology | What it isolates | Where it shows up |
|---|---|---|
| Intel SGX | A piece of a process | Intel servers, Azure |
| Intel TDX | A whole virtual machine | Clouds with recent Xeons |
| AMD SEV-SNP | A whole virtual machine | AWS, Azure, GCP |
| Arm TrustZone / CCA | A separate "secure world" | Phones, embedded devices |
| Apple Secure Enclave | A dedicated coprocessor | iPhone, Mac (Face ID, keys) |
| AWS Nitro Enclaves | An isolated VM with no network or disk | AWS EC2 |
The umbrella name for all of this is TEE (Trusted Execution Environment), and in the cloud it usually shows up as confidential computing.
What enclaves do not solve
- Bugs in your code. If the code inside the enclave leaks the secret, the hardware will not save you. That is why enclave code should be small and auditable.
- Side-channel attacks. Execution time, cache and power draw have been used to extract secrets from enclaves (Foreshadow, Plundervolt, SGAxe). Vendors patch them, but it is an ongoing race.
- Availability. The operating system cannot read the enclave, but it can simply refuse to run it.
- Trust in the manufacturer. The root of everything is the key of Intel, AMD, Arm or Apple. You trade "trusting the owner of the machine" for "trusting whoever made the chip".
Quick glossary
- TCB (Trusted Computing Base)
- Everything you need to trust for the system to be secure. Enclaves exist to shrink the TCB.
- Measurement
- Hash of the code and configuration loaded into the enclave.
- Attestation
- Proof signed by the hardware that a specific measurement is running in a genuine enclave.
- Nonce
- Random number used only once, to prove the answer is fresh and not a recording.
- Sealing
- Encrypting data so that only the same enclave, on the same chip, can decrypt it later.
- ECALL / OCALL
- Calls that enter the enclave and leave it, respectively.
The idea
A policy engine is the part of the system that answers a single question: "can whoever is asking do this to this resource?". It takes the request, looks at the rules written by the owner of the data and returns allow or deny.
The problem is the same as in the first part. If the policy engine runs on a server someone else controls, that person can swap the rules, forge an "allow" or wipe the record of what happened. With the policy engine inside an enclave, whoever operates the server still runs the service, but loses the power to tamper with the decisions.
Who talks to whom
Before the first request
The setup uses exactly the pieces from the first part:
- Attestation. The policy author asks for the enclave's report and checks that the measurement matches the audited version of the policy engine. The report carries the public signing key the enclave generated inside.
- Sending the policies. The policy bundle is signed by the author and encrypted for the enclave. The host forwards it, but cannot read or change it.
- Sealing. The enclave checks the author's signature, stores the bundle sealed on disk and records its version.
- Publishing the key. The protected resources now accept only decisions signed by the key that appeared in the attested report.
The rules
For the example, a small bundle with three rules. Deny always beats allow, and whatever no rule allows is forbidden.
deny never-export-pii:
action = "export" and resource has the tag "pii"
allow read-own-team:
action = "read" and resource.team = requester.team
default: denyThe flow of each request
Pick a request to see the path it takes inside the enclave:
No request picked: the flowchart shows every path.
What goes into the decision
The answer is not just "yes" or "no". It ties the decision to the request and to the rules used, so nobody can reuse an old "allow" on another request:
decision: allow
rule: read-own-team
request: sha256(ana · read · q3-report.pdf · nonce)
policies: version 12 (sha256 of the bundle)
previous log: sha256 of entry 4,311
signature: enclave key (the same as in the attested report)What the enclave guarantees here
- Decisions cannot be forged. Only the enclave has the private signing key, and the resource only accepts decisions signed by it. The server admin controls the gateway, but cannot make up an "allow".
- Rules do not change silently. Policies arrive signed by the author and stay sealed. Each decision carries the policy version it used, so swapping rules without the author becomes visible.
- Rules can stay secret. Fraud thresholds or block lists are in plaintext only inside the enclave. The operator runs the service without being able to read them.
- The log is tamper-evident. Each entry includes the hash of the previous one and is signed. Deleting or editing an entry breaks the chain from there on.
What is still on you
- The gateway may not ask. If the resource accepts requests without a signed decision, the enclave is useless. Checking the signature at the resource is mandatory.
- Rolling back to an old policy. The host can hand back a sealed blob from an earlier version, which the enclave can open. To stop that, the enclave keeps the version in a counter that only goes up, and the resource rejects decisions with a version lower than the last one it saw.
- Wrong rules stay wrong. The enclave guarantees the rules are applied as written, not that they are right.
- Availability. The operator can still turn everything off. In that case nothing is allowed, which at least fails on the safe side.
Glossary for this part
- Policy engine
- Component that evaluates rules and decides whether a request is allowed.
- PDP (Policy Decision Point)
- Who decides. Here, the policy engine inside the enclave.
- PEP (Policy Enforcement Point)
- Who enforces the decision on the request's path. Here, the gateway.
- Deny by default
- Whatever no rule explicitly allows is forbidden.
- Chained log
- Record where each entry includes the hash of the previous one, so any change in the middle shows.
