Guide
Step-by-step examples for common secret management tasks
Quick Start
From zero to automatic secret injection in 5 minutes
Install the CLI
Download from the Downloads page, or use curl:
macOS (Apple Silicon — includes Touch ID helper)
Initialize the CLI
If you have an invite code from your admin:
Or if you are the admin (server operator):
Your token is stored in the OS keychain (Touch ID on macOS) or printed as export SG_TOKEN=... on Linux. The config file at ~/.sg/config.json stores only the gateway URL — never the token.
Store the token in the keychain (macOS only)
Triggers a Touch ID or macOS login password prompt and stores your token in the Data Protection Keychain. On Linux, add the export SG_TOKEN="..." line printed by sg init to your shell profile instead.
Install the shell plugin
Then reload your shell (or open a new terminal):
This installs an integration snippet that starts the sg agent daemon once per session (Touch ID fires once) and automatically resolves sg:// references — no sg exec prefix needed.
Store your first secret
Run commands — secrets resolve automatically
No prefix needed. The shell plugin resolves sg:// references in .env, ~/.aws/credentials, ~/.kube/config, and other well-known files automatically on every directory change.
Shell Plugin
Automatic secret injection via sg agent — no sg exec prefix required
The shell plugin installs an integration snippet into your shell profile. It starts a background daemon (sg agent) once per session and automatically resolves sg:// references on every directory change.
Install / uninstall
Agent commands
The agent holds your bearer token in memory and caches resolved secrets (15-minute TTL). Touch ID is triggered once when the agent starts, not on every command.
How it works
1. Shell opens → agent starts → Touch ID prompt (once)
2. cd project/ → hook fires → eval "$(sg shell-env)"
3. shell-env asks agent to resolve sg:// refs in well-known files
4. Agent returns cached values (no Touch ID re-prompt)
5. Shell exports resolved paths as env vars
6. aws s3 ls → reads credentials from exported temp file
7. Shell closes → EXIT trap stops the agent
Without the shell plugin
Use sg exec to wrap individual commands:
Vaults & Items
Organize secrets hierarchically: Vault → Item → Field
Hierarchy
📦 myapp (vault)
├── 📋 database (item)
│ ├── 🔑 host = db.example.com
│ ├── 🔑 port = 5432
│ ├── 🔑 username = app_user
│ └── 🔑 password = ••••••••
├── 📋 aws (item)
│ ├── 🔑 access_key = AKIA...
│ └── 🔑 secret_key = ••••••••
└── 📋 stripe (item)
└── 🔑 api_key = sk_live_...
Managing Vaults
Managing Items
Storing Secrets
Add, update, and manage secret fields
CLI Commands
REST API
REST API equivalent
Note: All field values are encrypted with AES-256-GCM using per-field derived keys (HKDF). They are decrypted only when explicitly read.
Reading Secrets
Resolve secrets using sg:// references
Single secret
Batch resolve (API)
You can also use the Resolve page in this webapp to test references interactively.
Environment Injection
Secrets resolved automatically — or via sg run / sg exec
Create a .env file with sg:// references instead of hardcoded values:
.env
Option A — Shell plugin (recommended)
With sg shell install active, just run commands normally — no prefix needed:
With shell plugin active
Option B — sg run (per-command)
Without the shell plugin, wrap each command with sg run:
Without shell plugin
Zero code changes needed. Your app reads standard $DB_PASSWORD env vars — it never needs to know about SecretsGateway. Secrets are never written to disk.
Template File Injection
Replace sg:// references in config files
Create a template file with sg:// references:
config.yml.tpl (template)
Render it with resolved values:
Resolve template
Team Access
Onboard team members with scoped invite codes
For admins: Create an invite
Use the Invites page or the API:
For team members: Redeem the invite
The invite code can only be used once. The team member gets a scoped token that is automatically stored in their OS keychain.
Access control
Can create, read, update, and delete secrets within their scoped vaults.
Can only read secrets. Cannot create, update, or delete.
Reference Format
The sg:// URI scheme for addressing secrets
sg://{vault}/{item}/{field}
sg://{vault}/{item}/{section}/{field}
Examples
sg://production/database/passwordVault "production", item "database", field "password"
sg://myapp/aws/access_keyVault "myapp", item "aws", field "access_key"
sg://dev/api-keys/stripe/secretWith section: vault "dev", item "api-keys", section "stripe", field "secret"
Where references are used
sg shell install — automatic injection in every shell session (recommended)sg exec -- <cmd> — auto-discover and resolve for a single commandsg read sg://... — read a single secretsg run --env-file .env — resolve refs in env filesg inject --in-file tpl — resolve refs in templatePOST /v1/resolve — batch resolve via REST API