Deploy On-chain KMS Smart Contracts
Deploy theDstackKms smart contract to enforce that only authorized workloads can receive keys. This page covers the full contract deployment workflow, including the recommended Safe + Timelock governance setup for production.
Overview
Note: Safe and Timelock are optional security enhancements, not part of dstack. They are recommended for production but not required for development.
Governance Models
Model A: Direct Admin (Simplest)
- Admin is a single EOA (externally owned account)
- No multisig, no timelock
- Governance actions execute immediately
- Suitable for development and testing
Model B: Timelock Only
- Admin is a TimelockController contract
- Governance actions require a delay before execution
- Anyone can execute after delay (or restricted to specific executors)
- Suitable for simple production setups
Model C: Safe + Timelock (Recommended for Production)
- Admin is a Safe multisig wallet
- Timelock enforces a delay
- Requires multi-party approval + delay period
- Maximum security and transparency
Prerequisites
- Foundry installed (
forge,cast) - A wallet with funds for deployment gas
- Testnet: Use a faucet (e.g., Base Sepolia faucet)
- Mainnet: Sufficient ETH for contract deployment
- RPC endpoint for the target network
Step 1: Set Up the Project
Step 2: Configure Environment
Create a.env file:
Security: Never commit your private key. Add.envto.gitignore.
Step 3: Deploy DstackKms (Basic, No Timelock)
For development/testing, you can deploy DstackKms with direct EOA admin:Why ERC1967Proxy? DstackKms uses UUPS upgradeable pattern. You must deploy a proxy to have a working upgradeable instance. The proxy is the actual application address.
Step 4: Deploy with Timelock (Recommended for Production)
Timelock Configuration
The timelock delay depends on your deployment environment:4.1 Prepare Timelock Configuration
4.2 Deploy All Contracts
4.3 Understanding TimelockController Roles
Step 5: Configure Safe (Optional but Recommended)
For production, use a Safe multisig as the proposer/executor:5.1 Create a Safe
- Go to Safe web app
- Connect your wallet
- Create a new Safe on your target network
- Add signers (3-7 addresses recommended)
- Set threshold (≥ 2/3 of signers)
5.2 Use Safe Address in Deployment
When deploying the TimelockController, use your Safe address:5.3 Governance Flow with Safe + Timelock
- Draft transaction — Use Safe web interface to create a transaction
- Collect signatures — Required signers approve
- Schedule in timelock — Safe calls
timelock.schedule() - Wait for delay — Wait the configured delay period
- Execute — Anyone (or only executor) calls
timelock.execute()
Step 6: Verify Deployment
Verify on block explorer:DstackKmsowner is set to the TimelockController address- TimelockController has correct proposer/executor roles
How to Execute Governance Actions (With Timelock)
Once deployed, allonlyOwner operations must go through the timelock:
Schedule an Operation
Execute After Delay
All Governance-Protected Methods
Once ownership is transferred to timelock, these methods require timelock governance:Common Issues
Next Steps
- Register KMS Measurements — Register KMS measurements before bootstrap
- Register Workload Measurements — Authorize workloads to receive keys
- Manage Governance — How to create proposals and execute governance actions
- Concept: Governance — Understand the governance model

