Created
February 25, 2020 08:22
-
-
Save analytik/69780da3524c8ec595e846f14be864ac to your computer and use it in GitHub Desktop.
How to create an IP whitelist for Istio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Whitelist office IP's only | |
| kubectl -n istio-system patch svc istio-ingressgateway -p '{"spec":{"externalTrafficPolicy": "Local"}}' | |
| ingressgatewaypod=$(kubectl -n istio-system get pods -l app=istio-ingressgateway -o name | cut -d / -f 2) | |
| kubectl -n istio-system delete pod $ingressgatewaypod | |
| # If this rule needs changing then delete previous isntances beforehand, otherwise it does not seem to be picked up | |
| # kubectl -n istio-system delete handler whitelistip | |
| # kubectl -n istio-system delete instance sourceip | |
| # kubectl -n istio-system delete rule checkip | |
| kubectl apply -f - <<EOF | |
| apiVersion: config.istio.io/v1alpha2 | |
| kind: handler | |
| metadata: | |
| name: whitelistip | |
| namespace: istio-system | |
| spec: | |
| compiledAdapter: listchecker | |
| params: | |
| blacklist: false | |
| entryType: IP_ADDRESSES | |
| overrides: | |
| - 123.123.123.123 | |
| --- | |
| apiVersion: config.istio.io/v1alpha2 | |
| kind: instance | |
| metadata: | |
| name: sourceip | |
| namespace: istio-system | |
| spec: | |
| compiledTemplate: listentry | |
| params: | |
| value: request.headers["x-envoy-external-address"] | "0.0.0.0" | |
| --- | |
| apiVersion: config.istio.io/v1alpha2 | |
| kind: rule | |
| metadata: | |
| name: checkip | |
| namespace: istio-system | |
| spec: | |
| actions: | |
| - handler: whitelistip | |
| instances: | |
| - sourceip | |
| match: (source.labels["istio"] | "") == "ingressgateway" && (request.headers["x-envoy-external-address"] | "") !="" | |
| EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment