๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ/Web

[Web] XFF - Load balancers ํ˜น์€ Proxy ํ™˜๊ฒฝ์—์„œ Client IP ๊ฐ€์ ธ์˜ค๊ธฐ

by ynzu๐Ÿค 2022. 1. 20.
๋ฐ˜์‘ํ˜•

 

๊ธฐ์กด์—๋Š” request.getRemoteAddr(); ๋ฅผ ํ†ตํ•ด Client์˜ IP๋ฅผ ๊ฐ€์ ธ์™”๋Š”๋ฐ ์›น์„œ๋ฒ„๋‚˜ WAS ์•ž์— L4์™€ ๊ฐ™์€ Load balancers๋‚˜ Proxy server, caching server๋“ฑ์ด ์žˆ๋Š” ๊ฒฝ์šฐ๋Š” ์›ํ•˜๋Š” ๊ฒฐ๊ณผ๋ฅผ ์–ป์ง€ ๋ชปํ•˜๋Š” ๊ฒƒ์„ ๋ฐœ๊ฒฌํ•˜์˜€๋‹ค.

์ด๋Ÿฐ ์ œํ’ˆ์€ ์›น์„œ๋ฒ„ ํ˜น์€ WAS์— HTTP๋‚˜ AJP ์š”์ฒญ์„ ๋ณด๋‚ธ ํ›„ ๋ฐ›์€ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ€๊ณตํ•˜์—ฌ ํด๋ผ์ด์–ธํŠธ์— ์žฌ์ „์†กํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์œ„์™€ ๊ฐ™์€ ํ˜„์ƒ์ด ๋ฐœ์ƒํ•œ ๊ฒƒ์ด๋‹ค. ( ํด๋ผ์ด์–ธํŠธ  IP -> ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ, ํ”„๋ก์‹œ ์žฅ๋น„ -> ์›น์„œ๋ฒ„ )

๊ทธ๋ž˜์„œ ๋“ฑ์žฅํ•œ ๊ฒƒ์ด XFF(X-Forwarded-For)์ด๋‹ค!

 

XFF ์—๋Š” Client์™€ Proxy IP ๊ฐ€ ์ฝค๋งˆ๋ฅผ ๊ตฌ๋ถ„์ž๋กœ ๋“ค์–ด๊ฐ€๊ฒŒ ๋˜์–ด์žˆ๋Š”๋ฐ ์ˆœ์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™๊ธฐ ๋•Œ๋ฌธ์— ์ฒซ๋ฒˆ์งธ IP๋ฅผ ๊ฐ€์ ธ์˜ค๋ฉด Client์˜ IP๋ฅผ ํš๋“ํ•  ์ˆ˜ ์žˆ๋‹ค. 

X-Forwarded-For: client, proxy1, proxy2

 

XFF๋Š” ํ‘œ์ค€์ด์ง€๋งŒ ์ •์‹  RFC์— ํฌํ•จ๋œ๊ฒŒ ์•„๋‹ˆ๋ผ ๋ชจ๋“  ์ œํ’ˆ์ด XFF ํ—ค๋”๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋‹ค. 

์˜ˆ๋ฅผ ๋“ค์–ด WebLogic Connector(mod_wl) ๋Š” XFF ํ—ค๋”๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  WL-Proxy-Client-IP ๋‚˜ Proxy-Client-IP ํ—ค๋”๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. 

๋”ฐ๋ผ์„œ ์ œํ’ˆ์˜ ์ข…๋ฅ˜์— ์˜ํ–ฅ์„ ๋ฐ›์ง€ ์•Š๊ณ  Client IP๋ฅผ ๊ฐ€์ ธ์˜ค๊ณ ์ž ํ•œ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์ž‘์„ฑํ•ด์•ผ ํ•œ๋‹ค.

public String getClientIp(HttpServletRequest request) {
    String ip = null;

    ip = request.getHeader("X-Forwarded-For");
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("HTTP_CLIENT_IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("HTTP_X_FORWARDED_FOR");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getRemoteAddr();
    }

    log.debug("Client IP : " + ip);

    return ip;
}

 

 

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€