strimzi / strimzi-kafka-operator

Apache Kafka® running on Kubernetes
https://strimzi.io/
Apache License 2.0
4.84k stars 1.29k forks source link

[Enabling Kafka using google oauth as the authentication mechanism in the TLS listener] ... #3364

Closed vperi1730 closed 4 years ago

vperi1730 commented 4 years ago

Hi Team,

I have launched a new Kafka cluster with the following tls configuration by enabling the authentication type as OAuth. primarily my client id and client secret are referring to the one's created inside the google OAuth API. This is the first time I am trying with this approach which is returning me an error related to SSLHandshake about the token.

I am looking out for any clue or input through which I can troubleshoot as I am unsure of the error.

listeners:
        plain: {}
        tls:
          authentication:
            type: oauth
            validIssuerUri: "https://accounts.google.com/o/oauth2/v2/auth"
            introspectionEndpointUri: "https://accounts.google.com/o/oauth2/token"
            clientId: "835970994981-14mqluev54fa9vutrmpkj89fjppacd49.apps.googleusercontent.com"
            clientSecret:
              key: secret
              secretName: "broker-oauth-secret"
*** Certificate chain
chain [0] = [
[
  Version: V3
  Subject: CN=accounts.google.com, O=Google LLC, L=Mountain View, ST=California, C=US
  Signature Algorithm: SHA256withRSA, OID = 1.2.840.113549.1.1.11

  Key:  Sun EC public key, 256 bits
  public x coord: 83508092503275986165870600328334743522929768053118105244764112311836052254560
  public y coord: 42779350362272473081193696148359387582210898269797998689583726615942304013899
  parameters: secp256r1 [NIST P-256, X9.62 prime256v1] (1.2.840.10045.3.1.7)
  Validity: [From: Tue Jun 30 20:48:31 UTC 2020,
               To: Tue Sep 22 20:48:31 UTC 2020]
  Issuer: CN=GTS CA 1O1, O=Google Trust Services, C=US
  SerialNumber: [    c4d2f223 bde01402 02000000 00715cbc]

Certificate Extensions: 10
[1]: ObjectId: 1.3.6.1.4.1.11129.2.4.2 Criticality=false
Extension unknown: DER encoded OCTET string =
0000: 04 81 F6 04 81 F3 00 F1   00 76 00 07 B7 5C 1B E5  .........v...\..
0010: 7D 68 FF F1 B0 C6 1D 23   15 C7 BA E6 57 7C 57 94  .h.....#....W.W.
0020: B7 6A EE BC 61 3A 1A 69   D3 A2 1C 00 00 01 73 07  .j..a:.i......s.
0030: 33 F2 70 00 00 04 03 00   47 30 45 02 20 57 F1 77  3.p.....G0E. W.w
0040: 86 B5 8B 84 E7 78 16 C4   36 0D F9 F9 B1 18 DF 97  .....x..6.......
0050: D2 09 CE 75 BA 42 67 02   FA 3D 52 EC 68 02 21 00  ...u.Bg..=R.h.!.
0060: C6 9F 7C 60 2B B4 4F 8F   03 17 BE 75 33 34 5C 79  ...`+.O....u34\y
0070: B0 8B 4D 53 89 17 D0 D7   3F 0E A8 4D 8A 0B 59 5E  ..MS....?..M..Y^
0080: 00 77 00 C6 52 A0 EC 48   CE B3 FC AB 17 09 92 C4  .w..R..H........
0090: 3A 87 41 33 09 E8 00 65   A2 62 52 40 1B A3 36 2A  :.A3...e.bR@..6*
00A0: 17 C5 65 00 00 01 73 07   33 F2 4C 00 00 04 03 00  ..e...s.3.L.....
00B0: 48 30 46 02 21 00 E6 BC   74 45 E8 6C 21 A5 7E 6D  H0F.!...tE.l!..m
00C0: 0D 03 1A C9 29 B3 87 A1   E3 80 F1 67 FC 8A EC 84  ....)......g....
00D0: 46 56 8C 7B A9 02 02 21   00 80 FD AA E8 CC 7E 44  FV.....!.......D
00E0: 10 F0 75 71 8F AC 5C 27   41 39 51 7B 0F 20 24 01  ..uq..\'A9Q.. $.
00F0: 3A F7 7C D1 44 AE 96 8D   A5                       :...D....

[2]: ObjectId: 1.3.6.1.5.5.7.1.1 Criticality=false
AuthorityInfoAccess [
  [
   accessMethod: ocsp
   accessLocation: URIName: http://ocsp.pki.goog/gts1o1core
,
   accessMethod: caIssuers
   accessLocation: URIName: http://pki.goog/gsr2/GTS1O1.crt
]
]

[3]: ObjectId: 2.5.29.35 Criticality=false
AuthorityKeyIdentifier [
KeyIdentifier [
0000: 98 D1 F8 6E 10 EB CF 9B   EC 60 9F 18 90 1B A0 EB  ...n.....`......
0010: 7D 09 FD 2B                                        ...+
]
]

[4]: ObjectId: 2.5.29.19 Criticality=true
BasicConstraints:[
  CA:false
  PathLen: undefined
]

[5]: ObjectId: 2.5.29.31 Criticality=false
CRLDistributionPoints [
  [DistributionPoint:
     [URIName: http://crl.pki.goog/GTS1O1core.crl]
]]

[6]: ObjectId: 2.5.29.32 Criticality=false
CertificatePolicies [
  [CertificatePolicyId: [2.23.140.1.2.2]
[]  ]
  [CertificatePolicyId: [1.3.6.1.4.1.11129.2.5.3]
[]  ]
]

[7]: ObjectId: 2.5.29.37 Criticality=false
ExtendedKeyUsages [
  serverAuth
]

[8]: ObjectId: 2.5.29.15 Criticality=true
KeyUsage [
  DigitalSignature
]

[9]: ObjectId: 2.5.29.17 Criticality=false
SubjectAlternativeName [
  DNSName: accounts.google.com
  DNSName: *.partner.android.com
]

[10]: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 13 3B 31 56 4E 6F B1 8A   95 49 7E AB 9F 3D 56 59  .;1VNo...I...=VY
0010: 66 DD DD 56                                        f..V
]
]

]
  Algorithm: [SHA256withRSA]
  Signature:
0000: 73 72 EB A9 0E 97 78 70   30 5E 72 3C 65 03 3E 11  sr....xp0^r<e.>.
0010: 77 F2 73 55 F3 CD EF 59   79 64 2F 51 29 C8 61 D5  w.sU...Yyd/Q).a.
0020: 9C 9E 44 2D 62 C0 8C 96   10 83 9C EB 7C A9 C0 10  ..D-b...........
0030: DC 38 76 30 71 DE B4 8A   AA 1B D1 CC 0F 1C 7D 1B  .8v0q...........
0040: 78 87 C6 2A BD A5 3D 49   2B 4A 52 A2 F4 98 EA 1F  x..*..=I+JR.....
0050: A8 52 5B 6F 3C E8 AC 30   71 58 8C 59 6D 5F 1B C9  .R[o<..0qX.Ym_..
0060: FE 77 AA 0B 65 57 DF DF   8E 0D 34 02 21 5F E5 65  .w..eW....4.!_.e
0070: 3C 5A 8A B7 25 61 2E FA   E8 1E 01 A6 EE BB F8 74  <Z..%a.........t
0080: D2 87 04 59 EB 8C F4 0A   12 69 30 97 39 82 D2 DD  ...Y.....i0.9...
0090: AA C6 6A 5D DA 2C 1B A4   BF B9 10 2D BD 2E 18 51  ..j].,.....-...Q
00A0: E7 A9 FD 3E FF 89 2F F8   FE EE 5D 60 E3 93 F6 E8  ...>../...]`....
00B0: FC D6 66 2B 18 83 34 D4   C9 8D 3E E0 A1 8A F7 EB  ..f+..4...>.....
00C0: F7 97 05 2A FB DE 4D 5B   F7 9C 9E EA FF 67 CD 8F  ...*..M[.....g..
00D0: E6 21 97 85 4F F9 06 B7   12 14 34 25 08 43 C2 1A  .!..O.....4%.C..
00E0: 49 77 92 E8 AB CD 2B 4D   B4 93 A3 4D DA FA 48 31  Iw....+M...M..H1
00F0: 93 BE 24 C9 4B C3 59 66   21 03 03 EF 85 DA 10 6A  ..$.K.Yf!......j

]
chain [1] = [
[
  Version: V3
  Subject: CN=GTS CA 1O1, O=Google Trust Services, C=US
  Signature Algorithm: SHA256withRSA, OID = 1.2.840.113549.1.1.11

  Key:  Sun RSA public key, 2048 bits
  modulus: 26269801531899897577901397628129768396310117154722111998302380600635413896531116363750045902786736302705131724095478519616606299023895145655746808892285752988930019974591973546931458114715554265078724718547960324541834616401014259212201521058332874204257425862103971348650680978888262959869761258115884544433253120380553333792186795670369626922403997399844281387984516714325891255733252935742350706385789521287375269196970094028922706633069471330695250381466716142933896182302890680432873976462431593315458003990118395901701394864226607634896601077267548878140687343418675545931561691994107018413405352266039281626119
  public exponent: 65537
  Validity: [From: Thu Jun 15 00:00:42 UTC 2017,
               To: Wed Dec 15 00:00:42 UTC 2021]
  Issuer: CN=GlobalSign, O=GlobalSign, OU=GlobalSign Root CA - R2
  SerialNumber: [    01e3b49a a18d8aa9 81256950 b8]

Certificate Extensions: 8
[1]: ObjectId: 1.3.6.1.5.5.7.1.1 Criticality=false
AuthorityInfoAccess [
  [
   accessMethod: ocsp
   accessLocation: URIName: http://ocsp.pki.goog/gsr2
]
]

[2]: ObjectId: 2.5.29.35 Criticality=false
AuthorityKeyIdentifier [
KeyIdentifier [
0000: 9B E2 07 57 67 1C 1E C0   6A 06 DE 59 B4 9A 2D DF  ...Wg...j..Y..-.
0010: DC 19 86 2E                                        ....
]
]

[3]: ObjectId: 2.5.29.19 Criticality=true
BasicConstraints:[
  CA:true
  PathLen:0
]

[4]: ObjectId: 2.5.29.31 Criticality=false
CRLDistributionPoints [
  [DistributionPoint:
     [URIName: http://crl.pki.goog/gsr2/gsr2.crl]
]]

[5]: ObjectId: 2.5.29.32 Criticality=false
CertificatePolicies [
  [CertificatePolicyId: [2.23.140.1.2.2]
[PolicyQualifierInfo: [
  qualifierID: 1.3.6.1.5.5.7.2.1
  qualifier: 0000: 16 1C 68 74 74 70 73 3A   2F 2F 70 6B 69 2E 67 6F  ..https://pki.go
0010: 6F 67 2F 72 65 70 6F 73   69 74 6F 72 79 2F        og/repository/

]]  ]
]

[6]: ObjectId: 2.5.29.37 Criticality=false
ExtendedKeyUsages [
  serverAuth
  clientAuth
]

[7]: ObjectId: 2.5.29.15 Criticality=true
KeyUsage [
  DigitalSignature
  Key_CertSign
  Crl_Sign
]

[8]: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 98 D1 F8 6E 10 EB CF 9B   EC 60 9F 18 90 1B A0 EB  ...n.....`......
0010: 7D 09 FD 2B                                        ...+
]
]

]
  Algorithm: [SHA256withRSA]
  Signature:
0000: 1A 80 3E 36 79 FB F3 2E   A9 46 37 7D 5E 54 16 35  ..>6y....F7.^T.5
0010: AE C7 4E 08 99 FE BD D1   34 69 26 52 66 07 3D 0A  ..N.....4i&Rf.=.
0020: BA 49 CB 62 F4 F1 1A 8E   FC 11 4F 68 96 4C 74 2B  .I.b......Oh.Lt+
0030: D3 67 DE B2 A3 AA 05 8D   84 4D 4C 20 65 0F A5 96  .g.......ML e...
0040: DA 0D 16 F8 6C 3B DB 6F   04 23 88 6B 3A 6C C1 60  ....l;.o.#.k:l.`
0050: BD 68 9F 71 8E EE 2D 58   34 07 F0 D5 54 E9 86 59  .h.q..-X4...T..Y
0060: FD 7B 5E 0D 21 94 F5 8C   C9 A8 F8 D8 F2 AD CC 0F  ..^.!...........
0070: 1A F3 9A A7 A9 04 27 F9   A3 C9 B0 FF 02 78 6B 61  ......'......xka
0080: BA C7 35 2B E8 56 FA 4F   C3 1C 0C ED B6 3C B4 4B  ..5+.V.O.....<.K
0090: EA ED CC E1 3C EC DC 0D   8C D6 3E 9B CA 42 58 8B  ....<.....>..BX.
00A0: CC 16 21 17 40 BC A2 D6   66 EF DA C4 15 5B CD 89  ..!.@...f....[..
00B0: AA 9B 09 26 E7 32 D2 0D   6E 67 20 02 5B 10 B0 90  ...&.2..ng .[...
00C0: 09 9C 0C 1F 9E AD D8 3B   EA A1 FC 6C E8 10 5C 08  .......;...l..\.
00D0: 52 19 51 2A 71 BB AC 7A   B5 DD 15 ED 2B C9 08 2A  R.Q*q..z....+..*
00E0: 2C 8A B4 A6 21 AB 63 FF   D7 52 49 50 D0 89 B7 AD  ,...!.c..RIP....
00F0: F2 AF FB 50 AE 2F E1 95   0D F3 46 AD 9D 9C F5 CA  ...P./....F.....

]
***
%% Invalidated:  [Session-1, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256]
main, SEND TLSv1.2 ALERT:  fatal, description = certificate_unknown
main, WRITE: TLSv1.2 Alert, length = 2
main, called closeSocket()
main, handling exception: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
[2020-07-22 15:41:39,855] ERROR sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target (org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule)
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
        at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
        at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1946)
        at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:316)
        at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:310)
        at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1639)
        at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:223)
        at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1037)
        at sun.security.ssl.Handshaker.process_record(Handshaker.java:965)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1064)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
        at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:167)
        at io.strimzi.kafka.oauth.common.HttpUtil.request(HttpUtil.java:117)
        at io.strimzi.kafka.oauth.common.HttpUtil.post(HttpUtil.java:61)
        at io.strimzi.kafka.oauth.common.OAuthAuthenticator.post(OAuthAuthenticator.java:87)
        at io.strimzi.kafka.oauth.common.OAuthAuthenticator.loginWithClientSecret(OAuthAuthenticator.java:60)
        at io.strimzi.kafka.oauth.client.JaasClientOauthLoginCallbackHandler.handleCallback(JaasClientOauthLoginCallbackHandler.java:153)
        at io.strimzi.kafka.oauth.client.JaasClientOauthLoginCallbackHandler.handle(JaasClientOauthLoginCallbackHandler.java:133)
        at org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule.identifyToken(OAuthBearerLoginModule.java:316)
        at org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule.login(OAuthBearerLoginModule.java:301)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at javax.security.auth.login.LoginContext.invoke(LoginContext.java:755)
        at javax.security.auth.login.LoginContext.access$000(LoginContext.java:195)
        at javax.security.auth.login.LoginContext$4.run(LoginContext.java:682)
        at javax.security.auth.login.LoginContext$4.run(LoginContext.java:680)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)
        at javax.security.auth.login.LoginContext.login(LoginContext.java:587)
        at org.apache.kafka.common.security.oauthbearer.internals.expiring.ExpiringCredentialRefreshingLogin.login(ExpiringCredentialRefreshingLogin.java:204)
        at org.apache.kafka.common.security.oauthbearer.internals.OAuthBearerRefreshingLogin.login(OAuthBearerRefreshingLogin.java:150)
        at org.apache.kafka.common.security.authenticator.LoginManager.<init>(LoginManager.java:62)
        at org.apache.kafka.common.security.authenticator.LoginManager.acquireLoginManager(LoginManager.java:105)
        at org.apache.kafka.common.network.SaslChannelBuilder.configure(SaslChannelBuilder.java:147)
        at org.apache.kafka.common.network.ChannelBuilders.create(ChannelBuilders.java:146)
        at org.apache.kafka.common.network.ChannelBuilders.clientChannelBuilder(ChannelBuilders.java:67)
        at org.apache.kafka.clients.ClientUtils.createChannelBuilder(ClientUtils.java:99)
        at org.apache.kafka.clients.producer.KafkaProducer.newSender(KafkaProducer.java:450)
        at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:421)
        at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:298)
        at kafka.tools.ConsoleProducer$.main(ConsoleProducer.scala:45)
        at kafka.tools.ConsoleProducer.main(ConsoleProducer.scala)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
        at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:450)
        at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:317)
        at sun.security.validator.Validator.validate(Validator.java:262)
        at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:330)
        at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:237)
        at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:132)
        at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1621)
        ... 42 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
        at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
        at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
        at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
        at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:445)
        ... 48 more
org.apache.kafka.common.KafkaException: Failed to construct kafka producer
        at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:432)
        at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:298)
        at kafka.tools.ConsoleProducer$.main(ConsoleProducer.scala:45)
        at kafka.tools.ConsoleProducer.main(ConsoleProducer.scala)
Caused by: org.apache.kafka.common.KafkaException: javax.security.auth.login.LoginException: An internal error occurred while retrieving token from callback handler
        at org.apache.kafka.common.network.SaslChannelBuilder.configure(SaslChannelBuilder.java:158)
        at org.apache.kafka.common.network.ChannelBuilders.create(ChannelBuilders.java:146)
        at org.apache.kafka.common.network.ChannelBuilders.clientChannelBuilder(ChannelBuilders.java:67)
        at org.apache.kafka.clients.ClientUtils.createChannelBuilder(ClientUtils.java:99)
        at org.apache.kafka.clients.producer.KafkaProducer.newSender(KafkaProducer.java:450)
        at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:421)
        ... 3 more
Caused by: javax.security.auth.login.LoginException: An internal error occurred while retrieving token from callback handler
        at org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule.identifyToken(OAuthBearerLoginModule.java:319)
        at org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule.login(OAuthBearerLoginModule.java:301)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at javax.security.auth.login.LoginContext.invoke(LoginContext.java:755)
        at javax.security.auth.login.LoginContext.access$000(LoginContext.java:195)
        at javax.security.auth.login.LoginContext$4.run(LoginContext.java:682)
        at javax.security.auth.login.LoginContext$4.run(LoginContext.java:680)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)
        at javax.security.auth.login.LoginContext.login(LoginContext.java:587)
        at org.apache.kafka.common.security.oauthbearer.internals.expiring.ExpiringCredentialRefreshingLogin.login(ExpiringCredentialRefreshingLogin.java:204)
        at org.apache.kafka.common.security.oauthbearer.internals.OAuthBearerRefreshingLogin.login(OAuthBearerRefreshingLogin.java:150)
        at org.apache.kafka.common.security.authenticator.LoginManager.<init>(LoginManager.java:62)
        at org.apache.kafka.common.security.authenticator.LoginManager.acquireLoginManager(LoginManager.java:105)
        at org.apache.kafka.common.network.SaslChannelBuilder.configure(SaslChannelBuilder.java:147)
        ... 8 more

Need some inputs here.

scholzj commented 4 years ago

I do not think anyone from the Strimzi team tried it. So you will need to figure it out your self. For the TLS, maybe you need to provide certificate or something: https://strimzi.io/docs/operators/latest/full/using.html#type-KafkaListenerAuthenticationOAuth-reference

vperi1730 commented 4 years ago

Hi Scholzj,

I am getting the below error while running the producer sh after enabling the Oauth in the CR. I haven't set this grant type anywhere in my Kafka CR, however i knew that the value has to be authorization_code instead of client_credentials.

Do we have any workaround to resolve this?

tls: 
          authentication:
            type: oauth
            validIssuerUri: "https://accounts.google.com/o/oauth2/v2/auth"
            introspectionEndpointUri: "https://accounts.google.com/o/oauth2/token"
            clientId: "835970994981-14mqluev54fa9vutrmpkj89fjppacd49.apps.googleusercontent.com"
            clientSecret:
              secretName: my-client-oauth-secret
              key: client-secret
[kafka@kafka-oauth-cluster-kafka-0 kafka]$ ./bin/kafka-console-producer.sh --broker-list   kafka-oauth-cluster-kafka-bootstrap.kafka-oauth:9093 --topic july22-topic   --producer-property 'security.protocol=SASL_SSL'   --producer-property 'sasl.mechanism=OAUTHBEARER'   --producer-property 'sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required;'   --producer-property 'sasl.login.callback.handler.class=io.strimzi.kafka.oauth.client.JaasClientOauthLoginCallbackHandler'
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
org.apache.kafka.common.KafkaException: Failed to construct kafka producer
        at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:432)
        at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:298)
        at kafka.tools.ConsoleProducer$.main(ConsoleProducer.scala:45)
        at kafka.tools.ConsoleProducer.main(ConsoleProducer.scala)
Caused by: org.apache.kafka.common.KafkaException: javax.security.auth.login.LoginException: io.strimzi.kafka.oauth.common.HttpException: POST request to https://accounts.google.com/o/oauth2/token failed with status 400: {
  "error": "unsupported_grant_type",
  "error_description": "Invalid grant_type: client_credentials"
}
scholzj commented 4 years ago

I think you are mixing very different use cases. This is not a web application which would use OAuth for people to log in. OAuth in Kafka is used for applications and not for persons. That means it is using different mechanisms such as client credentials etc. You cannot expect that some person will be logging into Google every time some pod restarts in Kubernetes cluster in order to authenticate.

I have no idea if there are some workarounds or ways to make this work through some hacks etc. But it is well beyond our scope in Strimzi.

vperi1730 commented 4 years ago

Does strimzi support Google Oauth2.0 authorization server approach as in the documentation I see it for Keycloak and Hydra only and nowhere it is mentioned if any other list is supported??

Basically I have a requirement to enable Kafka with auth type as Oauth using Google Oauth2 API, So I was trying all the configurations provided in the Strimzi doc, couldn't get there somehow.

scholzj commented 4 years ago

Does strimzi support Google Oauth2.0 authorization server approach as in the documentation I see it for Keycloak and Hydra only and nowhere it is mentioned if any other list is supported??

Well, I told you right at the beginning that I'm sure that nobody tried it. Please understand that this is an open source project - nobody gives you any guarantees that something does or doesn't work. As you noticed, we are testing against Keycloak and Hydra. If you need more, you might need to figure it out your self and contribute it to the project.

Basically I have a requirement to enable Kafka with auth type as Oauth using Google Oauth2 API, So I was trying all the configurations provided in the Strimzi doc, couldn't get there somehow.

I'm not sure what your use case is. But as I said before, Google IMHO does not offer a regular OAuth 2.0 Authorization server. It just lets you use their accounts for logging in into different WebApps. This is a very different use case from securing application to application communication with a protocol like Kafka. So it might be non-trivial to get it working.

vperi1730 commented 4 years ago

Sure, I agree with this. Thanks, Scholzj.

forsberg commented 4 years ago

https://stackoverflow.com/questions/40102110/can-i-use-grant-type-client-credentials-for-google-api confirms that Google Oauth only supports two types of Oauth grants:

I'm in no way an expert on these things. What I would like to accomplish is to have an external listener for my Kafka cluster with authentication against Google Oauth, used only to provide developer access from workstations, with developers authenticating using their regular Gsuite accounts.

Fully understand that nobody has tried this. Will experiment a bit if I find the time.

forsberg commented 4 years ago

@vperi1730 - perhaps https://github.com/strimzi/strimzi-kafka-oauth#configuring-the-oauth2-1 can be of help? It specifically mentions ways to do password authentication, although I don't know if that's your use case.

flecno commented 3 years ago

Google has full support to use OIDC ID tokens in server-to-server use cases to authenticate the identity of a service account. I could run a test locally the auth flow with access token where broker performing fast local validation.

server config

apiVersion: kafka.strimzi.io/v1beta1
kind: Kafka
metadata:
  name: my-cluster
spec:
  kafka:
    version: 2.6.0
    replicas: 1
    listeners:
      - name: external
        port: 9094
        type: nodeport
        authentication:
          type: oauth
          validIssuerUri: "https://accounts.google.com"
          jwksEndpointUri: "https://www.googleapis.com/oauth2/v3/certs"
          userNameClaim: email
          # disable because JWT tokens get the "typ": "JWT"
          checkAccessTokenType: false

clients

For kafka clients use this config:

oauth.token.endpoint.uri=https://oauth2.googleapis.com/token
oauth.username.claim=email
oauth.access.token=$JWT_TOKEN

Generate a ID token via cli:

gcloud auth activate-service-account --key-file=/path/to/svc_account.json
gcloud auth print-identity-token --audience=https://example.com

# impersonate an SA https://cloud.google.com/iam/docs/impersonating-service-accounts
gcloud auth print-identity-token --audiences=https://example.com --impersonate-service-account impersonated-account@projectID.iam.gserviceaccount.com

or in java using google-auth-library-java

GoogleCredentials credentials = GoogleCredentials.getApplicationDefault();
ImpersonatedCredentials tokenProvider = ImpersonatedCredentials.create(credentials, "impersonated-account@projectID.iam.gserviceaccount.com",
        null, Arrays.asList("https://www.googleapis.com/auth/cloud-platform"), 300);
IdTokenCredentials idToken = IdTokenCredentials.newBuilder()
        .setIdTokenProvider((IdTokenProvider) tokenProvider)
        .setTargetAudience("https://example.com")
        .setOptions(Arrays.asList(IdTokenProvider.Option.INCLUDE_EMAIL))
        .build();
idToken.refreshIfExpired();
String token = idToken.getIdToken().getTokenValue();