AI MCP OAuth2 플러그인
AI MCP OAuth2 플러그인 (AI MCP OAuth2 Plugin)
AI MCP OAuth2 플러그인은 AI Gateway에서 Model Context Protocol(MCP) 트래픽을 OAuth 2.0 사양에 따라 보호하는 플러그인이에요. 외부 Authorization Server가 발급한 액세스 토큰을 검증해서 승인된 MCP 클라이언트만 보호된 MCP 서버에 접근할 수 있도록 해줘요. 검증된 토큰에서 클레임을 추출해 헤더로 업스트림에 전달하고, 기본적으로는 액세스 토큰 자체를 업스트림으로 보내지 않아서 토큰 탈취나 confused deputy 공격 위험을 낮춰줘요. AI Gateway Enterprise 오퍼링에만 포함된 플러그인이라는 점도 기억해두면 좋아요
출처: 문서
본문
AI Gateway Enterprise: 이 플러그인은 AI Gateway Enterprise 오퍼링의 일부로만 제공돼요.
AI MCP OAuth2 플러그인은 MCP 서버를 위한 OAuth 2.0 사양을 사용해 AI Gateway에서 Model Context Protocol(MCP) 트래픽을 보호해요. 이 플러그인은 승인된 MCP 클라이언트만 보호된 MCP 서버에 접근할 수 있도록 보장하며, MCP 서버의 중요한 보안 계층 역할을 해요.
주요 변경 사항
v3.13+ MCP OAuth2 플러그인은 잠재적인 인증 우회 취약점을 해결하기 위해, 이제 들어오는 모든 트래픽을 MCP 요청으로 취급해요.
이 플러그인을 같은 라우트에서
conversion-listener모드의 AI MCP Proxy 플러그인과 함께 사용하지 마세요. MCP가 아닌 요청은 실패해요.MCP OAuth2는
listener또는passthrough-listener모드의 MCP Proxy와 함께 사용하세요. REST API 노출이 필요한 경우에는 별도의 라우트에서conversion-only모드로 MCP Proxy를 구성하세요.
목적과 핵심 기능
이 플러그인은 MCP 트래픽에 OAuth 2.0 인증을 제공해서 MCP 클라이언트가 안전하게 접근을 요청할 수 있게 해요. 액세스 토큰이 대상 MCP 서버를 위해 특별히 발급된 것인지 검증해서, 승인된 요청만 수락되도록 보장해요. 토큰 탈취나 혼란스러운 대리자(confused deputy) 공격의 위험을 줄이기 위해, 이 플러그인은 액세스 토큰을 업스트림 서비스에 전달하지 않아요.
이 플러그인은 세 가지 핵심 기능을 수행해요:
- 외부 인가 서버(Authorization Server)에서 액세스 토큰을 검증해서 들어오는 MCP 요청을 확인해요.
- 검증된 토큰에서 클레임을 추출하고, 헤더를 통해 업스트림 MCP 서비스에 전달해요.
- OAuth 2.1 기반의 MCP 인증 요구 사항 준수를 보장해요.
인증 흐름
이 플러그인은 다음 인증 흐름을 따라요:
- AI Gateway는 Resource Server 역할을 하며 접근 제어를 강제해요.
- MCP 클라이언트는 유효한
Authorization: Bearer <access-token>헤더와 함께 요청을 보내요. - 플러그인은 토큰을 검증하고 의도된 대상(audience)을 확인하며, 유효하지 않거나 만료된 토큰은
401 Unauthorized로 차단해요. - 액세스 토큰은 기본적으로 업스트림 서비스에 전달되지 않아서, 토큰 탈취나 혼란스러운 대리자 공격으로부터 보호돼요.
sequenceDiagram
participant C as MCP client
participant K as AI MCP OAuth2 plugin
participant AS as Authorization server
participant U as Upstream MCP server
C->>K: Discover protected resource metadata
activate K
K-->>C: Protected resource metadata (includes auth server address)
deactivate K
C->>AS: Request access token
activate AS
AS-->>C: Access token
deactivate AS
C->>K: MCP auth request
activate K
K->>AS: Introspect token
activate AS
AS-->>K: Valid / invalid
deactivate AS
alt If token valid
K->>U: Forward request with claims as headers
activate U
U-->>K: MCP server response
deactivate U
K-->>C: MCP response
else If token invalid
K-->>C: 401 Unauthorized
end
deactivate K
플러그인 실행
AI MCP OAuth2 플러그인은 AI 특화 처리가 일어나기 전에 승인되지 않은 접근을 막을 수 있도록, 요청 라이프사이클에서 최대한 이른 시점에 MCP 트래픽을 보호하도록 설계됐어요.
참고: AI MCP Proxy 플러그인과 마찬가지로, AI MCP OAuth2 플러그인은 LLM 요청 흐름의 일부로 호출되지 않아요.
대신 일반 플러그인으로 등록되고 실행되기 때문에, LLM 요청 흐름과 독립적으로 MCP 트래픽을 캡처할 수 있어요. AI MCP OAuth2 플러그인은 업스트림 MCP 프록싱을 위해 단독으로 사용하거나, 요청/응답 변환이 필요할 때 AI MCP Proxy 플러그인과 함께 사용할 수 있어요.
토큰 검증 방법 v3.14+
이 플러그인은 두 가지 토큰 검증 방법을 지원해요. 인트로스펙션(introspection)이 구성되어 있으면 항상 이 방법이 사용되고, JWKS는 인트로스펙션 엔드포인트가 구성되어 있지 않을 때만 사용돼요.
- 인트로스펙션(Introspection):
config.introspection_endpoint를 설정하면 플러그인이 인가 서버를 호출해서 불투명(opaque) 토큰을 검증해요.config.client_auth가client_secret_basic또는client_secret_post일 때는config.client_id가 필요해요. - JWKS:
config.jwks_endpoint를 설정하면 인가 서버의 공개 키를 사용해 서명된 JWT를 로컬에서 검증해요. 설정하지 않으면 플러그인이 인가 서버 메타데이터에서 JWKS URI를 찾으려고 시도해요.
클레임 전달
이 플러그인은 검증된 토큰에서 클레임을 추출해서 HTTP 헤더 형태로 업스트림 MCP 서버에 전달할 수 있어요. 두 가지 방식을 사용할 수 있으며, 이 두 방식은 서로 배타적이에요.
최상위 클레임
config.claim_to_header를 사용하면 토큰의 최상위 클레임을 업스트림 헤더에 매핑할 수 있어요. 각 항목에는 claim 이름과 header 이름이 필요해요:
decK
_format_version: "3.0"
plugins:
- name: ai-mcp-oauth2
config:
resource: https://api.example.com/mcp
authorization_servers:
- https://auth.example.com
claim_to_header:
- claim: sub
header: X-User-Id
- claim: email
header: X-User-Email
{: data-file="kong.yaml" data-tool="deck" }
Admin API
curl -i -X POST http://localhost:8001/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "ai-mcp-oauth2",
"config": {
"resource": "https://api.example.com/mcp",
"authorization_servers": [
"https://auth.example.com"
],
"claim_to_header": [
{
"claim": "sub",
"header": "X-User-Id"
},
{
"claim": "email",
"header": "X-User-Email"
}
]
}
}
'
Konnect API
다음 요청을 보내세요:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "ai-mcp-oauth2",
"config": {
"resource": "https://api.example.com/mcp",
"authorization_servers": [
"https://auth.example.com"
],
"claim_to_header": [
{
"claim": "sub",
"header": "X-User-Id"
},
{
"claim": "email",
"header": "X-User-Email"
}
]
}
}
'
KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name: ai-mcp-oauth2
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
labels:
global: 'true'
config:
resource: https://api.example.com/mcp
authorization_servers:
- https://auth.example.com
claim_to_header:
- claim: sub
header: X-User-Id
- claim: email
header: X-User-Email
plugin: ai-mcp-oauth2
" | kubectl apply -f -
Terraform
resource "konnect_gateway_plugin_ai_mcp_oauth2" "my_ai_mcp_oauth2" {
enabled = true
config = {
resource = "https://api.example.com/mcp"
authorization_servers = ["https://auth.example.com"]
claim_to_header = [
{
claim = "sub"
header = "X-User-Id"
},
{
claim = "email"
header = "X-User-Email"
} ]
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}
중첩 클레임 v3.14+
config.upstream_headers를 사용하면 경로 배열을 통해 토큰 페이로드의 어떤 깊이에 있는 클레임이든 매핑할 수 있어요. 이 필드는 claim_to_header와 상호 배타적이에요:
decK
_format_version: "3.0"
plugins:
- name: ai-mcp-oauth2
config:
resource: https://api.example.com/mcp
authorization_servers:
- https://auth.example.com
upstream_headers:
- header: X-Org-Id
path:
- org
- id
- header: X-User-Role
path:
- realm_access
- roles
{: data-file="kong.yaml" data-tool="deck" }
Admin API
curl -i -X POST http://localhost:8001/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "ai-mcp-oauth2",
"config": {
"resource": "https://api.example.com/mcp",
"authorization_servers": [
"https://auth.example.com"
],
"upstream_headers": [
{
"header": "X-Org-Id",
"path": [
"org",
"id"
]
},
{
"header": "X-User-Role",
"path": [
"realm_access",
"roles"
]
}
]
}
}
'
Konnect API
다음 요청을 보내세요:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "ai-mcp-oauth2",
"config": {
"resource": "https://api.example.com/mcp",
"authorization_servers": [
"https://auth.example.com"
],
"upstream_headers": [
{
"header": "X-Org-Id",
"path": [
"org",
"id"
]
},
{
"header": "X-User-Role",
"path": [
"realm_access",
"roles"
]
}
]
}
}
'
KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name: ai-mcp-oauth2
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
labels:
global: 'true'
config:
resource: https://api.example.com/mcp
authorization_servers:
- https://auth.example.com
upstream_headers:
- header: X-Org-Id
path:
- org
- id
- header: X-User-Role
path:
- realm_access
- roles
plugin: ai-mcp-oauth2
" | kubectl apply -f -
Terraform
resource "konnect_gateway_plugin_ai_mcp_oauth2" "my_ai_mcp_oauth2" {
enabled = true
config = {
resource = "https://api.example.com/mcp"
authorization_servers = ["https://auth.example.com"]
upstream_headers = [
{
header = "X-Org-Id"
path = ["org", "id"]
},
{
header = "X-User-Role"
path = ["realm_access", "roles"]
} ]
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}
컨슈머 매핑 v3.14+
이 플러그인은 토큰 클레임을 Kong 컨슈머와 컨슈머 그룹에 매핑할 수 있어서, 컨슈머 기반 속도 제한, ACL, 그리고 다른 컨슈머 인식(consumer-aware) 플러그인이 MCP 트래픽에서도 동작할 수 있어요.
컨슈머
config.consumer_claim을 컨슈머 조회에 사용할 클레임의 경로로 설정하세요. 문자열을 여러 개 제공하면 플러그인이 이를 토큰 페이로드 안의 중첩된 경로로 취급해요. 예를 들어 ["sub"]는 최상위 sub 클레임을 매핑하고, ["realm_access", "user_id"]는 token.realm_access.user_id를 매핑해요.
config.consumer_by를 사용하면 조회 시 어떤 컨슈머 필드를 확인할지 제어할 수 있어요. 허용되는 값은 id, username, custom_id이며, 기본값은 ["username", "custom_id"]예요.
매칭되는 컨슈머를 찾지 못했을 때 플러그인이 실패하지 않고 계속 진행하게 하려면 config.consumer_optional을 true로 설정하세요.
decK
_format_version: "3.0"
plugins:
- name: ai-mcp-oauth2
config:
resource: https://api.example.com/mcp
authorization_servers:
- https://auth.example.com
consumer_claim:
- sub
consumer_by:
- username
- custom_id
consumer_optional: false
{: data-file="kong.yaml" data-tool="deck" }
Admin API
curl -i -X POST http://localhost:8001/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "ai-mcp-oauth2",
"config": {
"resource": "https://api.example.com/mcp",
"authorization_servers": [
"https://auth.example.com"
],
"consumer_claim": [
"sub"
],
"consumer_by": [
"username",
"custom_id"
],
"consumer_optional": false
}
}
'
Konnect API
다음 요청을 보내세요:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "ai-mcp-oauth2",
"config": {
"resource": "https://api.example.com/mcp",
"authorization_servers": [
"https://auth.example.com"
],
"consumer_claim": [
"sub"
],
"consumer_by": [
"username",
"custom_id"
],
"consumer_optional": false
}
}
'
KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name: ai-mcp-oauth2
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
labels:
global: 'true'
config:
resource: https://api.example.com/mcp
authorization_servers:
- https://auth.example.com
consumer_claim:
- sub
consumer_by:
- username
- custom_id
consumer_optional: false
plugin: ai-mcp-oauth2
" | kubectl apply -f -
Terraform
resource "konnect_gateway_plugin_ai_mcp_oauth2" "my_ai_mcp_oauth2" {
enabled = true
config = {
resource = "https://api.example.com/mcp"
authorization_servers = ["https://auth.example.com"]
consumer_claim = ["sub"]
consumer_by = ["username", "custom_id"]
consumer_optional = false
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}
컨슈머 그룹
config.consumer_groups_claim을 컨슈머 그룹 이름이 담긴 클레임의 경로로 설정하세요. 문자열을 여러 개 제공하면 플러그인이 이를 중첩된 경로로 취급해요.
매칭되는 컨슈머 그룹이 없어도 요청이 진행될 수 있게 하려면 config.consumer_groups_optional을 true로 설정하세요.
decK
_format_version: "3.0"
plugins:
- name: ai-mcp-oauth2
config:
resource: https://api.example.com/mcp
authorization_servers:
- https://auth.example.com
consumer_groups_claim:
- groups
consumer_groups_optional: true
{: data-file="kong.yaml" data-tool="deck" }
Admin API
curl -i -X POST http://localhost:8001/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "ai-mcp-oauth2",
"config": {
"resource": "https://api.example.com/mcp",
"authorization_servers": [
"https://auth.example.com"
],
"consumer_groups_claim": [
"groups"
],
"consumer_groups_optional": true
}
}
'
Konnect API
다음 요청을 보내세요:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "ai-mcp-oauth2",
"config": {
"resource": "https://api.example.com/mcp",
"authorization_servers": [
"https://auth.example.com"
],
"consumer_groups_claim": [
"groups"
],
"consumer_groups_optional": true
}
}
'
KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name: ai-mcp-oauth2
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
labels:
global: 'true'
config:
resource: https://api.example.com/mcp
authorization_servers:
- https://auth.example.com
consumer_groups_claim:
- groups
consumer_groups_optional: true
plugin: ai-mcp-oauth2
" | kubectl apply -f -
Terraform
resource "konnect_gateway_plugin_ai_mcp_oauth2" "my_ai_mcp_oauth2" {
enabled = true
config = {
resource = "https://api.example.com/mcp"
authorization_servers = ["https://auth.example.com"]
consumer_groups_claim = ["groups"]
consumer_groups_optional = true
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}
가상 크리덴셜
컨슈머 매핑을 사용하지 않는 경우, 토큰에서 가상 크리덴셜을 도출하도록 config.credential_claim을 설정하세요. 이 크리덴셜은 rate-limiting 같은 플러그인이 사용량을 추적하는 데 사용돼요. 기본값은 ["sub"]이에요.
토큰 교환 v3.14+
토큰 교환을 사용하면 플러그인이 요청을 업스트림 MCP 서버로 전달하기 전에 클라이언트의 액세스 토큰을 다른 토큰으로 교환할 수 있어요. 업스트림이 다른 인가 서버의 토큰이나 다른 스코프를 가진 토큰을 요구할 때 유용해요.
토큰 교환을 사용하려면
config.passthrough_credentials를true로 설정해야 해요.
config.token_exchange.enabled가 true이면 플러그인은 들어오는 토큰을 검증한 후 다음 작업을 수행해요:
sequenceDiagram
participant C as MCP client
participant K as AI MCP OAuth2 plugin
participant AS as Authorization server
participant TE as Token exchange endpoint
participant U as Upstream MCP server
C->>K: MCP request with Bearer token
activate K
K->>AS: Validate token (introspect / JWKS)
activate AS
AS-->>K: Token valid
deactivate AS
K->>TE: Token exchange request (subject_token = original token)
activate TE
TE-->>K: Exchanged access token
deactivate TE
K->>U: Forward request with exchanged token
activate U
U-->>K: MCP server response
deactivate U
K-->>C: MCP response
deactivate K
client_auth 필드는 플러그인이 토큰 교환 엔드포인트에 인증하는 방식을 제어해요. 허용되는 값은 client_secret_basic, client_secret_post, none, inherit이에요. inherit을 사용하면 플러그인이 인트로스펙션 엔드포인트에 구성된 client_id와 client_secret을 재사용해요.
config.token_exchange.request.actor_token_source를 header로 설정한 경우, 액터 토큰을 담고 있는 헤더의 이름을 actor_token_header에 지정하세요. config로 설정한 경우, 정적 액터 토큰 값을 actor_token에 지정하세요.
교환된 토큰은 기본적으로 캐시돼요. 캐싱을 비활성화하려면 config.token_exchange.cache.enabled를 false로 설정하세요. TTL 기본값은 3600초이며, 토큰 교환 엔드포인트가 expires_in 값을 반환하지 않을 때 사용돼요.
토큰 패스스루 v3.14+
기본적으로 플러그인은 요청을 업스트림 MCP 서버로 전달하기 전에 들어오는 액세스 토큰을 제거해서 토큰 탈취와 혼동된 대리자(confused deputy) 공격을 방지해요. 원본 토큰을 요청에 유지하려면 config.passthrough_credentials를 true로 설정하세요.
업스트림 MCP 서버가 원본 액세스 토큰을 명시적으로 요구하는 경우, 또는 토큰 교환이 구성된 경우에만 토큰 패스스루를 활성화하세요.
관련 리소스
더 알아보기 (Learn more)
- 이 플러그인과 함께 사용할 때의 구성 모드와 주의 사항을 확인할 수 있어요 — AI MCP Proxy
- AI Gateway에서 MCP 트래픽을 처리하는 전체 흐름을 살펴볼 수 있어요 — MCP Traffic Gateway