Kong Gateway 라우트 충돌(Route Collision) 이해와 예방
이 문서는 Kong Gateway에서 여러 라우트가 같은 요청 조건에 매칭돼 발생하는 라우트 충돌 문제를 설명해요. Kong은 라우트를 만들거나 수정할 때만 충돌을 검증하기 때문에, 이미 남아 있는 충돌은 운영 환경까지 그대로 넘어올 수 있어요. 배포 전에 decK lint 규칙으로 잘못 설정된 라우트를 미리 걸러내고, Event Hooks로 라우트 생성을 감시해 새로 생긴 충돌까지 놓치지 않는 방법을 안내해요
출처: 문서
본문
TL;DR
Kong Gateway에서 라우트 충돌을 이해하고 예방하려면 어떤 단계를 거쳐야 할까요?
라우트 충돌은 Kong이 KONG_ROUTE_VALIDATION_STRATEGY로 제어되는 라우트 생성 또는 업데이트 시점에만 충돌을 검사하기 때문에 발생해요. 그래서 기존에 있던 충돌은 소급해서 잡히지 않아요. 배포 전에 decK lint 룰셋과 자동화 계정이 아닌 계정에 대한 읽기 전용 Kong Manager 접근 권한으로 충돌을 예방하고, 라우트 생성을 모니터링하는 Event Hook으로 빠져나간 충돌을 잡아내세요.
문제
여러 라우트가 동일한 요청 조건(경로, 메서드, 호스트 등)에 일치하면 라우트 충돌이 발생해서 모호한 라우팅이 생겨요. Kong은 KONG_ROUTE_VALIDATION_STRATEGY를 기준으로 라우트 생성 또는 업데이트 시점에만 이런 충돌을 검사해요. 기존에 있던 충돌은 소급해서 검사하지 않기 때문에, 수동 변경이나 잘못 설정된 파이프라인을 통해 충돌이 여전히 프로덕션까지 도달할 수 있어요.
해결 방법
참고 자료:
- Kong Gateway는 Workspace 간 엔티티 충돌을 어떻게 해결하나요?
- API route collides with an existing API 오류가 발생하는 경우
검증 범위와 시점
- 검증은 라우트 생성 또는 업데이트 시에만 수행돼요
- 기존에 있던 충돌은 소급해서 검증되지 않아요
- 나중에 전략을 바꿔도 이전에 추가된 충돌 라우트는 표시되지 않아요
해결 방법
사전 예방: 배포 전 린트 검사
KONG_ROUTE_VALIDATION_STRATEGY를smart로 설정해서 중복 라우트를 검증하세요.- deck 룰셋을 사용해서 잘못 설정된 라우트가 Kong에 도달하기 전에 차단하세요. 자세한 내용은 deck file lint - deck | Kong Docs 문서를 참고하세요.
rules:
# Rule 1: Ensure 'paths' field exists on every route
# Purpose:
# Prevent routes missing the 'paths' field entirely,
# which can cause ambiguous routing or unexpected behavior.
# Examples:
# Accepted:
# paths: ["/api"]
# paths: ["/users", "/admin"]
# Rejected:
# (missing 'paths' field)
route-paths-exist:
description: "Routes must have a 'paths' field"
given: $.services[*].routes[*]
severity: error
then:
function: truthy
field: paths
# Rule 2: Validate 'paths' is a non-empty array of non-empty, valid strings
# Purpose:
# Ensure the 'paths' array is present and contains at least one non-empty string.
# Reject empty arrays and empty or whitespace-only strings.
# Pattern explanation:
# "^\\S+.*$" means:
# - Path must start with a non-whitespace character
# - Followed by zero or more characters
#
# Examples:
# Accepted:
# paths: ["/api"]
# paths: ["/v1/users", "/v2/admin"]
# paths: ["/api/v1 test"] # spaces allowed after first char
# Rejected:
# paths: []
# paths: [""]
# paths: [" "]
# paths: ["\t"]
route-paths-validation:
description: "Paths must be a non-empty array with non-empty strings starting with a non-whitespace character"
given: $.services[*].routes[*]
severity: error
then:
function: schema
field: paths
functionOptions:
schema:
type: array
minItems: 1
items:
type: string
pattern: "^\\S+.*$"
# Rule 3: Disallow literal root path "/"
# Purpose:
# Prevent routes that specify the root path "/" alone,
# which causes ambiguous or overly broad routing behavior.
#
# Pattern "^/[^/].*" explained:
# - Path must start with "/"
# - Followed by at least one character that is NOT "/"
# - So "/" alone is rejected, but "/api", "/v1/status" are allowed
#
# Examples:
# Accepted:
# paths: ["/api"]
# paths: ["/v1/status"]
# Rejected:
# paths: ["/"]
route-no-root-path:
description: "Reject routes that use '/' as a path"
given: $.services[*].routes[*].paths[*]
severity: error
then:
function: pattern
functionOptions:
match: "^/[^/].*"
- decK dump나 Kong의 Admin API로 라우트 설정을 감사하세요.
통합:
- 현재 배포 파이프라인을 확장해서 이 deck lint 룰셋을 도입하고, 잘못 설정된 라우트가 Kong에 도달하기 전에 차단하세요.
추가 고려 사항 - 수동 라우트 생성 방지
문제:
린트 검사가 마련되어 있어도 사용자가 Kong Manager에서 안전장치를 우회해서 잘못된 라우트를 수동으로 생성하거나 업데이트할 수 있어요.
해결 방법:
- 대부분의 사용자에게는 Kong Manager 접근을 읽기 전용으로 제한하세요
- 쓰기 권한은 자동화 계정이나 admin 검토자에게만 부여하세요.
사후 대응: Event Hook으로 모니터링
Event Hook을 사용하면 라우트 생성을 실시간으로 감지할 수 있어요.
관련 자료
더 알아보기 (Learn more)
이 문서에는 원문에서 추출한 별도의 관련 문서 링크가 없어요.