Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Backend] Create Production-Grade Super Admin Setup Script (Secure, Idempotent, Environment-Safe)

Aperta
#2 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
node.js, typescript

Direzione di ricerca

Start with the requested scripts/createSuperAdmin.js entry point and inspect the existing user schema, role definitions, database connection, and audit-log conventions before choosing an implementation path. Run the proposed npm run create:superadmin flow in development, then verify that valid creation, repeated execution, invalid inputs, database failures, and production flag enforcement meet the acceptance criteria.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

We need a setup script to create the first Super Admin in the system.

👉 This is required because:

  • System starts empty
  • No admin exists initially
  • We need a secure way to bootstrap admin access

🎯 Goals

Build a script that is:

  • Secure (no unauthorized access)
  • Idempotent (runs safely multiple times)
  • Environment-aware (dev vs prod safe)
  • Easy to use (CLI or script)
  • Production-ready

🧱 Features to Build


1. Super Admin Creation Script

Command
npm run create:superadmin

OR

node scripts/createSuperAdmin.js

2. Required Inputs

Script should accept:

fullName
email
password

Input Methods

Support:

  • CLI prompt (preferred)
  • Environment variables (for automation)

Example:

[email protected] npm run create:superadmin


3. What Script Should Do


Step-by-Step Flow
Start script
→ Validate inputs
→ Check if admin already exists
→ If exists → stop (no duplicate)
→ Hash password
→ Create user with role = SuperAdmin
→ Mark emailVerified = true
→ Save audit log
→ Show success message


4. Role Definition

Add new role:

SuperAdmin

Permissions

SuperAdmin can:

  • approve/reject communities
  • suspend communities
  • view all data
  • manage users


🔐 Security Requirements


1. Password Security

  • Use bcrypt
  • Minimum 10 salt rounds

2. Script Protection (IMPORTANT)

Prevent misuse:

In Production:
  • Allow script ONLY if:

    ALLOW_ADMIN_BOOTSTRAP=true
    

After first admin:
  • Disable script automatically OR
  • Prevent creating second super admin


3. Idempotency

If script runs again:

If admin exists → exit safely

4. Input Validation

Validate:

  • email format
  • strong password
  • required fields


🧾 Database Changes


User Schema Update

Add:

role = SuperAdmin


🧾 Audit Logs

Log action:

super_admin_created


⚙️ Implementation Details


File Location

scripts/createSuperAdmin.js

Structure

connect DB
→ read input
→ validate
→ check existing admin
→ create admin
→ log
→ exit


🧪 Testing


Manual Testing

  • run script locally
  • run script twice (should not duplicate)

Edge Cases

  • missing input
  • weak password
  • DB connection failure


🌍 Environment Handling


DEV

  • allow easy creation

PRODUCTION

  • require env flag
  • log action
  • restrict multiple runs


⚠️ Error Handling


Return clear errors:

"Super admin already exists"
"Invalid email format"
"Password too weak"


🧠 Optional Enhancements (Recommended)


1. Interactive CLI

Use:

  • inquirer

2. Mask Password Input

  • hide password in terminal

3. Confirmation Step

"Are you sure you want to create super admin?"

4. Seeder Support

Allow script to run in:

CI/CD pipelines


📊 Observability

Log:

  • script run
  • success/failure
  • timestamp


🔐 Advanced Security (Optional but Strong)


1. One-Time Token

Require:

ADMIN_SETUP_SECRET

2. IP Restriction

Allow only trusted IPs (optional)



✅ Acceptance Criteria


✔ Script creates super admin
✔ Password securely hashed
✔ No duplicate admin created
✔ Works in dev & prod
✔ Protected by env flag
✔ Logs action
✔ Handles errors properly
✔ Easy to run

Lingua principale
TypeScript
Stelle
1
Fork
0
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Non abbiamo ancora controllato i file di configurazione di questo progetto. Parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NexGenStudioDev/CommDesk-Backend

Tutte le issue di NexGenStudioDev/CommDesk-Backend

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.