dsec Integration
Overview
netapi integrates with dsec (Domain Secrets Manager) for secure secrets management, providing encrypted credential handling across different environments with multiple security layers.
First-Time Setup
Before using dsec, install the shell wrapper functions:
# Add to your shell config
dsec shell-init >> ~/.zshrc # or ~/.bashrc for bash users
source ~/.zshrc
# Fish shell users
dsec shell-init fish >> ~/.config/fish/config.fish
This installs the secure dsource and dsunsource wrapper functions.
Environment Structure
~/.secrets/
├── .metadata/
│ ├── keys/
│ │ ├── master.age.key # Age private key (chmod 600)
│ │ ├── master.age.pub # Age public key
│ │ └── passphrase.age # Optional passphrase (encrypted)
│ └── audit.log # Access audit trail
└── environments/
└── domains/
├── d000/ # Personal domain (nested structure)
│ ├── dev/
│ │ ├── network.env.age
│ │ ├── identity.env.age
│ │ └── app.env.age
│ └── prod/
└── d001/ # Client domain (flat structure)
├── dev.env.age
└── prod.env.age
Loading Secrets
Security Features
Eval Context Protection
dsec uses strict mode by default, which requires the DSEC_EVAL_VERIFIED environment variable to be set. This prevents accidental secret exposure when users mistakenly run:
# WRONG - would expose secrets to terminal (now blocked)
$(dsec source d000 dev/network)
# CORRECT - uses secure wrapper
dsource d000 dev/network
Security Modes
| Mode | Behavior |
|---|---|
|
Requires |
|
Allows |
To use permissive mode:
export DSEC_SECURITY_MODE=permissive
Passphrase Protection
Add an additional authentication layer:
# Enable passphrase protection
dsec set-passphrase
# You'll be prompted for passphrase on each secrets load
dsource d000 dev/network
# dsec passphrase: ********
# Disable passphrase
dsec remove-passphrase
# Bypass passphrase for a session
export DSEC_REQUIRE_PASSPHRASE=false
Environment Variables
After loading secrets, the following metadata is available:
| Variable | Description |
|---|---|
|
Domain ID (e.g., |
|
Tier path (e.g., |
|
Number of variables loaded |
|
ISO8601 timestamp of load |
|
Space-separated list of variable names |
|
Display name for shell prompts (e.g., |
Python Integration
Direct Usage
from netapi.primitives.config import DsecConfig
# Load from pre-sourced environment
config = DsecConfig.from_env()
host = config.get("ISE_PAN_IP")
# Or decrypt directly (requires age key access)
config = DsecConfig.from_domain("d000", "dev/network")
token = config.require("ISE_API_TOKEN")
# Get all variables with a prefix
ise_vars = config.get_prefixed("ISE_")
Vendor Factory Methods
All vendor clients support environment-based initialization:
from netapi.vendors.cisco.ise import ERSClient, MnTClient
# Clients read from environment variables
ers = ERSClient.from_env()
mnt = MnTClient.from_env()
# Or with explicit config
ers = ERSClient(
host=config.get("ISE_PAN_IP"),
token=config.get("ISE_API_TOKEN"),
)
CLI Commands Reference
dsec list # List all domains and tiers
dsec init <id> <name> # Initialize new domain
dsec add <id> <tier> <file> # Add/update encrypted secrets
dsec edit <id> <tier> # Edit secrets (decrypts to RAM)
dsec show <id> <tier> # Display secrets (review only)
dsec load <id> <tier> [dir] # Decrypt to directory
dsec unload [dir] # Securely remove decrypted files
# Security commands
dsec shell-init [shell] # Output shell wrapper functions
dsec set-passphrase # Enable passphrase protection
dsec remove-passphrase # Disable passphrase protection
Security Best Practices
|