安全加固
本文档介绍 KubePolaris 的安全加固配置和最佳实践。
认证安全
密码策略
配置强密码策略:
security:
password:
min_length: 12
require_uppercase: true
require_lowercase: true
require_number: true
require_special: true
max_age: 90 # 天
history: 5 # 禁止重复使用最近 5 个密码
登录安全
security:
login:
max_attempts: 5 # 最大尝试次数
lockout_duration: 900 # 锁定时间(秒)
captcha_after_attempts: 3 # 验证码触发次数
会话管理
security:
session:
single_login: false # 单点登录(禁止多处登录)
idle_timeout: 1800 # 空闲超时(秒)
max_concurrent: 5 # 最大并发会话
JWT 配置
jwt:
# 使用强随机密钥
secret: $(openssl rand -base64 32)
# 合理的过期时间
expire: 8h
# 刷新 Token 过期时间
refresh_expire: 24h
网络安全
HTTPS
强制使用 HTTPS:
server {
listen 80;
server_name kubepolaris.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
# TLS 配置
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
# HSTS
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
}
安全头
# 防止点击劫持
add_header X-Frame-Options "SAMEORIGIN" always;
# 防止 MIME 类型嗅探
add_header X-Content-Type-Options "nosniff" always;
# XSS 防护
add_header X-XSS-Protection "1; mode=block" always;
# CSP 策略
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline';" always;
# Referrer 策略
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
CORS 配置
cors:
enabled: true
allow_origins:
- "https://kubepolaris.example.com" # 指定具体域名
allow_methods:
- GET
- POST
- PUT
- DELETE
allow_headers:
- Authorization
- Content-Type
allow_credentials: true
max_age: 3600
请求限制
rate_limit:
enabled: true
requests_per_minute: 100
burst: 50