Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OIDC - grpc message - Unauthenticated Authorisation required to get the Namespace 'default' due to unauthorised #6549

Closed
TWBrown42 opened this issue Aug 1, 2023 · 23 comments
Labels
kind/question An issue that reports a question about the project

Comments

@TWBrown42
Copy link

Summary
I am attempting to use OIDC with my AWS EKS cluster. I have configured the Identity Provider to be an AWS Cognito instance. I have made the following Kubeapps helm value changes:-
extraFlags:
- --oidc-issuer-url=https://cognito-idp.eu-central-1.amazonaws.com/eu-central-X_YYYYYYYY
- --proxy-prefix=/oauth2
- --scope=openid email
- --ssl-insecure-skip-verify
- --set-authorization-header=true
- --session-store-type=redis
- --redis-connection-url=redis://localcharts-redis-master:6379/0

I have a user created in Cognito (user1@mydomain) I have also configured that user as being email verified.
ClientId and Client Secrets have been defined in the Kubeapps helm chart so as far as I am concerned I am good to go for a logon to KubeApps.

When I browse to my KubeApps site I get the "Welcome to KubeApps" and because I have it configured this way it is showing me the Login via OIDC Provider button. I click the button and am directed to my Cognito instance where I logon as my user ([email protected]).
I am brought back to KubeApps where I am returned to the Welcome to KubeApps screen - i.e. no dashboard.

I have followed troubleshooting section of your website and can confirm that during Chrome Tracing I can see the JWT bearer token, the username and the group memberships are being returned. The Issuer and the Audience are as I would expect within the token. Within the trace the first point of failure I see is a second call to the CheckNamespace Exists (the first call happens on application load before I have authenticated and in that case I get what I assume is the correct 403 response. However, on the second call although the HTTP Status is 200 the header detail shows the following error:-
grpc message - rpc error = Unauthenticated Authorisation required to get the Namespace 'default' due to unauthorised

Cool I think...so I check the K8s API logs...
E0801 12:13:55.600504 11 webhook.go:154] Failed to make webhook authenticator request: unknown
E0801 12:13:55.600568 11 authentication.go:70] "Unable to authenticate the request" err="[invalid bearer token, oidc: verify token: oidc: expected audience "3cb09302hdv909hv0nh3f2e72a" got [], unknown]"

Given the above I wondered whether the session state (I am using redis) was not working and therefore no session cookie with the tokens was been found server side (even though we can see them for debugging purposes client side). However, I do see a key being created within Redis (albeit I lack the understanding of how to decrypt it manually to check its contents.

As I mentioned, I have followed the various steps in the https://kubeapps.dev/docs/latest/howto/oidc/oauth2oidc-debugging/ article and when I grab the token from my Chrome network trace and use it within a curl to the K8s API Server I am able to view all resources (to get over this current hurdle I have a cluster-admin role binding to this particular user, which when using curl I can add and remove the binding and see 403 / 200 responses as you would expect.

Your time would be appreciated in helping me understand where I am slipping up here. Obviously any logs or information I can provide with your guidance I'll happily grab.

@TWBrown42 TWBrown42 added the kind/question An issue that reports a question about the project label Aug 1, 2023
@absoludity
Copy link
Contributor

Thanks for following through the debugging steps - that really helps.

From what you've said, you have a valid token since you can CuRL with it, which is odd, because that's exactly what the oauth2proxy service will send through with the request. Can you verify that the CuRL also works fine if you execute it from within your cluster, preferably from the kubeapps frontend nginx pod? (you may need to setup a separate pod in the same namespace, if curl isn't available on one of the kubeapps pods such as the frontend nginx). This gives us one step closer to exactly what happens on Kubeapps.

Assuming that also works, please triple check that the token shown in the chrome network tab when logging in is the same one that you're using via curl. At this point, I'm pretty stumped from the info you've given: the k8s api server is saying the token is invalid because it doesn't have the expected audience, yet you can curl with the same, identical token and it accepts the correct audience from the token?

Can you check that:

  1. the clientId you've got set in your oauth2proxy settings is the expected audience mentioned in your k8s API logs of "3cb09302hdv909hv0nh3f2e72a" ? (from the cognito docs, it appears that the audience in the token is the clientID - not 100%, but seems to be mentioned multiple times).
  2. The token which you are grabbing from the chrome network tab can be parsed (see jwt.io or use a local tool) and shows you the audience field, and
  3. The token which you are grabbing is the id_token and is the one that works with curl (it's not clear to me whether cognito is expecting the access token, rather than the id token, but if you've verified the curl command works with the id token that should already be enough). Otherwise, we have a setting that ensures oauth2proxy sends the access token rather than the id token with the requests.

Let me know how you go. We've not tried Kubeapps with Cognito before, but assuming it's OIDC compliant, which it seems to be, there should be no issue. As above, the main thing we need to understand is whether your k8s api server is expecting the id token or an access-token with the requests.

Let me know how you go!

@TWBrown42
Copy link
Author

Thanks for the quick response...Firstly, your checklist: -

  1. Confirmed that this is the audience (partial payload segment of the JWT shown below...)
    {
    "at_hash": "-BvsWmPF4VRE6yoeMwOQ9Q",
    "sub": "328246af-8932-4700-87f6-9a7415a8d4d7",
    "cognito:groups": [
    "gid:kubeappsreader",
    "KubeappsReader"
    ],
    "email_verified": true,
    "iss": "https://mycognitoname.myregion.amazonaws.com/eu-central-myuniqueid",
    "cognito:username": "328246af-8932-4700-87f6-9a7415a8d4d7",
    "origin_jti": "6f635779-604e-4bde-9200-2137a9d01841",
    "aud": "3fb09302hdv709hv0nh3f2f72a",
    "event_id": "4f8be662-9d2d-4b2b-be17-546c3403626c",
    "token_use": "id",
    "auth_time": 1690965876,
    "exp": 1690969476,
    "iat": 1690965876,
    "jti": "1fd6d15b-d3b3-4058-89a0-8d773df211a7",...

  2. The above JWT was taken from the Chrome Network tab and copied to the JWT.IO site to obtain the decode. A partial screenshot is shown below:-
    image

  3. It is definitely an ID token I am copying (the type: id) within the token indicates this. Also the groups that I configures for this user, email, etc...indicate this.

I also took your suggestion (thanks) and performed the curl both without and within the cluster. Curl WORKS in both cases. The specific curls are shown below:-
export TOKEN = eyJraWQiOiJpdHZQdEY3M3F4bEhybUd4R0hZc1lSYUltb04xd2RTa3NxNGlrS1hjT0xBPSIsImFsZyI6IlJTMjU2In0.eyJhdF9oYXNoIjoiLUJ2c1dtUEY0VlJFNnlvZU13T1E5USIsInN1YiI6IjMyOD
I0NmFmLTg5MzItNDcwMC04N2Y2LTlhNzQxNWE4ZDRkNyIsImNvZ25pdG86Z3JvdXBzIjpbImdpZDprdWJlYXBwc3JlYWRlciIsIkt1YmVhcHBzUmVhZGVyIl0sImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJpc3MiOiJodHRwczpcL
1wvY29nbml0by1pZHAuZXUtY2VudHJhbC0xLmFtYXpvbmF3cy5jb21cL2V1LWNlbnRyYWwtMV83d1NPNGxYUTEiLCJjb2duaXRvOnVzZXJuYW1lIjoiMzI4MjQ2YWYtODkzMi00NzAwLTg3ZjYtOWE3NDE1YThkNGQ3Iiwib3Jp
Z2luX2p0aSI6IjZmNjM1Nzc5L......

curl -k -H "Authorization: Bearer $TOKEN" https://myAPISERVERUNIQUEADDRESS.gr7.eu-central-1.eks.amazonaws.com/api/v1/namespaces

I am returned:-
{
"kind": "NamespaceList",
"apiVersion": "v1",
"metadata": {
"resourceVersion": "92458040"
},
"items": [
{
"metadata": {
"name": "cert-manager",
...

This also works if I curl to the root..
curl -k -H "Authorization: Bearer $TOKEN" https://myAPISERVERUNIQUEADDRESS.gr7.eu-central-1.eks.amazonaws.com
{
"paths": [
"/.well-known/openid-configuration",
"/api",
"/api/v1",
"/apis",
"/apis/",
"/apis/acme.cert-manager.io",
"/apis/acme.cert-manager.io/v1",
"/apis/admissionregistration.k8s.io",
"/apis/admissionregistration.k8s.io/v1",
"/apis/apiextensions.k8s.io",
"/apis/apiextensions.k8s.io/v1",
....

I will own up and say that I did this from within an alpine container that I dropped into the kubeapps namespace so that I could get curl installed. I did this as I am unsure how to install curl into your nginx based pod that is running Kubeapps as non root...if you know then happy to try this also.
I am pretty sure AWS EKS cluster API Server is expecting the id_token as it is lifting the username from it.

Again...appreciate the speedy response, I've had a few false starts in getting KubeApps running trying various combinations of Cloud Platform supplier and Identity Providers and this is the closest I have come to what I think will be a great demonstrator to our internal solutions teams as well as possible clients, so appreciate your persistence here.

@absoludity
Copy link
Contributor

From the data you've provided, you've shown that after authenticating, the id-token which oauth2proxy is storing for use with all requests to the k8s API server is valid and works via curl. This shows that, from Kubeapps point of view, there is nothing wrong. So unfortunately I can only suggest that you:

  • paste your (redacted) complete chart settings (I can only see your extraFlags for the authproxy service above, but can't, for example, see which provider you're using,
  • check and paste the relevant logs from the auth-proxy container service of the frontend pod after the successful authentication and subsequent failed requests
  • check and paste the relevant logs from the kubeapps-apis pod showing the request that's erroring.

That said, I don't expect to see any new information there but worth trying. I can't see or imagine why we're seeing a valid token in use by oauth2proxy, but that same token is failing when used by kubeapps. The only possibility that I can fathom is that we have a bug in Kubeapps that is causing it to try to send its service account token instead in your particular request, and that service token doesn't have the correct audience etc. required by cognito.

Actually, that's something else you could try: verify that the kubeapps-apis service account (token?) is able to be used to access the k8s API server (ie. use curl after extracting the token, or even verify with kubectl auth can-i --as system:serviceaccount:...). See k8s docs for more info. It obviously should be able to do so, but perhaps something in your clusters' auth setup means it can't. But I feel I'm clutching at straws there.

@absoludity
Copy link
Contributor

Related, re-check your k8s apis logs: it could be that you've shown an error for a different request (the k8s-api server does check if it can use its service account token to list namespaces in some cases, but handles that failure... so there could be other relevant requests failing - not sure).

Also, if you can give a screenshot of the requests tab showing the requests right after your authenticate (highlighting the one you've mentioned with the grpc error message).

@absoludity
Copy link
Contributor

A final thought, you may get more information about exactly what request is hitting your k8s api server by temporarily running your api server with a debug log level or similar. Either that or tracing the network requests - but we really want to know what is actually reaching your k8s api server when the request is sent from Kubeapps.

@TWBrown42
Copy link
Author

Thanks @absoludity for the suggests, from the top here's a copy of the chart values:-

KubeApps Chart Values

kubeapps:
authProxy:
clientID: 3fb09302hdv709hv0nh3f2f72a
clientSecret: 7dgl7dra1b38aunupuba2tpr9u4877473hjlo
extraFlags:
- --oidc-issuer-url=https://MyCognito.eu-central-1.amazonaws.com/eu-central-1_AUID
- --proxy-prefix=/oauth2
- --scope=openid email
- --ssl-insecure-skip-verify
- --set-authorization-header=true
- --session-store-type=redis
- --redis-connection-url=redis://localcharts-redis-master:6379/0
provider: oidc
frontend:
service:
type: NodePort
ingress:
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
nginx.ingress.kubernetes.io/proxy-buffer-size: 16k
nginx.ingress.kubernetes.io/proxy-buffers-number: "4"
hostname: aaaaaaaaaaaaa-123456789.eu-central-1.elb.amazonaws.com
ingressClassName: nginx

Logs from Auth-Proxy

I deleted the old pod, waited for new one to start so I could capture the whole log in its entirety.

Taken with after I had launched KubeApps, clicked the Authenticate with OIDC, entered my credentials in AWS Cognito:-
kubectl logs localcharts-kubeapps-d4bd84fb-fv2qc -c auth-proxy -n ka-auth

Results (I've redacted certain details and commented some of the major points I can see with ''):-
[2023/08/03 08:27:36] [provider.go:55] Performing OIDC Discovery...
[2023/08/03 08:27:36] [proxy.go:89] mapping path "/" => upstream "http://localhost:8080/"
[2023/08/03 08:27:36] [oauthproxy.go:162] OAuthProxy configured for OpenID Connect Client ID: 3fb09302hdv709hv0nh3f2f72a
[2023/08/03 08:27:36] [oauthproxy.go:168] Cookie settings: name:_oauth2_proxy secure(https):true httponly:true expiry:168h0m0s domains: path:/ samesite: refresh:after 2m0s
[2023/08/03 08:27:36] [oauthproxy.go:449] Skipping auth - Method: ALL | Path: ^/config.json$
[2023/08/03 08:27:36] [oauthproxy.go:449] Skipping auth - Method: ALL | Path: ^/site.webmanifest$
[2023/08/03 08:27:36] [oauthproxy.go:449] Skipping auth - Method: ALL | Path: ^/custom_style.css$
[2023/08/03 08:27:36] [oauthproxy.go:449] Skipping auth - Method: ALL | Path: ^/clr-ui.min.css$
[2023/08/03 08:27:36] [oauthproxy.go:449] Skipping auth - Method: ALL | Path: ^/clr-ui-dark.min.css$
[2023/08/03 08:27:36] [oauthproxy.go:449] Skipping auth - Method: ALL | Path: ^/custom_locale.json$
[2023/08/03 08:27:36] [oauthproxy.go:449] Skipping auth - Method: ALL | Path: ^/favicon.
.png$
[2023/08/03 08:27:36] [oauthproxy.go:449] Skipping auth - Method: ALL | Path: ^/favicon.
.ico$
[2023/08/03 08:27:36] [oauthproxy.go:449] Skipping auth - Method: ALL | Path: ^/android-chrome-.
.png$
[2023/08/03 08:27:36] [oauthproxy.go:449] Skipping auth - Method: ALL | Path: ^/static/
[2023/08/03 08:27:36] [oauthproxy.go:449] Skipping auth - Method: ALL | Path: ^/apis/core/plugins/v1alpha1/configured-plugins$
[2023/08/03 08:27:36] [oauthproxy.go:449] Skipping auth - Method: ALL | Path: ^/apis/kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins$
[2023/08/03 08:27:36] [oauthproxy.go:449] Skipping auth - Method: ALL | Path: ^/$
172.31.35.188:34304 - 2087eefab6c6103bf59d2e6b3fd08165 - - [2023/08/03 08:28:56] mydomain.eu-central-1.elb.amazonaws.com GET / "/" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 206 0.003
172.31.35.188:34306 - 0a1a384b851c09c98c43a33a69f36005 - - [2023/08/03 08:28:57] mydomain.eu-central-1.elb.amazonaws.com GET / "/static/css/main.d4740ec6.css" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 240289 0.072
172.31.35.188:34306 - a59ae0b1ec600c0a7e6fcdb14bea0724 - - [2023/08/03 08:28:57] mydomain.eu-central-1.elb.amazonaws.com GET / "/static/css/main.d4740ec6.css.map" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 1408364 0.039
172.31.35.188:34304 - 3fe2020a3df75bda3fe4595906c20674 - - [2023/08/03 08:28:57] mydomain.eu-central-1.elb.amazonaws.com GET / "/static/js/main.db6b74a5.js" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 1958729 0.581
172.31.35.188:34306 - c5d3a374a9831cf706b6837d901d2311 - - [2023/08/03 08:28:58] mydomain.eu-central-1.elb.amazonaws.com GET / "/config.json" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 677 0.002
172.31.35.188:34306 - f463b39151d19f7f396377913a01c94d - - [2023/08/03 08:28:58] mydomain.eu-central-1.elb.amazonaws.com GET / "/custom_locale.json" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 2 0.002
172.31.35.188:34306 - 524a4ede4d1c261e9d6e36093ed8a3bb - - [2023/08/03 08:28:58] mydomain.eu-central-1.elb.amazonaws.com GET / "/favicon.ico" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 15086 0.002
172.31.35.188:34306 - f1bd93386de17e3cd42dbb0f4a4c220e - - [2023/08/03 08:28:59] mydomain.eu-central-1.elb.amazonaws.com POST / "/apis/kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 92 0.002
172.31.35.188:34304 - d73efb048cfe30048111695743b46e11 - - [2023/08/03 08:28:57] mydomain.eu-central-1.elb.amazonaws.com GET / "/static/js/main.db6b74a5.js.map" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 24074398 1.421
172.31.35.188:34306 - fc7eceafb656213b856e30e439e0e473 - - [2023/08/03 08:28:59] mydomain.eu-central-1.elb.amazonaws.com GET / "/custom_style.css" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 0 0.002
172.31.35.188:34316 - 4fad40077af74a2a1c9390662569e5f6 - - [2023/08/03 08:28:59] mydomain.eu-central-1.elb.amazonaws.com GET / "/config.json" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 677 0.003
172.31.35.188:34332 - 8fd95149f7a0ab5d14bae1baca298eeb - - [2023/08/03 08:28:59] mydomain.eu-central-1.elb.amazonaws.com GET / "/clr-ui.min.css" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 160958 0.017
[2023/08/03 08:28:59] [oauthproxy.go:959] No valid authentication in request. Initiating login.

*** This is the first call to a resource without authentication so I guess 403 is valid here
172.31.35.188:34332 - 333280b573f607c79513736fc3dec9e4 - - [2023/08/03 08:28:59] mydomain.eu-central-1.elb.amazonaws.com POST - "/apis/kubeappsapis.plugins.resources.v1alpha1.ResourcesService/CheckNamespaceExists" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 403 8580 0.001
172.31.35.188:34316 - d65bef4793a4c1cefcc32709976b73df - - [2023/08/03 08:28:59] mydomain.eu-central-1.elb.amazonaws.com GET / "/favicon.ico" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 15086 0.045
172.31.35.188:34332 - c6e97eb12e1d57d2c9c93eb489947d50 - - [2023/08/03 08:28:59] mydomain.eu-central-1.elb.amazonaws.com GET / "/favicon-32x32.png" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 2379 0.002
172.31.35.188:34306 - 90db392433e90fee06821317134e581d - - [2023/08/03 08:28:59] mydomain.eu-central-1.elb.amazonaws.com GET / "/favicon-32x32.png" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 2379 0.002
172.31.35.188:34316 - 66fe24f573e842ae17be4ecb19063e28 - - [2023/08/03 08:28:59] mydomain.eu-central-1.elb.amazonaws.com GET / "/favicon.ico" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 15086 0.046
172.31.35.188:34306 - 13dcb8ac252b8c39b1efc6350f13f3a1 - - [2023/08/03 08:28:59] mydomain.eu-central-1.elb.amazonaws.com GET / "/favicon.ico" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 15086 0.045
172.31.35.188:34306 - efc993b4edb35b0884db5be4771bea09 - - [2023/08/03 08:29:00] mydomain.eu-central-1.elb.amazonaws.com GET / "/static/media/ClarityCity-SemiBold.508f08b507bb08382c2e.woff2" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 17252 0.002
172.31.35.188:34304 - 8b2c30c69ce2e3548e9c4966fd61fd07 - - [2023/08/03 08:29:00] mydomain.eu-central-1.elb.amazonaws.com GET / "/clr-ui-dark.min.css" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 141581 0.015
172.31.35.188:34316 - 54972eaa14743ae63c04c6f5dcd6c9fc - - [2023/08/03 08:29:00] mydomain.eu-central-1.elb.amazonaws.com GET / "/static/media/ClarityCity-Regular.7f3f0d7447ea1c59ab46.woff2" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 16856 0.045
[2023/08/03 08:29:00] [oauthproxy.go:959] No valid authentication in request. Initiating login.

*** Not sure why this resource requires protection but it gives a 403
172.31.35.188:34316 - c3af4596deb7db7c7523f2f6a243d2e6 - - [2023/08/03 08:29:00] mydomain.eu-central-1.elb.amazonaws.com GET - "/clr-ui-dark.min.css.map" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 403 8521 0.000

*** I started the authentication here using the "Login via OIDC Provider button in KubeApps"
172.31.35.188:34316 - 15706271d1bc6bd1d1064f421b5b824c - - [2023/08/03 08:29:36] mydomain.eu-central-1.elb.amazonaws.com GET - "/oauth2/start" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 302 389 0.000
*** After I login user1 in AWS Cognito...
172.31.35.188:34316 - 134ccd38dd3fdb93cb972684f7bec9eb - [email protected] [2023/08/03 08:29:53] [AuthSuccess] Authenticated via OAuth2: Session{email:[email protected] user:328246af-8932-4700-87f6-9a7415a8d4d7 PreferredUsername: token:true id_token:true created:2023-08-03 08:29:53.180553423 +0000 UTC m=+136.774992892 expires:2023-08-03 09:29:53.062312547 +0000 UTC m=+3736.656752020 refresh_token:true}
*** Strange ordering in the log file, this is one second before the previous line but it shows the redirection coming back with the auth code
172.31.35.188:34316 - 134ccd38dd3fdb93cb972684f7bec9eb - - [2023/08/03 08:29:52] mydomain.eu-central-1.elb.amazonaws.com GET - "/oauth2/callback?code=a8ec23b7-ef9b-4f1e-9794-88ce8300ef2d&state=v1okBYSqumuEpQBAExiRixKr3-176Xd90mDNy7xNYcs:/" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 302 24 0.403

172.31.35.188:34316 - e0c5cd91a880e346bddf9f97525bd9db - [email protected] [2023/08/03 08:29:53] mydomain.eu-central-1.elb.amazonaws.com GET / "/" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 206 0.003
172.31.35.188:34304 - e46c7a12656e45aa982ea9792f9f1998 - [email protected] [2023/08/03 08:29:53] mydomain.eu-central-1.elb.amazonaws.com GET / "/static/css/main.d4740ec6.css" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 240289 0.045
172.31.35.188:34304 - 9ffc9fc4ed490d5df1ed1368928c6418 - [email protected] [2023/08/03 08:29:53] mydomain.eu-central-1.elb.amazonaws.com GET / "/static/css/main.d4740ec6.css.map" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 1408364 0.025
172.31.35.188:34316 - ce879b709655b6826ddd9024594db78e - [email protected] [2023/08/03 08:29:53] mydomain.eu-central-1.elb.amazonaws.com GET / "/static/js/main.db6b74a5.js" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 1958729 0.553
172.31.35.188:34304 - c1ea78142d803a0a1498b3a8138b348a - [email protected] [2023/08/03 08:29:54] mydomain.eu-central-1.elb.amazonaws.com GET / "/config.json" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 677 0.003
172.31.35.188:34306 - f9fdfdcc20880f4ed9ed294bb3362c01 - [email protected] [2023/08/03 08:29:54] mydomain.eu-central-1.elb.amazonaws.com GET / "/custom_locale.json" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 2 0.003
172.31.35.188:34306 - e42f47caa33a3fa6b562d1d0c93865a5 - [email protected] [2023/08/03 08:29:55] mydomain.eu-central-1.elb.amazonaws.com GET / "/favicon.ico" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 15086 0.003

*** Highlighing here that the HTTP Status for GetConfiguredPlugins is SUCCESS
172.31.35.188:34306 - fb3b1ce0484f665b3597f91142fe44d2 - [email protected] [2023/08/03 08:29:55] mydomain.eu-central-1.elb.amazonaws.com POST / "/apis/kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 92 0.004
172.31.35.188:34316 - 6787ccc6a47465dbef285271bc4b3762 - [email protected] [2023/08/03 08:29:54] mydomain.eu-central-1.elb.amazonaws.com GET / "/static/js/main.db6b74a5.js.map" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 24074398 1.425
172.31.35.188:34306 - 8099470cf8ac0f646181d62456e8dd01 - [email protected] [2023/08/03 08:29:56] mydomain.eu-central-1.elb.amazonaws.com GET / "/config.json" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 677 0.003
172.31.35.188:46644 - 6cee50ae55eee17d6bf75fdcf2e7c383 - [email protected] [2023/08/03 08:29:56] mydomain.eu-central-1.elb.amazonaws.com GET / "/favicon.ico" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 15086 0.004
172.31.35.188:34304 - 3e7c3189ab54015b4d81dc6fc4ec5816 - [email protected] [2023/08/03 08:29:56] mydomain.eu-central-1.elb.amazonaws.com GET / "/clr-ui.min.css" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 160958 0.016
172.31.35.188:34306 - c1349863385c41150aeb6162695b0f80 - [email protected] [2023/08/03 08:29:56] mydomain.eu-central-1.elb.amazonaws.com GET / "/custom_style.css" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 0 0.017

*** Highlighing here that the HTTP Status for CheckNamespaceExists is SUCCESS (This is important as looking at the network tracing from Chrome the GPRC calll fails with an authentication error)
172.31.35.188:34332 - 39b308f187d65097a250dac3aa76c572 - [email protected] [2023/08/03 08:29:56] mydomain.eu-central-1.elb.amazonaws.com POST / "/apis/kubeappsapis.plugins.resources.v1alpha1.ResourcesService/CheckNamespaceExists" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 0 0.016

172.31.35.188:34316 - 3dca78f84b3425e0f39b1b5b6e21f55a - [email protected] [2023/08/03 08:29:56] mydomain.eu-central-1.elb.amazonaws.com GET / "/clr-ui-dark.min.css" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 141581 0.013
172.31.35.188:34316 - 2572cdc5d32a0c437b3615dda8c34726 - [email protected] [2023/08/03 08:29:57] mydomain.eu-central-1.elb.amazonaws.com GET / "/static/media/ClarityCity-SemiBold.508f08b507bb08382c2e.woff2" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 17252 0.003
172.31.35.188:34332 - 683189bf0bdfef1e1d039f473346dd18 - [email protected] [2023/08/03 08:29:57] mydomain.eu-central-1.elb.amazonaws.com GET / "/static/media/ClarityCity-Regular.7f3f0d7447ea1c59ab46.woff2" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 16856 0.003

*** Not sure why this resource requires protection but the previous 403 is now a SUCCESS
172.31.35.188:34332 - 1c5d8acf1a6d067bce510952c8d96180 - [email protected] [2023/08/03 08:29:57] mydomain.eu-central-1.elb.amazonaws.com GET / "/clr-ui-dark.min.css.map" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 867148 0.008

Chrome Network Trace for the same period

Overview

I will start with two screen shots showing the overall flow from launch through login in AWS Cognito back to KubeApps - I've redacted where I felt necessary and have annotated where I see correlation with the Auth Log above.

Page 1
Chrome Redacted Network Overview page1

Page 2
Chrome Redacted Network Overview page2

Details

Some specific details for individual line items

I show here the GetConfiguredPlugins as this seems to show that a GRPC call can succeed on my infrastructure:-
Chrome Redacted Network GetConfiguredPlugins Detail

The Response:-
Chrome Redacted Network GetConfiguredPlugins Response

I show below the call to CheckNamespaceExists, although in the overview it shows as a 200 success the detail shows otherwise.

Chrome Redacted Network CheckNamespaceExists

The following is the Payload sent to this command:-
Chrome Redacted Network ChecknamespaceExists Payload

I do not see much in the logs for the kubeapps internal api service...
kubectl logs localcharts-kubeapps-internal-kubeappsapis-5c785bffcf-gzfdf -n ka-auth

Returns
I0801 11:53:49.113440 1 root.go:36] "kubeapps-apis has been configured with serverOptions" serverOptions={Port:50051 PluginDirs:[/plugins/helm-packages /plugins/resources] ClustersConfigPath:/config/clusters.conf PluginConfigPath:/config/kubeapps-apis/plugins.conf PinnipedProxyURL:http://kubeapps-internal-pinniped-proxy.kubeapps:3333 PinnipedProxyCACert: GlobalHelmReposNamespace:ka-auth UnsafeLocalDevKubeconfig:false QPS:50 Burst:100}
I0801 11:53:49.521642 1 server.go:105] +helm NewServer(globalPackagingCluster: [default], globalPackagingNamespace: [ka-auth], pluginConfigPath: [/config/kubeapps-apis/plugins.conf]
I0801 11:53:49.521983 1 server.go:117] +helm using custom config: [{{3 3 3} 300 }]
I0801 11:53:49.522026 1 server.go:129] +helm NewServer effective globalPackagingNamespace: [ka-auth]
I0801 11:53:49.523013 1 plugins.go:157] "Successfully registered plugin" pluginPath="/plugins/helm-packages/helm-packages-v1alpha1-plugin.so"
I0801 11:53:50.011257 1 server.go:118] +resources using custom config: [{{ }}]
I0801 11:53:50.011867 1 plugins.go:157] "Successfully registered plugin" pluginPath="/plugins/resources/resources-v1alpha1-plugin.so"
I0801 11:53:50.012140 1 packages.go:52] Registered name:"helm.packages" version:"v1alpha1" for core.packaging.v1alpha1 packages aggregation.
I0801 11:53:50.013068 1 repositories.go:53] Registered name:"helm.packages" version:"v1alpha1" for core.packaging.v1alpha1 repositories aggregation.
I0801 11:53:50.019519 1 server.go:126] Starting server on ":50051"
I0801 12:00:09.435385 1 namespaces.go:29] "+resources CheckNamespaceExists" cluster="default" namespace="default"
I0801 12:13:55.592510 1 namespaces.go:29] "+resources CheckNamespaceExists" cluster="default" namespace="default"
I0802 08:44:40.180231 1 namespaces.go:29] "+resources CheckNamespaceExists" cluster="default" namespace="default"
I0803 08:29:56.300929 1 namespaces.go:29] "+resources CheckNamespaceExists" cluster="default" namespace="default"

The timings don't correspond with anything I had done during this period of analysis, maybe I am misunderstand the Architecture so I have also taken the logs of the Frontend KubeApps Pod:-

localcharts-kubeapps-d4bd84fb-fv2qc

Defaulted container "nginx" out of: nginx, auth-proxy
nginx 08:27:32.21
nginx 08:27:32.21 Welcome to the Bitnami nginx container
nginx 08:27:32.22 Subscribe to project updates by watching https://github.com/bitnami/containers
nginx 08:27:32.22 Submit issues and feature requests at https://github.com/bitnami/containers/issues
nginx 08:27:32.22
nginx 08:27:32.22 INFO ==> ** Starting NGINX setup **
nginx 08:27:32.26 INFO ==> Validating settings in NGINX_* env vars
Generating RSA private key, 4096 bit long modulus (2 primes)
.............................................................................................................++++
......................................................................................................................++++
e is 65537 (0x010001)
Signature ok
subject=CN = example.com
Getting Private key
nginx 08:27:36.38 INFO ==> No custom scripts in /docker-entrypoint-initdb.d
nginx 08:27:36.38 INFO ==> Initializing NGINX
realpath: /bitnami/nginx/conf/vhosts: No such file or directory

nginx 08:27:36.48 INFO ==> ** NGINX setup finished! **
nginx 08:27:36.56 INFO ==> ** Starting NGINX **
172.31.35.204 - - [03/Aug/2023:08:27:37 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"
172.31.35.204 - - [03/Aug/2023:08:27:47 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"
172.31.35.204 - - [03/Aug/2023:08:27:57 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"
172.31.35.204 - - [03/Aug/2023:08:28:07 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"
172.31.35.204 - - [03/Aug/2023:08:28:17 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"
172.31.35.204 - - [03/Aug/2023:08:28:27 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"
172.31.35.204 - - [03/Aug/2023:08:28:37 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"
172.31.35.204 - - [03/Aug/2023:08:28:47 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"
127.0.0.1 - - [03/Aug/2023:08:28:56 +0000] "GET / HTTP/1.1" 200 217 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:28:57 +0000] "GET /static/css/main.d4740ec6.css HTTP/1.1" 200 240770 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
172.31.35.204 - - [03/Aug/2023:08:28:57 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"
127.0.0.1 - - [03/Aug/2023:08:28:57 +0000] "GET /static/css/main.d4740ec6.css.map HTTP/1.1" 200 1408364 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:28:57 +0000] "GET /static/js/main.db6b74a5.js HTTP/1.1" 200 1962570 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:28:58 +0000] "GET /static/js/main.db6b74a5.js.map HTTP/1.1" 200 24074398 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:28:58 +0000] "GET /config.json HTTP/1.1" 200 677 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:28:58 +0000] "GET /custom_locale.json HTTP/1.1" 200 2 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:28:58 +0000] "GET /favicon.ico HTTP/1.1" 200 15086 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:28:59 +0000] "POST /apis/kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins HTTP/1.1" 200 103 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:28:59 +0000] "GET /custom_style.css HTTP/1.1" 200 0 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:28:59 +0000] "GET /config.json HTTP/1.1" 200 677 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:28:59 +0000] "GET /clr-ui.min.css HTTP/1.1" 200 161287 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:28:59 +0000] "GET /favicon.ico HTTP/1.1" 200 15086 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:28:59 +0000] "GET /favicon.ico HTTP/1.1" 200 15086 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:28:59 +0000] "GET /favicon-32x32.png HTTP/1.1" 200 2379 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:28:59 +0000] "GET /favicon-32x32.png HTTP/1.1" 200 2379 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:28:59 +0000] "GET /favicon.ico HTTP/1.1" 200 15086 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:00 +0000] "GET /static/media/ClarityCity-SemiBold.508f08b507bb08382c2e.woff2 HTTP/1.1" 200 17252 "https://mydomain.eu-central-1.elb.amazonaws.com/static/css/main.d4740ec6.css" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:00 +0000] "GET /static/media/ClarityCity-Regular.7f3f0d7447ea1c59ab46.woff2 HTTP/1.1" 200 16856 "https://mydomain.eu-central-1.elb.amazonaws.com/static/css/main.d4740ec6.css" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:00 +0000] "GET /clr-ui-dark.min.css HTTP/1.1" 200 141870 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
172.31.35.204 - - [03/Aug/2023:08:29:07 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"
172.31.35.204 - - [03/Aug/2023:08:29:17 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"
172.31.35.204 - - [03/Aug/2023:08:29:27 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"
172.31.35.204 - - [03/Aug/2023:08:29:37 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"
172.31.35.204 - - [03/Aug/2023:08:29:47 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"
127.0.0.1 - - [03/Aug/2023:08:29:53 +0000] "GET / HTTP/1.1" 200 217 "https://mycognito.auth.eu-central-1.amazoncognito.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:53 +0000] "GET /static/css/main.d4740ec6.css HTTP/1.1" 200 240770 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:53 +0000] "GET /static/css/main.d4740ec6.css.map HTTP/1.1" 200 1408364 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:54 +0000] "GET /static/js/main.db6b74a5.js HTTP/1.1" 200 1962576 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:54 +0000] "GET /static/js/main.db6b74a5.js.map HTTP/1.1" 200 24074398 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:54 +0000] "GET /config.json HTTP/1.1" 200 677 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:54 +0000] "GET /custom_locale.json HTTP/1.1" 200 2 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:55 +0000] "GET /favicon.ico HTTP/1.1" 200 15086 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:55 +0000] "POST /apis/kubeappsapis.core.plugins.v1alpha1.PluginsService/GetConfiguredPlugins HTTP/1.1" 200 103 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:56 +0000] "GET /config.json HTTP/1.1" 200 677 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:56 +0000] "GET /favicon.ico HTTP/1.1" 200 15086 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:56 +0000] "GET /clr-ui.min.css HTTP/1.1" 200 161287 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:56 +0000] "GET /custom_style.css HTTP/1.1" 200 0 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:56 +0000] "POST /apis/kubeappsapis.plugins.resources.v1alpha1.ResourcesService/CheckNamespaceExists HTTP/1.1" 200 5 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:56 +0000] "GET /clr-ui-dark.min.css HTTP/1.1" 200 141870 "https://mydomain.eu-central-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:57 +0000] "GET /static/media/ClarityCity-SemiBold.508f08b507bb08382c2e.woff2 HTTP/1.1" 200 17252 "https://mydomain.eu-central-1.elb.amazonaws.com/static/css/main.d4740ec6.css" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
127.0.0.1 - - [03/Aug/2023:08:29:57 +0000] "GET /static/media/ClarityCity-Regular.7f3f0d7447ea1c59ab46.woff2 HTTP/1.1" 200 16856 "https://mydomain.eu-central-1.elb.amazonaws.com/static/css/main.d4740ec6.css" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
172.31.35.204 - - [03/Aug/2023:08:29:57 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"
127.0.0.1 - - [03/Aug/2023:08:29:57 +0000] "GET /clr-ui-dark.min.css.map HTTP/1.1" 200 867148 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" "172.31.34.113, 172.31.35.188"
172.31.35.204 - - [03/Aug/2023:08:30:07 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"
172.31.35.204 - - [03/Aug/2023:08:30:17 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"
172.31.35.204 - - [03/Aug/2023:08:30:27 +0000] "GET / HTTP/1.1" 200 279 "-" "kube-probe/1.24+" "-"

As this POST is getting rather large I will look at your other suggestions and respond back with my findings separately.

Again, thanks for your support.

@TWBrown42
Copy link
Author

TWBrown42 commented Aug 3, 2023

@absoludity - "Actually, that's something else you could try: verify that the kubeapps-apis service account (token?) is able to be used to access the k8s API server (ie. use curl after extracting the token, or even verify with kubectl auth can-i --as system:serviceaccount:...). See k8s docs for more info. It obviously should be able to do so, but perhaps something in your clusters' auth setup means it can't. But I feel I'm clutching at straws there."@A@a

ok - So I am pushing the limits of my understanding so excuse if what I have done is not as you suggested:-

kubectl get serviceaccounts -n ka-auth

Gives me-

NAME SECRETS AGE
default 0 28d
localcharts-kubeapps-internal-apprepository-controller 0 2d1h
localcharts-kubeapps-internal-kubeappsapis 0 2d1h
localcharts-redis 0 2d1h

So, I created a token based on the localcharts-kubeapps-internal-kubeappsapis Service Account...
kubectl create token localcharts-kubeapps-internal-kubeappsapis -n ka-auth

eyJhbGciOiJSUzI1NiIsImtpZCI6ImY0NDhhMDIwM2Q0MjYwMGIzZjg3MGFkMjA3NDMzZDcyZTA2YjgyYzIifQ.eyJhdWQiOlsiaHR0cHM6Ly9rdWJuc3ZjIl0sImV4cCI6MTY5MTA3NjkxNCwiaWF0IjoxNjkxMDczMzE0LCJpc3MiOiJodHRwczovL29pZGMuZWtzLmV1LWNlbnRyYWwtMS5hbWF6b25hd3MuY29tL2lkL0IzODQ4NDU3QUQyNTMxQzkyNDg1RTNBRjA2QUY2ODQwIiwia3ViZXJuZXRlcy5pbyI6eyJuYW1lc3BhY2UiOiJrYS1hdXRoIiwic2VydmljZWFjY291bnQiOnsibmFtZSI6ImxvY2FsY2hhcnRzLWt1YmVhcHBzLWludGVybmFsLWt1YmVhcHBzYXBpcyIsInVpZCI6ImRlZjI0YjUwLTNlZjYtNGJmOS04ODJiLWIxYTc3MWFlMGZjNiJ9fSwibmJmIjoxNjkxMDczMzE0LCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a2EtYXV0aDpsb2NhbGNoYXJ0cy1rdWJlYXBwcy1pbnRlcm5hbC1rdWJlYXBwc2FwaXMifQ.mRlCDjSgeb1hmW_HmEAVjFAAdY43W-neCizS8oV70B7pdJzJCQ0URuIK7vbsUZmdDobs98DEf6Db_kDHtXtWVHn7hMaeD7aHqQaG0X0E2BcVvhYrofMaBcrDNt6K67fbDDhbSjmF-mVI0xDZqk3TipJCwyvtE9MNPoJniCJfxr6LekwdH19bnVI0LvGM60J6TaU-RhAt83p6AWlIMjHA9Hz9-Q0fJQTRgD0WOMME2i1Xsq8x_0cHbrHNcw06opa-F6NGhvZ5fnsJJU6J69FHzw-X1uSk06caBYOvwHRLJVz5BQjiM1FMihx-_WgqYgooQdAu6V6SIeIBeri-7Ata3w

export token = eyJhbGciOiJSUzI1NiIsImtpZCI6ImY0NDhhMDIwM2Q0MjYwMGIzZjg3MGFkMjA3NDMzZDcyZTA2YjgyYzIifQ.eyJhdWQiOlsiaHR0cHM6Ly9rdWJlcm5ldGVzLmRlZmF1bHQuc3ZjIl0sImV4cCI6MTY5MTA3NjkxNCwiaWF0IjoxNjkxMDczMzE0LCJpc3MiOiJodHRwcWwtMS5hbWF6b25hd3MuY29tL2lkL0IzODQ4NDU3QUQyNTMxQzkyNDg1RTNBRjA2QUY2ODQwIiwia3ViZXJuZXRlcy5pbyI6eyJuYW1lc3BhY2UiOiJrYS1hdXRoIiwic2VydmljZWFjY291bnQiOnsibmFtZSI6ImxvY2FsY2hhcnRzLWt1YmVhcHBzLWludGVybmFsLWt1YmVhcHBzYXBpcyIsInVpZCI6ImRlZjI0YjUwLTNlZjYtNGJmOS04ODJiLWIxYTc3MWFlMGZjNiJ9fSwibmJmIjoxNjkxMDczMzE0LCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a2EtYXV0aDpsb2NhbGNoYXJ0cy1rdWJlYXBwcy1pbnRlcm5hbC1rdWJlYXBwc2FwaXMifQ.mRlCDjSgeb1hmW_HmEAVjFAAdY43W-neCizS8oV70B7pdJzJCQ0URuIK7vbsUZmdDobs98DEf6Db_kDHtXtWVHn7hMaeD7aHqQaG0X0E2BcVvhYrofMaBcrDNt6K67fbDDhbSjmF-mVI0xDZqk3TipJCwyvtE9MNPoJniCJfxr6LekwdH19bnVI0LvGM60J6TaU-RhAt83p6AWlIMjHA9Hz9-Q0fJQTRgD0WOMME2i1Xsq8x_0cHbrHNcw06opa-F6NGhvZ5fnsJJU6J69FHzw-X1uSk06caBYOvwHRLJVz5BQjiM1FMihx-_WgqYgooQdAu6V6SIeIBeri-7Ata3w

curl -k -H "Authorization: Bearer $token" https://myapiserver.gr7.eu-central-1.eks.amazonaws.com/api/v1/namespaces

returns me:-

{
"kind": "NamespaceList",
"apiVersion": "v1",
"metadata": {
"resourceVersion": "93086226"
},
"items": [
{
"metadata": {
"name": "cert-manager",
"uid": "e094ffc0-c227-48c1-a046-1cb5103f42bd",
"resourceVers...........

So if I have this correct the internal-kubeappsapis pod has a token that is successfully authenticated against my K8s cluster.

TBH - I am was not sure that this was the correct service account given that the logs for the internal-kubeappsapis didn't seem to show any activity related to my requests. So I took a punt at perhaps the default service account might be being used...
when getting a token from the default service account I and performing the same curl I get the following not authenticated response:-
{
"kind": "Status",
"apiVersion": "v1",
"metadata": {},
"status": "Failure",
"message": "namespaces is forbidden: User "system:serviceaccount:ka-auth:default" cannot list resource "namespaces" in API group "" at the cluster scope",
"reason": "Forbidden",
"details": {
"kind": "namespaces"
},
"code": 403
}

My relevant pods:-
kubeapps-d4bd84fb-fv2qc 2/2 Running
kubeapps-internal-apprepository-controller-7f6hzp9r 1/1 Running
kubeapps-internal-dashboard-5f5f7464f4-7pfwk 1/1 Running
kubeapps-internal-kubeappsapis-5c785bffcf-gzfdf 1/1 Running
postgresql-0 1/1 Running
redis-master-0 1/1 Running

Given that the calls are coming from this end pod (kubeapps-d4bd84fb-fv2qc) and I confirmed that this is using the default service account is it possible that the code is using the service account token NOT the bearer token it is being passed from the client?

PS - I have deliberately modified the tokens in this post so they won't be readable.

@absoludity
Copy link
Contributor

absoludity commented Aug 4, 2023

Thanks for all the detail. Just some notes:

  • In your Kubeapps chart values, you don't appear to have authProxy.enabled set to true? Though I don't understand how the UI would be redirecting you without this (unless you were running our development image which did have an issue where it would display the OIDC login simply if the login url was defined, but I don't think that issue was ever released, I fixed it yesterday in Ensure token auth can be configured while oauthLoginURI is defined. #6557 ). authProxy.enabled should be set to true. I'm guessing you are but just didn't list it above? Either way, can you please paste the output for listing the pods in your kubeapps namespace?
  • You're using the oidc provider in oauth2config settings... I don't know that it's relevant (doesn't seem to be, since you're seeing an audience), but Audience Claim should be treated as optional oauth2-proxy/oauth2-proxy#2037
  • Yes, the GetConfiguredPlugins call does not need to contact the k8s API server, so it's expected that it succeeds either way. It is the CheckNamespaceExists call that we're interested in (it's used to verify the authentication).
  • Yes, gRPC responses do respond as http 200 even if the functionality they provide itself fails, since the gRPC request itself was successful, hence the separate grpc-status etc that you've noted. (though I don't yet know why our kubeapps-apis does reply with a 403 http status for the unauth'd one then, need to check - could be because there's no authentication so the gRPC request itself fails - not sure).
  • The calls to the k8s API will definitely be coming from the kubeapps-apis service, and the timings do match:
    • you highlighted the following in your authproxy logs:
*** Highlighing here that the HTTP Status for CheckNamespaceExists is SUCCESS (This is important as looking at the network tracing from Chrome the GPRC calll fails with an authentication error)
172.31.35.188:34332 - 39b308f187d65097a250dac3aa76c572 - [[email protected]](mailto:[email protected]) [2023/08/03 08:29:56] mydomain.eu-central-1.elb.amazonaws.com POST / "/apis/kubeappsapis.plugins.resources.v1alpha1.ResourcesService/CheckNamespaceExists" HTTP/1.1 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" 200 0 0.016

which matches the following line from the kubeapps-apis:

I0803 08:29:56.300929 1 namespaces.go:29] "+resources CheckNamespaceExists" cluster="default" namespace="default"

(though I didn't try to match the others).

  • Yes, the request for css.map should not require auth, it just doesn't match our regex (since we don't control that path - it's from a UI library we import)

As it is, unless you somehow aren't setting the authProxy.enabled to true, I'm still at a loss as to how you're seeing the valid token and can confirm it via curl, and yet it's apparently not working (or not being used) for requests from the kubeapps-apis service. Let me know about the enabled, and otherwise we might have to schedule some time to try to reproduce it.

@TWBrown42
Copy link
Author

@absoludity , sorry missed the copy and paste of the authproxy.enabled flag, it was ENABLED I just missed it.

I understand the rest of what you said and again - missed the correlated internal-kubeappsapis log entry for the CheckNamespaceExists - must have been going snow blind at that point ;-)

"Either way, can you please paste the output for listing the pods in your kubeapps namespace?", sure find below: -
apprepo-ka-auth-sync-bitnami-28185590-glg6p 0/1 Completed 0 25m
apprepo-ka-auth-sync-bitnami-28185600-vww6v 0/1 Completed 0 15m
apprepo-ka-auth-sync-bitnami-28185610-gbzqt 0/1 Completed 0 5m
apprepo-kubeapps-sync-bitnami-28185610-ws97f 0/1 CrashLoopBackOff 5 (109s ago) 5m
apprepo-kubeapps-sync-internal-28185610-mwhsg 0/1 CreateContainerConfigError 0 5m
apprepo-kubeapps-sync-internal-7g2tj-gjdd8 0/1 CreateContainerConfigError 0 18d
apprepo-kubeapps-sync-internal-9vgw7-zqccj 0/1 CreateContainerConfigError 0 2d20h
apprepo-kubeapps-sync-internal-pgrjc-2msdw 0/1 CreateContainerConfigError 0 18d
apprepo-kubeapps-sync-internal-xjz5b-2zrj4 0/1 CreateContainerConfigError 0 18d
localcharts-kubeapps-d4bd84fb-fv2qc 2/2 Running 0 23h
localcharts-kubeapps-internal-apprepository-controller-7f6hzp9r 1/1 Running 0 2d20h
localcharts-kubeapps-internal-dashboard-5f5f7464f4-7pfwk 1/1 Running 0 2d20h
localcharts-kubeapps-internal-kubeappsapis-5c785bffcf-gzfdf 1/1 Running 0 2d20h
localcharts-postgresql-0 1/1 Running 0 42h
localcharts-redis-master-0 1/1 Running 0 2d20h

You'll no doubt pick up that chartmuseum is there and that there are failing sync pods... Chart museum is going to be an option for internal hosting of our companies charts. The syncs are there because on previous runs of the Kubeapps I had configured the initial repos to include this as well as the bitnami. This is actually no longer part of the chart (I removed it while I was trying to get Auth working), unfortunately I think because this data is stored in postgresql persistent storage it is still being picked up even after a chart uninstall / install cycle. I've left here for transparency and am hoping that you agree that it is not related to the current auth issue.

@ppbaena ppbaena added this to Kubeapps Aug 4, 2023
@github-project-automation github-project-automation bot moved this to 🗂 Backlog in Kubeapps Aug 4, 2023
@absoludity
Copy link
Contributor

@antgamdia Not sure if you've any other thoughts or things to try here? I'm stumped based on the info we have (see above).

@TWBrown42
Copy link
Author

I'm really keen to make this a success, if there is anything else I could provide in terms of logs or act as a guinea pig to capture more details in some way then happy to do so. Also, as you might be able to tell I am no expert so it's possible I am doing something stupid...

@antgamdia
Copy link
Contributor

antgamdia commented Aug 7, 2023

Happy to jump in and try to help (not sure if I will be able to, but I'll try at least :P)
I'm setting up an AWS Cognito pool and will try to replicate the issue. Will keep you all posted!

Some random thoughts off the top of my head:

  • Have you tried setting frontend.proxypassAccessTokenAsBearer: true ?
    • Additionally, have you tried using: authProxy.extraFlags: --set-xauthrequest=true
  • Have you tried using oauth2proxy v7.21 instead of v7.3 or v7.4 ?

@antgamdia antgamdia moved this from 🗂 Backlog to 🏗 In Progress in Kubeapps Aug 7, 2023
@TWBrown42
Copy link
Author

Thanks, appreciate your thoughts. If you have any questions about my set up of the Cognito pool and the configuration of the EKS cluster then please let me know.

In answer to your questions....No, No and No but I will try all three and let you know the results.

@antgamdia
Copy link
Contributor

Hi, I have just tested the setup with Cognito + local cluster with Kind... and it works :S - I haven't been able to reproduce the issue:

cognito.mp4

Let the describe the steps I followed:

Creation of the cluster

  1. Create the cluster
kind create cluster --config .\devel\kind-oidc.yaml  
  1. Add the RBAC
 kubectl apply -f .\6549-rbac.yaml
Kind configuration (kind-oidc.yaml)
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
  - role: control-plane
    kubeadmConfigPatches:
      - |
        kind: InitConfiguration
        nodeRegistration:
          kubeletExtraArgs:
            node-labels: "ingress-ready=true"
      - |
          kind: ClusterConfiguration
          apiServer:
            extraArgs:
              oidc-issuer-url: https://cognito-idp.us-east-1.amazonaws.com/us-east-1_jQ766r6X0
              oidc-client-id: 7krqldp3cso0621gt8dk6dlmnj
              oidc-username-claim: email
    extraPortMappings:
      - containerPort: 80
        hostPort: 80
        protocol: TCP
      - containerPort: 443
        hostPort: 443
        protocol: TCP
RBAC configuration (6549-rbac.yaml)
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: kubeapps-operator
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - apiGroup: rbac.authorization.k8s.io
    kind: User
    name: [email protected]

Installing Kubeapps

  1. Some prerequisites
helm repo add bitnami https://charts.bitnami.com/bitnami
kubectl create ns kubeapps
kubectl create ns ka-auth
  1. Installing Kubeapps
helm upgrade --install kubeapps bitnami/kubeapps -n ka-auth --values .\6549.yaml

I haven't redacted the Cognito credentials, it is a dummy account created just for this scenario and I will delete it soon.
If you want to use it to debug, use the credentials below:

Kubeapps configuration (6549.yaml)
apprepository:
  initialRepos:
  - name: bitnami-application-catalog
    namespace: kubeapps
    url: https://charts.bitnami.com/bitnami

authProxy:
  enabled: true
  clientID: 7krqldp3cso0621gt8dk6dlmnj
  clientSecret: nbe7p070pn1leq261e09frb4rbk1el89h9v1ffk8316hk7n6uqm
  cookieSecret: bm90LWdvb2Qtc2VjcmV0Cg==
  scope: openid email
  provider: oidc
  extraFlags:
  - --redirect-url=http://localhost:8080/oauth2/callback
  - --oidc-issuer-url=https://cognito-idp.us-east-1.amazonaws.com/us-east-1_jQ766r6X0
  - --proxy-prefix=/oauth2
  - --scope=openid email
 # - --ssl-insecure-skip-verify
 # - --set-authorization-header=true

dashboard:
  customLocale:
    login-desc-oidc: Access to Kubeapps using AWS Cognito.
    login-oidc: Login via AWS Cognito.
Cognito user
email: [email protected]
password: kubeapps

Checking the oidc workflow separately

I have also tested the oidc workflow in Postman. Using the id_token seems to work.

image


Let me know if using this configuration makes any difference. Do you see any divergence in your and mine config files?

Regarding the random thoughts, I threw yesterday... they don't make much sense for your problem, but I faced some OIDC issues with managed AKS clusters (using Active Directory) in the past, so I just wanted to share it just in case.

@TWBrown42
Copy link
Author

TWBrown42 commented Aug 8, 2023

Cool...One by one then:-
For some reason I could not view the MP4 attached, but I'll trust that this is all working for you...

Looking at the cluster, I am using AWS EKS so for your Kind based configuration:-
kind: ClusterConfiguration
apiServer:
extraArgs:
oidc-issuer-url: https://cognito-idp.us-east-1.amazonaws.com/us-east-1_jQ766r6X0
oidc-client-id: 7krqldp3cso0621gt8dk6dlmnj
oidc-username-claim: email

I have:-
EKSCluster

RBAC:-
Your RBAC looks a little different in that you have the Subject listed as a User, I have the following with subject as a service account:-
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
creationTimestamp: "2023-04-13T15:24:49Z"
name: kubeapps-operator
resourceVersion: "41458638"
uid: 9372eee7-83b1-43d5-8722-b1c7e0114e0f
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:

  • kind: ServiceAccount
    name: kubeapps-operator
    namespace: default

May be this my misunderstanding but the ServiceAccount is defined within the default namespace, that is NOT the namespace I Helmed KubeApps into.

In terms of the kubeapps Values file, I can see a couple of differences:-
You have a Scope attribute that I do not have, but I do override that as part of the extraFlags:-
- --session-store-type=redis
- --set-authorization-header=true
- --oidc-issuer-url=https://cognito-idp.eu-central-1.amazonaws.com/eu-central-...
- --proxy-prefix=/oauth2
- --scope=openid email
- --ssl-insecure-skip-verify
- --session-store-type=redis
- --redis-connection-url=redis://localcharts-redis-master:6379/0

Also, you have a redirect_url in your extra_flags that I do not.

In your setup you have some dashboard values. I have none of those, mine are restricted to basic resource constraint config:-
dashboard:
replicaCount: 1
resources:
limits:
cpu: 250m
memory: 128Mi
requests:
cpu: 25m
memory: 32Mi

I will make a change to my cluster to point it at your Cognito shortly, but before I do, in the interest of making one change at a time, do you see anything that stands out (I am concerned about the kubeapps-operator service account listed in default namespace)?

@antgamdia
Copy link
Contributor

antgamdia commented Aug 8, 2023

Thanks for the quick input.

For some reason I could not view the MP4 attached, but I'll trust that this is all working for you...

Find below the mp4 transcoded as an animated gif instead:

Video as a GIF

cognito

I'm not an expert (at all) in AWS Cognito: I just created a user pool with a single hardcoded user + a client. Find below my config, but I guess it is not the issue.

Cognito config

image

So, apart from some minor differences (for instance, the redirect_url I need it because I'm using a plain HTTP domain, so I need to "force" it to redirect where I want to; it shouldn't be required in production environments), I don't see anything differing so much. I'd assume your config is OK.

However, the big difference seems to be in the RBAC we have applied. Just for the record, they are:

Mine
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: kubeapps-operator
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - apiGroup: rbac.authorization.k8s.io
    kind: User
    name: [email protected]
Yours
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: kubeapps-operator
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: kubeapps-operator
    namespace: default

First and foremost: how are you linking the Cognito users with their proper RBAC? I mean, given that you are requesting the claim email (- --scope=openid email), it is precisely what you will use to identify your users in k8s.

A user in AWS Cognito

image

If you want to avoid that burden, you can switch to group claims (see below). But this would require you to create a group (my-awesome-user-group in this example) in AWS Cognito as well.

Example with group
    # ...
  - apiGroup: rbac.authorization.k8s.io
    kind: Group
    name: my-awesome-user-group

image

May be this my misunderstanding but the ServiceAccount is defined within the default namespace, that is NOT the namespace I Helmed KubeApps into.

I don't fully get your point here. I mean, for accessing Kubeapps with a token (like in our getting started docs), yep, you will want a service account as the RBAC subject (to grant perms to this SA)... but if you want to use your Cognito users, you need to let k8s know about the emails/groups that have access to your cluster, no?
I'd say here is the crux of the problem. Let's see if we can solve it soon!

@TWBrown42
Copy link
Author

Agreed - this feels like it is where the problem is.

My final solution will be to map groups within cognito to specific roles via the role bindings objects in k8s. Here is an exert from the id-token which shows the group name for my user1 user:-
{
"at_hash": "-BvsWmPF4VRE6yoeMwOQ9Q",
"sub": "328246af-8932-4700-87f6-9a7415a8d4d7",
"cognito:groups": [ "KubeappsReader"
],
"email_verified": true,
"iss": "https://mycognitoname.myregion.amazonaws.com/eu-central-myuniqueid",
"cognito:username": "328246af-8932-4700-87f6-9a7415a8d4d7",
"email":[email protected]....

You can see the cognito:groups array with in this case my user being a member of the KubeappsReader cognito group.

At some point I was struggling to understand if I needed some group prefix (there is reference n the kubeapps documentation about requiring a prefix to tell K8s this is from the OIDC Issuer.) anyway in order to simplify I decided to try and get this working simply based on the username in the first instance then go back and tackle the group membership option.
What I currently have is mapping user1 to cluster admin via a cluster role binding: -
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
creationTimestamp: "2023-08-01T10:43:04Z"
name: example-admin-user
resourceVersion: "91991466"
uid: 076a42d8-a706-4515-aedf-2f287f183f79
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:

Notice that this is not the kubeapps-operator cluster role binding. It is one that I created following the pattern in your documentation https://kubeapps.dev/docs/latest/howto/access-control/#applications.

I will take a look this afternoon and try and get my RBAC setup to align with yours. I am a little perplexed however how curl works with the id token and kubeapps does not I would have expected them to behave the same. Whatever, I will come back to you.

Thanks for the continued support.

@ppbaena ppbaena moved this from 🏗 In Progress to 🔎 In Review in Kubeapps Aug 9, 2023
@TWBrown42
Copy link
Author

Hi @antgamdia , so I have replicated your configuration but this seems to have made no difference to the outcome:-

  • I removed any manually created RoleBindings that I had in place (I created some to provide for Readonly and Installer based roles)
  • I have made sure that I have your kubeapps-operator cluster role binding with the subject of a user: [email protected] (matching the user within the JWT id_token): -

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
creationTimestamp: "2023-04-13T15:24:49Z"
name: kubeapps-operator
resourceVersion: "95986681"
uid: 9372eee7-83b1-43d5-8722-b1c7e0114e0f
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:

I do have service accounts that have been created as part of the kubeapps helm chart:-
kubectl get serviceaccounts -n ka-auth
NAME SECRETS AGE
default 0 34d
localcharts-kubeapps-internal-apprepository-controller 0 18m
localcharts-kubeapps-internal-kubeappsapis 0 18m
localcharts-redis 0 18m

I have the following role bindings created by the helm chart and a default:-
kubectl get rolebindings -n ka-auth
NAME ROLE AGE
kubeapps:ka-auth:global-repos-read ClusterRole/kubeapps:ka-auth:apprepositories-read 19m
localcharts-kubeapps-internal-apprepository-controller Role/localcharts-kubeapps-internal-apprepository-controller 19m

I have the following cluster role bindings created by the helm chart:-
kubeapps:controller:ka-auth:apprepositories-read ClusterRole/kubeapps:ka-auth:apprepositories-read 19m
kubeapps:ka-auth:kubeappsapis-ns-discovery ClusterRole/kubeapps:ka-auth:kubeappsapis-ns-discovery 19m

I have re-tested and the failure still occurs within CheckNamespaceExists, I can still take the JWT token and issue it with curl to get Namespaces. Is there anything you can see in the RBAC I have posted above that provides insight?

I have not tested against your cognito as I would need to give you my public url (which offline I would be happy to do given it's demo status).

@TWBrown42
Copy link
Author

TWBrown42 commented Aug 14, 2023

Another update,
@antgamdia I ran through your example in Kind and used your Cognito (thanks for keeping it alive), ad as you stated it works. - SUCCESS

I then ran the same but pointing at my cognito which also works. - SUCCESS

I thought it would be useful to show the differences in the client traces between the SUCCESS Local Kind based deployment an the EKS Failing deployment:-

One thing that stands out is in the Failure scenario I have a duplicate Authorization Response Headers:-
image

The request cookies are significantly different in terms of size - you have 2 totalling around 5k in size for oauth2_proxy_0.._1. My understanding is that this is due to the Mine using the Redis as session store where yours is all in the cookie.

So some differences I know we have:-

  • EKS Cluster vs local Kind based cluster
  • Nginx Ingress vs port forward direct to service
  • Session state Redis vs local cookie based.

Nginx Ingress I did have the buffer size increased as your document suggests:-
ingress:
ingressClassName: "nginx"
hostname: mydomain.eu-central-1.elb.amazonaws.com
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
nginx.ingress.kubernetes.io/proxy-buffer-size: "16k"
nginx.ingress.kubernetes.io/proxy-buffers-number: "4"

In my production set up I am using redis, you have the full 0auth2-proxy information within the cookie.

If you have any comments / observations then please let me know, my Next step will be to introduce Redis in to the Kind cluster to see if this fails.

@TWBrown42
Copy link
Author

@absoludity @antgamdia I have succeeded in the login.

As per my previous post here I went through a couple of replication steps:-

  1. Reproducing the environment on my local Kind cluster - this worked as per @antgamdia instructions above
  2. I took my charts and again deployed to my Kind cluster with a minimal configuration as per (1). This involved going back to Cookie based session state (removing Redis) and not having Ingress controller - this worked!
  3. Introduced Redis back in to my configuration - this worked
  4. Introduced Postgresql persistent storage - this worked.

At this point on Kind I have almost my complete system replicated with the exception of the Ingress Controller.

So I turned my attention back to my EKS Cluster:-

  1. Redeployed without Postgresql persistent storage - This worked!
  2. Redeployed putting Postgresql persistent storage back in place - This also worked - in effect getting me back to the original installation state I was after but now it is working.

I can only assume that something in the Postgresql db was upsetting the authentication process in some way and by in effect removing this persistent data and starting from scratch it has fixed whatever was there before. It would be good to understand if there is anything held in PG that pertains to Authentication to give me some comfort (hate it when things just start working, inexplicably!)

Anyway appreciate your help.

@absoludity
Copy link
Contributor

Excellent! Really glad it's working, but yeah, really keen to know what was breaking it earlier. No, the postgresql storage is acting as a cache only (we even destroy it during upgrade to have it recreated sometimes), of chart metadata.

Feel free to close the issue for now.

@TWBrown42
Copy link
Author

It remains a mystery how this corrected 'itself'. Anyway, I will close for now.

@github-project-automation github-project-automation bot moved this from 🔎 In Review to ✅ Done in Kubeapps Aug 16, 2023
@antgamdia
Copy link
Contributor

I have been pretty busy these days and haven't had the chance to get back to this issue. Thanks for the detailed report on each step you performed!!

I hate it when things just start working, inexplicably

100% agree... it's such a bittersweet feeling :S

Anyway, happy to hear the issue is gone for now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question An issue that reports a question about the project
Projects
Archived in project
Development

No branches or pull requests

3 participants