Krakend POST to endpoint with preconfigured query parameters

43 views
Skip to first unread message

yto yto

unread,
Dec 29, 2024, 2:19:53 AM12/29/24
to KrakenD Community

I have an endpoint that requires auth and a specific query parameter that is not proxied  from user but needs to be POSTed as specific in configuration in krakend to the endpoint
https://username:pass...@ip.ip.ip.ip:80/api?do=start&Location=one&Key=12345

I am reading and testing documentation https://www.krakend.io/docs/endpoints/ and am unsuccessful

{
  "endpoints": [
    {
      "endpoint": "/v1/test-api",
      "method": "POST",
      "backend": [
        {
          "url_pattern": "/api?do=start&Location=one&Key=12345",
          "method": "POST",
          "host": [
            "https://username:pass...@ip.ip.ip.ip"
          ]
        }
      ]
    }
  ]
}

What is configuration required for a user page load of a krakend endpoint over wan at for example https://krakenurl.com/v1/test-api  to trigger krakend to perform POST the auth and query parameters to one specific url endpoint with preconfigured auth and preconfigured parameters https://username:pass...@ip.ip.ip.ip:80/api?do=start&Location=one&Key=12345

Thank you

Jorge Tarrero

unread,
Dec 30, 2024, 4:19:04 AM12/30/24
to KrakenD Community, yto yto
Hi there,

You're getting close to a working configuration, but you're probably stuck in a host validation error during KrakenD startup. This is due to the fact you're adding the credentials in the host entry, and the initial validation does not like it.

To workaround this issue, you can add a flag to disable the host sanitization: https://www.krakend.io/docs/backends/#disable_host_sanitize . Here's a working config example:

{
"version": 3,
"debug_endpoint": true,
"endpoints": [
{
"endpoint": "/v1/test-api",
"method": "POST",
"backend": [
{
"url_pattern": "/__debug?do=start&Location=one&Key=12345",
"method": "POST",
"host": [
"http://user:pass@localhost:8080"
],
"disable_host_sanitize": true
}
]
}
]
}

Anyway, I'd really recommend removing the credentials in the host list, as they could be written and exposed in log files or traces. Specifying the credentials in the host is equivalent to adding them to a Authorization Basic header, which can be easily achieved with a Martian header modifier, check this example out:

{
"version": 3,
"debug_endpoint": true,
"endpoints": [
{
"endpoint": "/v1/test-api",
"method": "POST",
"backend": [
{
"url_pattern": "/__debug?do=start&Location=one&Key=12345",
"method": "POST",
"host": [
],
"extra_config": {
"modifier/martian": {
"header.Modifier": {
"scope": [
"request"
],
"name": "Authorization",
"value": "Basic <credentials>"
}
}
}
}
]
}
]
}

Please notice that the <credentials> value must be a base64 encoded string of "user:password" (colon included), for example "Basic dXNlcjpwYXNz"

Hope this helps!
 
On Sunday, December 29, 2024 at 8:19:53 AM UTC+1 yto yto wrote:

I have an endpoint that requires auth and a specific query parameter that is not proxied  from user but needs to be POSTed as specific in configuration in krakend to the endpoint

https://username:password@ip.ip.ip.ip:80/api?do=start&Location=one&Key=12345

I am reading and testing documentation https://www.krakend.io/docs/endpoints/ and am unsuccessful

{
  "endpoints": [
    {
      "endpoint": "/v1/test-api",
      "method": "POST",
      "backend": [
        {
          "url_pattern": "/api?do=start&Location=one&Key=12345",
          "method": "POST",
          "host": [

            "https://username:password@ip.ip.ip.ip"
          ]
        }
      ]
    }
  ]
}

What is configuration required for a user page load of a krakend endpoint over wan at for example https://krakenurl.com/v1/test-api  to trigger krakend to perform POST the auth and query parameters to one specific url endpoint with preconfigured auth and preconfigured parameters https://username:password@ip.ip.ip.ip:80/api?do=start&Location=one&Key=12345

Thank you

Reply all
Reply to author
Forward
Message has been deleted
0 new messages