From 0bdd1bc68fb8ba6d13fd3cc064e948ac05db5465 Mon Sep 17 00:00:00 2001 From: Radoslav Dimitrov Date: Mon, 19 Jul 2021 16:00:43 +0300 Subject: [PATCH 1/2] Add documentation for configuring Supervisor with Dex and Github The following guide describes the process of configuring Supervisor with Dex and identify users through their Github account. Issue #415 Signed-off-by: Radoslav Dimitrov --- .../howto/configure-supervisor-with-dex.md | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 site/content/docs/howto/configure-supervisor-with-dex.md diff --git a/site/content/docs/howto/configure-supervisor-with-dex.md b/site/content/docs/howto/configure-supervisor-with-dex.md new file mode 100644 index 00000000..3c88fb78 --- /dev/null +++ b/site/content/docs/howto/configure-supervisor-with-dex.md @@ -0,0 +1,132 @@ +--- +title: Configure the Pinniped Supervisor to use Dex with Github as an OIDC provider +description: Set up the Pinniped Supervisor to use Dex login. +cascade: + layout: docs +menu: + docs: + name: Configure Supervisor With Dex OIDC + weight: 80 + parent: howtos +--- + +The Supervisor is an [OpenID Connect (OIDC)](https://openid.net/connect/) issuer that supports connecting a single +"upstream" identity provider to many "downstream" cluster clients. + +This guide shows you how to configure the Supervisor so that users can authenticate to their Kubernetes +cluster using Dex and Github. + +## Prerequisites + +This how-to guide assumes that you have already [installed the Pinniped Supervisor]({{< ref "install-supervisor" >}}) with working ingress, +and that you have [configured a FederationDomain to issue tokens for your downstream clusters]({{< ref "configure-supervisor" >}}). + +## Configure Dex to use Github as an external identity provider + +Dex is an OIDC issuer that supports various identity providers through connectors, i.e. LDAP, Github, Gitlab, Google, SAML and much more. Take a look at its [documentation](https://dexidp.io/docs/connectors/) to understand how to configure such connector in Dex. + +In this example, we'll show how to use Dex to identify users through their GitHub account. + +First, we need to go to your Github account settings and [create an OAuth app](https://github.com/settings/applications/new) by populating the following rows - + +- Application name - `Dex application` +- Homepage URL - `https://` +- Authorization callback URL - `https:///callback` // this is where Github will redirect you to once your app has authorized + +Once completed, copy your `Client ID` and `Client secret` (generate one if there's none) as those two will be needed to configure a Github connector in Dex. + +To setup one, edit the configuration used by Dex by adding the following - + +```bash +... +connectors: +- type: github + id: github + name: GitHub + config: + clientID: $GITHUB_CLIENT_ID + clientSecret: $GITHUB_CLIENT_SECRET + redirectURI: https:///callback +... +``` + +## Register an application in Dex + +Follow the instructions for [registering an application in Dex](https://dexidp.io/docs/using-dex/#configuring-your-app) and create a static client application, in our case the client happens be the Supervisor. Note that the "openid" scope is always included, but you can always request additional scopes that you can then pass to your Kubernetes cluster, such as "groups" for example. + +To create a static client application, edit the configuration used by Dex (can be a file or a ConfigMap) by adding the following - + +```bash +... +staticClients: +- id: pinniped-supervisor + secret: pinniped-supervisor-secret + name: 'Pinniped Supervisor client' + redirectURIs: + - 'http:///callback' +... +``` + +## Configure the Supervisor + +Create an [OIDCIdentityProvider](https://github.com/vmware-tanzu/pinniped/blob/main/generated/1.20/README.adoc#oidcidentityprovider) resource in the same namespace as the Supervisor. + +For example, the following OIDCIdentityProvider and the corresponding Secret use Dex's `email` claim as the Kubernetes username: + +```yaml +apiVersion: idp.supervisor.pinniped.dev/v1alpha1 +kind: OIDCIdentityProvider +metadata: + namespace: pinniped-supervisor + name: dex +spec: + # Specify the upstream issuer URL (no trailing slash). + issuer: https:// + + # Request any scopes other than "openid" for claims besides + # the default claims in your token. The "openid" scope is always + # included. + authorizationConfig: + additionalScopes: [groups, email] + + # Specify how Dex claims are mapped to Kubernetes identities. + claims: + # Specify the name of the claim in your Dex ID token that will be mapped + # to the "username" claim in downstream tokens minted by the Supervisor. + username: email + + # Specify the name of the claim in your Dex ID token that represents the groups + # that the user belongs to. This matches what you specified above + # with the Groups claim filter. + groups: groups + + # Specify the name of the Kubernetes Secret that contains your Dex + # application's client credentials (created below). + client: + secretName: dex-client-credentials +--- +apiVersion: v1 +kind: Secret +metadata: + namespace: pinniped-supervisor + name: dex-client-credentials +type: secrets.pinniped.dev/oidc-client +stringData: + # The "Client ID" that you set in Dex. For example, in our case this is "pinniped-supervisor" + clientID: "" + + # The "Client secret" that you set in Dex. For example, in our case this is "pinniped-supervisor-secret" + clientSecret: "" +``` + +Once your OIDCIdentityProvider resource has been created, you can validate your configuration by running: + +```bash +kubectl describe OIDCIdentityProvider -n pinniped-supervisor dex +``` + +Look at the `status` field. If it was configured correctly, you should see `phase: Ready`. + +## Next steps + +Now that you have configured the Supervisor to use Dex, you will want to [configure the Concierge to validate JWTs issued by the Supervisor]({{< ref "configure-concierge-supervisor-jwt" >}}). From f6273b06040c67857746642fdac072ab84eb16c0 Mon Sep 17 00:00:00 2001 From: Radoslav Dimitrov Date: Tue, 20 Jul 2021 13:44:12 +0300 Subject: [PATCH 2/2] Update the Prerequisites section and add a note about the groups scope Add Dex to the prerequisites and add a note that to query for the groups scope the user must set the organizations Dex should search against. Otherwise the groups claim would be empty. This is because of the format group claims are represented, i.e. "org:team". Signed-off-by: Radoslav Dimitrov --- site/content/docs/howto/configure-supervisor-with-dex.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/site/content/docs/howto/configure-supervisor-with-dex.md b/site/content/docs/howto/configure-supervisor-with-dex.md index 3c88fb78..db44d20e 100644 --- a/site/content/docs/howto/configure-supervisor-with-dex.md +++ b/site/content/docs/howto/configure-supervisor-with-dex.md @@ -21,6 +21,8 @@ cluster using Dex and Github. This how-to guide assumes that you have already [installed the Pinniped Supervisor]({{< ref "install-supervisor" >}}) with working ingress, and that you have [configured a FederationDomain to issue tokens for your downstream clusters]({{< ref "configure-supervisor" >}}). +You'd also have to have an instance of Dex up and running, i.e. accessible at `https://`. You can refer to the [Getting started with Dex](https://dexidp.io/docs/getting-started/) guidelines for more information on how to deploy it. + ## Configure Dex to use Github as an external identity provider Dex is an OIDC issuer that supports various identity providers through connectors, i.e. LDAP, Github, Gitlab, Google, SAML and much more. Take a look at its [documentation](https://dexidp.io/docs/connectors/) to understand how to configure such connector in Dex. @@ -98,6 +100,10 @@ spec: # Specify the name of the claim in your Dex ID token that represents the groups # that the user belongs to. This matches what you specified above # with the Groups claim filter. + # Note that the group claims from Github are in the format of "org:team". + # To query for the group scope, you should set the organization you want Dex to + # search against in its configuration, otherwise your group claim would be empty. + # An example config can be found at - https://dexidp.io/docs/connectors/github/#configuration groups: groups # Specify the name of the Kubernetes Secret that contains your Dex