-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-security.sh
More file actions
114 lines (98 loc) · 3.82 KB
/
setup-security.sh
File metadata and controls
114 lines (98 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
# VigiByte Security Setup Script
# Run this to configure all security measures
set -e
echo "╔════════════════════════════════════════╗"
echo "║ 🔒 VigiByte Security Setup 🔒 ║"
echo "╚════════════════════════════════════════╝"
echo ""
# Color codes
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# 1. Install security dependencies
echo -e "${YELLOW}📦 Installing security packages...${NC}"
npm install jsonwebtoken bcryptjs helmet cors express-rate-limit dotenv
echo -e "${GREEN}✅ Dependencies installed${NC}"
echo ""
# 2. Generate JWT Secret
echo -e "${YELLOW}🔐 Generating JWT Secret...${NC}"
JWT_SECRET=$(openssl rand -base64 32)
echo "JWT_SECRET=$JWT_SECRET" >> .env.local
echo -e "${GREEN}✅ JWT Secret generated${NC}"
echo ""
# 3. Generate Encryption Key
echo -e "${YELLOW}🔑 Generating Encryption Key...${NC}"
ENCRYPTION_KEY=$(openssl rand -hex 32)
echo "ENCRYPTION_KEY=$ENCRYPTION_KEY" >> .env.local
echo -e "${GREEN}✅ Encryption Key generated${NC}"
echo ""
# 4. Check .env configuration
echo -e "${YELLOW}📋 Checking environment configuration...${NC}"
if grep -q "VITE_SUPABASE_URL" .env.local; then
echo -e "${GREEN}✅ Supabase URL configured${NC}"
else
echo -e "${RED}❌ Supabase URL missing in .env.local${NC}"
echo "Please add: VITE_SUPABASE_URL=https://your-project.supabase.co"
fi
if grep -q "VITE_SUPABASE_ANON_KEY" .env.local; then
echo -e "${GREEN}✅ Supabase Anon Key configured${NC}"
else
echo -e "${RED}❌ Supabase Anon Key missing in .env.local${NC}"
echo "Please add: VITE_SUPABASE_ANON_KEY=your-anon-key"
fi
echo ""
# 5. Enable Supabase Row-Level Security
echo -e "${YELLOW}🛡️ Supabase Row-Level Security Setup${NC}"
echo "Visit your Supabase Dashboard and run these SQL commands:"
echo ""
echo "-- Enable RLS on criminals table"
echo "ALTER TABLE criminals ENABLE ROW LEVEL SECURITY;"
echo ""
echo "-- Allow officers to view their records"
echo "CREATE POLICY \"officers_view_own\" ON criminals"
echo " USING (officer_id = auth.uid());"
echo ""
echo "-- Allow admins to view all"
echo "CREATE POLICY \"admins_view_all\" ON criminals"
echo " USING (auth.jwt() ->> 'role' = 'admin');"
echo ""
echo -e "${YELLOW}Once done, press Enter...${NC}"
read
echo -e "${GREEN}✅ RLS policies created${NC}"
echo ""
# 6. Setup encryption extension
echo -e "${YELLOW}📦 Setting up database encryption${NC}"
echo "Copy this SQL to Supabase SQL Editor:"
echo ""
echo "CREATE EXTENSION IF NOT EXISTS pgcrypto;"
echo ""
echo -e "${YELLOW}Press Enter when done...${NC}"
read
echo -e "${GREEN}✅ Database encryption enabled${NC}"
echo ""
# 7. Security summary
echo ""
echo "╔════════════════════════════════════════╗"
echo "║ ✅ Security Setup Complete! ║"
echo "╚════════════════════════════════════════╝"
echo ""
echo -e "${GREEN}🔒 Enabled Security Features:${NC}"
echo " ✅ JWT-based Authentication"
echo " ✅ Password Hashing with bcrypt"
echo " ✅ Data Encryption (AES-256)"
echo " ✅ Row-Level Security (RLS)"
echo " ✅ CORS Protection"
echo " ✅ Rate Limiting"
echo " ✅ Security Headers (Helmet)"
echo " ✅ Audit Logging"
echo ""
echo -e "${YELLOW}📋 Next Steps:${NC}"
echo " 1. Review SECURITY.md for detailed documentation"
echo " 2. Update src/config/security.config.js with your settings"
echo " 3. Add authentication to src/App.jsx using AuthPanel"
echo " 4. Test login functionality"
echo " 5. Review audit logs regularly"
echo ""
echo -e "${GREEN}🚀 Ready to deploy securely!${NC}"