Terraform Cloud Backend
OpenTaco provides full compatibility with Terraform’scloud
backend configuration, offering a self-hosted alternative to Terraform Cloud. This enables teams to use the familiar cloud block syntax while maintaining control over their infrastructure state.
Overview
The cloud backend support in OpenTaco includes:- Terraform Cloud API compatibility - Full
/tfe/api/v2
endpoint implementation - OAuth2/PKCE authentication - Secure login flow compatible with
terraform login
- Workspace management - Create, read, update, and manage workspaces
- State locking and versioning - Advanced state management with atomic operations
- RBAC integration - Fine-grained permissions for workspace access
- Service discovery - Automatic configuration via
/.well-known/terraform.json
Quick Start
1. Configure Your Terraform Project
Add a cloud block to your Terraform configuration:2. Login to OpenTaco
Use the Terraform CLI to authenticate:- Open your browser to OpenTaco’s OAuth2 flow
- Authenticate with your OIDC provider (if configured)
- Store credentials in
~/.terraform.d/credentials.tfrc.json
- Automatically work with all
taco
CLI commands - no need for separatetaco login
!
3. Initialize and Apply
Cloud Block Configuration
Single Workspace
Workspace Tags (Multiple Workspaces)
Authentication Flow
OpenTaco implements the full Terraform login protocol with a hybrid token model designed for production HA deployments:Service Discovery
OpenTaco exposes/.well-known/terraform.json
which tells Terraform where to find:
- OAuth2 authorization endpoint
- Token exchange endpoint
- API endpoints
OAuth2 with PKCE
The authentication flow follows OAuth2 with PKCE (Proof Key for Code Exchange):- Authorization Request - Terraform generates a code challenge and redirects to OpenTaco
- User Authentication - User authenticates with configured OIDC provider
- Authorization Code - OpenTaco returns an authorization code
- Token Exchange - Terraform exchanges the code for both token types
- API Access - Different tokens used for different API surfaces
Hybrid Token Model
OpenTaco uses a dual-token architecture that balances performance, security, and compatibility:Opaque API Tokens (/tfe/api/v2/*
)
- Format:
otc_tfe_<random>
(stored in S3 or memory) - Lifetime: No expiry (manually revoked like Terraform Cloud)
- Use Case: Terraform CLI interactions, workspace management
- Benefits: Individual revocation, audit trail, TFC compatibility
- Storage: S3-backed for HA, memory fallback for development
JWT Tokens (/v1/*
Management API)
- Format: EdDSA (Ed25519) signed JSON Web Tokens
- Lifetime: Short-lived (1 hour default, configurable)
- Use Case: Internal management operations, taco CLI
- Benefits: Stateless verification, high performance, no storage dependency
- Verification: Local signature validation using JWKS
SigV4 Authentication (/s3/*
S3-Compatible API)
- Format: AWS Signature Version 4
- Tokens: Short-lived STS credentials (JWT in session token)
- Use Case: S3-compatible state backend
- Benefits: Standard AWS tooling compatibility
Industry Alignment
Design Rationale
This hybrid approach follows established patterns across the infrastructure industry:- Terraform Cloud: Long-lived opaque API tokens for CLI access
- GitHub: Personal access tokens (opaque) + JWT for apps
- AWS: Long-lived access keys + short-lived session tokens
- Kubernetes: Service account tokens (JWT) + API tokens (opaque)
- Docker Hub: API tokens (opaque) + JWT for internal services
- Terraform CLI expects non-expiring tokens (no refresh mechanism)
- JWT key rotation affects ALL tokens simultaneously (poor incident response)
- S3 dependency for revocation would be required anyway for individual control
- Every API call → S3 lookup (performance cost)
- S3 dependency becomes single point of failure
- Higher operational overhead (token cleanup, caching, etc.)
- TFE compatibility - Matches Terraform Cloud behavior exactly
- Performance optimization - Fast JWT validation for high-volume APIs
- HA deployment - Stateless where beneficial, stateful where needed
- Individual revocation - Per-token control for security incidents
- Operational flexibility - Different token lifetimes per use case
- Clean upgrade path - Can consolidate to single model if requirements change
Stateless OAuth Implementation
OpenTaco implements a fully stateless OAuth2 + PKCE flow using industry-standard JWT tokens and encrypted session state:Architecture Overview
- JWT Authorization Codes - Cryptographically signed tokens using EdDSA (Ed25519)
- Encrypted OAuth Sessions - AES-256-GCM encrypted session data in state parameters
- Load Balancer Compatible - Any server instance can handle any step of the OAuth flow
- Auto-Expiring - All tokens expire automatically (5 minutes) without cleanup processes
- Key Rotation Support - JWT key IDs enable seamless key rotation
JWT Signing Key Configuration
OpenTaco uses EdDSA (Ed25519) keys to sign JWT authorization codes. All server instances must use the same signing key pair: Development (Ephemeral Keys):OAuth State Encryption Key Configuration
For OAuth session state encryption, all server instances must share the same encryption key:Key Management Best Practices
Development:Key Rotation Support
JWT Signing Key Rotation:- Seamless rotation - Old tokens verify until expiration
- Multiple key support - JWKS can serve multiple public keys
- Industry standard - Compatible with JWT tooling and debuggers
- Cryptographic security - EdDSA signatures prevent tampering
Security Considerations
JWT Signing Keys:- Key Compromise - If private key is compromised, attackers can mint valid OAuth codes - rotate immediately
- Key Distribution - All instances need the same private key, but only public key is exposed via JWKS
- Rotation Impact - Graceful rotation supported; old tokens remain valid until natural expiration
- Algorithm Security - EdDSA (Ed25519) provides quantum-resistant signatures
- State Key Rotation - Changing encryption key invalidates in-flight OAuth sessions (5-minute impact)
- Key Compromise - Attackers can forge OAuth session state - rotate both keys immediately
- Shared Requirement - All instances must share identical encryption key
- Never Commit Keys - Keep all private keys out of version control and configuration files
- File Permissions - JWT private keys should have restricted permissions (0400)
- Key Storage - Use dedicated secret management systems in production
- Audit Logging - Monitor key rotation events and OAuth failures
Troubleshooting
“Invalid or expired authorization code” errors:- Check JWT signing key consistency across all server instances
- Verify
OPENTACO_TOKENS_PRIVATE_KEY_PEM_PATH
points to valid Ed25519 private key - Ensure system clocks are synchronized (JWT timestamps are validated)
- Test JWT verification with online JWT debuggers using JWKS endpoint
- Verify all server instances have identical
OPENTACO_OAUTH_STATE_KEY
- Check if encryption key was recently rotated (invalidates active sessions)
- Ensure the key has sufficient entropy (use
openssl rand -base64 32
)
- Confirm both JWT signing keys and OAuth encryption keys are identical across instances
- Verify JWKS endpoint returns consistent public keys:
GET /oidc/jwks.json
- Test with single server instance to isolate load balancer issues
- Verify new
OPENTACO_TOKENS_KID
is unique and matches the key - Check that old OAuth codes expire naturally (wait 5 minutes after rotation)
- Monitor logs for JWT verification failures during rotation window
Workspace Operations
Workspace Lifecycle
OpenTaco supports all standard workspace operations:State Management
Each workspace maintains its own state with:- Atomic uploads - State changes are atomic and lock-protected
- Version history - Full state version tracking
- Rollback capability - Restore previous state versions
- Checksums - Integrity verification for all state operations
Locking
OpenTaco provides robust state locking:- Automatic locking - State is locked during
plan
andapply
- Lock metadata - Tracks who locked the state and when
- Force unlock - Administrators can force unlock stuck states
- Lock timeouts - Configurable lock timeout behavior
RBAC Integration
When RBAC is enabled, workspace access is controlled by permissions:Permission Model
- unit:read - Read workspace state and metadata
- unit:write - Modify workspace state
- unit:lock - Lock/unlock workspace state
- unit:manage - Full workspace administration
Role Assignment
API Endpoints
OpenTaco implements the Terraform Cloud API v2 specification:Core Endpoints
Method | Endpoint | Description |
---|---|---|
GET | /tfe/api/v2/organizations/:org/workspaces/:name | Get workspace details |
POST | /tfe/api/v2/workspaces/:id/actions/lock | Lock workspace |
POST | /tfe/api/v2/workspaces/:id/actions/unlock | Unlock workspace |
GET | /tfe/api/v2/workspaces/:id/current-state-version | Get current state |
POST | /tfe/api/v2/workspaces/:id/state-versions | Create new state version |
Authentication Endpoints
Method | Endpoint | Description |
---|---|---|
GET | /.well-known/terraform.json | Service discovery |
GET | /oauth/authorization | OAuth2 authorization |
POST | /oauth/token | Token exchange |
GET | /oidc/jwks.json | JWT public keys (JWKS) |
Upload Endpoints
State upload endpoints are exempted from authentication middleware since Terraform doesn’t send auth headers during uploads. Security is maintained through:- Upload URLs are only provided to authenticated clients
- Lock ownership validation
- RBAC permission checks in handlers
Configuration Options
Essential Environment Variables
JWT Signing Keys (Required for Production)
OAuth State Encryption (Required for HA)
Base URL (Required behind Load Balancers)
OIDC Provider Configuration
Token Lifetime Configuration
Complete Configuration Examples
Development Setup
Production with Auth0
Production with WorkOS
Token Lifecycle and Management
Terraform Login Flow
When you runterraform login your-host
, the OAuth flow issues both token types:
token
field) and uses it for all /tfe/api/v2/*
operations.
Authentication Requirements by API Surface
API Surface | Token Type | Authentication Method | Use Case |
---|---|---|---|
/tfe/api/v2/* | Opaque | Authorization: Bearer otc_tfe_... | Terraform CLI operations |
/v1/* | JWT | Authorization: Bearer eyJ0eXA... | taco CLI, management |
/s3/* | SigV4 | AWS signature with JWT session token | S3-compatible backend |
- ✅
terraform login
→ Terraform CLI works immediately - ⚠️
taco login
→ Still required for/v1/*
management operations
Token Storage Locations
Terraform Credentials:Token Revocation
Opaque TFE Tokens:- Revoked by rotating the JWT signing key (
OPENTACO_TOKENS_KID
) - Short-lived by design (1 hour default)
- Refresh tokens can be individually invalidated (planned feature)
High Availability Considerations
Shared Secrets (Critical): All server instances must share these identical values:- Opaque tokens: Stored in S3 (HA-safe) or memory (dev only)
- JWT verification: Stateless (no storage required)
- OAuth sessions: Encrypted in URL state parameter (stateless)
- Set
OPENTACO_PUBLIC_BASE_URL
to the public-facing URL - Ensure health checks hit
/healthz
- No session affinity required (fully stateless)
Migration from Terraform Cloud
Export from Terraform Cloud
- Download state files from Terraform Cloud workspaces
- Note workspace configurations and variables
- Export team and user permissions
Import to OpenTaco
- Configure cloud blocks to point to OpenTaco
- Initialize workspaces with
terraform init
- Import existing state files:
RBAC Migration
Configure equivalent permissions in OpenTaco:Troubleshooting
Common Authentication Issues
“JWT signer not available” during OAuth:HA Deployment Issues
Authentication works on one server but not others:Load Balancer Configuration Issues
OAuth redirects to wrong URL:Token and Credential Issues
Terraform CLI shows “invalid credentials”:Debug Logging
Enable comprehensive debugging:Security Considerations
Network Security
- Use HTTPS in production environments
- Configure proper firewall rules for OpenTaco server
- Consider VPN or private network access
Authentication Security
- Use strong OIDC providers (WorkOS, Auth0, etc.)
- Configure token expiration appropriately
- Rotate signing keys periodically
State Security
- Enable encryption at rest for S3 storage
- Use IAM roles with minimal required permissions
- Audit workspace access regularly
RBAC Security
- Follow principle of least privilege
- Regular review of user permissions
- Use groups/roles rather than direct user assignments
- Monitor permission changes through audit logs