fix: comprehensive security, performance, and quality hardening
Security: apply AdminOnly middleware to mutating routes, require ENCRYPTION_KEY and ADMIN_PASSWORD (no insecure defaults), restrict CORS to same-origin, fix OIDC token delivery via cookie instead of URL query param, add rate limiting on login, add MaxBytesReader, validate volume paths against traversal, add security headers, validate user roles, add Secure flag to OIDC cookie. Performance: set SQLite MaxOpenConns(1) to prevent SQLITE_BUSY, add FK indexes on 8 columns, track notifier goroutines with WaitGroup for graceful shutdown, use GetRegistryByName instead of GetAllRegistries in deployer, pass basePath param to avoid redundant settings query, return empty slices from store to remove reflection. Quality: refactor TriggerDeploy to delegate to runDeploy (~100 lines removed), consolidate duplicated utilities (extractPort, boolToInt, now, isTerminalStatus) into shared exports, migrate all log.Printf to slog structured logging, use consistent webhook response envelope, remove dead code (parseEnvVars, duplicate auth types). UX: clean up NPM proxy on instance removal via API, add README with quickstart guide, add .env.example, require ADMIN_PASSWORD in docker-compose, document staging-net prerequisite.
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
// CreateInstance inserts a new instance record.
|
||||
func (s *Store) CreateInstance(inst Instance) (Instance, error) {
|
||||
inst.ID = uuid.New().String()
|
||||
inst.CreatedAt = now()
|
||||
inst.CreatedAt = Now()
|
||||
inst.UpdatedAt = inst.CreatedAt
|
||||
|
||||
_, err := s.db.Exec(
|
||||
@@ -32,7 +32,7 @@ func (s *Store) CreateInstanceWithID(inst Instance) (Instance, error) {
|
||||
if inst.ID == "" {
|
||||
return Instance{}, fmt.Errorf("instance ID is required")
|
||||
}
|
||||
inst.CreatedAt = now()
|
||||
inst.CreatedAt = Now()
|
||||
inst.UpdatedAt = inst.CreatedAt
|
||||
|
||||
_, err := s.db.Exec(
|
||||
@@ -75,7 +75,7 @@ func (s *Store) GetInstancesByStageID(stageID string) ([]Instance, error) {
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var instances []Instance
|
||||
instances := []Instance{}
|
||||
for rows.Next() {
|
||||
var inst Instance
|
||||
if err := rows.Scan(&inst.ID, &inst.StageID, &inst.ProjectID, &inst.ContainerID, &inst.ImageTag,
|
||||
@@ -89,7 +89,7 @@ func (s *Store) GetInstancesByStageID(stageID string) ([]Instance, error) {
|
||||
|
||||
// UpdateInstance updates an existing instance's mutable fields.
|
||||
func (s *Store) UpdateInstance(inst Instance) error {
|
||||
inst.UpdatedAt = now()
|
||||
inst.UpdatedAt = Now()
|
||||
result, err := s.db.Exec(
|
||||
`UPDATE instances SET stage_id=?, project_id=?, container_id=?, image_tag=?, subdomain=?, npm_proxy_id=?, status=?, port=?, updated_at=?
|
||||
WHERE id=?`,
|
||||
@@ -108,7 +108,7 @@ func (s *Store) UpdateInstance(inst Instance) error {
|
||||
|
||||
// UpdateInstanceStatus sets only the status field on an instance.
|
||||
func (s *Store) UpdateInstanceStatus(id string, status string) error {
|
||||
ts := now()
|
||||
ts := Now()
|
||||
result, err := s.db.Exec(
|
||||
`UPDATE instances SET status=?, updated_at=? WHERE id=?`,
|
||||
status, ts, id,
|
||||
|
||||
Reference in New Issue
Block a user