# Kubernetes ConfigMap 和 Secret 生成策略 ## 📊 配置分析汇总 **总服务数:** 34 个微服务 **需要 Secret 的服务:** 34 个(100%) **Web/Gateway 服务(不需要数据库):** 9 个 ### 敏感信息分类统计 | 敏感信息类型 | 服务数 | 说明 | |-----------|------|------| | Database Password | 26 | MySQL/RDS 数据库密码 | | Redis Password | 30+ | Redis Sentinel 集群密码 | | RabbitMQ Password | 20+ | 消息队列密码 | | WeChat AppID/Secret | 5 | 微信小程序认证信息 | | MongoDB Password | 3 | MongoDB 密码(注释状态) | | Nacos Password | 2 | Nacos 认证信息 | | Seata Password | 2 | 分布式事务框架密码 | | Dubbo 配置 | 15+ | Dubbo 协议配置 | --- ## 🔐 Secret 类型分析 ### 1. 数据库服务(26 个) **包含敏感信息:** - MySQL 用户名:`root` - MySQL 密码:`Fxjxtdacf8f_a3d_202600104d6c_41`(所有数据库服务相同) - 各个数据库名 **服务列表:** ``` shop-recycle-account shop-recycle-async-web shop-recycle-data-statistics shop-recycle-dealdata-service shop-recycle-dispatcher shop-recycle-erp-pc-web shop-recycle-gateway-out shop-recycle-gateway-out-upgrade shop-recycle-import-web shop-recycle-marketer-pc-web shop-recycle-merchant shop-recycle-merchant-pc-web shop-recycle-merchant-wechat-web shop-recycle-msg shop-recycle-order-center shop-recycle-order-search shop-recycle-oss-web shop-recycle-out-web shop-recycle-payment shop-recycle-payment-web shop-recycle-pis shop-recycle-platform shop-recycle-sche shop-recycle-store shop-recycle-store-pc-web shop-recycle-store-wechat-web shop-recycle-wechat ``` ### 2. 仅 Redis/RabbitMQ(无数据库)(8 个) **包含敏感信息:** - Redis Sentinel 密码:`3sm_redis` - RabbitMQ 密码:`guest` **服务列表:** ``` shop-recycle-agent-pc-web shop-recycle-customer-wechat-web shop-recycle-gateway shop-recycle-login-center shop-recycle-platform-pc-web shop-recycle-wechat-web shop-recycle-ws-web ``` ### 3. 微信认证信息(5 个) **包含敏感信息:** - WeChat AppID - WeChat AppSecret - 微信授权 URL **服务列表:** ``` shop-recycle-login-center shop-recycle-out-web shop-recycle-platform shop-recycle-platform-pc-web shop-recycle-wechat ``` --- ## 🗂️ 推荐的配置分割方案 ### ConfigMap 用途 存储**非敏感、可公开**的配置: - 应用端口 - Logging 配置 - 服务名称 - Nacos 服务地址(不含密码) - Redis Sentinel 节点地址(不含密码) - RabbitMQ 主机地址(不含凭证) - Dubbo 配置 - MyBatis 配置 - 业务配置参数 ### Secret 用途 存储**敏感、保密**的配置: - 数据库密码 - Redis 密码 - RabbitMQ 密码 - WeChat AppID/AppSecret - MongoDB 密码 - Nacos 凭证 - Seata 凭证 - API 密钥 - Token 等 --- ## 📋 每个服务的分类 ### 需要完整 Secret 的服务(26 个 - 有数据库) ``` shop-recycle-account shop-recycle-async-web shop-recycle-data-statistics shop-recycle-dealdata-service shop-recycle-dispatcher shop-recycle-erp-pc-web shop-recycle-gateway-out shop-recycle-gateway-out-upgrade shop-recycle-import-web shop-recycle-marketer-pc-web shop-recycle-merchant shop-recycle-merchant-pc-web shop-recycle-merchant-wechat-web shop-recycle-msg shop-recycle-order-center shop-recycle-order-search shop-recycle-oss-web shop-recycle-out-web shop-recycle-payment shop-recycle-payment-web shop-recycle-pis shop-recycle-platform shop-recycle-sche shop-recycle-store shop-recycle-store-pc-web shop-recycle-store-wechat-web shop-recycle-wechat ``` **Secret 包含字段:** - `db-username` - `db-password` - `db-url` - `redis-password` - `rabbitmq-password` - `rabbitmq-username` ### 需要简化 Secret 的服务(8 个 - 无数据库) ``` shop-recycle-agent-pc-web shop-recycle-customer-wechat-web shop-recycle-gateway shop-recycle-login-center shop-recycle-platform-pc-web shop-recycle-wechat-web shop-recycle-ws-web ``` **Secret 包含字段:** - `redis-password` - `rabbitmq-password` - `rabbitmq-username` - (如果有)`wechat-app-id`、`wechat-app-secret` ### 需要特殊 Secret 的服务(5 个 - 有微信信息) ``` shop-recycle-login-center shop-recycle-out-web shop-recycle-platform shop-recycle-platform-pc-web shop-recycle-wechat ``` **额外的 Secret 字段:** - `wechat-store-app-id` - `wechat-store-app-secret` - `wechat-merchant-app-id` - `wechat-merchant-app-secret` - `wechat-buy-app-id` - `wechat-buy-app-secret` - 等 --- ## 🎯 实现方案 ### 方案 1:全局共享 Secret(推荐) 优点: - 一个 Secret 管理所有公共凭证(DB, Redis, RabbitMQ) - 简化部署配置 - 易于更新凭证 缺点: - 如果 Secret 泄露,所有服务都受影响 - 权限管理不细粒度 ### 方案 2:按服务类型分组 Secret(推荐) 优点: - 细粒度权限控制 - 降低风险范围 - 易于合规审计 缺点: - Secret 数量较多 - 管理复杂度增加 **分组建议:** 1. `common-db-credentials` - 数据库凭证(26 个服务共用) 2. `common-redis-credentials` - Redis 凭证(30+ 服务共用) 3. `common-rabbitmq-credentials` - RabbitMQ 凭证(20+ 服务共用) 4. `wechat-credentials` - 微信凭证(5 个服务) 5. `mongodb-credentials` - MongoDB 凭证(2 个服务) 6. `nacos-credentials` - Nacos 凭证(2 个服务) --- ## 📐 推荐的配置架构 ``` Kubernetes ConfigMaps: ├── [service-name]-config-public # 非敏感配置 │ ├── application.yml (去除敏感字段) │ └── application.properties └── shared-config # 全局非敏感配置 ├── nacos-server-address ├── redis-sentinel-nodes └── rabbitmq-host Kubernetes Secrets: ├── common-db-credentials # 共享:数据库凭证 ├── common-redis-credentials # 共享:Redis 凭证 ├── common-rabbitmq-credentials # 共享:RabbitMQ 凭证 ├── wechat-credentials # 共享:微信密钥 └── [service-name]-secret # 服务特定:敏感信息 ├── mongodb-password ├── nacos-password ├── seata-password └── custom-api-keys ``` --- ## ✅ 行动清单 - [ ] 生成 `common-db-credentials` Secret - [ ] 生成 `common-redis-credentials` Secret - [ ] 生成 `common-rabbitmq-credentials` Secret - [ ] 生成 `wechat-credentials` Secret - [ ] 为每个服务生成 ConfigMap(非敏感部分) - [ ] 为每个服务生成或引用 Secret - [ ] 更新 Deployment 引用 ConfigMap 和 Secret - [ ] 使用 kustomize 或 helm 管理不同环境的敏感信息 - [ ] 配置 RBAC 限制 Secret 访问权限