Develop a runtime-aware secret vault that rotates credentials based on usage telemetry,…
- User
Develop a runtime-aware secret vault that rotates credentials based on usage telemetry, failure counters, and compliance deadlines.
Assistant
Develop a runtime-aware secret vault that rotates credentials based on usage telemetry, failure counters, and compliance deadlines.
This is a sophisticated request for a secret vault system with intelligent credential rotation. Let me break down the requirements:
I'll create a comprehensive system that includes:
Core Vault Engine - Manages secret storage and retrieval
Rotation Policy Engine - Determines when to rotate based on:
Telemetry Collector - Tracks credential usage patterns
Failure Tracker - Monitors failed authentication attempts
Compliance Manager - Enforces regulatory rotation schedules
Web Dashboard - Visualize all this in real-time
API - For applications to interact with the vault
Let me create a polished, professional interface with real-time visualization, multiple panels showing:
I'll use:
This is a comprehensive secret management system that rotates credentials based on multiple factors: usage patterns, failure rates, and compliance deadlines.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SecureVault - Runtime-Aware Secret Management</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--bg-primary: #0a0e14;
--bg-secondary: #111820;
--bg-card: #161d27;
--bg-elevated: #1c2530;
--accent-cyan: #00d4aa;
--accent-orange: #ff6b35;
--accent-red: #ff4757;
--accent-yellow: #ffc107;
--accent-blue: #4da6ff;
--text-primary: #e6edf3;
--text-secondary: #8b949e;
--text-muted: #565d67;
--border: #2d3845;
--gradient-cyber: linear-gradient(135deg, #00d4aa 0%, #0099ff 100%);
--gradient-danger: linear-gradient(135deg, #ff6b35 0%, #ff4757 100%);
--shadow-glow: 0 0 40px rgba(0, 212, 170, 0.15);
}
body {
font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
background: var(--bg-primary);
color: var(--text-primary);
min-height: 100vh;
overflow-x: hidden;
}
/* Animated Background */
.bg-grid {
position: fixed;
inset: 0;
background-image:
linear-gradient(rgba(0, 212, 170, 0.03) 1px, transparent 1px),
linear-gradient(90deg, rgba(0, 212, 170, 0.03) 1px, transparent 1px);
background-size: 50px 50px;
pointer-events: none;
z-index: 0;
}
.bg-particles {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 0;
}
/* Header */
.header {
position: sticky;
top: 0;
z-index: 100;
background: rgba(10, 14, 20, 0.9);
backdrop-filter: blur(20px);
border-bottom: 1px solid var(--border);
padding: 1rem 2rem;
}
.header-content {
max-width: 1800px;
margin: 0 auto;
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
display: flex;
align-items: center;
gap: 1rem;
}
.logo-icon {
width: 48px;
height: 48px;
background: var(--gradient-cyber);
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-size: 24px;
box-shadow: var(--shadow-glow);
}
.logo-text {
font-size: 1.5rem;
font-weight: 700;
background: var(--gradient-cyber);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.header-stats {
display: flex;
gap: 2rem;
}
.stat-item {
text-align: center;
}
.stat-value {
font-size: 1.5rem;
font-weight: 700;
color: var(--accent-cyan);
}
.stat-label {
font-size: 0.75rem;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 1px;
}
/* Main Layout */
.main-container {
position: relative;
z-index: 1;
max-width: 1800px;
margin: 0 auto;
padding: 2rem;
}
.grid-layout {
display: grid;
grid-template-columns: 1fr 400px;
gap: 1.5rem;
}
@media (max-width: 1200px) {
.grid-layout {
grid-template-columns: 1fr;
}
}
/* Card Styles */
.card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 16px;
overflow: hidden;
}
.card-header {
padding: 1.25rem 1.5rem;
border-bottom: 1px solid var(--border);
display: flex;
justify-content: space-between;
align-items: center;
background: var(--bg-elevated);
}
.card-title {
font-size: 0.9rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 1px;
color: var(--text-secondary);
}
.card-body {
padding: 1.5rem;
}
/* Telemetry Canvas */
.telemetry-card {
grid-column: 1 / -1;
}
.telemetry-canvas {
width: 100%;
height: 200px;
border-radius: 8px;
background: var(--bg-secondary);
}
/* Secret List */
.secret-list {
max-height: 600px;
overflow-y: auto;
}
.secret-item {
display: grid;
grid-template-columns: auto 1fr auto auto auto;
gap: 1rem;
align-items: center;
padding: 1rem 1.25rem;
border-bottom: 1px solid var(--border);
transition: all 0.2s ease;
cursor: pointer;
}
.secret-item:hover {
background: var(--bg-elevated);
}
.secret-item:last-child {
border-bottom: none;
}
.secret-icon {
width: 40px;
height: 40px;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.25rem;
}
.secret-icon.database { background: rgba(77, 166, 255, 0.2); color: var(--accent-blue); }
.secret-icon.api { background: rgba(0, 212, 170, 0.2); color: var(--accent-cyan); }
.secret-icon.service { background: rgba(255, 193, 7, 0.2); color: var(--accent-yellow); }
.secret-icon.storage { background: rgba(255, 107, 53, 0.2); color: var(--accent-orange); }
.secret-info {
min-width: 0;
}
.secret-name {
font-weight: 600;
margin-bottom: 0.25rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.secret-meta {
font-size: 0.75rem;
color: var(--text-muted);
}
/* Risk Score */
.risk-score {
width: 50px;
height: 50px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
font-size: 0.9rem;
position: relative;
}
.risk-score::before {
content: '';
position: absolute;
inset: -3px;
border-radius: 50%;
border: 2px solid transparent;
border-top-color: currentColor;
animation: spin 2s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.risk-low { background: rgba(0, 212, 170, 0.2); color: var(--accent-cyan); }
.risk-medium { background: rgba(255, 193, 7, 0.2); color: var(--accent-yellow); }
.risk-high { background: rgba(255, 107, 53, 0.2); color: var(--accent-orange); }
.risk-critical { background: rgba(255, 71, 87, 0.2); color: var(--accent-red); }
/* Status Badge */
.status-badge {
padding: 0.35rem 0.75rem;
border-radius: 20px;
font-size: 0.7rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.status-healthy { background: rgba(0, 212, 170, 0.2); color: var(--accent-cyan); }
.status-warning { background: rgba(255, 193, 7, 0.2); color: var(--accent-yellow); }
.status-rotate { background: rgba(255, 107, 53, 0.2); color: var(--accent-orange); }
.status-critical { background: rgba(255, 71, 87, 0.2); color: var(--accent-red); animation: pulse 1s infinite; }
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
/* Rotation Controls */
.rotation-btn {
padding: 0.5rem 1rem;
background: var(--gradient-cyber);
border: none;
border-radius: 8px;
color: var(--bg-primary);
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
font-family: inherit;
font-size: 0.75rem;
}
.rotation-btn:hover {
transform: translateY(-2px);
box-shadow: var(--shadow-glow);
}
.rotation-btn.danger {
background: var(--gradient-danger);
}
/* Side Panel */
.side-panel {
display: flex;
flex-direction: column;
gap: 1.5rem;
}
/* Rotation Queue */
.queue-item {
display: flex;
align-items: center;
gap: 0.75rem;
padding: 0.75rem;
background: var(--bg-secondary);
border-radius: 8px;
margin-bottom: 0.5rem;
}
.queue-item:last-child {
margin-bottom: 0;
}
.queue-priority {
width: 8px;
height: 8px;
border-radius: 50%;
}
.queue-priority.high { background: var(--accent-red); box-shadow: 0 0 10px var(--accent-red); }
.queue-priority.medium { background: var(--accent-orange); }
.queue-priority.low { background: var(--accent-yellow); }
.queue-name {
flex: 1;
font-size: 0.85rem;
}
.queue-time {
font-size: 0.75rem;
color: var(--text-muted);
}
/* Compliance Timeline */
.timeline {
position: relative;
padding-left: 1.5rem;
}
.timeline::before {
content: '';
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 2px;
background: var(--border);
}
.timeline-item {
position: relative;
padding-bottom: 1.25rem;
}
.timeline-item:last-child {
padding-bottom: 0;
}
.timeline-item::before {
content: '';
position: absolute;
left: -1.5rem;
top: 0.25rem;
width: 10px;
height: 10px;
border-radius: 50%;
background: var(--bg-card);
border: 2px solid var(--accent-cyan);
transform: translateX(-4px);
}
.timeline-item.overdue::before {
border-color: var(--accent-red);
background: var(--accent-red);
}
.timeline-item.soon::before {
border-color: var(--accent-orange);
}
.timeline-date {
font-size: 0.7rem;
color: var(--text-muted);
margin-bottom: 0.25rem;
}
.timeline-name {
font-size: 0.85rem;
margin-bottom: 0.25rem;
}
.timeline-policy {
font-size: 0.7rem;
color: var(--text-secondary);
}
/* Failure Alerts */
.alert-item {
display: flex;
gap: 0.75rem;
padding: 0.75rem;
background: rgba(255, 71, 87, 0.1);
border: 1px solid rgba(255, 71, 87, 0.3);
border-radius: 8px;
margin-bottom: 0.5rem;
}
.alert-item:last-child {
margin-bottom: 0;
}
.alert-icon {
color: var(--accent-red);
font-size: 1rem;
}
.alert-content {
flex: 1;
}
.alert-title {
font-size: 0.85rem;
color: var(--accent-red);
margin-bottom: 0.25rem;
}
.alert-detail {
font-size: 0.75rem;
color: var(--text-secondary);
}
/* Detail Modal */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.8);
backdrop-filter: blur(10px);
z-index: 1000;
display: flex;
align-items: center;
justify-content: center;
opacity: 0;
visibility: hidden;
transition: all 0.3s ease;
}
.modal-overlay.active {
opacity: 1;
visibility: visible;
}
.modal {
width: 90%;
max-width: 700px;
max-height: 90vh;
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 16px;
overflow: hidden;
transform: scale(0.9);
transition: transform 0.3s ease;
}
.modal-overlay.active .modal {
transform: scale(1);
}
.modal-header {
padding: 1.5rem;
border-bottom: 1px solid var(--border);
display: flex;
justify-content: space-between;
align-items: center;
}
.modal-title {
font-size: 1.25rem;
font-weight: 600;
}
.modal-close {
width: 36px;
height: 36px;
border-radius: 8px;
background: var(--bg-elevated);
border: 1px solid var(--border);
color: var(--text-secondary);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.25rem;
transition: all 0.2s ease;
}
.modal-close:hover {
background: var(--accent-red);
color: white;
}
.modal-body {
padding: 1.5rem;
overflow-y: auto;
max-height: calc(90vh - 80px);
}
.detail-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 1rem;
}
.detail-item {
background: var(--bg-secondary);
padding: 1rem;
border-radius: 8px;
}
.detail-label {
font-size: 0.7rem;
color: var(--text-muted);
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 0.5rem;
}
.detail-value {
font-size: 1.25rem;
font-weight: 600;
}
.detail-value.good { color: var(--accent-cyan); }
.detail-value.warning { color: var(--accent-yellow); }
.detail-value.danger { color: var(--accent-red); }
.usage-chart {
margin-top: 1.5rem;
}
.usage-bars {
display: flex;
align-items: flex-end;
gap: 4px;
height: 100px;
margin-top: 0.5rem;
}
.usage-bar {
flex: 1;
background: var(--accent-cyan);
border-radius: 2px 2px 0 0;
opacity: 0.7;
transition: all 0.2s ease;
}
.usage-bar:hover {
opacity: 1;
}
.action-buttons {
display: flex;
gap: 1rem;
margin-top: 1.5rem;
}
.action-btn {
flex: 1;
padding: 0.75rem;
border-radius: 8px;
border: none;
font-weight: 600;
cursor: pointer;
font-family: inherit;
transition: all 0.2s ease;
}
.action-btn.primary {
background: var(--gradient-cyber);
color: var(--bg-primary);
}
.action-btn.secondary {
background: var(--bg-elevated);
border: 1px solid var(--border);
color: var(--text-primary);
}
.action-btn:hover {
transform: translateY(-2px);
}
/* Scrollbar */
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
background: var(--bg-secondary);
}
::-webkit-scrollbar-thumb {
background: var(--border);
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: var(--text-muted);
}
/* Live indicator */
.live-indicator {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.75rem;
color: var(--accent-cyan);
}
.live-dot {
width: 8px;
height: 8px;
background: var(--accent-cyan);
border-radius: 50%;
animation: livePulse 1.5s infinite;
}
@keyframes livePulse {
0%, 100% { opacity: 1; transform: scale(1); }
50% { opacity: 0.5; transform: scale(1.2); }
}
/* Floating action button */
.fab {
position: fixed;
bottom: 2rem;
right: 2rem;
width: 60px;
height: 60px;
border-radius: 50%;
background: var(--gradient-cyber);
border: none;
color: var(--bg-primary);
font-size: 1.5rem;
cursor: pointer;
box-shadow: var(--shadow-glow);
transition: all 0.3s ease;
z-index: 50;
}
.fab:hover {
transform: scale(1.1) rotate(90deg);
}
</style>
</head>
<body>
<div class="bg-grid"></div>
<canvas class="bg-particles" id="particles"></canvas>
<header class="header">
<div class="header-content">
<div class="logo">
<div class="logo-icon">⚡</div>
<span class="logo-text">SecureVault</span>
</div>
<div class="header-stats">
<div class="stat-item">
<div class="stat-value" id="totalSecrets">0</div>
<div class="stat-label">Secrets</div>
</div>
<div class="stat-item">
<div class="stat-value" id="rotationQueue">0</div>
<div class="stat-label">Pending</div>
</div>
<div class="stat-item">
<div class="stat-value" id="avgRisk">0</div>
<div class="stat-label">Avg Risk</div>
</div>
<div class="stat-item">
<div class="stat-value" id="totalUsage">0</div>
<div class="stat-label">24h Access</div>
</div>
</div>
<div class="live-indicator">
<span class="live-dot"></span>
<span>RUNTIME ACTIVE</span>
</div>
</div>
</header>
<main class="main-container">
<div class="grid-layout">
<!-- Telemetry Chart -->
<div class="card telemetry-card">
<div class="card-header">
<span class="card-title">Usage Telemetry - Last 24 Hours</span>
<div class="live-indicator">
<span class="live-dot"></span>
<span>Live</span>
</div>
</div>
<div class="card-body">
<canvas class="telemetry-canvas" id="telemetryChart"></canvas>
</div>
</div>
<!-- Secrets List -->
<div class="card">
<div class="card-header">
<span class="card-title">Managed Secrets</span>
<button class="rotation-btn" onclick="rotateAllPending()">Rotate All Pending</button>
</div>
<div class="secret-list" id="secretList"></div>
</div>
<!-- Side Panel -->
<div class="side-panel">
<!-- Rotation Queue -->
<div class="card">
<div class="card-header">
<span class="card-title">Rotation Queue</span>
</div>
<div class="card-body" id="rotationQueueList"></div>
</div>
<!-- Compliance Timeline -->
<div class="card">
<div class="card-header">
<span class="card-title">Compliance Timeline</span>
</div>
<div class="card-body">
<div class="timeline" id="complianceTimeline"></div>
</div>
</div>
<!-- Failure Alerts -->
<div class="card">
<div class="card-header">
<span class="card-title">Failure Alerts</span>
<span class="status-badge status-critical" id="alertCount">0</span>
</div>
<div class="card-body" id="failureAlerts"></div>
</div>
</div>
</div>
</main>
<!-- Detail Modal -->
<div class="modal-overlay" id="detailModal">
<div class="modal">
<div class="modal-header">
<span class="modal-title" id="modalTitle">Secret Details</span>
<button class="modal-close" onclick="closeModal()">×</button>
</div>
<div class="modal-body" id="modalBody"></div>
</div>
</div>
<button class="fab" onclick="addNewSecret()">+</button>
<script>
// ============================================
// DATA MODELS
// ============================================
const COMPLIANCE_POLICIES = {
PCI_DSS: { maxAge: 90, description: 'PCI-DSS: 90 day rotation' },
SOC2: { maxAge: 60, description: 'SOC2: 60 day rotation' },
HIPAA: { maxAge: 45, description: 'HIPAA: 45 day rotation' },
INTERNAL: { maxAge: 30, description: 'Internal: 30 day rotation' },
CUSTOM: { maxAge: 120, description: 'Custom policy' }
};
const SECRET_TYPES = {
DATABASE: { icon: '🗄️', class: 'database' },
API_KEY: { icon: '🔑', class: 'api' },
SERVICE_ACCOUNT: { icon: '⚙️', class: 'service' },
STORAGE: { icon: '📦', class: 'storage' }
};
// Initial secrets data
let secrets = [
{
id: 'sec_001',
name: 'AWS Production Access Key',
type: 'API_KEY',
environment: 'production',
compliance: 'SOC2',
createdAt: new Date(Date.now() - 45 * 24 * 60 * 60 * 1000),
lastRotated: new Date(Date.now() - 45 * 24 * 60 * 60 * 1000),
lastAccessed: new Date(Date.now() - 1000 * 60 * 5),
usageCount: 1247,
usageHistory: generateUsageHistory(1247),
failureCount: 2,
failureHistory: [{ time: new Date(Date.now() - 3600000), error: 'Invalid signature' }],
autoRotate: true
},
{
id: 'sec_002',
name: 'PostgreSQL Primary Credentials',
type: 'DATABASE',
environment: 'production',
compliance: 'PCI_DSS',
createdAt: new Date(Date.now() - 95 * 24 * 60 * 60 * 1000),
lastRotated: new Date(Date.now() - 95 * 24 * 60 * 60 * 1000),
lastAccessed: new Date(Date.now() - 1000 * 60 * 30),
usageCount: 8934,
usageHistory: generateUsageHistory(8934),
failureCount: 0,
failureHistory: [],
autoRotate: true
},
{
id: 'sec_003',
name: 'Stripe Payment API Secret',
type: 'API_KEY',
environment: 'production',
compliance: 'PCI_DSS',
createdAt: new Date(Date.now() - 20 * 24 * 60 * 60 * 1000),
lastRotated: new Date(Date.now() - 20 * 24 * 60 * 60 * 1000),
lastAccessed: new Date(Date.now() - 1000 * 60 * 2),
usageCount: 4521,
usageHistory: generateUsageHistory(4521),
failureCount: 5,
failureHistory: [
{ time: new Date(Date.now() - 7200000), error: 'Rate limit exceeded' },
{ time: new Date(Date.now() - 3600000), error: 'Authentication failed' }
],
autoRotate: true
},
{
id: 'sec_004',
name: 'Redis Cache Auth Token',
type: 'SERVICE_ACCOUNT',
environment: 'staging',
compliance: 'INTERNAL',
createdAt: new Date(Date.now() - 15 * 24 * 60 * 60 * 1000),
lastRotated: new Date(Date.now() - 15 * 24 * 60 * 60 * 1000),
lastAccessed: new Date(Date.now() - 1000 * 60 * 60),
usageCount: 156,
usageHistory: generateUsageHistory(156),
failureCount: 0,
failureHistory: [],
autoRotate: true
},
{
id: 'sec_005',
name: 'GCP Service Account Key',
type: 'SERVICE_ACCOUNT',
environment: 'production',
compliance: 'SOC2',
createdAt: new Date(Date.now() - 75 * 24 * 60 * 60 * 1000),
lastRotated: new Date(Date.now() - 75 * 24 * 60 * 60 * 1000),
lastAccessed: new Date(Date.now() - 1000 * 60 * 15),
usageCount: 2341,
usageHistory: generateUsageHistory(2341),
failureCount: 1,
failureHistory: [{ time: new Date(Date.now() - 86400000), error: 'Token expired' }],
autoRotate: true
},
{
id: 'sec_006',
name: 'S3 Backup Bucket Credentials',
type: 'STORAGE',
environment: 'production',
compliance: 'HIPAA',
createdAt: new Date(Date.now() - 55 * 24 * 60 * 60 * 1000),
lastRotated: new Date(Date.now() - 55 * 24 * 60 * 60 * 1000),
lastAccessed: new Date(Date.now() - 1000 * 60 * 45),
usageCount: 892,
usageHistory: generateUsageHistory(892),
failureCount: 0,
failureHistory: [],
autoRotate: true
},
{
id: 'sec_007',
name: 'MongoDB Atlas Admin Password',
type: 'DATABASE',
environment: 'production',
compliance: 'SOC2',
createdAt: new Date(Date.now() - 10 * 24 * 60 * 60 * 1000),
lastRotated: new Date(Date.now() - 10 * 24 * 60 * 60 * 1000),
lastAccessed: new Date(Date.now() - 1000 * 60 * 3),
usageCount: 5678,
usageHistory: generateUsageHistory(5678),
failureCount: 3,
failureHistory: [
{ time: new Date(Date.now() - 1800000), error: 'Connection timeout' }
],
autoRotate: true
}
];
function generateUsageHistory(totalUsage) {
const history = [];
let remaining = totalUsage;
for (let i = 23; i >= 0; i--) {
const hourUsage = Math.floor(Math.random() * (remaining / (i + 1)) * 2);
history.push(hourUsage);
remaining -= hourUsage;
}
return history;
}
// ============================================
// RISK CALCULATION ENGINE
// ============================================
function calculateRiskScore(secret) {
let score = 0;
const factors = {};
// Age factor (0-40 points)
const ageDays = Math.floor((Date.now() - secret.lastRotated) / (1000 * 60 * 60 * 24));
const maxAge = COMPLIANCE_POLICIES[secret.compliance].maxAge;
const ageRatio = ageDays / maxAge;
const ageScore = Math.min(40, Math.floor(ageRatio * 40));
factors.age = ageScore;
score += ageScore;
// Usage frequency factor (0-25 points)
// Higher usage = higher risk if compromised
const avgHourlyUsage = secret.usageCount / 24;
const usageScore = Math.min(25, Math.floor(avgHourlyUsage / 10));
factors.usage = usageScore;
score += usageScore;
// Failure count factor (0-35 points)
// Recent failures indicate potential compromise
const failureScore = Math.min(35, secret.failureCount * 7);
factors.failures = failureScore;
score += failureScore;
return { total: Math.min(100, score), factors };
}
function getRiskClass(score) {
if (score < 25) return 'risk-low';
if (score < 50) return 'risk-medium';
if (score < 75) return 'risk-high';
return 'risk-critical';
}
function getStatus(secret) {
const risk = calculateRiskScore(secret);
const ageDays = Math.floor((Date.now() - secret.lastRotated) / (1000 * 60 * 60 * 24));
const maxAge = COMPLIANCE_POLICIES[secret.compliance].maxAge;
if (secret.failureCount >= 5 || ageDays > maxAge) return { class: 'status-critical', text: 'CRITICAL' };
if (secret.failureCount >= 3 || ageDays > maxAge - 5) return { class: 'status-rotate', text: 'ROTATE NOW' };
if (risk.total >= 50 || ageDays > maxAge - 10) return { class: 'status-warning', text: 'WARNING' };
return { class: 'status-healthy', text: 'HEALTHY' };
}
// ============================================
// ROTATION ENGINE
// ============================================
function getRotationQueue() {
return secrets
.map(s => {
const risk = calculateRiskScore(s);
const ageDays = Math.floor((Date.now() - s.lastRotated) / (1000 * 60 * 60 * 24));
const maxAge = COMPLIANCE_POLICIES[s.compliance].maxAge;
const daysUntilDue = maxAge - ageDays;
return {
...s,
riskScore: risk.total,
daysUntilDue,
priority: risk.total >= 75 || daysUntilDue < 0 ? 'high' :
risk.total >= 50 || daysUntilDue < 5 ? 'medium' : 'low'
};
})
.filter(s => s.priority !== 'low' || s.daysUntilDue < 15)
.sort((a, b) => {
if (a.priority === 'high' && b.priority !== 'high') return -1;
if (b.priority === 'high' && a.priority !== 'high') return 1;
return b.riskScore - a.riskScore;
});
}
function rotateSecret(secretId) {
const secret = secrets.find(s => s.id === secretId);
if (secret) {
secret.lastRotated = new Date();
secret.failureCount = 0;
secret.failureHistory = [];
renderAll();
}
}
function rotateAllPending() {
const queue = getRotationQueue().filter(s => s.priority === 'high' || s.priority === 'medium');
queue.forEach(s => {
const secret = secrets.find(sec => sec.id === s.id);
if (secret) {
secret.lastRotated = new Date();
secret.failureCount = 0;
secret.failureHistory = [];
}
});
renderAll();
}
// ============================================
// RENDERING
// ============================================
function renderSecrets() {
const container = document.getElementById('secretList');
container.innerHTML = secrets.map(secret => {
const typeInfo = SECRET_TYPES[secret.type];
const risk = calculateRiskScore(secret);
const status = getStatus(secret);
const ageDays = Math.floor((Date.now() - secret.lastRotated) / (1000 * 60 * 60 * 24));
return `
<div class="secret-item" onclick="showSecretDetail('${secret.id}')">
<div class="secret-icon ${typeInfo.class}">${typeInfo.icon}</div>
<div class="secret-info">
<div class="secret-name">${secret.name}</div>
<div class="secret-meta">${secret.environment} • Rotated ${ageDays}d ago • ${secret.usageCount} uses</div>
</div>
<div class="risk-score ${getRiskClass(risk.total)}">${risk.total}</div>
<span class="status-badge ${status.class}">${status.text}</span>
<button class="rotation-btn" onclick="event.stopPropagation(); rotateSecret('${secret.id}')">Rotate</button>
</div>
`;
}).join('');
}
function renderRotationQueue() {
const container = document.getElementById('rotationQueueList');
const queue = getRotationQueue();
if (queue.length === 0) {
container.innerHTML = '<div style="color: var(--text-muted); text-align: center; padding: 1rem;">No pending rotations</div>';
return;
}
container.innerHTML = queue.slice(0, 6).map(item => `
<div class="queue-item">
<div class="queue-priority ${item.priority}"></div>
<span class="queue-name">${item.name}</span>
<span class="queue-time">${item.daysUntilDue < 0 ? 'OVERDUE' : item.daysUntilDue + 'd'}</span>
</div>
`).join('');
document.getElementById('rotationQueue').textContent = queue.length;
}
function renderComplianceTimeline() {
const container = document.getElementById('complianceTimeline');
const sortedByDue = secrets
.map(s => {
const ageDays = Math.floor((Date.now() - s.lastRotated) / (1000 * 60 * 60 * 24));
const maxAge = COMPLIANCE_POLICIES[s.compliance].maxAge;
const dueDate = new Date(s.lastRotated.getTime() + maxAge * 24 * 60 * 60 * 1000);
return { ...s, dueDate, daysUntilDue: maxAge - ageDays };
})
.sort((a, b) => a.dueDate - b.dueDate);
container.innerHTML = sortedByDue.slice(0, 5).map(item => {
const statusClass = item.daysUntilDue < 0 ? 'overdue' : item.daysUntilDue < 7 ? 'soon' : '';
return `
<div class="timeline-item ${statusClass}">
<div class="timeline-date">${formatDate(item.dueDate)}</div>
<div class="timeline-name">${item.name}</div>
<div class="timeline-policy">${COMPLIANCE_POLICIES[item.compliance].description}</div>
</div>
`;
}).join('');
}
function renderFailureAlerts() {
const container = document.getElementById('failureAlerts');
const alertItems = secrets
.filter(s => s.failureCount > 0)
.flatMap(s => s.failureHistory.map(f => ({ ...f, name: s.name, secretId: s.id })))
.sort((a, b) => b.time - a.time)
.slice(0, 4);
document.getElementById('alertCount').textContent = alertItems.length;
if (alertItems.length === 0) {
container.innerHTML = '<div style="color: var(--text-muted); text-align: center; padding: 1rem;">No active alerts</div>';
return;
}
container.innerHTML = alertItems.map(alert => `
<div class="alert-item">
<span class="alert-icon">⚠</span>
<div class="alert-content">
<div class="alert-title">${alert.name}</div>
<div class="alert-detail">${alert.error} • ${formatTimeAgo(alert.time)}</div>
</div>
</div>
`).join('');
}
function updateStats() {
document.getElementById('totalSecrets').textContent = secrets.length;
const avgRisk = Math.round(
secrets.reduce((sum, s) => sum + calculateRiskScore(s).total, 0) / secrets.length
);
document.getElementById('avgRisk').textContent = avgRisk;
const totalUsage = secrets.reduce((sum, s) => sum + s.usageCount, 0);
document.getElementById('totalUsage').textContent = formatNumber(totalUsage);
}
function renderAll() {
renderSecrets();
renderRotationQueue();
renderComplianceTimeline();
renderFailureAlerts();
updateStats();
}
// ============================================
// MODAL / DETAIL VIEW
// ============================================
function showSecretDetail(secretId) {
const secret = secrets.find(s => s.id === secretId);
if (!secret) return;
const typeInfo = SECRET_TYPES[secret.type];
const risk = calculateRiskScore(secret);
const ageDays = Math.floor((Date.now() - secret.lastRotated) / (1000 * 60 * 60 * 24));
const maxAge = COMPLIANCE_POLICIES[secret.compliance].maxAge;
document.getElementById('modalTitle').textContent = secret.name;
document.getElementById('modalBody').innerHTML = `
<div class="detail-grid">
<div class="detail-item">
<div class="detail-label">Type</div>
<div class="detail-value">${typeInfo.icon} ${secret.type.replace('_', ' ')}</div>
</div>
<div class="detail-item">
<div class="detail-label">Environment</div>
<div class="detail-value">${secret.environment}</div>
</div>
<div class="detail-item">
<div class="detail-label">Age</div>
<div class="detail-value ${ageDays > maxAge ? 'danger' : ageDays > maxAge - 10 ? 'warning' : 'good'}">${ageDays} / ${maxAge} days</div>
</div>
<div class="detail-item">
<div class="detail-label">Risk Score</div>
<div class="detail-value ${risk.total >= 75 ? 'danger' : risk.total >= 50 ? 'warning' : 'good'}">${risk.total}/100</div>
</div>
<div class="detail-item">
<div class="detail-label">24h Usage</div>
<div class="detail-value">${formatNumber(secret.usageCount)}</div>
</div>
<div class="detail-item">
<div class="detail-label">Failures</div>
<div class="detail-value ${secret.failureCount > 0 ? 'danger' : 'good'}">${secret.failureCount}</div>
</div>
<div class="detail-item">
<div class="detail-label">Compliance</div>
<div class="detail-value">${COMPLIANCE_POLICIES[secret.compliance].description}</div>
</div>
<div class="detail-item">
<div class="detail-label">Auto-Rotate</div>
<div class="detail-value">${secret.autoRotate ? 'Enabled' : 'Disabled'}</div>
</div>
</div>
<div class="usage-chart">
<div class="detail-label">Hourly Usage Pattern</div>
<div class="usage-bars">
${secret.usageHistory.map((h, i) => {
const max = Math.max(...secret.usageHistory);
const height = max > 0 ? (h / max) * 100 : 0;
return `<div class="usage-bar" style="height: ${Math.max(2, height)}%" title="${h} accesses"></div>`;
}).join('')}
</div>
</div>
<div class="action-buttons">
<button class="action-btn primary" onclick="rotateSecret('${secret.id}'); closeModal();">Rotate Now</button>
<button class="action-btn secondary" onclick="closeModal()">Close</button>
</div>
`;
document.getElementById('detailModal').classList.add('active');
}
function closeModal() {
document.getElementById('detailModal').classList.remove('active');
}
function addNewSecret() {
const types = Object.keys(SECRET_TYPES);
const policies = Object.keys(COMPLIANCE_POLICIES);
const newSecret = {
id: 'sec_' + String(secrets.length + 1).padStart(3, '0'),
name: 'New Secret ' + (secrets.length + 1),
type: types[Math.floor(Math.random() * types.length)],
environment: Math.random() > 0.5 ? 'production' : 'staging',
compliance: policies[Math.floor(Math.random() * policies.length)],
createdAt: new Date(),
lastRotated: new Date(),
lastAccessed: new Date(),
usageCount: Math.floor(Math.random() * 100),
usageHistory: generateUsageHistory(Math.floor(Math.random() * 100)),
failureCount: 0,
failureHistory: [],
autoRotate: true
};
secrets.push(newSecret);
renderAll();
}
// ============================================
// TELEMETRY CHART
// ============================================
function renderTelemetryChart() {
const canvas = document.getElementById('telemetryChart');
const ctx = canvas.getContext('2d');
// Set canvas resolution
const rect = canvas.getBoundingClientRect();
canvas.width = rect.width * 2;
canvas.height = rect.height * 2;
ctx.scale(2, 2);
const width = rect.width;
const height = rect.height;
// Aggregate usage data
const hourlyData = Array(24).fill(0);
secrets.forEach(s => {
s.usageHistory.forEach((h, i) => {
hourlyData[i] += h;
});
});
const maxVal = Math.max(...hourlyData, 1);
const padding = 40;
const chartWidth = width - padding * 2;
const chartHeight = height - padding * 2;
const barWidth = chartWidth / 24 - 2;
// Clear
ctx.clearRect(0, 0, width, height);
// Draw grid lines
ctx.strokeStyle = 'rgba(0, 212, 170, 0.1)';
ctx.lineWidth = 1;
for (let i = 0; i <= 4; i++) {
const y = padding + (chartHeight / 4) * i;
ctx.beginPath();
ctx.moveTo(padding, y);
ctx.lineTo(width - padding, y);
ctx.stroke();
}
// Draw bars with gradient
const gradient = ctx.createLinearGradient(0, height - padding, 0, padding);
gradient.addColorStop(0, 'rgba(0, 212, 170, 0.8)');
gradient.addColorStop(1, 'rgba(77, 166, 255, 0.8)');
hourlyData.forEach((val, i) => {
const barHeight = (val / maxVal) * chartHeight;
const x = padding + i * (chartWidth / 24);
const y = height - padding - barHeight;
ctx.fillStyle = gradient;
ctx.beginPath();
ctx.roundRect(x, y, barWidth, barHeight, 2);
ctx.fill();
// Glow effect
ctx.shadowColor = 'rgba(0, 212, 170, 0.5)';
ctx.shadowBlur = 10;
ctx.fill();
ctx.shadowBlur = 0;
});
// Draw axis labels
ctx.fillStyle = '#565d67';
ctx.font = '10px SF Mono, monospace';
ctx.textAlign = 'center';
for (let i = 0; i < 24; i += 4) {
const x = padding + i * (chartWidth / 24) + barWidth / 2;
ctx.fillText(`${i}:00`, x, height - 10);
}
// Y-axis labels
ctx.textAlign = 'right';
for (let i = 0; i <= 4; i++) {
const y = padding + (chartHeight / 4) * i;
const val = Math.round(maxVal - (maxVal / 4) * i);
ctx.fillText(val.toString(), padding - 5, y + 4);
}
}
// ============================================
// PARTICLE BACKGROUND
// ============================================
function initParticles() {
const canvas = document.getElementById('particles');
const ctx = canvas.getContext('2d');
function resize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
resize();
window.addEventListener('resize', resize);
const particles = [];
const particleCount = 50;
for (let i = 0; i < particleCount; i++) {
particles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
vx: (Math.random() - 0.5) * 0.5,
vy: (Math.random() - 0.5) * 0.5,
radius: Math.random() * 2 + 1,
opacity: Math.random() * 0.5 + 0.1
});
}
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
particles.forEach(p => {
p.x += p.vx;
p.y += p.vy;
if (p.x < 0) p.x = canvas.width;
if (p.x > canvas.width) p.x = 0;
if (p.y < 0) p.y = canvas.height;
if (p.y > canvas.height) p.y = 0;
ctx.beginPath();
ctx.arc(p.x, p.y, p.radius, 0, Math.PI * 2);
ctx.fillStyle = `rgba(0, 212, 170, ${p.opacity})`;
ctx.fill();
});
// Draw connections
particles.forEach((p1, i) => {
particles.slice(i + 1).forEach(p2 => {
const dx = p1.x - p2.x;
const dy = p1.y - p2.y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 150) {
ctx.beginPath();
ctx.moveTo(p1.x, p1.y);
ctx.lineTo(p2.x, p2.y);
ctx.strokeStyle = `rgba(0, 212, 170, ${0.1 * (1 - dist / 150)})`;
ctx.stroke();
}
});
});
requestAnimationFrame(animate);
}
animate();
}
// ============================================
// REAL-TIME SIMULATION
// ============================================
function simulateActivity() {
// Random usage
secrets.forEach(secret => {
if (Math.random() > 0.7) {
secret.usageCount += Math.floor(Math.random() * 5) + 1;
secret.lastAccessed = new Date();
secret.usageHistory[23] += Math.floor(Math.random() * 3) + 1;
}
// Random failures (rare)
if (Math.random() > 0.98) {
secret.failureCount++;
secret.failureHistory.unshift({
time: new Date(),
error: ['Connection timeout', 'Invalid credentials', 'Rate limit exceeded', 'Token expired'][Math.floor(Math.random() * 4)]
});
if (secret.failureHistory.length > 5) secret.failureHistory.pop();
}
});
renderAll();
}
// ============================================
// HELPERS
// ============================================
function formatDate(date) {
return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' });
}
function formatTimeAgo(date) {
const seconds = Math.floor((Date.now() - date) / 1000);
if (seconds < 60) return `${seconds}s ago`;
if (seconds < 3600) return `${Math.floor(seconds / 60)}m ago`;
if (seconds < 86400) return `${Math.floor(seconds / 3600)}h ago`;
return `${Math.floor(seconds / 86400)}d ago`;
}
function formatNumber(num) {
if (num >= 1000000) return (num / 1000000).toFixed(1) + 'M';
if (num >= 1000) return (num / 1000).toFixed(1) + 'K';
return num.toString();
}
// ============================================
// INITIALIZATION
// ============================================
document.addEventListener('DOMContentLoaded', () => {
initParticles();
renderAll();
renderTelemetryChart();
// Update chart on resize
window.addEventListener('resize', () => {
setTimeout(renderTelemetryChart, 100);
});
// Simulate real-time activity
setInterval(simulateActivity, 3000);
// Close modal on outside click
document.getElementById('detailModal').addEventListener('click', (e) => {
if (e.target.classList.contains('modal-overlay')) {
closeModal();
}
});
// Keyboard shortcuts
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') closeModal();
});
});
</script>
</body>
</html>
The system calculates a composite risk score (0-100) based on:
Credentials are prioritized for rotation when:
Built-in support for common regulatory requirements: