Skip to content

BE: Respect proxy settings for OAuth requests #4114

Open
@poom-kitti

Description

@poom-kitti

Issue submitter TODO list

  • I've looked up my issue in FAQ
  • I've searched for an already existing issues here
  • I've tried running master-labeled docker image and the issue still persists there
  • I'm running a supported version of the application which is listed here

Describe the bug (actual behavior)

To give some context, our Kafka UI is deployed in a server inside a virtual private network. This mean:

  • The client (user connecting to Kafka UI) is also in the private network but is capable of accessing the internet
  • The Kafka UI is unable to access the internet unless using a proxy server

When Kafka UI is deployed in the server, it does not respect using proxy declared in any of the following Java system properties when performing connection to Okta to perform authentication:

  • http.proxyHost
  • http.proxyPort
  • http.nonProxyHosts
  • https.proxyHost
  • https.proxyPort
  • https.nonProxyHosts

Once a client tried to connect to Kafka UI, they are directed to authenticate to Okta correctly. However, after the client passed the code which they received from Okta back to Kafka UI triggering Kafka UI to perform POST request to Okta's token URI, it fails due to java.net.NoRouteToHostException indicating that the proxy is not in-use.

From some exploration, I believe that Spring security is using the DefaultWebClient to perform authentication and this WebClient does not respect the system properties on using proxy.

Expected behavior

When specified the system property like -Dhttps.proxyHost=my.proxy.host -Dhttps.proxyPort=3218 -Dhttps.nonProxyHosts=XXXX.local|10.*, the authentication should be using proxy to make connection to Okta.

Your installation details

App version: 0.7.1 (as of commit b32ab0143679bd3224f097a9de0eefad4e60f8d6)

Application YAML:
I deliberately did not add any configuration regarding connection to Kafka as it is unnecessary to show behavior of Okta authentication. In addition, this way, it make showing debug log clearer as we will only get debug log regarding authentication.

auth:
  type: OAUTH2
  oauth2:
    client:
      okta:
        clientId: <client-id>
        clientSecret: <client-secret>
        scope: [ 'openid', 'profile', 'email', 'groups' ]
        client-name: Okta
        provider: okta
        redirect-uri: "{baseUrl}/login/oauth2/code/okta"
        authorization-grant-type: authorization_code
        issuer-uri: https://<okta-endpoint>
        authorization-uri: https://<okta-endpoint>/oauth2/v1/authorize
        token-uri: https://<okta-endpoint>/oauth2/v1/token
        user-info-uri: https://<okta-endpoint>/oauth2/v1/userinfo
        jwk-set-uri: https://<okta-endpoint>/oauth2/v1/keys
        user-name-attribute: email
        custom-params:
          type: oauth
          roles-field: groups
server:
  port: 8080

Steps to reproduce

  1. Add authentication with Okta configurations.
  2. Build the Docker image.
  3. Create a Docker container inside a server that cannot access the internet except through proxy server.
  4. Start Kafka UI with Java system properties related to proxy:
  • http.proxyHost
  • http.proxyPort
  • http.nonProxyHosts
  • https.proxyHost
  • https.proxyPort
  • https.nonProxyHosts
  1. Try to access Kafka UI and perform Okta authentication.

Screenshots

From the network tab in developer tool, we can see that Okta returns some code to user and this is passed to Kafka UI; however the get request to <kafka ui endpoint>/login/oauth2/code/okta?code=<some code> failed.

error_pixelate

Logs

From logs, I see the following error:

�[30m2023-08-12 22:48:08,259�[0;39m �[1;31mERROR�[0;39m [�[34mreactor-http-epoll-3�[0;39m] �[33mo.s.b.a.w.r.e.AbstractErrorWebExceptionHandler�[0;39m: [8200782c-3]  500 Server Error for HTTP GET "/login/oauth2/code/okta?code=pV9h3TwnnHan7NjkEYWZR6oPKMcBU8WTrH3m4tLMX40&state=VHDFtviuySJvVcmLMwurglU1u81s1mw1Bw32_BlUD4Y%3D"
org.springframework.web.reactive.function.client.WebClientRequestException: null: dev-61615254.okta.com/99.83.233.105:443
	at org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction.lambda$wrapException$9(ExchangeFunctions.java:136)
	Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
	*__checkpoint ⇢ Request to POST https://dev-61615254.okta.com/oauth2/v1/token [DefaultWebClient]
	*__checkpoint ⇢ OAuth2LoginAuthenticationWebFilter [DefaultWebFilterChain]
	*__checkpoint ⇢ OAuth2AuthorizationRequestRedirectWebFilter [DefaultWebFilterChain]
	*__checkpoint ⇢ ReactorContextWebFilter [DefaultWebFilterChain]
	*__checkpoint ⇢ HttpHeaderWriterWebFilter [DefaultWebFilterChain]
	*__checkpoint ⇢ ServerWebExchangeReactorContextWebFilter [DefaultWebFilterChain]
	*__checkpoint ⇢ org.springframework.security.web.server.WebFilterChainProxy [DefaultWebFilterChain]
	*__checkpoint ⇢ org.springframework.web.filter.reactive.ServerHttpObservationFilter [DefaultWebFilterChain]
	*__checkpoint ⇢ HTTP GET "/login/oauth2/code/okta?code=pV9h3TwnnHan7NjkEYWZR6oPKMcBU8WTrH3m4tLMX40&state=VHDFtviuySJvVcmLMwurglU1u81s1mw1Bw32_BlUD4Y%3D" [ExceptionHandlingWebHandler]
Original Stack Trace:
		at org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction.lambda$wrapException$9(ExchangeFunctions.java:136)
		xxx
Caused by: io.netty.channel.AbstractChannel$AnnotatedNoRouteToHostException: null: dev-61615254.okta.com/99.83.233.105:443
Caused by: java.net.NoRouteToHostException: null
xxx

When setting the environment variable LOGGING_LEVEL_ROOT=debug to show debug log, I see the following logs that signify that Kafka UI is trying to connect to the Okta endpoint directly. This should not be the case because it should use proxy instead.

�[30m2023-08-12 22:51:21,497�[0;39m �[39mDEBUG�[0;39m [�[34mreactor-http-epoll-3�[0;39m] �[33mo.s.w.r.f.c.ExchangeFunctions�[0;39m: [62de54f3] HTTP POST https://dev-61615254.okta.com/oauth2/v1/token
�[30m2023-08-12 22:51:21,684�[0;39m �[39mDEBUG�[0;39m [�[34mreactor-http-epoll-3�[0;39m] �[33mi.n.r.d.DnsNameResolver�[0;39m: [id: 0xfd2c1ad8] RECEIVED: UDP [43221: /127.0.0.11:53], DatagramDnsResponse(from: /127.0.0.11:53, id: 43221, QUERY(0), NoError(0), RD RA)
	DefaultDnsQuestion(dev-61615254.okta.com. IN A)
	DefaultDnsRawRecord(dev-61615254.okta.com. 270 IN CNAME 25B)
	DefaultDnsRawRecord(ok12-crtrs.tng.okta.com. 30 IN CNAME 30B)
	DefaultDnsRawRecord(ok12-crtrs.oktaedge.okta.com. 270 IN CNAME 44B)
	DefaultDnsRawRecord(a1c0075a909445e0e.awsglobalaccelerator.com. 75 IN A 4B)
	DefaultDnsRawRecord(a1c0075a909445e0e.awsglobalaccelerator.com. 75 IN A 4B)
	DefaultDnsRawRecord(OPT flags:0 udp:4000 0B)
�[30m2023-08-12 22:51:21,688�[0;39m �[39mDEBUG�[0;39m [�[34mreactor-http-epoll-3�[0;39m] �[33mr.n.t.TransportConnector�[0;39m: [5de47a0b] Connecting to [dev-61615254.okta.com/75.2.37.199:443].
�[30m2023-08-12 22:51:21,690�[0;39m �[39mDEBUG�[0;39m [�[34mreactor-http-epoll-3�[0;39m] �[33mr.n.t.TransportConnector�[0;39m: [5de47a0b] Connect attempt to [dev-61615254.okta.com/75.2.37.199:443] failed.       

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/authscope/backendstatus/acceptedAn issue which has passed triage and has been acceptedstatus/on-holdWaiting for something, but not the user input.type/enhancementEn enhancement to an already existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions