-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/replace kms #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Feat/replace kms #198
Conversation
| const secret = params?.secret ?? MyHttpHeaderTool.buildJwtSecret(); | ||
| // Verify HMAC-SHA256 signature manually | ||
| const message = [header, payload].join('.'); | ||
| const expectedSig = fromBase64(crypto.createHmac('sha256', secret).update(message).digest('base64')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crypto를 직접 쓰는것보다는 $U.md5() 같은것을 이용해줘요.
|
@aiden-lemon 도 리뷰 확인해줘요. |
| const HEADER_LEMON_LANGUAGE = $U.env('HEADER_LEMON_LANGUAGE', 'x-lemon-language'); | ||
| const HEADER_LEMON_IDENTITY = $U.env('HEADER_LEMON_IDENTITY', 'x-lemon-identity'); | ||
| const HEADER_COOKIE = $U.env('HEADER_COOKIE', 'cookie'); | ||
| const JWT_MAGIC_KEY = $U.env('JWT_MAGIC_KEY', ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM;
프로젝트에 공통적으로 JWT_MAGIC_KEY를 설정하여 이용하는 패턴이 맞을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 맞습니다 사용 방법도 정리해서 전달 드리겠습니다!
…once and timestamp validation
KMS sign/verify 개선주요 개선사항1. MyHttpHeaderToolV2 클래스 추가
2. encodeIdentityJWT 개선
3. signToken 메서드 추가
4. crypto3 유틸리티 추가
사용 시나리오: 커스텀 exp로 토큰 발급// 1. MyHttpHeaderToolV2 인스턴스 생성
const $tool = new MyHttpHeaderToolV2(headers, reqContext);
// 2. encodeIdentityJWT로 JWT 생성 (exp 직접 설정 가능)
const current = Date.now();
const expires = 60 * 60; // 1시간
const encoded = await $tool.encodeIdentityJWT(identity, {
current,
exp: Math.floor(current / 1000) + expires,
});
// 3. 토큰 사용
const accessToken = encoded.token;
// 또는 서명만 별도로 사용: encoded.signaturesignToken 단독 사용// 메시지에 직접 서명이 필요한 경우
const signature = await $tool.signToken('', encoded.token, { useKms: false });시나리오A(backend) -> token 발급
lemon-core -> 공통 검증
B(service) -> token 사용/검증
A(backend)와 lemon-core 영역의 KMS 대체(HS256 기반) 적용은 대부분 완료되어 현재 테스트 중입니다. 환경변수 정리
테스트 결과
테스트 전제
테스트 시나리오
발급 JWT 확인값
|
src/engine/utilities.spec.ts
Outdated
|
|
||
| // 1. basic encrypt/decrypt (like crypto2 pattern) | ||
| const $crypt = $U.crypto3(secret); | ||
| const encrypted = $crypt.encrypt(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
암호화된 결과도 보이주도록해줘요. (nonce, 와 current 고정시켜서)
KMS sign/verify 개선
lemon-core의 JWT 검증/서명 로직이 KMS 의존 없이도 동작하도록 확장했습니다. KMS 경로도 유지해 하위호환을 보장합니다.
시나리오
A(backend) -> token 발급
iss = kms/{alias}+ AWSKMSService.sign() 사용.iss = service+ HMAC(HS256) 서명 사용.lemon-core -> 공통 검증
B(service) -> token 사용/검증
A(backend)와 lemon-core 영역의 KMS 대체(HS256 기반) 적용은 대부분 완료되어 현재 테스트 중입니다.
B(service) 영역은 4~5번(backend 재검증 API 연동, 재검증 결과 기반 payload 활용)은 순차 적용할 계획입니다.
환경변수 정리
requiredoptional(default 0)optional