Skip to content
Open

Near #147

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2501dec
feat: integrate Near.AI provider (glm-5)
AnthonyRonning Feb 19, 2026
be95341
test: add Near.AI verification and E2EE tests
AnthonyRonning Feb 19, 2026
4ba1129
fix: improve Near.AI live verification
AnthonyRonning Feb 19, 2026
e74392b
fix: flatten text-array content for Near.AI E2EE encryption
AnthonyRonning Feb 20, 2026
21049fa
fix: harden Near.AI node selection and retries
AnthonyRonning Feb 20, 2026
7c0f738
fix: handle streaming billing when finish_reason and usage arrive on …
AnthonyRonning Feb 20, 2026
876f8ed
style: cargo fmt
AnthonyRonning Feb 20, 2026
ad118ef
fix: support TD15 TDX quotes in Near.AI attestation
AnthonyRonning Feb 20, 2026
2f7148c
fix: accept string verdict in NRAS JWT x-nvidia-overall-att-result
AnthonyRonning Feb 20, 2026
b99a904
fix: harden Near.AI verification strictness and retries
AnthonyRonning Feb 20, 2026
fed7b84
fix: redact api_key in ProxyConfig Debug output to prevent credential…
AnthonyRonning Feb 20, 2026
2463985
fix: harden Near.AI header handling and TDX policy
AnthonyRonning Feb 20, 2026
ddc5aa5
fix: reject multimodal content in Near.AI E2EE instead of silently pa…
AnthonyRonning Feb 20, 2026
641c7bb
docs: add Near.AI vsock proxy setup and API key provisioning to nitro…
AnthonyRonning Feb 20, 2026
c2de548
fix: add retry logic to Intel TDX and NVIDIA GPU attestation verifica…
AnthonyRonning Feb 20, 2026
0a14c59
fix: replace dcap-qvl collateral fetcher to avoid hickory-dns in encl…
AnthonyRonning Feb 20, 2026
0486b4d
fix: accept OutOfDate TDX TCB status with warning
AnthonyRonning Feb 21, 2026
e849c66
Update pcr
AnthonyRonning Feb 21, 2026
78013dd
Attempt to fix parsing issues
AnthonyRonning Feb 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,196 changes: 1,073 additions & 123 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dotenv = "0.15.0"
aes-gcm = "0.10.1"
aes-siv = "0.7"
hmac = "0.12.1"
hkdf = "0.12"
generic-array = "0.14"
cbc = "0.1.2"
secp256k1 = { version = "0.29.0", features = ["rand"] }
Expand All @@ -50,6 +51,7 @@ tokio-stream = "0.1"
async-stream = "0.3"
bytes = "1.0"
sha2 = { version = "0.10", default-features = false }
sha3 = "0.10"
hex = "0.4.3"
base64 = "0.22.1"
vsock = "0.5.1"
Expand All @@ -75,3 +77,7 @@ lazy_static = "1.4.0"
subtle = "2.6.1"
tiktoken-rs = "0.5"
once_cell = "1.19"
dcap-qvl = { version = "0.3.12", default-features = false, features = ["std", "report", "ring"] }

[dev-dependencies]
p384 = { version = "0.13", features = ["ecdsa", "pkcs8"] }
149 changes: 149 additions & 0 deletions docs/nitro-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,134 @@ sudo systemctl restart vsock-tinfoil-router-inf9.service
sudo systemctl restart vsock-tinfoil-router-inf10.service
```

## Vsock Near.AI proxies
Create vsock proxy services so that the enclave can talk to Near.AI and its attestation dependencies (NVIDIA NRAS for GPU attestation and Intel PCS for TDX DCAP collateral).

First configure the endpoints into their allowlist:

```sh
sudo vim /etc/nitro_enclaves/vsock-proxy.yaml
```

Add these lines:
```
- {address: cloud-api.near.ai, port: 443}
- {address: nras.attestation.nvidia.com, port: 443}
- {address: api.trustedservices.intel.com, port: 443}
- {address: certificates.trustedservices.intel.com, port: 443}
```

Restart the nitro vsock proxy service:
```
sudo systemctl restart nitro-enclaves-vsock-proxy.service
```

#### Near.AI Cloud API
```sh
sudo vim /etc/systemd/system/vsock-near-cloud-api-proxy.service
```

Add the following content:
```
[Unit]
Description=Vsock Near.AI Cloud API Proxy Service
After=network.target

[Service]
User=root
ExecStart=/usr/bin/vsock-proxy 8042 cloud-api.near.ai 443
Restart=always

[Install]
WantedBy=multi-user.target
```

#### NVIDIA NRAS (GPU Attestation)
```sh
sudo vim /etc/systemd/system/vsock-near-nras-proxy.service
```

Add the following content:
```
[Unit]
Description=Vsock NVIDIA NRAS Proxy Service
After=network.target

[Service]
User=root
ExecStart=/usr/bin/vsock-proxy 8043 nras.attestation.nvidia.com 443
Restart=always

[Install]
WantedBy=multi-user.target
```

#### Intel PCS (DCAP Collateral)
```sh
Comment on lines +1353 to +1394

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix heading level jump (use ### under the ## section).

#### Near.AI Cloud API introduces a two‑level jump from ##, which breaks heading hierarchy. Switch these #### headers to ### in this section.

Proposed change
-#### Near.AI Cloud API
+### Near.AI Cloud API
...
-#### NVIDIA NRAS (GPU Attestation)
+### NVIDIA NRAS (GPU Attestation)
...
-#### Intel PCS (DCAP Collateral)
+### Intel PCS (DCAP Collateral)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#### Near.AI Cloud API
```sh
sudo vim /etc/systemd/system/vsock-near-cloud-api-proxy.service
```
Add the following content:
```
[Unit]
Description=Vsock Near.AI Cloud API Proxy Service
After=network.target
[Service]
User=root
ExecStart=/usr/bin/vsock-proxy 8042 cloud-api.near.ai 443
Restart=always
[Install]
WantedBy=multi-user.target
```
#### NVIDIA NRAS (GPU Attestation)
```sh
sudo vim /etc/systemd/system/vsock-near-nras-proxy.service
```
Add the following content:
```
[Unit]
Description=Vsock NVIDIA NRAS Proxy Service
After=network.target
[Service]
User=root
ExecStart=/usr/bin/vsock-proxy 8043 nras.attestation.nvidia.com 443
Restart=always
[Install]
WantedBy=multi-user.target
```
#### Intel PCS (DCAP Collateral)
```sh
### Near.AI Cloud API
🧰 Tools
🪛 markdownlint-cli2 (0.21.0)

[warning] 1352-1352: Heading levels should only increment by one level at a time
Expected: h3; Actual: h4

(MD001, heading-increment)


[warning] 1358-1358: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


[warning] 1378-1378: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/nitro-deploy.md` around lines 1352 - 1393, The headings "Near.AI Cloud
API", "NVIDIA NRAS (GPU Attestation)" and the following "Intel PCS (DCAP
Collateral)" are using '####' which creates a two-level jump under the enclosing
'##' section; change those headers from '####' to '###' so they are proper
subsections (update the lines containing "Near.AI Cloud API", "NVIDIA NRAS (GPU
Attestation)", and "Intel PCS (DCAP Collateral)" to use '###' heading markers)
to restore correct hierarchy.

sudo vim /etc/systemd/system/vsock-near-intel-pcs-proxy.service
```

Add the following content:
```
[Unit]
Comment on lines +1341 to +1400

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add language tags to new fenced code blocks.

The new fenced blocks in this section omit language identifiers, which triggers MD040 and makes rendering/tooling less reliable. Add appropriate tags (e.g., sh, ini).

Proposed change
-```
+```yaml
 - {address: cloud-api.near.ai, port: 443}
 - {address: nras.attestation.nvidia.com, port: 443}
 - {address: api.trustedservices.intel.com, port: 443}

...
- +sh
sudo systemctl restart nitro-enclaves-vsock-proxy.service

...
-```
+```ini
[Unit]
Description=Vsock Near.AI Cloud API Proxy Service
After=network.target

[Service]
User=root
ExecStart=/usr/bin/vsock-proxy 8042 cloud-api.near.ai 443
Restart=always

[Install]
WantedBy=multi-user.target

...
- +ini
[Unit]
Description=Vsock NVIDIA NRAS Proxy Service
After=network.target

[Service]
User=root
ExecStart=/usr/bin/vsock-proxy 8043 nras.attestation.nvidia.com 443
Restart=always

[Install]
WantedBy=multi-user.target

...
-```
+```ini
[Unit]
Description=Vsock Intel PCS Proxy Service
After=network.target

[Service]
User=root
ExecStart=/usr/bin/vsock-proxy 8044 api.trustedservices.intel.com 443
Restart=always

[Install]
WantedBy=multi-user.target
</details>

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 markdownlint-cli2 (0.21.0)</summary>

[warning] 1341-1341: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

---

[warning] 1348-1348: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

---

[warning] 1352-1352: Heading levels should only increment by one level at a time
Expected: h3; Actual: h4

(MD001, heading-increment)

---

[warning] 1358-1358: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

---

[warning] 1378-1378: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

---

[warning] 1398-1398: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>

<details>
<summary>🤖 Prompt for AI Agents</summary>

Verify each finding against the current code and only fix it if needed.

In @docs/nitro-deploy.md around lines 1341 - 1399, The fenced code blocks in
this section are missing language tags (triggers MD040); update the blocks
around the three address list, the restart command, and each systemd unit
snippet (vsock-near-cloud-api-proxy.service, vsock-near-nras-proxy.service,
vsock-near-intel-pcs-proxy.service) by adding appropriate language identifiers
(e.g., yaml for the address list, sh for the sudo systemctl restart command, and
ini for the systemd unit files) so tooling and rendering treat them correctly.


</details>

<!-- fingerprinting:phantom:triton:eagle -->

<!-- This is an auto-generated comment by CodeRabbit -->

Description=Vsock Intel PCS Proxy Service
After=network.target

[Service]
User=root
ExecStart=/usr/bin/vsock-proxy 8044 api.trustedservices.intel.com 443
Restart=always

[Install]
WantedBy=multi-user.target
```

#### Intel Certificates (Root CA CRL)
```sh
sudo vim /etc/systemd/system/vsock-near-intel-certs-proxy.service
```

Add the following content:
```
[Unit]
Description=Vsock Intel Certificates Proxy Service
After=network.target

[Service]
User=root
ExecStart=/usr/bin/vsock-proxy 8045 certificates.trustedservices.intel.com 443
Restart=always

[Install]
WantedBy=multi-user.target
```

Activate all the services:

```sh
sudo systemctl daemon-reload
sudo systemctl enable vsock-near-cloud-api-proxy.service
sudo systemctl start vsock-near-cloud-api-proxy.service
sudo systemctl status vsock-near-cloud-api-proxy.service
sudo systemctl enable vsock-near-nras-proxy.service
sudo systemctl start vsock-near-nras-proxy.service
sudo systemctl status vsock-near-nras-proxy.service
sudo systemctl enable vsock-near-intel-pcs-proxy.service
sudo systemctl start vsock-near-intel-pcs-proxy.service
sudo systemctl status vsock-near-intel-pcs-proxy.service
sudo systemctl enable vsock-near-intel-certs-proxy.service
sudo systemctl start vsock-near-intel-certs-proxy.service
sudo systemctl status vsock-near-intel-certs-proxy.service
```

If you need to restart these services:
```sh
sudo systemctl restart vsock-near-cloud-api-proxy.service
sudo systemctl restart vsock-near-nras-proxy.service
sudo systemctl restart vsock-near-intel-pcs-proxy.service
sudo systemctl restart vsock-near-intel-certs-proxy.service
```

## KMS Key

You need to create an AWS KMS key that the enclave can encrypt/decrypt things to. Name it according to your environment:
Expand Down Expand Up @@ -1699,6 +1827,27 @@ INSERT INTO enclave_secrets (key, value)
VALUES ('os_flags_base_url', decode('your_base64_string', 'base64'));
```

#### Near.AI API Key

After the DB is initialized, we need to store the Near.AI Cloud API key encrypted to the enclave KMS key. This key is used for authenticated requests to `cloud-api.near.ai`.

```sh
echo -n "NEAR_API_KEY" | base64 -w 0
```

Take that output and encrypt to the KMS key, from a machine that has encrypt access to the key:

```sh
aws kms encrypt --key-id "KEY_ARN" --plaintext "BASE64_KEY" --query CiphertextBlob --output text
```

Take that encrypted base64 and insert it into the `enclave_secrets` table with key as `near_api_key` and value as the base64.

```sql
INSERT INTO enclave_secrets (key, value)
VALUES ('near_api_key', decode('your_base64_string', 'base64'));
```

## Secrets Manager

### Postgresql
Expand Down
47 changes: 47 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@ echo "127.0.0.31 router.inf9.tinfoil.sh" >> /etc/hosts
echo "127.0.0.32 router.inf10.tinfoil.sh" >> /etc/hosts
log "Added Tinfoil proxy domains to /etc/hosts"

# Add Near.AI + attestation hostnames to /etc/hosts
echo "127.0.0.34 cloud-api.near.ai" >> /etc/hosts
echo "127.0.0.35 nras.attestation.nvidia.com" >> /etc/hosts
echo "127.0.0.21 api.trustedservices.intel.com" >> /etc/hosts
echo "127.0.0.36 certificates.trustedservices.intel.com" >> /etc/hosts
log "Added Near.AI, NRAS, and Intel PCS domains to /etc/hosts"

# Add Kagi Search hostname to /etc/hosts
echo "127.0.0.23 kagi.com" >> /etc/hosts
log "Added Kagi Search domain to /etc/hosts"
Expand Down Expand Up @@ -461,6 +468,18 @@ run_forever tf_tinfoil_atc python3 /app/traffic_forwarder.py 127.0.0.25 443 3 80
log "Starting Tinfoil Inference traffic forwarder"
run_forever tf_tinfoil_inference python3 /app/traffic_forwarder.py 127.0.0.33 443 3 8041 &

log "Starting Near.AI Cloud API traffic forwarder"
run_forever tf_nearai_cloud_api python3 /app/traffic_forwarder.py 127.0.0.34 443 3 8042 &

log "Starting NVIDIA NRAS traffic forwarder"
run_forever tf_nras python3 /app/traffic_forwarder.py 127.0.0.35 443 3 8043 &

log "Starting Intel PCS traffic forwarder"
run_forever tf_intel_pcs python3 /app/traffic_forwarder.py 127.0.0.21 443 3 8044 &

log "Starting Intel Certificates traffic forwarder"
run_forever tf_intel_certs python3 /app/traffic_forwarder.py 127.0.0.36 443 3 8045 &

log "Starting Tinfoil Router Inf4 traffic forwarder"
run_forever tf_tinfoil_router_inf4 python3 /app/traffic_forwarder.py 127.0.0.26 443 3 8034 &

Expand Down Expand Up @@ -653,6 +672,34 @@ else
log "Tinfoil Inference connection failed"
fi

log "Testing connection to Near.AI Cloud API:"
if timeout 5 bash -c '</dev/tcp/127.0.0.34/443'; then
log "Near.AI Cloud API connection successful"
else
log "Near.AI Cloud API connection failed"
fi

log "Testing connection to NVIDIA NRAS:"
if timeout 5 bash -c '</dev/tcp/127.0.0.35/443'; then
log "NVIDIA NRAS connection successful"
else
log "NVIDIA NRAS connection failed"
fi

log "Testing connection to Intel PCS:"
if timeout 5 bash -c '</dev/tcp/127.0.0.21/443'; then
log "Intel PCS connection successful"
else
log "Intel PCS connection failed"
fi

log "Testing connection to Intel Certificates:"
if timeout 5 bash -c '</dev/tcp/127.0.0.36/443'; then
log "Intel Certificates connection successful"
else
log "Intel Certificates connection failed"
fi

log "Testing connection to Tinfoil Router Inf4:"
if timeout 5 bash -c '</dev/tcp/127.0.0.26/443'; then
log "Tinfoil Router Inf4 connection successful"
Expand Down
4 changes: 2 additions & 2 deletions pcrDev.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"HashAlgorithm": "Sha384 { ... }",
"PCR0": "a8ac79f4e3e57813727cc0c424ecdd7a50f6774e4e79e162f8a96f294293c9f7db4d160dab36e7f5fb642f7fa12cf6f3",
"PCR0": "07331a85d922e9d33b8bea190427e962a77e6f65425ff99e8545e4ce7ca1f4a637cf10b8f84eb0701bdebb7ae6ff181c",
"PCR1": "f004075c672258b499f8e88d59701031a3b451f65c7de60c81d09da2b0799272675481ec390527594dd7069cb7de59d7",
"PCR2": "bb1579a2089477c38f152701cd7c3e398d8c37f98aebc6d60d8d2c2ed3671e7cededae1bdf61c211d37dd3094f4ba5f3"
"PCR2": "af52809711e969c13b2d93ae5bed02008b9af021d35419be7047196d6731dff9d6dbdaf3609e55770a5da450dffead28"
}
7 changes: 7 additions & 0 deletions pcrDevHistory.json
Original file line number Diff line number Diff line change
Expand Up @@ -544,5 +544,12 @@
"PCR2": "bb1579a2089477c38f152701cd7c3e398d8c37f98aebc6d60d8d2c2ed3671e7cededae1bdf61c211d37dd3094f4ba5f3",
"timestamp": 1770852354,
"signature": "AfsiYvvNU6CsvfCtyCCLTRiTemej5pFqsCcIFhfSOUtAU0wV5n3za7jwU3p9lK5F3UsbNzS98dZwuw7PM4u9Ne83qltekPt7xXdXQ84epVhG+4hHxfa8g7GX60iVBZSb"
},
{
"PCR0": "07331a85d922e9d33b8bea190427e962a77e6f65425ff99e8545e4ce7ca1f4a637cf10b8f84eb0701bdebb7ae6ff181c",
"PCR1": "f004075c672258b499f8e88d59701031a3b451f65c7de60c81d09da2b0799272675481ec390527594dd7069cb7de59d7",
"PCR2": "af52809711e969c13b2d93ae5bed02008b9af021d35419be7047196d6731dff9d6dbdaf3609e55770a5da450dffead28",
"timestamp": 1771634556,
"signature": "hTLAVNQdFhdDlWMAmjsE+Wl7gRFTdY1TfA5C5I8PWPjzgot5oyJ1jK4RsLrRlBmZ5E5qE/xsP5hVy4daldY3aL973uGN8W/kiw3JdtWoih8YEoXyHniMS2q86FHCAEe/"
}
]
4 changes: 2 additions & 2 deletions pcrProd.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"HashAlgorithm": "Sha384 { ... }",
"PCR0": "4403544d28e867b9e2e4ae7ee881db9f9d75a2cbdd64ab31d413dfbc9ca36b0e6e7416fb4abfb852b0051ad2d3fd2734",
"PCR0": "fffbfb0cbe63a5a3f54a8bb38b727e8e93bfe58dd3d82d0c4d8b80022f960d2c5c688be01f7d989032e1f439166c77dc",
"PCR1": "f004075c672258b499f8e88d59701031a3b451f65c7de60c81d09da2b0799272675481ec390527594dd7069cb7de59d7",
"PCR2": "5fac6ea109cda1791a579bbd5f973b51d40bf53af409afd098dd8aa88ebafcd5d53b1bbb5c3a8a0855e26c9b1278c32c"
"PCR2": "f6b83a784d35cc136851ead7f54bb4524af81b28d0cae7397bf6b4568937570d941242685787b7f0dea5c2d4f75b7627"
}
7 changes: 7 additions & 0 deletions pcrProdHistory.json
Original file line number Diff line number Diff line change
Expand Up @@ -544,5 +544,12 @@
"PCR2": "5fac6ea109cda1791a579bbd5f973b51d40bf53af409afd098dd8aa88ebafcd5d53b1bbb5c3a8a0855e26c9b1278c32c",
"timestamp": 1770852382,
"signature": "dWP0Bk9xQPHjSYKfMQz0rIwBGMhxUpOQE/VsZiTLDlusSWG/QMH0TGPzfTFeFoPUuWAnmfWb4aoqt8OdYV1nXZyEgw7hfw9hlaZw2DUoHSbSyGvRtyDne82oQ7FyPeL0"
},
{
"PCR0": "fffbfb0cbe63a5a3f54a8bb38b727e8e93bfe58dd3d82d0c4d8b80022f960d2c5c688be01f7d989032e1f439166c77dc",
"PCR1": "f004075c672258b499f8e88d59701031a3b451f65c7de60c81d09da2b0799272675481ec390527594dd7069cb7de59d7",
"PCR2": "f6b83a784d35cc136851ead7f54bb4524af81b28d0cae7397bf6b4568937570d941242685787b7f0dea5c2d4f75b7627",
"timestamp": 1771634598,
"signature": "7uvD22Q9c32ui9m/y5ybTR1YokJYBsGFma+67gfvoTaPhfvGZiGTBnBfGKKp6eFKBeg0NCiS8lOsBKBQ+aXLNcEBID8CE4L+ma/AHslW66DvPlLZZ1NL88zgS0ah4K0H"
}
]
Loading
Loading