Skip to content

Commit ad4fe38

Browse files
yyyCodeclaude
andcommitted
security: externalize secrets to environment variables
Replace hardcoded credentials with ${ENV:} placeholders: - ${SPRING_DATASOURCE_PASSWORD} — MySQL password - ${SPRING_DATA_REDIS_PASSWORD} — Redis password - ${OPENBLOG_JWT_SECRET} — JWT signing key - ${OPENBLOG_STORAGE_MINIO_ACCESS_KEY} — MinIO access key - ${OPENBLOG_STORAGE_MINIO_SECRET_KEY} — MinIO secret key Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2fc7a8e commit ad4fe38

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

OpenBlog-business/src/main/resources/application-local.example.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ spring:
33
datasource:
44
url: jdbc:mysql://127.0.0.1:3306/openblog?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC&characterEncoding=utf8&useUnicode=true
55
username: root
6-
password: your_password
6+
password: ${SPRING_DATASOURCE_PASSWORD:your_password}
77
data:
88
redis:
99
host: 127.0.0.1
1010
port: 6379
11+
password: ${SPRING_DATA_REDIS_PASSWORD:}
1112

1213
openblog:
1314
cache:
@@ -26,7 +27,7 @@ openblog:
2627
login-lockout:
2728
enabled: false
2829
jwt:
29-
secret: "REPLACE_WITH_LONG_RANDOM_AT_LEAST_32_CHARS"
30+
secret: ${OPENBLOG_JWT_SECRET:REPLACE_WITH_LONG_RANDOM_AT_LEAST_32_CHARS}
3031
storage:
3132
# local:读写本机目录;minio:读写远程 MinIO(与生产共用 endpoint 即可在本地看到线上图片)
3233
type: minio
@@ -35,6 +36,6 @@ openblog:
3536
thumb-long-edge: 320
3637
minio:
3738
endpoint: "http://127.0.0.1:9000"
38-
access-key: "your_minio_access_key"
39-
secret-key: "your_minio_secret_key"
39+
access-key: ${OPENBLOG_STORAGE_MINIO_ACCESS_KEY:your_minio_access_key}
40+
secret-key: ${OPENBLOG_STORAGE_MINIO_SECRET_KEY:your_minio_secret_key}
4041
bucket: "openblog"

OpenBlog-business/src/main/resources/application.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ spring:
77
datasource:
88
url: jdbc:mysql://10.21.32.85:3307/openblog?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC&characterEncoding=utf8&useUnicode=true
99
username: root
10-
password: admin123
10+
password: ${SPRING_DATASOURCE_PASSWORD:}
1111
jpa:
1212
database-platform: org.hibernate.dialect.MySQL8Dialect
1313
hibernate:
@@ -30,7 +30,7 @@ spring:
3030
# 若 Redis 设置了 requirepass,在此填写密码
3131
# password: your_redis_password
3232
timeout: 3s
33-
password: admin123
33+
password: ${SPRING_DATA_REDIS_PASSWORD:}
3434
thymeleaf:
3535
prefix: classpath:/templates/
3636
suffix: .html
@@ -81,7 +81,7 @@ openblog:
8181
failure-window-seconds: 300
8282
lockout-seconds: 900
8383
jwt:
84-
secret: "PLEASE_CHANGE_THIS_TO_A_LONG_RANDOM_SECRET_32_PLUS_CHARS"
84+
secret: ${OPENBLOG_JWT_SECRET:}
8585
issuer: openblog
8686
access-token-expire-seconds: 7200
8787
refresh-token-expire-seconds: 2592000
@@ -95,6 +95,6 @@ openblog:
9595
# 当 type=minio 时填写以下配置
9696
minio:
9797
endpoint: "http://10.21.32.85:9000"
98-
access-key: "zoRKQFmL5UjnYz5HNrbh"
99-
secret-key: "3T8kopnAh4mQVLSDDgqQpxH3oSn8jhH5H0wzKlzE"
98+
access-key: ${OPENBLOG_STORAGE_MINIO_ACCESS_KEY:}
99+
secret-key: ${OPENBLOG_STORAGE_MINIO_SECRET_KEY:}
100100
bucket: "openblog-document"

0 commit comments

Comments
 (0)