Git Product home page Git Product logo

dexter's Introduction

dexter

dexter is a OIDC (OpenId Connect) helper to create a hassle-free Kubernetes login experience powered by Google or Azure as Identity Provider. All you need is a properly configured Google or Azure client ID & secret.

Supported identity providers

Identity Provider State
Google complete
Microsoft Azure complete

Authentication Flow

dexter will open a new browser tag/window and redirect you to your configured Idp. The only interaction you have is the login at your provider and your k8s config is updated automatically.

dexter flow

See dexter in action

dexter in action

OIDCProvider Configuration

Each OpenID Connect provider requires some configuration. This basic description may not be all you have to do but it worked at the time of writing.

Google

Microsoft Azure

Auto pilot configuration

dexter also support auto pilot mode. If your existing kubectl context uses one of the supported Identity Providers, dexter will try to use extract the OIDC data from kubeconfig.

Installation

You can download a prebuilt version from the Github release section or build it yourself. The easiest way to get everything set up correctly (e.g. ldflags) is to use goreleaser.

# cd DEXTER_SOURCE
# goreleaser release --snapshot --rm-dist
• releasing...
• loading config file       file=.goreleaser.yml
• loading environment variables
• getting and validating git state
   • building...               commit=377677a03da17461acf7775519518fb3336e6753 latest tag=v0.4.1
   • pipe skipped              error=disabled during snapshot mode
• parsing tag
• running before hooks
   • running                   hook=go mod tidy
• setting defaults
• snapshotting
   • building snapshot...      version=0.4.2-next
• checking distribution directory
   • --rm-dist is set, cleaning it up
• loading go mod information
• build prerequisites
• writing effective config file
   • writing                   config=dist/config.yaml
• building binaries
   • building                  binary=dist/dexter_darwin_arm64/dexter
   • building                  binary=dist/dexter_darwin_amd64/dexter
   • building                  binary=dist/dexter_linux_amd64/dexter
• universal binaries
   • creating from 2 binaries  binary=dist/dexter_darwin_all/dexter
• archives
   • creating                  archive=dist/dexter_0.4.2-next_Linux_x86_64.tar.gz
   • creating                  archive=dist/dexter_0.4.2-next_Darwin_all.tar.gz
• calculating checksums
• storing release metadata
   • writing                   file=dist/artifacts.json
   • writing                   file=dist/metadata.json
• release succeeded after 8.18s

Check ./dist for the build that matches your platform.

Embed credentials and template

You can also customize the build and embed client credentails and a default kubectl config into the binary. Again, using goreleaser for the build is the easiest approach. Client credentials are embedded automatically when you set two environment variables.

CLIENT_ID=abc123.apps.googleusercontent.com
CLIENT_SECRET=mySecret

You can streamline your user experience even more by also specifying a default provider. dexter auth will then run the specified provider. Valid choices are google and azure.

DEFAULT_PROVIDER=google

If you want to to change the default config template that is deployed when there is no config on the system you have to replace the contents of ./tmpl/kube-config.yaml with your valid kubectl configuration. This can come in handy if you want to pre-populate clusters and certificates.

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: XXX
    server: https://stage.cluster:6443
  name: stage
- cluster:
    certificate-authority-data: YYY
    server: https://production.cluster:6443
  name: production
contexts:
- context:
    cluster: stage
    user: {{ .User }}
  name: stage
- context:
    cluster: production
    user: {{ .User }}
  name: production
current-context: stage
kind: Config
preferences: {}

Please make sure that you have {{ .User }} in all contexts that need you want to enrich with the OIDC account you are about to configure.

Run dexter

Run dexter without a command to access the help screen/intro.

❯ ./dexter
    .___               __
  __| _/____ ___  ____/  |_  ___________
 / __ |/ __ \\  \/  /\   __\/ __ \_  __ \
/ /_/ \  ___/ >    <  |  | \  ___/|  | \/
\____ |\___  >__/\_ \ |__|  \___  >__|
     \/    \/      \/           \/

dexter is a authentication helper for Kubernetes that does the heavy
lifting for SSO (Single Sign On) for Kubernetes.

Usage:
  dexter [command]

Available Commands:
  auth        Authenticate with OIDC provider
  help        Help about any command
  version     Print the version number of dexter

Flags:
  -h, --help          help for dexter
      --timeout int   Timeout for HTTP requests to OIDC providers (default 2)
  -v, --verbose       verbose output

Use "dexter [command] --help" for more information about a command.

Running dexter auth [Idp] will start the authentication process.

 ❯ ./dexter auth --help
Use a provider sub-command to authenticate against your identity provider of choice.
For details go to: https://gini.net/en/blog/frictionless-kubernetes-openid-connect-integration/

Usage:
  dexter auth [flags]
  dexter auth [command]

Available Commands:
  azure       Authenticate with the Microsoft Azure Identity Provider
  google      Authenticate with the Google Identity Provider

Flags:
  -c, --callback string        Callback URL. The listen address is dreived from that. (default "http://127.0.0.1:64464/callback")
  -i, --client-id string       Google clientID (default "REDACTED")
  -s, --client-secret string   Google clientSecret (default "REDACTED")
  -d, --dry-run                Toggle config overwrite
  -h, --help                   help for auth
  -k, --kube-config string     Overwrite the default location of kube config (default "/Users/dkerwin/.kube/config")
  -t, --kube-template          Use the embedded template when there is no kubectl configuration (default true)
  -u, --kube-username string   Username identifier in the kube config
  -f, --write-email string     Write user email to the specified file for use with other tooling

Global Flags:
  -v, --verbose   verbose output

Use "dexter auth [command] --help" for more information about a command.

Contribution Guidelines

It's awesome that you consider contributing to dexter and it's really simple. Here's how it's done:

  • fork repository on Github
  • create a topic/feature branch
  • push your changes
  • update documentation if necessary
  • open a pull request

Authors & Contributors

Initial code was written by Daniel Kerwin & David González Ruiz

Contributors (in alphabetical order):

Thank you so much!

Acknowledgements

dexter was inspired by this blog post series by Joel Speed, Micah Hausler's k8s-oidc-helper & CoreOS dex.

License

MIT License. See License for full text.

dexter's People

Contributors

andrewsav avatar andrewsav-bt avatar bomme avatar cblims avatar dependabot[bot] avatar dkerwin avatar felixfriedrich avatar lujeni avatar pussinboots avatar tillepille avatar trundle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dexter's Issues

ID and Secret-id is still required even when the binary has been built with the said parameters

Hey Team,

I tried out Dexter on an Ubuntu 18 host and looks to be id & secret id are still required to get a successful login.

Built the binary with following parameters:
CLIENT_ID=529839178945-toh9cj642someid7hvu7id9n5.apps.googleusercontent.com CLIENT_SECRET=VzK7vrksome_secret3ts6AfZa6Diz OS=linux make

When a login attempt being made via dexter as follows getting a http 400.
$dexter auth
However when all the parameters are specified as follows can log in just fine.
dexter auth -i xxxxxx -s ffdfdff

Appreciate your feedback guys, could be something that I might have missed.

Add Microsoft Windows support

We need to find a reliable way to open the URL similar to MacOS & Linux. chrome.exe works but this may not be the best approach.

Missing tmpl/kube-config.yaml

Building from freshly cloned repository failed, because of missing tmpl/kube-config.yaml.

How to reproduce:

git clone https://github.com/gini/dexter.git
cd dexter
docker run --rm --privileged \
  -v $PWD:/go/src/github.com/user/repo \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -w /go/src/github.com/user/repo \
  --env-file ../env-file \
  goreleaser/goreleaser release --snapshot --rm-dist

In the .gitignore, there are lines:

# This is required to allow goreleaser to release with different templates.
# The actual config has to be copied to the location in a prep step.
tmpl/kube-config.yaml

Maybe, there should be a step, during the build, where the default kube-config.yaml is provided, if I don't provide custom one.

Unable to start dexter

Hi,
I have downloaded the pre built darwin package and tried to run "./dexter_darwin_amd64 --client-id=XXX --client-secret=XXX auth" command.
I am getting the below error.
ERRO[2018-05-15T15:17:11+05:30] oauth2 configuration failed: failed to create new dexterOIDC provider: Get https://accounts.google.com/.well-known/openid-configuration: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

My internet connectivity is fine. Please help me with this.

How to use generated credentials

Here is my steps for creating auth.

Go to Google Console:

Save Google ID and SECRET.

Change APIServer:

kops edit cluster --name=${NAME} --state=s3://${NAME}
...
spec:
  kubeAPIServer:
    authorizationMode: RBAC
    authorizationRbacSuperUser: admin
    oidcCAFile: /srv/kubernetes/ca.crt
    oidcClientID: ${ID}
    oidcIssuerURL: https://accounts.google.com
    oidcUsernameClaim: email
    runtimeConfig:
      rbac.authorization.k8s.io/v1alpha1: "true"

kops update cluster --name=${NAME} --yes
kops rolling-update cluster --name=${NAME} --state=s3://${NAME} --yes
kops validate cluster

Create RoleBinding:

cat <<EOF | kubectl create -f -
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: namespace-admin
  namespace: infra
subjects:
- kind: User
  apiGroup: rbac.authorization.k8s.io
  name: [email protected]
roleRef:
  kind: ClusterRole
  name: admin
  apiGroup: rbac.authorization.k8s.io
EOF

Compile and run dexter:

go get -u github.com/gini/dexter
cd ~/go/src/github.com/gini/dexter
make dep
CLIENT_ID=${ID} CLIENT_SECRET=${SECRET} OS=darwin make -j 8
cp ~/.kube/config ~/.kube/config.bak
./build/dexter_darwin_amd64 auth

Here is generated kubectl config:

$ kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: REDACTED
    server: https://api.k8s-dev.site.org
  name: k8s-dev.site.org
contexts:
- context:
    cluster: k8s-dev.site.org
    namespace: infra
    user: k8s-dev.site.org
  name: k8s-dev.site.org
current-context: k8s-dev.site.org
kind: Config
preferences: {}
users:
- name: [email protected]
  user:
    auth-provider:
      config:
        client-id: 1123441.apps.googleusercontent.com
        client-secret: googlesecret
        id-token: some-token
        idp-issuer-url: https://accounts.google.com
        refresh-token: 1/12345566
      name: oidc
- name: k8s-dev.site.org
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED
    password: 123456
    username: admin
- name: k8s-dev.site.org-basic-auth
  user:
    password: 123456
    username: admin

Switch to new user:

kubectl config set-context k8s-dev.site.org [email protected] --namespace=infra

Trying to check resources:

$ kubectl get nodes,svc,ing,pods
No resources found.
error: You must be logged in to the server (Unauthorized)
error: You must be logged in to the server (Unauthorized)
error: You must be logged in to the server (Unauthorized)
error: You must be logged in to the server (Unauthorized)

What I'm doing wrong?

Race condition on http server teardown

Sometimes, after authenticating with the browser, http server is wound down too quickly, which results in a error page from the browser:

image

When this happens, the processing (including writing kubeconfig) finishes correctly, this is a just a minor visual issue, but looks quite user unfriendly when happens.

Authenticate as Google Service Account

I've created a service account in the Google cloud console and am struggling to find out how to authenticate as that service account via kubectl. The idea is that our deployment server should be able to execute kubectl set image deployment ... against the cluster but to do that, it needs to authenticate. It makes more sense to use a service account as opposed to a normal IAM user account in this situation.

Is this possible using dexter? If not, does anyone know of an example I can look at for how to achieve this?

Embed default provider at compile time

Right now, google is the default provider set in the code unless told otherwise with a cli flag. Just like we can embed credentials at compile time, it would be great to be able to set the default provider as well.

Timeout too low

I've ran into timeout issues, which I could fix by changing this timeout here: https://github.com/gini/dexter/blob/master/cmd/google.go#L23

I attempted to authenticate using Google like this:

dexter auth google \
  --client-id=${id} \
  --client-secret=${secret}

The error looked like this:

ERRO[2023-03-03T13:47:56+01:00] Failed to exchange auth code: Post "https://oauth2.googleapis.com/token": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

Would you accept a pull request either raising the timeout or make it configurable?

Create a dedicated sub-command per provider

There are already command-line flags that only apply to a single OIDC provider. This will only get worse with new providers. I think it will be best to refactor the code in a way to make the majority reusable and only handle the individual bits differently.

Proposed command structure:

dexter auth google
dexter auth azure
dexter auth generic

dexter OIDC vs SSL Cert Login

Correct me if i'm wrong but isn't this kind of the same as using SSL certificates for client auth ?
I mean , the user will get a valid id-token and a refresh token (with google oidc at least). He/she can use the refresh token to get a new id-token once it expired indefinitely , so there's no actual way to revoke access to a token beside removing the user from the (Cluster|Role)Binding same as with SSL certificates.

Using dexter with dex?

This might be a silly question, but I can't find a reference in the docs. Is dexter able to be used with dex?

We are currently using dexter to authenticate directly to Google. However, we looking at setting up dex to be able to provide groups which Google Oidc doesn't handle by default.

Thanks.

Support an option to kubeconfig output path

Hello,

It would be interesting to choose the path of his kubeconfig.

dexter --file /path/to/kube/config
The file to write to. If not specified, ~/.kube/config is used

Thanks

goreleaser warnings

It looks like we might need a maintenance release. Currently goreleaser gives

• DEPRECATED: --rm-dist was deprecated in favor of --clean, check https://goreleaser.com/deprecations#-rm-dist for more details

and

• DEPRECATED: `archives.replacements` should not be used anymore, check https://goreleaser.com/deprecations#archivesreplacements for more info

would be good to make these in line with the supported version

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.