EnvoyFilter를 이용한 Header Remove
2025. 2. 7. 00:15ㆍDevops/Istio
728x90
반응형
Istio를 사용하게 되면 기본적으로 Header에 불필요한 데이터들이 들어가는경우가 있다.

server: istio-envoy 나 x-envoy-upstream-service-time의 header가 들어가는데 없애는것이 보안상 좋다..
해당 부분을 없앨수있는 방법 3가지를 적어보고자 한다.
1-1. EnvoyFilter & Virtualservice
처음방법은 EnvoyFilter와 virtualservice을 이용하는 방법이다.
virtualservice를 이용하는 서비스에 한정되게 사용이 가능하다.
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
namespace: istio-system
name: remove-server-header
spec:
workloadSelector:
labels:
istio: ingressgateway
configPatches:
- applyTo: NETWORK_FILTER
match:
context: GATEWAY
listener:
filterChain:
filter:
name: envoy.http_connection_manager
patch:
operation: MERGE
value:
typed_config:
'@type': type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
server_header_transformation: PASS_THROUGH
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: example
spec:
hosts:
- example.com
gateways:
- example
http:
- match:
- uri:
prefix: /
route:
- destination:
host: example
port:
number: 8080
headers:
response:
remove:
- Server
해당 yaml에서 Header를 컨트롤 할수있는 부분이 있는데 바로 server_header_transformation이다.
OVERWRITE
(DEFAULT) 서버 헤더를 server_name의 내용으로 덮어씁니다.
APPEND_IF_ABSENT
Server 헤더가 없으면 Server server_name Server 헤더가 있으면 통과시킵니다.
PASS_THROUGH
서버 헤더 값을 전달하고, 헤더가 없으면 추가하지 마십시오.
1-2. EnvoyFilter & lua
lua script를 이용하는 방법인데.. lua script를 한번 사용해보고싶다면 사용하는게 좋다.. 하지만 왠만하면 virtualservice나 아래에 명시하겠지만 EnvoyFilter로만 사용하는게 좋다.
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: response-server-passthrough-filter
namespace: istio-system
spec:
workloadSelector:
labels:
istio: ingressgateway
configPatches:
- applyTo: NETWORK_FILTER
match:
context: GATEWAY
listener:
filterChain:
filter:
name: "envoy.filters.network.http_connection_manager"
patch:
operation: MERGE
value:
typed_config:
"@type": "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager"
server_header_transformation: PASS_THROUGH
---
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: response-remove-headers-filter
namespace: istio-system
spec:
workloadSelector:
labels:
istio: ingressgateway
configPatches:
- applyTo: HTTP_FILTER
match:
context: GATEWAY
listener:
filterChain:
filter:
name: "envoy.filters.network.http_connection_manager"
subFilter:
name: "envoy.filters.http.router"
patch:
operation: INSERT_BEFORE
value:
name: envoy.lua
typed_config:
"@type": "type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua"
inlineCode: |
function envoy_on_response(response_handle)
response_handle:headers():remove("x-envoy-upstream-service-time")
response_handle:headers():remove("server")
end
1-3. EnvoyFilter
마지막으론 EnvoyFilter로만 사용하는 방법이다. 해당 방법은 Istio ingressgateway를 사용 시 모든 서비스에 적용되는 yaml이다.
---
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: gateway-response-remove-headers
namespace: istio-system
spec:
workloadSelector:
labels:
istio: ingressgateway
configPatches:
- applyTo: NETWORK_FILTER
match:
context: GATEWAY
listener:
filterChain:
filter:
name: "envoy.filters.network.http_connection_manager"
patch:
operation: MERGE
value:
typed_config:
"@type": "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager"
server_header_transformation: PASS_THROUGH
- applyTo: ROUTE_CONFIGURATION
match:
context: GATEWAY
patch:
operation: MERGE
value:
response_headers_to_remove:
- "x-envoy-upstream-service-time"
- "server"728x90
반응형
'Devops > Istio' 카테고리의 다른 글
| Istio AuthorizationPolicy 이해해보기 (0) | 2025.03.25 |
|---|---|
| Istio Gateway vs Gateway API (0) | 2025.03.14 |
| Istio DestinationRule 이해하기 (0) | 2025.03.07 |
| SNI를 사용한 트래픽 라우팅 (0) | 2025.02.23 |
| Istio의 Gateway와 VirtualService 이해하기 (0) | 2025.02.20 |