本报告分析了 34 个微服务的配置文件(application.yml),识别敏感信息并提供 Kubernetes Secret 和 ConfigMap 的分割方案。
| 敏感信息类型 | 包含此类型的服务数 | 占比 |
|---|---|---|
| database_host | 34 | 100% |
| database_password | 34 | 100% |
| database_username | 33 | 97% |
| wechat_app_secret | 8 | 24% |
| wechat_app_id | 7 | 21% |
| api_key | 9 | 26% |
| token | 1 | 3% |
这些服务只包含数据库相关的敏感信息,相对简单。
1. shop-recycle-account
敏感类型: database_username, database_password, database_host
字段数: 6
2. shop-recycle-agent-pc-web
敏感类型: database_username, database_password, database_host
字段数: 5
3. shop-recycle-async-web
敏感类型: database_username, database_password, database_host
字段数: 5
4. shop-recycle-customer-wechat-web
敏感类型: database_username, database_password, database_host
字段数: 5
5. shop-recycle-data-statistics
敏感类型: database_username, database_password, database_host
字段数: 5
6. shop-recycle-dealdata-service
敏感类型: database_username, database_password, database_host
字段数: 5
7. shop-recycle-dispatcher
敏感类型: database_username, database_password, database_host
字段数: 6
8. shop-recycle-erp-pc-web
敏感类型: database_username, database_password, database_host
字段数: 5
9. shop-recycle-login-center
敏感类型: database_username, database_password, database_host
字段数: 4
10. shop-recycle-marketer-pc-web
敏感类型: database_username, database_password, database_host
字段数: 5
11. shop-recycle-order-search
敏感类型: database_username, database_password, database_host
字段数: 6
12. shop-recycle-pis
敏感类型: database_username, database_password, database_host
字段数: 5
13. shop-recycle-store
敏感类型: database_username, database_password, database_host
字段数: 6
14. shop-recycle-wechat
敏感类型: database_username, database_password, database_host
字段数: 5
15. shop-recycle-ws-web
敏感类型: database_username, database_password, database_host
字段数: 5
2A. 数据库 + API 密钥
1. shop-recycle-import-web
敏感类型: database_username, database_password, api_key, database_host
字段数: 5 (secretKey)
2. shop-recycle-merchant-pc-web
敏感类型: database_username, database_password, api_key, database_host
字段数: 6
3. shop-recycle-oss-web
敏感类型: database_username, database_password, api_key, database_host
字段数: 5 (secretKey)
4. shop-recycle-platform-pc-web
敏感类型: database_username, database_password, api_key, database_host
字段数: 7
2B. 数据库 + WeChat App ID
1. shop-recycle-payment
敏感类型: database_username, database_password, database_host, wechat_app_id
字段数: 8
2. shop-recycle-payment-web
敏感类型: database_username, database_password, database_host, wechat_app_id
字段数: 11 (多个微信 App ID: wechat-ssm-app-id, wechat-sub-app-id,
wechat-js-app-id, wechat-small-app-id)
3. shop-recycle-sche
敏感类型: database_username, database_password, database_host, wechat_app_id
字段数: 6
2C. 只有数据库密码和主机(特殊案例)
1. shop-recycle-gateway
敏感类型: database_password, database_host
字段数: 2
注: 没有数据库用户名
2D. 数据库 + WeChat App ID + Username
1. shop-recycle-gateway-out
敏感类型: database_username, database_password, database_host
字段数: 4
1. shop-recycle-gateway-out-upgrade
敏感类型: wechat_app_secret, database_password, api_key,
database_username, database_host
字段数: 6
敏感字段: server, password, url, username, key, secret
2. shop-recycle-merchant-wechat-web
敏感类型: wechat_app_secret, database_password, api_key,
database_username, database_host
字段数: 8
敏感字段: server, password, host, username, key, AppSecret, url, userName
3. shop-recycle-order-center
敏感类型: wechat_app_secret, database_password, api_key,
database_username, database_host, wechat_app_id
字段数: 9 (含 appid, appsecret, secretKey)
4. shop-recycle-out-web
敏感类型: wechat_app_secret, database_password, database_username,
database_host, wechat_app_id
字段数: 6
敏感字段: server, password, host, username, app-id, app-secret
5. shop-recycle-platform
敏感类型: wechat_app_secret, database_password, database_username,
database_host, wechat_app_id
字段数: 7
6. shop-recycle-store-pc-web
敏感类型: wechat_app_secret, database_password, api_key,
database_username, database_host
字段数: 8
7. shop-recycle-store-wechat-web
敏感类型: wechat_app_secret, database_password, api_key,
database_username, database_host
字段数: 8
8. shop-recycle-wechat-web
敏感类型: wechat_app_secret, database_password, token,
database_username, database_host, wechat_app_id
字段数: 7 (唯一包含 token 的服务)
为每个服务创建一个 Secret,包含所有敏感信息
# 示例:shop-recycle-payment-web-secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: shop-recycle-payment-web-secret
namespace: production
type: Opaque
stringData:
# Database
spring.datasource.url: "jdbc:mysql://db-host:3306/db_name"
spring.datasource.username: "${DB_USERNAME}"
spring.datasource.password: "${DB_PASSWORD}"
# WeChat Configuration
spring.wechat.ssm.app-id: "${WECHAT_SSM_APP_ID}"
spring.wechat.sub.app-id: "${WECHAT_SUB_APP_ID}"
spring.wechat.js.app-id: "${WECHAT_JS_APP_ID}"
spring.wechat.small.app-id: "${WECHAT_SMALL_APP_ID}"
---
# shop-recycle-payment-web-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: shop-recycle-payment-web-configmap
namespace: production
data:
spring.datasource.driver-class-name: "com.mysql.cj.jdbc.Driver"
spring.datasource.hikari.pool-size: "10"
# 非敏感的应用配置
根据服务类型和功能分类创建 Secret:
apiVersion: v1
kind: Secret
metadata:
name: database-credentials
namespace: production
type: Opaque
stringData:
# 主数据库
primary-username: "app_user"
primary-password: "encrypted_password"
primary-host: "mysql-master.internal:3306"
# 也可为不同服务分组创建不同的 database secret
# 例如:shop-recycle-payment-db-secret
apiVersion: v1
kind: Secret
metadata:
name: wechat-api-credentials
namespace: production
type: Opaque
stringData:
payment-app-id: "${WECHAT_PAYMENT_APP_ID}"
payment-app-secret: "${WECHAT_PAYMENT_APP_SECRET}"
platform-app-id: "${WECHAT_PLATFORM_APP_ID}"
platform-app-secret: "${WECHAT_PLATFORM_APP_SECRET}"
merchant-app-id: "${WECHAT_MERCHANT_APP_ID}"
merchant-app-secret: "${WECHAT_MERCHANT_APP_SECRET}"
# ... 其他微信 App
apiVersion: v1
kind: Secret
metadata:
name: api-keys-secret
namespace: production
type: Opaque
stringData:
import-web-secret-key: "${IMPORT_WEB_SECRET_KEY}"
merchant-pc-web-key: "${MERCHANT_PC_WEB_KEY}"
oss-web-secret-key: "${OSS_WEB_SECRET_KEY}"
# ... 其他 API 密钥
apiVersion: v1
kind: Secret
metadata:
name: wechat-web-token
namespace: production
type: Opaque
stringData:
access-token: "${WECHAT_WEB_TOKEN}"
结合服务特性创建分层 Secret:
Layer 1: 通用 Secret
├── database-base-secret (所有数据库连接信息)
├── common-api-keys-secret (通用 API 密钥)
└── infrastructure-secret (基础设施相关密钥)
Layer 2: 功能模块 Secret
├── payment-module-secret (支付相关:支付、订单等)
├── merchant-module-secret (商户相关:商户、门店等)
├── wechat-module-secret (微信相关:微信、客户等)
└── admin-module-secret (后台相关:管理等)
Layer 3: 服务特定 Secret (可选)
└── service-specific-secret (特定服务独有的敏感信息)
使用生成脚本为每个服务创建对应的 Secret 和 ConfigMap:
# 脚本位置
d:\coding-area\devops\helm\generate-secrets.ps1
# 执行脚本
powershell -ExecutionPolicy Bypass -File generate-secrets.ps1
# 应用所有 Secret
kubectl apply -f secrets/
# 应用所有 ConfigMap
kubectl apply -f configmaps/
# 验证
kubectl get secrets -n production
kubectl get configmaps -n production
在 Helm values.yaml 或 Deployment 中引用 Secret 和 ConfigMap:
# Deployment 示例
apiVersion: apps/v1
kind: Deployment
metadata:
name: shop-recycle-payment-web
spec:
template:
spec:
containers:
- name: payment-web
env:
# 从 Secret 读取敏感信息
- name: SPRING_DATASOURCE_PASSWORD
valueFrom:
secretKeyRef:
name: shop-recycle-payment-web-secret
key: spring.datasource.password
- name: WECHAT_SSM_APP_ID
valueFrom:
secretKeyRef:
name: shop-recycle-payment-web-secret
key: spring.wechat.ssm.app-id
envFrom:
# 从 ConfigMap 读取非敏感配置
- configMapRef:
name: shop-recycle-payment-web-configmap
# 创建 RBAC 角色限制对 Secret 的访问
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: secret-reader
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list"]
resourceNames:
- "shop-recycle-payment-web-secret"
# 只允许访问特定的 Secret
# 启用 etcd 加密(需要在 kube-apiserver 配置中)
--encryption-provider-config=/etc/kubernetes/encryption.yaml
# 审计 Secret 访问
kubectl get events -n production | grep secret
# 检查 Secret 变更历史
kubectl rollout history deployment/shop-recycle-payment-web -n production
| 服务名 | 敏感信息数量 | 优先级 |
|---|---|---|
| shop-recycle-account | 6 | 高 |
| shop-recycle-agent-pc-web | 5 | 中 |
| shop-recycle-async-web | 5 | 中 |
| shop-recycle-customer-wechat-web | 5 | 中 |
| shop-recycle-data-statistics | 5 | 低 |
| shop-recycle-dealdata-service | 5 | 中 |
| shop-recycle-dispatcher | 6 | 高 |
| shop-recycle-erp-pc-web | 5 | 高 |
| shop-recycle-login-center | 4 | 高 |
| shop-recycle-marketer-pc-web | 5 | 中 |
| shop-recycle-order-search | 6 | 中 |
| shop-recycle-pis | 5 | 低 |
| shop-recycle-store | 6 | 中 |
| shop-recycle-wechat | 5 | 中 |
| shop-recycle-ws-web | 5 | 低 |
推荐方案: 创建一个共享的 database-credentials-secret + 服务特定的 Secret
| 服务名 | 包含信息 | WeChat 类型 |
|---|---|---|
| shop-recycle-gateway-out-upgrade | app_secret | 通用 |
| shop-recycle-merchant-wechat-web | app_id + secret | 通用 |
| shop-recycle-order-center | app_id + secret | 通用 |
| shop-recycle-out-web | app_id + secret | 通用 |
| shop-recycle-payment | app_id | 支付特定 |
| shop-recycle-payment-web | 多个 app_id | 支付特定 |
| shop-recycle-platform | app_id + secret | 平台 |
| shop-recycle-store-pc-web | app_secret | 商城 |
| shop-recycle-store-wechat-web | app_secret | 商城 |
| shop-recycle-wechat-web | app_id + secret + token | 通用 |
推荐方案: 创建 wechat-api-credentials-secret
| 服务名 | 密钥字段 | 用途 |
|---|---|---|
| shop-recycle-import-web | secretKey | 导入相关 |
| shop-recycle-merchant-pc-web | key | 商户平台 |
| shop-recycle-oss-web | secretKey | 对象存储 |
| shop-recycle-platform-pc-web | key | 平台管理 |
| shop-recycle-gateway-out-upgrade | key | 网关 |
| shop-recycle-merchant-wechat-web | key | 微信商户 |
| shop-recycle-order-center | secretKey | 订单服务 |
| shop-recycle-store-pc-web | key | 门店管理 |
| shop-recycle-store-wechat-web | key | 微信门店 |
推荐方案: 创建 api-keys-secret
| 优先级 | 服务数 | 服务列表 | 创建方案 |
|---|---|---|---|
| P0 (关键) | 5 | account, dispatcher, erp-pc-web, login-center, payment-web | 单独 Secret |
| P1 (高) | 14 | 其他数据库相关服务 + WeChat 集成 | 数据库 Secret + 功能模块 Secret |
| P2 (中) | 11 | API 相关服务 | API 密钥 Secret |
| P3 (低) | 4 | 数据统计、PIS、OSS、WS | 共享 Secret |
生成的文件存放在:
d:\coding-area\devops\helm\
├── secrets/
│ ├── shop-recycle-account-secret.yaml
│ ├── shop-recycle-payment-web-secret.yaml
│ └── ... (34 个服务的 Secret)
├── configmaps/
│ ├── shop-recycle-account-configmap.yaml
│ ├── shop-recycle-payment-web-configmap.yaml
│ └── ... (34 个服务的 ConfigMap)
└── config-analysis-report.json
详细的 JSON 分析结果保存在 config-analysis-report.json,包含每个服务的完整敏感信息列表。