mirror of
https://github.com/Dvorinka/Primora.git
synced 2026-10-28 07:41:23 +00:00
feat: phase 6 production hardening + DB-to-DB transfer
Security:
- Graceful shutdown: http.Server + signal.NotifyContext, 10s drain,
retention sweeper cancelled before pool close
- Scoped API keys (migration 00006): ingest/read/write/admin enforced in
auth middleware; scope picker + badges in Settings UI; scopeless legacy
keys act as admin. Read-only keys now get 403 on ingest (verified live)
- nginx: baseline security headers on all responses, CSP scoped to SPA;
fixed add_header inheritance shadowing
- better-auth rate limit enabled unconditionally (was gated on NODE_ENV,
which the shipped .env sets to development)
- Mailpit moved to docker-compose.dev.yml; prod compose cannot expose it
- setup.sh generates PRIMORA_ENCRYPTION_KEY
Reliability/ops:
- Retention: per-project retention_{events,audit,webhook}_days
(migration 00007, 0=off) + hourly RetentionSweeper; edit UI in Projects
- GET /api/v1/metrics Prometheus exposition
- compose: healthchecks + restart policies everywhere, dragonfly pinned
to v2.0.0, depends_on service_healthy
- backup.sh/restore.sh (pg_dump -Fc + storage volume); restore verified
against scratch postgres+volume
- .dockerignore: exclude target dirs (build context was 4.7GB)
Correctness/testing:
- DBX transfer endpoint: POST /db-connections/:id/transfer — SQL or Redis
target, 1000-row bound, server-side creds (verified live pg→dragonfly)
- Pagination audit: ListComponents capped at 500 (auto-registers)
- CI: goose up/reset/up job + compose e2e-smoke job (smoke-e2e.sh
verified locally: signup, bootstrap, scoped keys, ingest, metrics)
- k6 load sanity script: 6650 reqs, ~217/s, 0 real failures, p95 221ms
(429s = configured rate limiter working)
Docs: DEPLOYMENT_GUIDE.md, PRODUCTION_READINESS.md; verify script
repaired (stale refs + set -e arithmetic abort). ROADMAP: phase 2 +
phase 6 marked complete.
Authored By: TDvorak <[email protected]>
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
1b34dd43bb
commit
55edbf8b56
64 files changed
+2058
-165
No files matched your search
@@ -67,6 +67,11 @@ type UpdateProjectInput struct {
|
||||
Name string `json:"name" validate:"required,min=2"`
|
||||
Slug string `json:"slug" validate:"required,min=2"`
|
||||
Description *string `json:"description"`
|
||||
// Retention windows in days; nil leaves the current value, 0 disables
|
||||
// the sweeper for that stream.
|
||||
RetentionEventsDays *int32 `json:"retention_events_days" validate:"omitempty,min=0,max=3650"`
|
||||
RetentionAuditDays *int32 `json:"retention_audit_days" validate:"omitempty,min=0,max=3650"`
|
||||
RetentionWebhookDays *int32 `json:"retention_webhook_days" validate:"omitempty,min=0,max=3650"`
|
||||
}
|
||||
|
||||
type CreateInvitationInput struct {
|
||||
@@ -78,7 +83,8 @@ type CreateInvitationInput struct {
|
||||
}
|
||||
|
||||
type CreateAPIKeyInput struct {
|
||||
Name string `json:"name" validate:"required,min=2"`
|
||||
Name string `json:"name" validate:"required,min=2"`
|
||||
Scopes []string `json:"scopes" validate:"omitempty,dive,oneof=ingest read write admin"`
|
||||
}
|
||||
|
||||
type CreateBucketInput struct {
|
||||
@@ -736,10 +742,13 @@ func (s *PlatformService) UpdateProject(ctx context.Context, actor *models.Actor
|
||||
return db.CoreProject{}, err
|
||||
}
|
||||
updated, err := s.repo.Queries().UpdateProjectByID(ctx, db.UpdateProjectByIDParams{
|
||||
ID: projectID,
|
||||
Slug: normalizeSlug(input.Slug),
|
||||
Name: strings.TrimSpace(input.Name),
|
||||
Description: input.Description,
|
||||
ID: projectID,
|
||||
Slug: normalizeSlug(input.Slug),
|
||||
Name: strings.TrimSpace(input.Name),
|
||||
Description: input.Description,
|
||||
RetentionEventsDays: input.RetentionEventsDays,
|
||||
RetentionAuditDays: input.RetentionAuditDays,
|
||||
RetentionWebhookDays: input.RetentionWebhookDays,
|
||||
})
|
||||
if err != nil {
|
||||
return db.CoreProject{}, err
|
||||
@@ -1038,6 +1047,7 @@ func (s *PlatformService) CreateAPIKey(ctx context.Context, actor *models.Actor,
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("generate api key secret: %w", err)
|
||||
}
|
||||
scopes := normalizeAPIKeyScopes(input.Scopes)
|
||||
prefix := "prm_" + prefixSuffix
|
||||
rawKey := prefix + "_" + keySuffix
|
||||
secretHash := sha256.Sum256([]byte(rawKey))
|
||||
@@ -1046,6 +1056,7 @@ func (s *PlatformService) CreateAPIKey(ctx context.Context, actor *models.Actor,
|
||||
Name: strings.TrimSpace(input.Name),
|
||||
Prefix: prefix,
|
||||
SecretHash: secretHash[:],
|
||||
Scopes: scopes,
|
||||
CreatedByUserID: pgtype.UUID{Bytes: *actor.UserID, Valid: true},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -1062,9 +1073,27 @@ func (s *PlatformService) CreateAPIKey(ctx context.Context, actor *models.Actor,
|
||||
"prefix": row.Prefix,
|
||||
"secret": rawKey,
|
||||
"name": row.Name,
|
||||
"scopes": row.Scopes,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// normalizeAPIKeyScopes dedupes the requested scopes. An omitted or empty
|
||||
// list means a full-access key — the pre-scopes behaviour.
|
||||
func normalizeAPIKeyScopes(input []string) []string {
|
||||
if len(input) == 0 {
|
||||
return []string{"admin"}
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
out := make([]string, 0, len(input))
|
||||
for _, s := range input {
|
||||
if !seen[s] {
|
||||
seen[s] = true
|
||||
out = append(out, s)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *PlatformService) RevokeAPIKey(ctx context.Context, actor *models.Actor, projectID, apiKeyID uuid.UUID, requestID string) error {
|
||||
if err := s.requireProjectRole(ctx, actor, projectID, "admin"); err != nil {
|
||||
return err
|
||||
|
||||
Reference in new issue
Block a user