I am trying to implement a use case where I require to do host header manupulation while doing API looping.
I have 3 API definitions, where 2 are internal and 1 is public.
API definition, “entrypoint” in listening on path “/” and forwarding the apirequest to “apidefinition-apikey” if there is an “apikey” in query or to the “apidefinition-jwt” if there is a bearer in authorization.
In the api-definition all I am trying to do is implement authorization based on api key and proxy the traffic to “my-api-1.private.example.com”. Is there a way to manupulate target_url based on the host “my-api-1.public.example.com” to “my-api-1.private.example.com” using regex.
apidefinition-entrypoint
apiVersion: tyk.tyk.io/v1alpha1
kind: ApiDefinition
metadata:
name: apidefinition-entrypoint
namespace: tyk
spec:
name: apidefinition-entrypoint
protocol: http
use_keyless: true
active: true
domain: my-api-1.public.example.com
proxy:
target_url: https://foo/
listen_path: /
strip_listen_path: false
preserve_host_header: true
version_data:
default_version: default
not_versioned: true
versions:
Default:
name: default
use_extended_paths: true
extended_paths:
url_rewrites:
- match_pattern: /(.*)
method: GET
path: /{id}
triggers:
- "on": "all"
options:
query_val_matches:
"apikey":
match_rx: "(.*)"
rewrite_to_internal:
target:
name: apidefinition-apikey
namespace: dst
path: apikey/$1&check_limits=true
- "on": "all"
options:
header_matches:
"Authorization":
match_rx: "^Bearer"
rewrite_to_internal:
target:
name: apidefinition-jwt
namespace: dst
path: bearer/$1
apidefinition-apikey:
apiVersion: tyk.tyk.io/v1alpha1
kind: ApiDefinition
metadata:
name: apidefinition-apikey
namespace: dst
spec:
name: apidefinition-apikey
protocol: http
use_keyless: false
active: true
proxy:
target_url: https://bar/
listen_path: "/apikey"
strip_listen_path: true
preserve_host_header: true
auth:
auth_header_name: 'Authorization'
auth_configs:
authToken:
auth_header_name: 'Authorization'
use_param: true
param_name: apikey
base_identity_provided_by: auth_token
use_standard_auth: true
internal: true
version_data:
default_version: default
not_versioned: true
versions:
Default:
name: default
use_extended_paths: true
extended_paths:
url_rewrites:
- match_pattern: /(.*)
method: GET
path: /{id}
rewrite_to: '$tyk_context.headers_Host/$1' <this is rewriting the url to https://bar/(.*), what I need is manipulate host header based on original request and regex>