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

🌱 proxy: optionally enable OIDC auth #2319

Merged
merged 1 commit into from
Nov 10, 2022

Conversation

hardys
Copy link

@hardys hardys commented Nov 7, 2022

Summary

This adds OIDC to the enabled optional auth methods

Related issue(s)

Follow-up to #2178

This adds OIDC to the enabled optional auth methods
@openshift-ci openshift-ci bot requested review from csams and sttts November 7, 2022 18:47
@hardys
Copy link
Author

hardys commented Nov 7, 2022

Some test notes - I tested this locally using dex standalone

Since the kube API requires SSL, I generated certs using the gencert.sh script, modified so the SAN contained localhost e.g:

[alt_names]
DNS.1 = localhost
IP.1 = 127.0.0.1

Then I ran dex with a config like:

issuer: https://127.0.0.1:5554/dex

storage:
  type: sqlite3
  config:
    file: examples/dex.db

web:
  https: 127.0.0.1:5554
  tlsCert: /home/shardy/go/src/github.com/dexidp/dex/examples/k8s/ssl/cert.pem
  tlsKey: /home/shardy/go/src/github.com/dexidp/dex/examples/k8s/ssl/key.pem

staticClients:
- id: kcp
  name: kcp
  redirectURIs:
  - https://localhost:8000
  - https://localhost:18000
  secret: kcp

connectors:
- type: mockCallback
  id: mock
  name: Example

kubelogin can then be used to test the login e.g:

kubectl oidc-login setup --oidc-issuer-url=https://127.0.0.1:5554/dex --oidc-client-id=kcp --oidc-client-secret=kcp --certificate-authority /home/shardy/go/src/github.com/dexidp/dex/examples/k8s/ssl/ca.pem --local-server-cert=/home/shardy/go/src/github.com/dexidp/dex/examples/k8s/ssl/cert.pem --local-server-key=/home/shardy/go/src/github.com/dexidp/dex/examples/k8s/ssl/key.pem

Then create a clusterrolebinding as directed in the output.

Then we can configure the proxy when running sharded-test-server e.g:

go run ./cmd/sharded-test-server --proxy-token-auth-file=$PWD/test/e2e/framework/auth-tokens.csv --proxy-service-account-key-file=.kcp/service-account.crt --proxy-oidc-issuer-url=https://127.0.0.1:5554/dex --proxy-oidc-client-id=kcp --proxy-oidc-ca-file=/home/shardy/go/src/github.com/dexidp/dex/examples/k8s/ssl/ca.pem 

Then we can access KCP using OIDC auth with a kubeconfig containing a user like:

...
users:
- name: oidc
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1beta1
      args:
      - oidc-login
      - get-token
      - --oidc-issuer-url=https://127.0.0.1:5554/dex
      - --oidc-client-id=kcp
      - --oidc-client-secret=kcp
      - --certificate-authority=/home/shardy/go/src/github.com/dexidp/dex/examples/k8s/ssl/ca.pem
      - --local-server-cert=/home/shardy/go/src/github.com/dexidp/dex/examples/k8s/ssl/cert.pem
      - --local-server-key=/home/shardy/go/src/github.com/dexidp/dex/examples/k8s/ssl/key.pem
      command: kubectl
      env: null
      interactiveMode: IfAvailable
      provideClusterInfo: false

This is enough to prove the authn is working - but note when using the mock connector there is a limitation in that we can't configure groups for users - so if we want to test that, we'll need to run an IdP and use one of the "real" connectors instead.

@hardys
Copy link
Author

hardys commented Nov 7, 2022

/cc @csams

@hardys
Copy link
Author

hardys commented Nov 7, 2022

/test test

Appears to be a flake ref kcp-dev/contrib-tmc#93

@hardys
Copy link
Author

hardys commented Nov 7, 2022

I did notice one weird thing:

kubectl workspace
Current workspace is "root:users:zh:bg:https---127-0-0-1-5554-dex--g0w---4--0y---4--0w-g-tb2-r".

I don't think that's caused by this PR, but will investigate if it's a real issue with the username, or something caused by my test setup

@hardys
Copy link
Author

hardys commented Nov 8, 2022

I did notice one weird thing:

kubectl workspace
Current workspace is "root:users:zh:bg:https---127-0-0-1-5554-dex--g0w---4--0y---4--0w-g-tb2-r".

I don't think that's caused by this PR, but will investigate if it's a real issue with the username, or something caused by my test setup

Ok so the token looks like e.g

  "iss": "https://127.0.0.1:5554/dex",
  "sub": "Cg0wLTM4NS0yODA4OS0wEgRtb2Nr",
  "aud": "kcp",

Then the User for the clusterolebinding is a combination of the iss and sub fields:

kubectl create clusterrolebinding oidc-cluster-admin --clusterrole=cluster-admin --user='https://127.0.0.1:5554/dex#Cg0wLTM4NS0yODA4OS0wEgRtb2Nr'

So the username ends up as https://127.0.0.1:5554/dex#Cg0wLTM4NS0yODA4OS0wEgRtb2Nr in the user.DefaultInfo

KCP then replaces disallowed characters with - so this output is expected and unrelated to this PR (although I wonder how this is going to work in practice with real SSO/OIDC, @csams any thoughts on that?)

@hardys
Copy link
Author

hardys commented Nov 8, 2022

After discussing with @csams I now understand that the issue above is because the dex dev-setup isn't setting name/preferred_username in the claim - I've not yet figured out how to resolve that for test/dev but it sounds like in practice this should work fine.

@sttts
Copy link
Member

sttts commented Nov 10, 2022

/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 10, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 10, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sttts

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 10, 2022
@openshift-merge-robot openshift-merge-robot merged commit e8669e7 into kcp-dev:main Nov 10, 2022
@kcp-ci-bot kcp-ci-bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants