Skip to content

Commit da531d7

Browse files
remyluslosiusclaude
andcommitted
refactor(backend): Complete system_credentials removal - consolidate to unified_credentials
Step 2 of credentials migration - Remove all legacy code: 1. Dropped system_credentials table from PostgreSQL database 2. Deleted legacy backend/app/routes/system_settings.py (13 deprecated endpoints) 3. Removed v2_credentials router from main.py (deprecated /api/v2/credentials/*) 4. Updated init_roles.py init_default_system_credentials() to use unified_credentials table All credential operations now use single unified system: - Frontend: /api/system/credentials (from system_settings_unified.py) - Backend: unified_credentials table (PostgreSQL) - Init: Creates default credentials in unified_credentials Migration complete - simplified from dual-system to single unified approach. Related: docs/SIMPLE_CREDENTIALS_MIGRATION.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent bad2ba9 commit da531d7

3 files changed

Lines changed: 20 additions & 1339 deletions

File tree

backend/app/init_roles.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,19 @@ def create_default_super_admin(db: Session):
151151

152152

153153
def init_default_system_credentials(db: Session):
154-
"""Initialize default system SSH credentials for frictionless onboarding"""
154+
"""
155+
Initialize default system SSH credentials for frictionless onboarding
156+
157+
Uses unified_credentials table (system_credentials removed 2025-11-03)
158+
"""
155159
try:
156-
# Check if any system credentials already exist
160+
# Check if system-level credentials exist in unified_credentials
157161
result = db.execute(
158162
text(
159163
"""
160-
SELECT COUNT(*) as count FROM system_credentials WHERE is_active = true
164+
SELECT COUNT(*) as count
165+
FROM unified_credentials
166+
WHERE scope = 'system' AND is_active = true
161167
"""
162168
)
163169
)
@@ -168,7 +174,7 @@ def init_default_system_credentials(db: Session):
168174
logger.info(f"Found {existing_count} existing system credentials, skipping initialization")
169175
return
170176

171-
logger.info("No system credentials found - creating placeholder credentials for easy setup")
177+
logger.info("No system credentials found - creating placeholder in unified_credentials")
172178

173179
# Create placeholder credentials that guide users to configure actual credentials
174180
placeholder_description = (
@@ -185,38 +191,35 @@ def init_default_system_credentials(db: Session):
185191
encrypted_bytes = encryption_service.encrypt(b"CHANGE_ME_PLEASE")
186192
encrypted_password = base64.b64encode(encrypted_bytes).decode("ascii")
187193

188-
# Insert placeholder credentials (no actual sensitive data)
194+
# Insert into unified_credentials (NOT system_credentials)
189195
db.execute(
190196
text(
191197
"""
192-
INSERT INTO system_credentials
193-
(name, description, username, auth_method, encrypted_password,
194-
encrypted_private_key, private_key_passphrase, is_default, is_active,
195-
created_by, created_at, updated_at)
196-
VALUES (:name, :description, :username, :auth_method, :encrypted_password,
197-
:encrypted_private_key, :private_key_passphrase, :is_default, :is_active,
198-
:created_by, :created_at, :updated_at)
198+
INSERT INTO unified_credentials
199+
(name, description, username, auth_method,
200+
encrypted_password, encrypted_private_key, private_key_passphrase,
201+
scope, target_id, is_default, is_active, created_at, updated_at)
202+
VALUES (:name, :description, :username, :auth_method,
203+
:encrypted_password, :encrypted_private_key, :private_key_passphrase,
204+
'system', NULL, true, true, :created_at, :updated_at)
199205
"""
200206
),
201207
{
202208
"name": "Setup Required - Default SSH Credentials",
203209
"description": placeholder_description,
204210
"username": "root",
205211
"auth_method": "password",
206-
"encrypted_password": encrypted_password, # Obvious placeholder
212+
"encrypted_password": encrypted_password,
207213
"encrypted_private_key": None,
208214
"private_key_passphrase": None,
209-
"is_default": True,
210-
"is_active": True,
211-
"created_by": 1, # Created by default admin user
212215
"created_at": current_time,
213216
"updated_at": current_time,
214217
},
215218
)
216219

217220
db.commit()
218221

219-
logger.info("Created placeholder system credentials - users should update these in Settings")
222+
logger.info("Created placeholder system credentials in unified_credentials - users should update these in Settings")
220223
logger.warning(
221224
"SECURITY NOTICE: Default SSH credentials created with placeholder password. Users must update these credentials in Settings before performing SSH operations."
222225
)

backend/app/main.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
webhooks,
5252
)
5353
from .routes.system_settings_unified import router as system_settings_router
54-
from .routes.v2 import credentials as v2_credentials # WEEK 2: v2 credentials API
5554

5655
# Import security routes only if available
5756
try:
@@ -532,9 +531,6 @@ async def metrics():
532531
app.include_router(scan_templates.router, prefix="/api", tags=["Scan Templates"])
533532
app.include_router(webhooks.router, prefix="/api/v1", tags=["Webhooks"])
534533
app.include_router(credentials.router, tags=["Credential Sharing"])
535-
app.include_router(
536-
v2_credentials.router, prefix="/api", tags=["Credentials v2"]
537-
) # WEEK 2: v2 credentials API (adds /api prefix to router's /v2/credentials)
538534
app.include_router(api_keys.router, prefix="/api/api-keys", tags=["API Keys"])
539535
app.include_router(remediation_callback.router, tags=["AEGIS Integration"])
540536
app.include_router(

0 commit comments

Comments
 (0)