본문으로 건너뛰기

기능별 구현 쿡북: 5개 Gateway API 구현체

28분 읽기
AI용 문서 안내
정보

이 문서는 Gateway API 도입 가이드의 심화 가이드입니다. NGINX Ingress에서 사용하던 8가지 주요 기능을 각 Gateway API 구현체에서 어떻게 구현하는지 YAML 예제로 비교합니다. 솔루션 선정·비교표·의사결정 트리는 본 가이드의 섹션 4를 참조하세요.

개요​

이 쿡북은 다음 8가지 기능을 AWS Native(LBC v3), Cilium, NGINX Gateway Fabric, Envoy Gateway, kGateway별로 구현하는 방법을 다룹니다. URL Rewrite와 헤더 조작은 Gateway API v1 표준 기능이지만, 표준은 기능별로 Core·Extended 지원 수준을 구분하며 구현체와 버전에 따라 지원 범위가 다를 수 있습니다. 각 구현체에서 해당 필터가 지원되는지 확인한 뒤 사용합니다.

표 1. 쿡북에서 다루는 8가지 기능과 표준 여부

#기능표준 여부
1인증 (Basic Auth 대체)구현체별 상이
2Rate Limiting구현체별 상이
3IP 제어 (IP Allowlist)구현체별 상이
4URL RewriteGateway API v1 표준
5Header 조작Gateway API v1 표준
6세션 어피니티 (Cookie-based)구현체별 상이
7요청 본문 크기 제한구현체별 상이
8커스텀 에러 페이지구현체별 상이

1. 인증 (Basic Auth 대체)​

아래 탭은 서로 다른 controller의 대안 구성입니다. 해당 버전의 CRD/controller, production namespace, 같은 namespace의 production-gateway HTTPS listener(https)와 TLS 인증서, DNS, api-service:8080 backend가 준비되어야 합니다. example.com IdP/host와 Secret/공개 키 참조는 실제 환경에 맞게 바꿉니다. manifest를 렌더링·파싱한 것만으로 인증 성공을 확인할 수는 없습니다.

Authorization 헤더의 존재나 정규식 일치는 인증이 아닙니다. JWT 서명·issuer·audience·시간 조건 검증 또는 실제 인증 서비스의 allow/deny 결정이 필요합니다. 아래 예제는 학습용 자격 증명을 내장하지 않으며, 배포·인증 요청은 실행하지 않았습니다.

AWS LBC 3.0.0의 확장은 gateway.k8s.aws/v1beta1의 ListenerRuleConfiguration입니다. HTTPS listener에서 ALB가 RS256 JWT의 서명·iss·exp를 검증하고, 존재하면 nbf/iat도 확인합니다. 여기서는 문자열 aud=api-gateway-client를 추가로 요구합니다. IdP가 audience 배열을 내보내면 해당 claim 형식도 맞춰야 합니다. JWKS endpoint의 공개 접근성과 ALB 제한은 공식 JWT 문서를 확인합니다.

# auth-aws.yaml
# AWS Load Balancer Controller v3.0.0; existing HTTPS listener named https.
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: jwt-protected-route
namespace: production
spec:
parentRefs:
- name: production-gateway
sectionName: https
hostnames:
- api.example.com
rules:
- matches:
- path:
type: PathPrefix
value: /api
filters:
- type: ExtensionRef
extensionRef:
group: gateway.k8s.aws
kind: ListenerRuleConfiguration
name: api-jwt
backendRefs:
- name: api-service
port: 8080
---
apiVersion: gateway.k8s.aws/v1beta1
kind: ListenerRuleConfiguration
metadata:
name: api-jwt
namespace: production
spec:
actions:
- type: jwt-validation
jwtValidationConfig:
jwksEndpoint: https://idp.example.com/realms/production/protocol/openid-connect/certs
issuer: https://idp.example.com/realms/production
additionalClaims:
- name: aud
format: single-string
values:
- api-gateway-client

JWT 검증은 browser OIDC 로그인 redirect와 다른 기능입니다. 유효한 token은 backend에 그대로 전달되며 위 확장은 claimsToHeaders를 구성하지 않습니다. downstream identity header가 필요하면 별도 신뢰·덮어쓰기 계약을 정의합니다. LBC 3.0.0 LRC 계약

인증 적용 전후에는 선택한 메커니즘에 맞춰 정상 자격 증명, 누락·변조·만료된 token 또는 잘못된 비밀번호, 잘못된 issuer/audience, authorizer 장애, callback 경로와 backend 직접 접근을 확인합니다. route/policy 상태의 Accepted/ResolvedRefs와 실제 backend 요청 도달 여부를 함께 기록해야 합니다. 정적 schema 검사만으로 이 실행 결과를 대신하지 않습니다.

2. Rate Limiting​

제한 사항

AWS Native(LBC v3)는 게이트웨이 레벨의 네이티브 Rate Limiting을 지원하지 않습니다. AWS WAF Rate-based Rule을 사용하여 IP 기반 요청 제한을 구현합니다.

# ALB에 WAF Rate-based Rule 연결 (LBC v3 Gateway)
# WAF 연결은 Gateway 애너테이션이 아니라 LoadBalancerConfiguration의
# spec.wafV2.webACL(ARN 문자열)로 설정하고, Gateway의
# spec.infrastructure.parametersRef로 참조합니다.
apiVersion: gateway.k8s.aws/v1
kind: LoadBalancerConfiguration
metadata:
name: production-lb-config
namespace: production
spec:
wafV2:
webACL: arn:aws:wafv2:us-west-2:123456789012:regional/webacl/rate-limit/a1b2c3d4
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: production-gateway
namespace: production
spec:
gatewayClassName: aws-alb
infrastructure:
parametersRef:
group: gateway.k8s.aws
kind: LoadBalancerConfiguration
name: production-lb-config
listeners:
- name: http
port: 80
protocol: HTTP

ACK(AWS Controllers for Kubernetes)로 WAF Rate-based Rule 생성:

ACK WAFv2 컨트롤러를 사용하면 WAF 리소스를 Kubernetes 매니페스트로 선언적 관리할 수 있습니다.

EKS Capabilities로 ACK 활성화 (권장):

EKS Capabilities(2025년 11월 GA)를 사용하면 ACK 컨트롤러를 AWS 완전 관리형으로 운영할 수 있습니다. 컨트롤러가 AWS 관리 인프라에서 실행되므로 워커 노드에 별도 Pod가 배포되지 않습니다.

# 1. IAM Capability Role 생성
aws iam create-role \
--role-name EKS-ACK-Capability-Role \
--assume-role-policy-document '{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": { "Service": "capabilities.eks.amazonaws.com" },
"Action": ["sts:AssumeRole", "sts:TagSession"]
}]
}'

# WAFv2 권한 정책 연결
aws iam put-role-policy \
--role-name EKS-ACK-Capability-Role \
--policy-name ACK-WAFv2-Policy \
--policy-document '{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["wafv2:*"],
"Resource": "*"
}]
}'

# 2. EKS 클러스터에 ACK Capability 생성
aws eks create-capability \
--region <REGION> \
--cluster-name my-eks-cluster \
--capability-name my-ack \
--type ACK \
--role-arn arn:aws:iam::<ACCOUNT_ID>:role/EKS-ACK-Capability-Role \
--delete-propagation-policy RETAIN

# 3. Capability가 ACTIVE 상태인지 확인 후 CRD 등록 확인
aws eks describe-capability \
--region <REGION> \
--cluster-name my-eks-cluster \
--capability-name my-ack \
--query 'capability.status' --output text
kubectl get crds | grep wafv2
대안: Helm으로 직접 설치 (비 EKS 환경)

EKS가 아닌 환경이나 컨트롤러를 직접 관리해야 하는 경우 Helm으로 설치할 수 있습니다.

helm install ack-wafv2-controller \
oci://public.ecr.aws/aws-controllers-k8s/wafv2-chart \
--namespace ack-system \
--create-namespace \
--set aws.region=ap-northeast-2

이 방식은 컨트롤러가 워커 노드에 Pod로 배포되며, IRSA(IAM Roles for Service Accounts)로 권한을 관리합니다.

# ACK WAFv2 WebACL - Rate-based Rule 정의
apiVersion: wafv2.services.k8s.aws/v1alpha1
kind: WebACL
metadata:
name: rate-limit-acl
namespace: production
spec:
name: rate-limit-acl
scope: REGIONAL
defaultAction:
allow: {}
rules:
- name: ip-rate-limit
priority: 1
action:
block: {}
statement:
rateBasedStatement:
limit: 500 # 평가 기간당 허용 요청 수(예시). 허용 최솟값은 10
evaluationWindowSec: 300 # 평가 기간: 60/120/300/600초 중 선택(기본 300초)
aggregateKeyType: IP # 집계 기준의 한 예: 소스 IP별 집계
visibilityConfig:
sampledRequestsEnabled: true
cloudWatchMetricsEnabled: true
metricName: ip-rate-limit
visibilityConfig:
sampledRequestsEnabled: true
cloudWatchMetricsEnabled: true
metricName: rate-limit-acl
# 생성된 WebACL ARN을 Gateway에 연결
# WebACL 생성 후 status.ackResourceMetadata.arn 에서 ARN 확인:
# kubectl get webacl rate-limit-acl -n production \
# -o jsonpath='{.status.ackResourceMetadata.arn}'
apiVersion: gateway.k8s.aws/v1
kind: LoadBalancerConfiguration
metadata:
name: production-lb-config
namespace: production
spec:
wafV2:
webACL: <WebACL ARN>
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: production-gateway
namespace: production
spec:
gatewayClassName: aws-alb
infrastructure:
parametersRef:
group: gateway.k8s.aws
kind: LoadBalancerConfiguration
name: production-lb-config
listeners:
- name: http
port: 80
protocol: HTTP
ACK WAFv2 컨트롤러 요구사항
  • ACK WAFv2 컨트롤러에 wafv2:CreateWebACL, wafv2:UpdateWebACL, wafv2:DeleteWebACL, wafv2:GetWebACL 등의 IAM 권한이 필요합니다
  • EKS Capabilities 사용 시: IAM Capability Role에 WAFv2 권한을 연결합니다. 컨트롤러는 AWS 관리 인프라에서 실행됩니다
  • Helm 설치 사용 시: IRSA(IAM Roles for Service Accounts) 또는 EKS Pod Identity를 통해 최소 권한을 부여하세요
  • WebACL과 ALB는 동일 리전에 있어야 합니다

3. IP 제어 (IP Allowlist)​

# ALB에 WAF IP Allowlist 연결 (LBC v3 Gateway)
apiVersion: gateway.k8s.aws/v1
kind: LoadBalancerConfiguration
metadata:
name: production-lb-config
namespace: production
spec:
wafV2:
webACL: arn:aws:wafv2:us-west-2:123456789012:regional/webacl/ip-allowlist/a1b2c3d4
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: production-gateway
namespace: production
spec:
gatewayClassName: aws-alb
infrastructure:
parametersRef:
group: gateway.k8s.aws
kind: LoadBalancerConfiguration
name: production-lb-config
listeners:
- name: http
port: 80
protocol: HTTP

ACK(AWS Controllers for Kubernetes)로 WAF IP Allowlist 생성:

ACK WAFv2 컨트롤러를 사용하면 IPSet과 WebACL을 Kubernetes 매니페스트로 선언적 관리할 수 있습니다.

# 1. ACK WAFv2 IPSet - 허용할 IP 목록 정의
apiVersion: wafv2.services.k8s.aws/v1alpha1
kind: IPSet
metadata:
name: allowed-ips
namespace: production
spec:
name: allowed-ips
scope: REGIONAL
ipAddressVersion: IPV4
addresses:
- "10.0.0.0/8" # VPC 내부
- "192.168.1.0/24" # 사무실 네트워크
- "203.0.113.100/32" # 특정 허용 IP
# 2. ACK WAFv2 WebACL - IPSet 기반 Allowlist 규칙
# IPSet 생성 후 status.ackResourceMetadata.arn 에서 ARN 확인:
# kubectl get ipset allowed-ips -n production \
# -o jsonpath='{.status.ackResourceMetadata.arn}'
apiVersion: wafv2.services.k8s.aws/v1alpha1
kind: WebACL
metadata:
name: ip-allowlist-acl
namespace: production
spec:
name: ip-allowlist-acl
scope: REGIONAL
defaultAction:
block: {} # 기본 차단, 허용 목록만 통과
rules:
- name: allow-trusted-ips
priority: 1
action:
allow: {}
statement:
ipSetReferenceStatement:
arn: <IPSet ARN> # allowed-ips IPSet의 ARN
visibilityConfig:
sampledRequestsEnabled: true
cloudWatchMetricsEnabled: true
metricName: allow-trusted-ips
visibilityConfig:
sampledRequestsEnabled: true
cloudWatchMetricsEnabled: true
metricName: ip-allowlist-acl
# 3. 생성된 WebACL ARN을 Gateway에 연결
# WebACL 생성 후 status.ackResourceMetadata.arn 에서 ARN 확인:
# kubectl get webacl ip-allowlist-acl -n production \
# -o jsonpath='{.status.ackResourceMetadata.arn}'
apiVersion: gateway.k8s.aws/v1
kind: LoadBalancerConfiguration
metadata:
name: production-lb-config
namespace: production
spec:
wafV2:
webACL: <WebACL ARN>
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: production-gateway
namespace: production
spec:
gatewayClassName: aws-alb
infrastructure:
parametersRef:
group: gateway.k8s.aws
kind: LoadBalancerConfiguration
name: production-lb-config
listeners:
- name: http
port: 80
protocol: HTTP
ACK WAFv2 IPSet 관리 팁
  • IPSet의 addresses 필드를 업데이트하면 ACK 컨트롤러가 자동으로 AWS WAF IPSet을 동기화합니다
  • GitOps(ArgoCD/Flux)와 결합하면 IP 변경을 PR 기반으로 관리할 수 있습니다
  • IPSet과 WebACL은 동일 리전에 있어야 하며, wafv2:*IPSet*, wafv2:*WebACL* 권한이 필요합니다 (EKS Capabilities: IAM Capability Role / Helm: IRSA)

4. URL Rewrite​

Gateway API 표준

URL Rewrite는 Gateway API v1 표준 기능이지만, 경로 접두사 재작성(ReplacePrefixMatch)과 전체 경로 재작성의 지원 수준은 구현체와 버전에 따라 다를 수 있습니다. 사용 전 해당 구현체의 지원 범위를 확인합니다.

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: api-rewrite
namespace: production
spec:
parentRefs:
- name: production-gateway
rules:
# /api/v1/users → /users
- matches:
- path:
type: PathPrefix
value: /api/v1
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: /
backendRefs:
- name: api-service
port: 8080

# /old-api/users → /v2/users
- matches:
- path:
type: PathPrefix
value: /old-api
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: /v2
backendRefs:
- name: api-service-v2
port: 8080

5. Header 조작​

Gateway API 표준

Header 조작은 Gateway API v1 표준 기능이지만, 요청·응답 헤더 수정 필터의 지원 수준은 구현체와 버전에 따라 다를 수 있습니다. 사용 전 해당 구현체의 지원 범위를 확인합니다.

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: header-manipulation
spec:
parentRefs:
- name: production-gateway
rules:
- matches:
- path:
value: /api
filters:
# 요청 헤더 추가
- type: RequestHeaderModifier
requestHeaderModifier:
add:
- name: X-Custom-Header
value: "gateway-api"
- name: X-Forwarded-Proto
value: "https"
remove:
- Authorization # 기존 Authorization 제거
# 응답 헤더 추가
- type: ResponseHeaderModifier
responseHeaderModifier:
add:
- name: X-Server
value: "gateway-api"
- name: Strict-Transport-Security
value: "max-age=31536000; includeSubDomains"
backendRefs:
- name: api-service
port: 8080
# LBC v3 Gateway에서 스티키니스는 HTTPRoute 애너테이션이 아니라
# TargetGroupConfiguration(targetReference로 backend Service를 지정)의
# targetGroupProps.targetGroupAttributes에 대상 그룹 속성(key/value)으로 설정합니다.
apiVersion: gateway.k8s.aws/v1
kind: TargetGroupConfiguration
metadata:
name: api-service-tg-config
namespace: production
spec:
targetReference:
name: api-service
defaultConfiguration:
targetGroupAttributes:
- key: stickiness.enabled
value: "true"
- key: stickiness.type
value: lb_cookie
- key: stickiness.lb_cookie.duration_seconds
value: "3600"
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: sticky-session
namespace: production
spec:
parentRefs:
- name: production-gateway
rules:
- backendRefs:
- name: api-service
port: 8080

7. 요청 본문 크기 제한​

제한 사항

ALB에 연결된 AWS WAF는 요청 본문의 처음 8KiB(8,192바이트)만 검사합니다. 아래 sizeConstraintStatement의 oversizeHandling: MATCH는 8KiB를 넘는 본문을 지정한 size 임계값과 무관하게 매칭(차단)하므로, 이 규칙은 "10 MiB 업로드 상한"이 아니라 "검사 한도를 넘는 본문 차단"입니다. 요청 본문 전체 크기를 제한하려면 본문 전체를 수신하는 구성 요소(예: Envoy의 요청 버퍼링, NGINX의 본문 크기 설정)에서 적용해야 합니다.

# ALB에 WAF Body Size Limit Rule 연결 (LBC v3 Gateway)
apiVersion: gateway.k8s.aws/v1
kind: LoadBalancerConfiguration
metadata:
name: production-lb-config
namespace: production
spec:
wafV2:
webACL: arn:aws:wafv2:us-west-2:123456789012:regional/webacl/body-size-limit/a1b2c3d4
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: production-gateway
namespace: production
spec:
gatewayClassName: aws-alb
infrastructure:
parametersRef:
group: gateway.k8s.aws
kind: LoadBalancerConfiguration
name: production-lb-config
listeners:
- name: http
port: 80
protocol: HTTP

ACK(AWS Controllers for Kubernetes)로 WAF Body Size Rule 생성:

ACK WAFv2 컨트롤러를 사용하면 Body Size 제한 규칙을 Kubernetes 매니페스트로 선언적 관리할 수 있습니다.

# ACK WAFv2 WebACL - Body Size Limit Rule 정의
apiVersion: wafv2.services.k8s.aws/v1alpha1
kind: WebACL
metadata:
name: body-size-limit-acl
namespace: production
spec:
name: body-size-limit-acl
scope: REGIONAL
defaultAction:
allow: {}
rules:
- name: block-large-body
priority: 1
action:
block: {}
statement:
sizeConstraintStatement:
fieldToMatch:
body:
oversizeHandling: MATCH # 8KiB를 넘는 본문은 크기와 무관하게 매칭(차단)
comparisonOperator: GT
size: 10485760 # 10 MiB(바이트 단위). WAF 본문 검사 범위와는 별개
textTransformations:
- priority: 0
type: NONE
visibilityConfig:
sampledRequestsEnabled: true
cloudWatchMetricsEnabled: true
metricName: block-large-body
visibilityConfig:
sampledRequestsEnabled: true
cloudWatchMetricsEnabled: true
metricName: body-size-limit-acl
# 생성된 WebACL ARN을 Gateway에 연결
# WebACL 생성 후 status.ackResourceMetadata.arn 에서 ARN 확인:
# kubectl get webacl body-size-limit-acl -n production \
# -o jsonpath='{.status.ackResourceMetadata.arn}'
apiVersion: gateway.k8s.aws/v1
kind: LoadBalancerConfiguration
metadata:
name: production-lb-config
namespace: production
spec:
wafV2:
webACL: <WebACL ARN>
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: production-gateway
namespace: production
spec:
gatewayClassName: aws-alb
infrastructure:
parametersRef:
group: gateway.k8s.aws
kind: LoadBalancerConfiguration
name: production-lb-config
listeners:
- name: http
port: 80
protocol: HTTP
단일 WebACL로 규칙 통합

IP Allowlist, Rate Limiting, Body Size 제한을 모두 사용한다면, 별도의 WebACL을 각각 만들 필요 없이 하나의 WebACL에 여러 규칙을 priority로 구분하여 통합할 수 있습니다. ALB당 WebACL은 하나만 연결 가능하므로 통합 관리가 필수입니다.

규칙을 통합할 때는 평가 순서에 주의합니다. 허용 목록 규칙이 action: allow로 요청을 허용하면 그 규칙에서 평가가 종료되어 뒤 순위의 Rate Limiting·Body Size 규칙이 실행되지 않습니다. 허용된 IP에도 요청 제한·본문 검사를 적용하려면 이들 검사를 허용 규칙보다 앞 순위에 두거나, 허용 규칙이 평가를 종료하지 않도록 규칙 구조를 설계해야 합니다. 허용된 IP의 비정상 요청과 차단 대상 IP의 요청을 모두 테스트해 의도한 순서로 동작하는지 확인합니다.

8. 커스텀 에러 페이지​

LBC v3 Gateway에서 고정 응답은 Ingress용 alb.ingress.kubernetes.io/actions.* 애너테이션이나 존재하지 않는 error-503 Service로 구성하지 않습니다. HTTPRoute에 ListenerRuleConfiguration(gateway.k8s.aws/v1beta1)을 ExtensionRef로 연결하고 그 안에서 fixed-response 액션을 정의합니다. 배포 후 실제 응답 코드·본문이 의도대로 반환되는지 확인합니다.

# LBC v3 Gateway: ListenerRuleConfiguration fixed-response 액션
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: error-response
namespace: production
spec:
parentRefs:
- name: production-gateway
rules:
- matches:
- path:
type: PathPrefix
value: /maintenance
filters:
- type: ExtensionRef
extensionRef:
group: gateway.k8s.aws
kind: ListenerRuleConfiguration
name: error-503
---
apiVersion: gateway.k8s.aws/v1beta1
kind: ListenerRuleConfiguration
metadata:
name: error-503
namespace: production
spec:
actions:
- type: fixed-response
fixedResponseConfig:
contentType: text/html
statusCode: "503"
messageBody: "<html><body><h1>Service Under Maintenance</h1><p>Please try again later.</p></body></html>"

참고 자료​

공식 문서​

관련 문서 (내부)​