You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use secrets management (AWS Secrets Manager, HashiCorp Vault)
Consider RS256 for microservices architectures
Authorization (RBAC)
Role-Based Access Control
graph TD
subgraph "Roles"
Admin[Admin]
Operator[Operator]
Viewer[Viewer]
end
subgraph "Permissions"
DC[deployments:create]
DR[deployments:read]
DU[deployments:update]
DD[deployments:delete]
DCT[deployments:control]
UC[users:create]
UR[users:read]
UU[users:update]
UD[users:delete]
AR[audit:read]
end
Admin --> DC & DR & DU & DD & DCT
Admin --> UC & UR & UU & UD & AR
Operator --> DC & DR & DU & DCT & AR
Viewer --> DR & AR
Loading
Permission Matrix
Permission
Admin
Operator
Viewer
deployments:create
✅
✅
❌
deployments:read
✅
✅
✅
deployments:update
✅
✅
❌
deployments:delete
✅
❌
❌
deployments:control
✅
✅
❌
users:create
✅
❌
❌
users:read
✅
❌
❌
users:update
✅
❌
❌
users:delete
✅
❌
❌
audit:read
✅
✅
✅
Role Assignment Best Practices
Production Team Structure:
├── Platform Admins (admin role)
│ └── Full system access, user management
├── DevOps Engineers (operator role)
│ └── Deploy and manage applications
├── Developers (operator role)
│ └── Deploy to staging/development
└── Stakeholders (viewer role)
└── View deployment status only
Recommendations:
Principle of least privilege - assign minimum required permissions
Critical: Change default admin password immediately after installation!
# Change admin password via API
curl -X POST http://localhost:8000/api/v1/auth/change-password \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "current_password": "<your-current-password>", "new_password": "<your-secure-new-password>" }'
Network Security
TLS/SSL Configuration
graph LR
subgraph "Internet"
Client[Client]
end
subgraph "Edge"
LB[Load Balancer<br/>TLS 1.3]
end
subgraph "Internal Network"
API[API Server]
DB[(Database)]
end
Client -->|HTTPS| LB
LB -->|HTTP/2| API
API -->|TLS| DB
frompydanticimportBaseModel, Field, validatorclassDeploymentCreate(BaseModel):
service_name: str=Field(..., min_length=1, max_length=200)
environment: EnvironmentEnumstrategy: DeploymentStrategyEnumtarget_version: str=Field(..., min_length=1, max_length=100)
@validator('service_name')defvalidate_service_name(cls, v):
# Only allow alphanumeric, hyphens, and underscoresifnotre.match(r'^[a-zA-Z0-9_-]+$', v):
raiseValueError('Invalid characters in service name')
returnv
SQL Injection Prevention
# Use parameterized queries with SQLAlchemyfromsqlalchemyimportselect# Safe - parameterized queryquery=select(Deployment).where(Deployment.service_name==service_name)
# Never do this - vulnerable to SQL injection# query = f"SELECT * FROM deployments WHERE service_name = '{service_name}'"
XSS Prevention
# Escape HTML in responsesfrommarkupsafeimportescapedefformat_message(message: str) ->str:
returnescape(message)
Audit Logging
Audit Events
graph LR
subgraph "Actions"
Login[Login]
Deploy[Deployment]
Control[Control Actions]
Admin[Admin Actions]
end
subgraph "Audit Log"
AL[(Audit Log DB)]
end
subgraph "Outputs"
SIEM[SIEM]
Alert[Alerts]
Report[Reports]
end
Login --> AL
Deploy --> AL
Control --> AL
Admin --> AL
AL --> SIEM
AL --> Alert
AL --> Report
Loading
Logged Events
Event
Severity
Data Captured
Login Success
INFO
Username, IP, User-Agent
Login Failure
WARNING
Username, IP, Reason
Deployment Created
INFO
Deployment details, Creator
Deployment Started
INFO
Deployment ID, Operator
Deployment Paused
INFO
Deployment ID, Reason, Operator
Deployment Rollback
WARNING
Deployment ID, Reason, Operator
User Created
INFO
Username, Role, Creator
User Deleted
WARNING
Username, Deletor
Permission Changed
WARNING
User, Old/New Role, Admin
Audit Log Schema
CREATETABLEaudit_logs (
id SERIALPRIMARY KEY,
timestampTIMESTAMP WITH TIME ZONE DEFAULT NOW(),
action VARCHAR(100) NOT NULL,
resource_type VARCHAR(50) NOT NULL,
resource_id VARCHAR(200),
user_id INTEGERREFERENCES users(id),
username VARCHAR(100),
ip_address VARCHAR(45),
user_agent TEXT,
success BOOLEAN DEFAULT TRUE,
error_message TEXT,
request_data JSONB,
response_data JSONB
);
CREATEINDEXidx_audit_timestampON audit_logs(timestampDESC);
CREATEINDEXidx_audit_userON audit_logs(user_id);
CREATEINDEXidx_audit_actionON audit_logs(action);
Log Retention
Log Type
Retention
Storage
Security Logs
1 year
Immutable storage
Audit Logs
2 years
Encrypted storage
Access Logs
90 days
Standard storage
Error Logs
30 days
Standard storage
Secrets Management
Environment Variables
# Required secrets (must be set in production)
SECRET_KEY=<64-char-random-string>
DATABASE_URL=postgresql+asyncpg://user:password@host:5432/db
# Optional secrets
PROMETHEUS_URL=http://prometheus:9090
SLACK_WEBHOOK_URL=https://hooks.slack.com/...
graph TD
A[Incident Detected] --> B{Severity?}
B -->|Critical| C[Immediate Response]
B -->|High| D[1-Hour Response]
B -->|Medium| E[24-Hour Response]
B -->|Low| F[Next Business Day]
C --> G[Isolate System]
G --> H[Preserve Evidence]
H --> I[Investigate]
I --> J[Remediate]
J --> K[Post-Mortem]
D --> I
E --> I
F --> I