Skip to content

Commit dda17f2

Browse files
committed
chore: unify credential passing pattern across all integrations
Standardize how user-provided secrets are passed into the sandbox: - Add TELEGRAM_BOT_TOKEN to sandbox creation env vars (was only in deploy path, missing from onboard) - Standardize NVIDIA_API_KEY to use getCredential() like all other tokens instead of checking process.env directly - Add inline comment documenting the credential passing pattern - Add "Credential Handling" section to architecture doc with inventory table covering all six credentials and their flow All four user tokens (NVIDIA, Discord, Slack, Telegram) now follow the same getCredential() || process.env pattern at sandbox creation. Closes #616
1 parent 1dbf82f commit dda17f2

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

‎bin/lib/onboard.js‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,15 @@ async function createSandbox(gpu) {
443443

444444
console.log(` Creating sandbox '${sandboxName}' (this takes a few minutes on first run)...`);
445445
const chatUiUrl = process.env.CHAT_UI_URL || 'http://127.0.0.1:18789';
446+
// Pass user-provided secrets into the sandbox as environment variables.
447+
// All tokens follow the same pattern: getCredential() checks env first,
448+
// then ~/.nemoclaw/credentials.json. OpenClaw auto-enables channels when
449+
// it detects the corresponding env var (e.g., DISCORD_BOT_TOKEN).
450+
// See docs/reference/architecture.md "Credential Handling" for the full inventory.
446451
const envArgs = [`CHAT_UI_URL=${shellQuote(chatUiUrl)}`];
447-
if (process.env.NVIDIA_API_KEY) {
448-
envArgs.push(`NVIDIA_API_KEY=${shellQuote(process.env.NVIDIA_API_KEY)}`);
452+
const apiKey = getCredential("NVIDIA_API_KEY") || process.env.NVIDIA_API_KEY;
453+
if (apiKey) {
454+
envArgs.push(`NVIDIA_API_KEY=${shellQuote(apiKey)}`);
449455
}
450456
const discordToken = getCredential("DISCORD_BOT_TOKEN") || process.env.DISCORD_BOT_TOKEN;
451457
if (discordToken) {
@@ -455,6 +461,10 @@ async function createSandbox(gpu) {
455461
if (slackToken) {
456462
envArgs.push(`SLACK_BOT_TOKEN=${shellQuote(slackToken)}`);
457463
}
464+
const tgToken = getCredential("TELEGRAM_BOT_TOKEN") || process.env.TELEGRAM_BOT_TOKEN;
465+
if (tgToken) {
466+
envArgs.push(`TELEGRAM_BOT_TOKEN=${shellQuote(tgToken)}`);
467+
}
458468

459469
// Run without piping through awk — the pipe masked non-zero exit codes
460470
// from openshell because bash returns the status of the last pipeline

‎docs/reference/architecture.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,31 @@ Agent (sandbox) ──▶ OpenShell gateway ──▶ NVIDIA Endpoint (build
100100
```
101101

102102
Refer to [Inference Profiles](../reference/inference-profiles.md) for provider configuration details.
103+
104+
## Credential Handling
105+
106+
All user-provided secrets follow the same pattern:
107+
108+
1. Stored on the host in `~/.nemoclaw/credentials.json` (mode 0600) or as environment variables.
109+
2. Retrieved via `getCredential(key)` which checks env vars first, then the credentials file.
110+
3. Passed into the sandbox as environment variables at creation time.
111+
4. Never written to `openclaw.json` (immutable at runtime).
112+
113+
### Credential Inventory
114+
115+
| Credential | Passed to sandbox | Used inside sandbox | Used on host | Notes |
116+
|---|---|---|---|---|
117+
| `NVIDIA_API_KEY` | Yes (env var) | Yes — startup script writes `auth-profiles.json` | Yes — deploy, Telegram bridge | OpenClaw requires a specific JSON file format; `nemoclaw-start.sh` handles the translation |
118+
| `DISCORD_BOT_TOKEN` | Yes (env var) | Yes — OpenClaw reads env var directly, auto-enables Discord channel | No | |
119+
| `SLACK_BOT_TOKEN` | Yes (env var) | Yes — OpenClaw reads env var directly, auto-enables Slack channel | No | |
120+
| `TELEGRAM_BOT_TOKEN` | Yes (env var) | Available but unused — bridge runs on host | Yes — Telegram bridge (host-side) | Bridge uses SSH to relay messages into sandbox |
121+
| `GITHUB_TOKEN` | Deploy path only | No | Yes — private repo access | Not needed inside sandbox |
122+
| Gateway auth token | No — baked at build time | Yes — `openclaw.json` (root:root 444) | N/A | Per-build unique, immutable security boundary |
123+
124+
### Why Telegram runs on the host
125+
126+
The Telegram bridge (`scripts/telegram-bridge.js`) runs on the host and communicates with the sandbox via OpenShell SSH. This is intentional:
127+
128+
- It avoids giving the sandbox direct Telegram API access beyond what the network policy allows.
129+
- It allows the bridge to manage multiple sandboxes from one host process.
130+
- The `TELEGRAM_BOT_TOKEN` is still passed into the sandbox for future OpenClaw channel plugin support.

0 commit comments

Comments
 (0)