F5 AI Gateway 설정 기초 가이드
이 포스트는 F5 AI Gateway 설정 파일의 구성 요소들을 알아보고, 클라이언트의 요청을 받아 LLM 서비스로 전달하기 위한 기초적인 구성 방법을 설명합니다.
목차
1. F5 AI Gateway 설정 흐름
2. 버전 정보
3. 기본 F5 AI Gateway 설정
4. Routes 설정
5. Policies 설정
6. Profiles 설정
7. Processors 설정
8. Services 설정
9. F5 AI Gateway 설정 예시
10. 결론
1. F5 AI Gateway 설정 흐름

F5 AI Gateway 설정에 따른 흐름은 위 그림과 같은 형태로 구성됩니다.
- Routes
- AI Gateway가 노출할 엔드포인트를 정의하고, 연결될 Policy를 정의합니다.
- 엔드포인트의 input/output 스키마를 구성합니다.
- Policies
- Policy를 통해 연결될 Profile을 정의합니다.
- JWT 인증 구성을 적용할 수 있습니다. 하지만 Upstream Proxy에서 인증을 수행하는 것을 권장합니다.
- Profiles
- Profile을 통해 연결될 Service(AI 모델)를 정의합니다.
- 요청에 적용할 Processor를 정의합니다.
- 응답에 적용할 Processor를 정의합니다.
- Processors
- AI Gateway와 상호작용을 하여 요청/응답의 데이터를 확인/변경합니다.
- 요청/응답에 대한 거절, 수정, 태그 추가 처리를 할 수 있습니다.
- Services
- AI Gateway가 트래픽을 보낼 업스트림 LLM을 정의합니다.
- 업스트림 LLM의 openai, antropic, ollama와 같은 executor와 모델의 타입을 정의합니다.
2. 버전 정보
- Kubernetes: v1.32.2
- F5 AI Gateway: v1.0.2
- F5 AI Gateway Helm chart: aigw-0.1.1
3. 기본 F5 AI Gateway 설정
F5 AI Gateway는 Helm을 통해 Kubernetes에 배포 시 기본적으로 aigw-config 이름의 ConfigMap 리소스를 생성하며 설정이 적용됩니다.
config:
# -- Enable creation of the AI Gateway `aigw.yaml` config map
create: true
# -- Name of ConfigMap to use
name: aigw-config
# -- The contents of an aigw.yaml configuration file
contents: |
server:
address: :4141
위와 같이 기본적으로 4141 port로 요청을 수신하는 설정만 구성됩니다. 사전에 구성된 ConfigMap을 사용할 경우, create 값을 false로 설정 후 name 값에 참조할 ConfigMap의 이름을 작성합니다.
AI Gateway의 server 설정에는 address 설정뿐만이 아닌, tls, mtls 설정도 가능합니다.
server:
address: :4141
tls:
enabled: true
serverCertPath: /etc/tls/server.crt
serverKeyPath: /etc/tls/server.key
mtls:
enabled: true
clientCertPath: /etc/internal-ca/ca.crt
설정에 사용할 인증서 파일은 AI Gateway Pod에 mount 되어야 합니다. F5 AI Gateway Kubernetes NGINX Ingress Controller 통합 포스트의 Policy 구성 섹션에서 예시를 확인하실 수 있습니다.
logging 설정에서 log level 구성이 가능합니다.
server:
address: :4141
logging:
level: debug
debug, info, warn, error level을 지원합니다.
4. Routes 설정
Route는 AI Gateway가 노출할 엔드포인트를 정의하고, 연결될 Policy를 정의합니다.
routes:
- path: /llama3
schema: v1/chat_completions
policy: llama3
timeoutSeconds: 30
- path: 요청의 진입점이 될 경로를 정의합니다. 모든 routes에서 고유한 값을 가져야 합니다.
- policy: 해당 route를 통해 연결될 policy를 정의합니다. 이후 정의될 policy 이름과 일치해야 합니다.
- schema: 해당 route의 input/output 스키마를 정의합니다.
v1/chat_completions,v1/models옵션을 지원합니다.v1/chat_completions: OpenAI Chat Completions API 일부를 포함하는 chat completions를 위한 스키마입니다.v1/models: OpenAI v1 List Models API 엔드포인트를 준수하는 사용 가능한 모델 리스트 관련 스키마입니다.
- timeoutSeconds: 해당 route의 요청이 타임아웃 되기까지의 시간을 정의합니다. 기본값은 30초입니다.
5. Policies 설정
Policy는 route를 통해 수신한 요청을 연결할 Profile을 정의합니다. 또한 JWT 인증 설정을 정의할 수 있습니다. 하지만 JWT 인증은 AI Gateway가 아닌, Upstream 프록시(ex: NGINX Plus Ingress Controller)에서 수행하는 것을 권장합니다.
policies:
- name: my-policy
authentication:
jwtSigningKeyFile: .certs/jwtES256.key
jwtSigningKeyType: ES256.key
insecureAllowUnverifiedJWT: false
profiles:
- name: my-profile
- name: policy 이름을 정의합니다.
- profiles: 연결될 profile 이름을 정의합니다.
- authentication: JWT 인증을 적용할 경우 구성합니다. 인증 설정 미구성 시 생략 가능합니다.
- jwtSigningKeyFile: JWT 서명 키 파일의 경로를 정의합니다.
- jwtSigningKeyType: JWT 서명 키의 타입을 정의합니다.
- insecureAllowUnverifiedJWT: JWT 검증을 생략합니다. NGINX와 같은 Upstream 프록시에서 JWT 인증을 수행하고, mTLS 통신이 활성화된 상태에서
true로 설정하는 것을 권장합니다.
JWT의 claim 값에 따라 다른 profile로 연결되도록 구성할 수 있습니다.
policies:
- name: my-policy
authentication:
jwtSigningKeyFile: .certs/jwtES256.key
jwtSigningKeyType: ES256.key
profiles:
- name: admin-group
selector:
type: jwt
key: aud
values:
- admin.aud
- name: user-group
selector:
type: jwt
key: aud
values:
- user.aud
profiles:
- name: admin-group
# truncated
- name: user-group
# truncated
위와 같이 구성 시 selector 설정으로 인해 JWT의 aud claim 값에 따라 다른 profile로 요청이 전달됩니다.
6. Profiles 설정
Profile은 요청/응답에 적용할 프로세서와 요청이 전달될 Service(AI 모델)를 정의합니다.
profiles:
- name: llama3
inputStages:
- name: protect # 사용자 지정 이름 사용
steps:
- name: prompt-injection # processor 이름 명시
services:
- name: ollama/llama3
responseStages:
- name: repetition-detect
steps:
- name: repetition-detect
- name: profile의 이름을 정의합니다.
- inputStages: 요청을 AI 모델에 전달하기 전에 적용할 프로세서를 정의합니다.
- services: 요청을 전달할 service(AI 모델)를 정의합니다
- responseStages: AI 모델의 응답을 클라이언트에게 전달하기 전에 적용할 프로세서를 정의합니다.
Profile에 지원하는 모델의 리스트를 정의할 수 있습니다.
profiles:
- name: default
models:
- name: best
- name: mini
- name: old
services:
- name: service-best
selector:
type: input.model
values:
- best
- name: service-mini
selector:
type: input.model
values:
- mini
- name: service-old
selector:
type: input.model
values:
- old
위와 같이 models 설정을 통해 지원하는 모델의 리스트를 정의하면, 모든 클라이언트의 요청은 리스트의 모델 중 하나를 포함해야 하며(예: -d '{"model": "mini", ...}) 그 외의 경우 AI Gateway는 404 응답을 반환합니다.
만약 models 리스트가 빈값일 경우, 클라이언트의 요청은 모델값을 포함하지 않아야 합니다. 만약 특정 모델값을 포함한 요청을 전송하면 AI Gateway는 400 응답을 반환합니다.
7. Processors 설정
Processor는 AI Gateway가 요청과 응답의 데이터 흐름을 변경하기 위해 상호작용 하는 구성 요소입니다. Processor는 요청과 응답을 평가하여 reject(거부), modify(수정), annotate(주석) 처리를 할 수 있습니다.
(거부): AI Gateway에 요청 혹은 응답을 거절하고 에러를 반환하도록 전달합니다.rejectmodify(수정): 요청 혹은 응답을 수정하여 AI Gateway에 반환합니다.annotate(주석): 요청 혹은 응답에 하나 이상의 태그를 추가합니다. 해당 태그는 AI Gateway 내부적으로 추가 processor 처리 혹은 AI 모델 선택에 사용됩니다.
processors:
- name: prompt-injection
type: external
config:
endpoint: http://aigw-processors-f5.ai-gateway.svc.cluster.local
namespace: f5
version: 1
params:
reject: true
threshold: 0.95
- name: processor의 이름입니다. processor 서버에서 제공하는 이름과 일치해야 합니다.
- type: processor의 타입을 내부/외부로 설정합니다. F5 AI Gateway processor는 별개의 Pod로 구성되어 external로 설정해야 합니다.
- config: processor의 설정 항목입니다. 외부(external) processor 설정을 위해 필요합니다.
- endpoint: processor의 엔드포인트 URL입니다.
- namespace: processor의 네임스페이스입니다. processor 서버에서 제공하는 값과 일치해야 합니다.
- version: processor의 버전입니다. processor 서버에서 제공하는 값과 일치해야 합니다.
- params: processor의 동작에 특화된 매개변수를 설정합니다. 키/값은 processor에 따라 다릅니다.
F5 AI Gateway에서 제공하는 processor에 대한 자세한 정보는 공식 문서를 참고하세요.
8. Services 설정
Services는 AI Gateway가 트래픽을 전송할 업스트림 LLM을 정의합니다.
services:
- name: openai/public
type: gpt-4o
executor: openai
config:
endpoint: "https://api.openai.com/v1/chat/completions"
secrets:
- source: EnvVar
targets:
apiKey: OPENAI_API_KEY
- name: openai/azure
type: azure
executor: openai
config:
endpoint: "https://myvm.openai.azure.com/openai/deployments/chat/completions"
apiVersion: 2024-02-15-preview # type이 azure일 경우에만 사용
secrets:
- source: File
targets:
apiKey: AZURE_API_KEY
meta:
path: /etc/aigw/secrets/
- name: anthropic/sonnet
type: claude-3-sonnet-20240229
executor: anthropic
config:
anthropicVersion: "2023-06-01"
secrets:
- source: DotEnv
targets:
apiKey: ANTHROPIC_API
meta:
path: /etc/aigw/secrets/.env
- name: ollama/llama3
type: llama3
executor: ollama
- name: ollama/phi
type: phi3
executor: ollama
- name: service의 이름을 정의합니다. 사용자 정의 이름을 사용하며, 중복될 수 없습니다.
- type: 사용할 모델을 정의합니다.
- executor: 명시된 모델의 스키마에 맞춰 요청을 준비하고, 전송합니다.
openai,anthropic,ollama를 지원합니다. - config: executor의 설정을 구성합니다.
- endpoint: LLM의 엔드포인트 URL을 명시합니다.
- secrets: LLM 연결에 필요한 secret 설정을 구성합니다.
- caPath: CA 인증서의 경로를 명시합니다.
- tlsMinVersion: 허용되는 최소 TLS 버전을 명시합니다. 기본값은 v1.2입니다.
- clientCertPath: AI Gateway와 모델 사이에 mTLS 구성 시 클라이언트 인증서의 경로를 명시합니다.
- clientKeyPath: AI Gateway와 모델 사이에 mTLS 구성 시 클라이언트 키 파일의 경로를 명시합니다.
secrets는 다음과 같은 설정 항목이 존재합니다.
- source: 사용할 SecretSource를 정의합니다.
| Source | 설명 | 유효한 meta 값 |
| DotEnv | .env 파일로부터 secret을 불러옵니다. | path: .env 파일의 경로를 지정합니다. |
| EnvVar | 환경 변수로부터 secret을 불러옵니다. | 사용하지 않습니다. |
| File | 파일로부터 secret을 불러옵니다. | path: 파일을 포함하는 디렉터리의 경로를 지정합니다. |
- targets: SecretSource에서 불러올 secret 값을 나타내는 키-값 리스트입니다. 키는 AI Gateway의 카겟이고 값은 source의 값입니다.
- apiKey: 선택된 executor에 맞춰 API key를 설정합니다.
- meta: SecretSource에 제공할 메타데이터를 설정합니다. 각 source에 따라 필요한 값이 달라집니다.
예: DotEnV의 경우 .env 파일로의 경로를 필요로함.
9. F5 AI Gateway 설정 예시
Ollama에 구성된 hermes3:8b 모델을 사용하는 간단한 F5 AI Gateway 구성입니다.
version: 1
# 4141 포트로 listen 설정
server:
address: :4141
# log level debug 설정
logging:
level: debug
routes:
- path: /api/chat
policy: chat-policy
schema: v1/chat_completions
timeoutSeconds: 240
# 별도의 인증 과정 없는 route - policy - profile 연결 구성
policies:
- name: chat-policy
profiles:
- name: chat-profile
# hermes3:8b 모델 명시 및 요청의 prompt-injection 공격 탐지를 위한 구성
profiles:
- name: chat-profile
models:
- name: hermes3:8b
inputStages:
- name: check-prompt-injection
steps:
- name: prompt-injection
services:
- name: ollama/chat
selector:
type: input.model
values:
- hermes3:8b
# 요청을 Ollama의 hermes3:8b 모델로 전달
services:
- name: ollama/chat
type: hermes3:8b
executor: ollama
config:
endpoint: "http://ollama.example.com/api/chat"
# 요청에서 prompt-injection 공격 탐지 시 요청 차단 설정
processors:
- name: prompt-injection
type: external
config:
endpoint: http://aigw-processors-f5.ai-gateway.svc.cluster.local
namespace: f5
version: 1
params:
threshold: 0.8
reject: true
10. 결론
이번 포스트에서는 F5 AI Gateway 설정 파일의 구성 요소들을 알아보고, 클라이언트의 요청을 받아 LLM 서비스로 전달하기 위한 기초적인 구성 방법을 알아봤습니다.
F5 AI Gateway는 클라이언트와 LLM 모델 사이에서 프록시로 동작하여 다양한 processor를 활용하여 요청/응답을 검사하고 처리할 수 있습니다. 또한 JWT claim 값에 따라 다른 모델로 요청을 라우팅한다거나, 클라이언트가 지정한 모델값에 따라 동일한 엔드포인트의 다양한 모델로 요청을 라우팅할 수 있습니다.
운영 중인 AI 서비스에 강력한 보안이 필요하신가요? NGINX STORE를 통해 문의하여 F5 AI Gateway with NGINX Integration 서비스를 통해 AI 서비스를 보호 하세요.
댓글을 달려면 로그인해야 합니다.