๐ Java ๊ฐ๋ฐ์๋ฅผ ์ํ ํ๋ ๋ณด์ ๊ฐ์ด๋
Source: Dev.to
ZeroโTrust ๊ท์น โ ์ฌ์ฉ์๊ฐ ๋๊ตฌ์ธ์ง ํ์ธํ๊ณ , ๊ทธ๋ค์ด ๋ฌด์์ ์ ๊ทผํ ์ ์๋์ง ๊ฒ์ฆํ๋ฉฐ, VPC ๋ด๋ถ๋ผ๋ ์๋ฌต์ ์ธ ์ ๋ขฐ๋ฅผ ๋์ง ๋ง์ธ์.
ํต์ฌ ํ๋ฆ
Client โ API Gateway โ Authorization Server โ Resource Server
ZeroโTrust ๊ท์น
- ์ฌ์ฉ์๊ฐ ๋๊ตฌ์ธ์ง ํ์ธํฉ๋๋ค.
- ์ฌ์ฉ์๊ฐ ๋ฌด์์ ์ ๊ทผํ ์ ์๋์ง ํ์ธํฉ๋๋ค.
- ์๋ฌต์ ์ธ ์ ๋ขฐ ๊ธ์ง โ VPC ๋ด๋ถ๋ผ๋ ๋ง์ฐฌ๊ฐ์ง์ ๋๋ค.
- ํ ํฐ์ ํญ์ ๋จ๊ธฐ๊ฐ์ ๋ง๋ฃ๋๋๋ก ํฉ๋๋ค.
JWT โ ๋น๋์นญ ํค ์ฌ์ฉ (RS256)
ํค ์ ๋ต
- Private Key: Authorization Server์๋ง ๋ณด๊ดํฉ๋๋ค.
- Public Key: ๊ฒ์ฆ์ ์ํด Gateway์ ๋ง์ดํฌ๋ก์๋น์ค์ ๊ณต์ ํฉ๋๋ค.
Stepโฏ1: RSA ํค ์์ฑ
openssl genrsa -out private.pem 4096
openssl rsa -in private.pem -pubout -out public.pem
Stepโฏ2: Spring Boot JWT ๊ฒ์ฆ (Public Key)
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(auth -> auth
.requestMatchers("/public/**").permitAll()
.anyRequest().authenticated()
)
.oauth2ResourceServer(oauth -> oauth
.jwt(jwt -> jwt.publicKey(publicKey()))
)
.sessionManagement(session -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
);
return http.build();
}
@Bean
public RSAPublicKey publicKey() throws Exception {
String key = Files.readString(Path.of("public.pem"))
.replace("-----BEGIN PUBLIC KEY-----", "")
.replace("-----END PUBLIC KEY-----", "")
.replaceAll("\\s", "");
byte[] decoded = Base64.getDecoder().decode(key);
return (RSAPublicKey) KeyFactory
.getInstance("RSA")
.generatePublic(new X509EncodedKeySpec(decoded));
}
๋ฐฉ์ด ๋ชฉ๋ก โ ๋ณด์ HTTP ํค๋
- ContentโSecurityโPolicy (CSP): ์ ์ฑ JS ์ฝ์ ์ ์ฐจ๋จํ์ฌ ๋๋ถ๋ถ์ XSS๋ฅผ ๋ฐฉ์งํฉ๋๋ค.
- StrictโTransportโSecurity (HSTS): HTTPS๋ฅผ ๊ฐ์ ํ๊ณ SSL ๋ค์ด๊ทธ๋ ์ด๋๋ฅผ ๋ฐฉ์งํฉ๋๋ค.
- XโFrameโOptions: ํ๋ ์ ์ฝ์ ์ ์ฐจ๋จํด ํด๋ฆญ์ฌํน์ ๋ฐฉ์งํฉ๋๋ค.
- XโContentโTypeโOptions: MIME ์ค๋ํ์ ์ฐจ๋จํฉ๋๋ค.
๋ณด์ ํค๋ ์ค์ (Spring Security)
http.headers(headers -> headers
.contentSecurityPolicy(csp -> csp
.policyDirectives("default-src 'self'; script-src 'self'")
)
.xssProtection(xss -> xss.block(true))
.frameOptions(HeadersConfigurer.FrameOptionsConfig::deny)
.httpStrictTransportSecurity(hsts -> hsts
.includeSubDomains(true)
.maxAgeInSeconds(31536000)
)
.contentTypeOptions(Customizer.withDefaults())
);
CSRF ์ค์
- JWT๋ฅผ ํค๋์ ์ฌ์ฉํ ๋: CSRF๋ฅผ ๋นํ์ฑํํฉ๋๋ค (ํ ํฐ ์์ฒด๊ฐ ๋ณดํธ ์ญํ ์ ํจ).
http.csrf(csrf -> csrf.disable());
- ์ฟ ํค ๊ธฐ๋ฐ ์ธ์ฆ์ ์ฌ์ฉํ ๋: CSRF ๋ณดํธ๋ฅผ ํ์ฑํํฉ๋๋ค.
์ ๋ ฅ ๊ฒ์ฆ ๋ฐ ์ ํ
// Example using Google's JSON Sanitizer (or similar)
String sanitized = JsonSanitizer.sanitize(userInput);
// Log sanitized data only
log.info("User input: {}", sanitized);
// Simple length check
if (userInput.length() > 200) {
throw new BadRequestException();
}
API Gateway ์ญํ
ํ๋ฆ: Client โ WAF โ Load Balancer โ API Gateway โ Microservices
- ์ค์ ์ง์ค์ ์ธ์ฆ
- JWT ๊ฒ์ฆ
- Rate limiting ๋ฐ IP ์ฐจ๋จ ๋ฆฌ์คํธ
- ๋ผ์ฐํธ ๊ฒฉ๋ฆฌ
Spring Cloud Gateway Token Relay ์์
spring:
cloud:
gateway:
routes:
- id: secure-service
uri: http://localhost:8082
predicates:
- Path=/secure/**
filters:
- RemoveRequestHeader=Cookie
- TokenRelay
Stateless architecture โ JWT๋ฅผ ์ฌ์ฉํ๋ฉด ์ธ์ ์คํฐํค๋์ค๊ฐ ํ์ ์์ต๋๋ค.
Client
|
Load Balancer
โ
Microservice A โ Microservice B
Actuator ๋ ธ์ถ ๊ด๋ฆฌ
์ ์ฒด ์์คํ ๋ฉํ๋ฐ์ดํฐ๊ฐ ์ ์ถ๋์ง ์๋๋ก ๋ ธ์ถ์ ๋ช ์์ ์ผ๋ก ์ค์ ํฉ๋๋ค:
management.endpoints.web.exposure.include=health,info
management.endpoints.web.exposure.exclude=env,beans
๋น๋ฐ๋ฒํธ ์ธ์ฝ๋ฉ
์ง์ ์ํธํ ๋ก์ง์ ๊ตฌํํ์ง ๋ง์ธ์. BCrypt๋ฅผ ์ฌ์ฉํ๋ฉด ์๋์ ์ผ๋ก ๋๋ฆฌ๊ฒ ๋์ํด ๋ฌด์ฐจ๋ณ ๋์ ๊ณต๊ฒฉ์ ๊ฐํฉ๋๋ค.
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder(12);
}
Enterprise Control List (๊ณ์ธตํ ๋ณด์)
| Layer | Focus |
|---|---|
| 1 โ Perimeter | WAF, DDoS mitigation |
| 2 โ Network | ZeroโTrust, TLSโฏ1.3 |
| 3 โ Gateway | Auth, rate limits |
| 4 โ Application | OAuth2, JWTโฏRS256 |
| 5 โ Headers | CSP, HSTS, XโFrameโOptions |
| 6 โ Code | Input validation |
| 7 โ Secrets | Vault / AWS Secrets Manager |
| 8 โ Monitoring | SIEM, audit logs |
์ํคํ ์ฒ ์ฒญ์ฌ์ง
๐ฑ Client
โ (TLSโฏ1.3)
๐ API Gateway (JWT validation, throttling)
โ
๐ Microservices (RBAC + scopes)
โ
๐ Encrypted Database (leastโprivilege access)
์ ๋ฆฌ
๋๋ถ๋ถ์ ํ๋ก์ ํธ๋ ๋ก๊ทธ์ธ ํ์ด์ง๋ง ๋ณดํธํฉ๋๋ค. ์ํฐํ๋ผ์ด์ฆ ์์ค ์์คํ ์ ๋ชจ๋ ๊ณ์ธต์์ ๋ณดํธ๊ฐ ํ์ํฉ๋๋ค. ์ฌ๊ธฐ์ ์ ์ํ ์ค์ฒ ํญ๋ชฉ ์ค ์ ๋ฐ์ด๋ผ๋ ์ ์ฉํ๋ฉด ๋๋ถ๋ถ์ ๊ฐ๋ฐ์๋ณด๋ค ์์ ๋๊ฐ ์ ์์ต๋๋ค. ๐