[TIL] 230807 port:8443์œผ๋กœ redirect ๋ผ์š” (Security)

CountryGirlยท2023๋…„ 8์›” 7์ผ

TIL

๋ชฉ๋ก ๋ณด๊ธฐ
36/80

๐Ÿ“Œ ๋ฌธ์ œ์  & ์‹œ๋„ & ํ•ด๊ฒฐ

๐Ÿ‘ฟ ๋ฌธ์ œ์ 

๊ฐ„๋‹จํ•˜๊ฒŒ HelloController.java๋ฅผ ๋งŒ๋“ค์–ด์„œ CI/CD๋ฅผ ํ•ด๋ณด์•˜๋‹ค.
๋ฐฐํฌ๊ฐ€ ๋จผ์ € ๋˜์–ด์žˆ์œผ๋ฉด ํŽธํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค!

@RestController
public class HelloController {
    @GetMapping("/api/hello")
    public String hello() {
        return "hello controller";
    }
}

https://domain.store:8080/api/hello
๋ฅผ ์ž…๋ ฅํ–ˆ๋Š”๋ฐ ๊ณ„์†
https://domain.store:8443/api/hello
์œผ๋กœ redirect๊ฐ€ ๋˜๊ณ  ์›ํ•˜๋Š” hello controller ๋ผ๋Š” ๋ฌธ์ž๊ฐ€ ๋ณด์ด์ง€ ์•Š์•˜๊ณ  ํŽ˜์ด์ง€์— ์˜ค๋ฅ˜๊ฐ€ ๋‚ฌ๋‹ค๊ณ  ํ–ˆ๋‹ค.

์ฒ˜์Œ์— ์„ธํŒ…์„ ํ•  ๋•Œ,

- Lombok
- JPA
- Web
- Validation
- MySQL
- Security: ๋‚˜์ค‘์— ํšŒ์›๊ฐ€์ž… / ๋กœ๊ทธ์ธ API๋ฅผ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด

์ด๋ ‡๊ฒŒ dependency๋ฅผ ์ถ”๊ฐ€ํ–ˆ์—ˆ๋‹ค.

์š”๊ฑฐ๊ฐ€ ๋ฌธ์ œ์˜€๋‹ค. ์ด ๋ฌธ์ œ์˜ ์‹œ๋ฐœ์ 


๐Ÿค” ์‹œ๋„

netstat -ntup
netstat -tuln | grep 443
netstat -tuln | grep 80
netstat -tuln | grep 8080
netstat -tuln | grep 22

์ด๊ฒƒ ์ €๊ฒƒ ๋ช…๋ น์–ด๋ฅผ ๊ณ„์† ์ž…๋ ฅํ•ด๋ณด์•˜๋‹ค.....

๊ณ„์† ์˜ค๋ฅ˜๊ฐ€ ๋‚˜๊ณ  redirect๊ฐ€ ๋ผ์„œ ๋ช‡ ์‹œ๊ฐ„๋™์•ˆ ๊ณ„์† ์‚ฝ์งˆ์„ ํ•˜์˜€๋‹ค.


๐Ÿ˜Ž ํ•ด๊ฒฐ

ํ˜น์‹œ๋‚˜ ํ•˜๋Š” ๋งˆ์Œ์— Security๋ฅผ exclude ํ•ด๋ณด์•˜๋‹ค.

@SpringBootApplication(exclude = SecurityAutoConfiguration.class)

๊ฐ™์ด ์˜ค๋ฅ˜๋ฅผ ํ•ด๊ฒฐํ–ˆ๋˜ ๋ถ„์ด ์˜ค๋ฅ˜๊ฐ€ ํ•ด๊ฒฐ๋œ ํ›„ ๊ณต์‹๋ฌธ์„œ๋ฅผ ์ฐพ์•„๋ณด์•˜๋‹ค๊ณ  ํ•œ๋‹ค.
Web Application Security : port-mappings

By default, an instance of PortMapperImpl will be added to the configuration for use in redirecting to secure and insecure URLs. This element can optionally be used to override the default mappings which that class defines. Each child element defines a pair of HTTP:HTTPS ports. The default mappings are 80:443 and 8080:8443. An example of overriding these can be found in Redirect to HTTPS.

Security AutoConfigure๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด https์— ๋งคํ•‘๋œ ํฌํŠธ๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ๊ฐ€ ๋œ๋‹ค.
Spring Boot ์—์„œ ์ œ๊ณตํ•˜๋Š” ๋‚ด์žฅ Tomcat์„ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด default port๊ฐ€ 8080์ด๊ธฐ ๋•Œ๋ฌธ์— 8443์œผ๋กœ ๊ณ„์† ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ๊ฐ€ ๋œ ๊ฒƒ์ด๋‹ค!

- 80 : 443
- 8080 : 8443

์ด๋ ‡๊ฒŒ ๋งคํ•‘์ด ๋˜์–ด์žˆ๋‹ค.

์—ฌ๋Ÿฌ๊ฐ€์ง€ ํ•ด๊ฒฐ๋ฒ•์ด ์žˆ์ง€๋งŒ Security๋ฅผ exclude ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ํ•ด๊ฒฐํ•˜์˜€๋‹ค.

โœ… Reference

IT, ์†Œํ†ต์˜ ์ง•๊ฒ€๋‹ค๋ฆฌ : [230807] Java Security AutoConfigure๊ฐ€ ๋  ๋•Œ Https Port ๋งคํ•‘

profile
๐Ÿ’ป๐ŸŒพ์‹œ๊ณจ์†Œ๋…€์˜ ์—‰๋ง์ง•์ฐฝ ๊ฐœ๋ฐœ ์„ฑ์žฅ์ผ์ง€๐ŸŒพ๐Ÿ’ป (2023.05.23 ~)

0๊ฐœ์˜ ๋Œ“๊ธ€