@ahhaohho/auth-middleware 2.2.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/utils/secretManager.js +30 -3
package/package.json
CHANGED
|
@@ -46,7 +46,7 @@ class SecretManager {
|
|
|
46
46
|
return JSON.parse(cachedKeys);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
// 2. AWS Secrets Manager에서 가져오기
|
|
49
|
+
// 2. AWS Secrets Manager에서 가져오기 (AWSCURRENT + AWSPREVIOUS)
|
|
50
50
|
console.log('[@ahhaohho/auth-middleware] Fetching JWT keys from AWS Secrets Manager');
|
|
51
51
|
const command = new GetSecretValueCommand({ SecretId: this.secretName });
|
|
52
52
|
const response = await this.client.send(command);
|
|
@@ -56,9 +56,36 @@ class SecretManager {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const secret = JSON.parse(response.SecretString);
|
|
59
|
+
const currentKey = secret.current || secret.jwt_secret_key || secret.dev;
|
|
60
|
+
|
|
61
|
+
// previous 키 결정: secret 내 previous 필드 → AWSPREVIOUS 버전 순서
|
|
62
|
+
let previousKey = secret.previous || null;
|
|
63
|
+
|
|
64
|
+
if (!previousKey) {
|
|
65
|
+
try {
|
|
66
|
+
const prevCommand = new GetSecretValueCommand({
|
|
67
|
+
SecretId: this.secretName,
|
|
68
|
+
VersionStage: 'AWSPREVIOUS'
|
|
69
|
+
});
|
|
70
|
+
const prevResponse = await this.client.send(prevCommand);
|
|
71
|
+
if (prevResponse.SecretString) {
|
|
72
|
+
const prevSecret = JSON.parse(prevResponse.SecretString);
|
|
73
|
+
const prevCandidate = prevSecret.current || prevSecret.jwt_secret_key || prevSecret.dev;
|
|
74
|
+
// 이전 키가 현재 키와 다를 때만 사용
|
|
75
|
+
if (prevCandidate && prevCandidate !== currentKey) {
|
|
76
|
+
previousKey = prevCandidate;
|
|
77
|
+
console.log('[@ahhaohho/auth-middleware] Using AWSPREVIOUS version as fallback key');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} catch (prevError) {
|
|
81
|
+
// AWSPREVIOUS가 없을 수 있음 (첫 시크릿이거나 로테이션 미사용)
|
|
82
|
+
console.log('[@ahhaohho/auth-middleware] No AWSPREVIOUS version available');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
59
86
|
const keys = {
|
|
60
|
-
current:
|
|
61
|
-
previous:
|
|
87
|
+
current: currentKey,
|
|
88
|
+
previous: previousKey
|
|
62
89
|
};
|
|
63
90
|
|
|
64
91
|
// 3. Redis에 캐싱 (5분 TTL)
|