├── LICENSE ├── README.md ├── ca-cm.yml ├── charts ├── README.md └── examples │ └── SAML.md ├── crb-all-auth.yml ├── dex-cm.yml ├── dex-crd.yml ├── dex-deploy.yml ├── dex-ing-svc.yml ├── loginapp-cm.yml ├── loginapp-deploy.yml ├── loginapp-ing-svc.yml └── rbac.yml /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kubernetes - LDAP authentication with Dex 2 | 3 | - [Kubernetes - LDAP authentication with Dex](#kubernetes---ldap-authentication-with-dex) 4 | - [Docs](#docs) 5 | - [Requirements](#requirements) 6 | - [Helm chart](#helm-chart) 7 | - [Login application](#login-application) 8 | - [Dex](#dex) 9 | - [CRD](#crd) 10 | - [Deployment](#deployment) 11 | 12 | ## Docs 13 | 14 | This deployment follows Dex by CoreOS & Kubernetes Documentations: 15 | 16 | * [Kubernetes OIDC Doc](https://kubernetes.io/docs/reference/access-authn-authz/authentication/#openid-connect-tokens) 17 | * [Dex by CoreOS](https://github.com/coreos/dex) 18 | * [Login App](https://github.com/fydrah/loginapp) 19 | 20 | ## Requirements 21 | 22 | * DNS entries: 23 | * **dex.k8s.example.com** --> Dex OIDC provider 24 | * **login.k8s.example.com** --> Custom Login Application 25 | 26 | * Kubernetes cluster available with the following requirements: 27 | * RBAC enabled 28 | * OIDC authentication enabled. API server configuration: 29 | * **--oidc-issuer-url=https://dex.k8s.example.com/dex**: External Dex endpoint 30 | * **--oidc-client-id=loginapp**: ID for our Login Application 31 | * **--oidc-ca-file=/etc/kubernetes/ssl/letsencrypt.pem**: Letsencrypt CA file because we will use automatic certificate requests. 32 | * **--oidc-username-claim=name**: Map to **nameAttr** Dex configuration. This will be used by Kubernetes RBAC to authorize users based on their name. 33 | * **oidc-groups-claim=groups**: This will be used by Kubernetes RBAC to authorize users based on their groups. 34 | * Ingress Controller available. 35 | * Automatic certificate requests for Kubernetes (ex: https://github.com/jetstack/cert-manager) 36 | 37 | * An available LDAP server 38 | 39 | ## Helm chart 40 | 41 | Helm chart is available [here](https://github.com/ObjectifLibre/kube-oidc). 42 | 43 | ## Login application 44 | 45 | * Create the auth namespace: 46 | 47 | ```shell 48 | kubectl create ns auth 49 | ``` 50 | 51 | * Create resources: 52 | 53 | ```shell 54 | # CA (letsencrypt) configmap 55 | kubectl create -f ca-cm.yml 56 | # Login App configuration 57 | kubectl create -f loginapp-cm.yml 58 | # Login App Ingress and SVC 59 | kubectl create -f loginapp-ing-svc.yml 60 | # Login App Deployment 61 | kubectl create -f loginapp-deploy.yml 62 | ``` 63 | 64 | It should fail because Dex is not deployed. 65 | 66 | ## Dex 67 | 68 | ### CRD 69 | 70 | We will use Kubernetes Custom Resource Definitions (https://kubernetes.io/docs/concepts/api-extension/custom-resources/) as Dex storage backend. 71 | 72 | ```shell 73 | kubectl create -f dex-crd.yml 74 | ``` 75 | 76 | ### Deployment 77 | 78 | * Create Dex resources: 79 | 80 | ```shell 81 | # Dex configuration 82 | kubectl create -f dex-cm.yml 83 | # Dex ingress and service 84 | kubectl create -f dex-ing-svc.yml 85 | # Dex deployment 86 | kubectl create -f dex-deploy.yml 87 | ``` 88 | 89 | Now it should work: try https://login.k8s.example.org, login and retrieve k8s configuration. 90 | 91 | ```shell 92 | kubectl --token=token get pods -n auth 93 | Error from server (Forbidden): pods is forbidden: User "#" cannot list pods in the namespace "auth" 94 | ``` 95 | 96 | User prefix can be updated with the **--oidc-username-prefix** apiserver option. 97 | 98 | * Create ClusterRoleBinding resource: 99 | ```shell 100 | kubectl create -f crb-all-auth.yml 101 | ``` 102 | 103 | Try again: 104 | 105 | ```shell 106 | kubectl --token=$token get po 107 | NAME READY STATUS RESTARTS AGE 108 | dex-6f6568d499-m89z6 1/1 Running 0 7m 109 | loginapp-6474748f4b-gb5kb 1/1 Running 0 8m 110 | loginapp-6474748f4b-prq25 1/1 Running 0 8m 111 | loginapp-6474748f4b-vnvnb 1/1 Running 0 8m 112 | ``` 113 | -------------------------------------------------------------------------------- /ca-cm.yml: -------------------------------------------------------------------------------- 1 | kind: ConfigMap 2 | apiVersion: v1 3 | metadata: 4 | name: ca 5 | namespace: auth 6 | data: 7 | ca.pem: | 8 | -----BEGIN CERTIFICATE----- 9 | MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/ 10 | MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT 11 | DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow 12 | PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD 13 | Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB 14 | AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O 15 | rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq 16 | OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b 17 | xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw 18 | 7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD 19 | aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV 20 | HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG 21 | SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69 22 | ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr 23 | AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz 24 | R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5 25 | JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo 26 | Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ 27 | -----END CERTIFICATE----- 28 | -------------------------------------------------------------------------------- /charts/README.md: -------------------------------------------------------------------------------- 1 | # k8s-ldap Helm chart 2 | 3 | This repository has been: 4 | * renamed **kube-oidc** 5 | * moved to [ObjectifLibre/kube-oidc](https://github.com/ObjectifLibre/kube-oidc) 6 | 7 | New issues and PR related to this Helm chart must be submitted to the new GitHub repository. 8 | -------------------------------------------------------------------------------- /charts/examples/SAML.md: -------------------------------------------------------------------------------- 1 | # Example SAML config 2 | 3 | Since dex is a backend app that can support multiple [connectors](https://github.com/dexidp/dex/tree/master/Documentation/connectors), we can modify the chart in order to use SAML as the connector without modyfing the chart itself. 4 | 5 | ## SAML configuration 6 | In most SAML Identity Providers (IP) we need to create a metadata file, which registers our application in the IP. This file can be created manually, or by the use of a UI, however the effect should be similar to this: 7 | 8 | ```xml 9 | 10 | 11 | 12 | 13 | 14 | dex.k8s.example.org 15 | 16 | IDENTITY_CERT 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | ``` 25 | 26 | ## Dex configuration 27 | We only need to modify the connectors part of the configuration in order to change our backend: 28 | 29 | ```yaml 30 | dex: 31 | config: 32 | connectors: 33 | - type: saml 34 | # Required field for connector id. 35 | id: APP_ID 36 | # Required field for connector name. 37 | name: APP_NAME 38 | config: 39 | # entityId taken from the metadata 40 | entityIssuer: dex.k8s.example.org 41 | # URL to the POST endpoint of the SSO provider 42 | ssoURL: YOUR_SSO_POST_ENDPOINT 43 | # Base64 of the same cert we used in the metadata 44 | caData: BASE64_IDENTITY_CERT 45 | # POST endpoint of DEX 46 | redirectURI: https://dex.k8s.example.org/dex/callback 47 | # Parameter mapping, similar to LDAP 48 | usernameAttr: name 49 | emailAttr: email 50 | groupsAttr: groups 51 | groupsDelim: ", " 52 | insecureSkipSignatureValidation: true 53 | ``` 54 | -------------------------------------------------------------------------------- /crb-all-auth.yml: -------------------------------------------------------------------------------- 1 | apiVersion: rbac.authorization.k8s.io/v1beta1 2 | kind: ClusterRoleBinding 3 | metadata: 4 | name: dex-system-authenticated 5 | namespace: kube-system 6 | roleRef: 7 | apiGroup: rbac.authorization.k8s.io 8 | kind: ClusterRole 9 | name: view 10 | subjects: 11 | - kind: Group 12 | name: system:authenticated 13 | apiGroup: rbac.authorization.k8s.io -------------------------------------------------------------------------------- /dex-cm.yml: -------------------------------------------------------------------------------- 1 | kind: ConfigMap 2 | apiVersion: v1 3 | metadata: 4 | name: dex 5 | namespace: auth 6 | data: 7 | config.yaml: | 8 | issuer: https://dex.k8s.example.org/dex 9 | storage: 10 | type: kubernetes 11 | config: 12 | inCluster: true 13 | web: 14 | http: 0.0.0.0:5556 15 | logger: 16 | level: "debug" 17 | format: text 18 | 19 | connectors: 20 | - type: ldap 21 | # Required field for connector id. 22 | id: ldap 23 | # Required field for connector name. 24 | name: LDAP 25 | config: 26 | # Host and optional port of the LDAP server in the form "host:port". 27 | # If the port is not supplied, it will be guessed based on "insecureNoSSL", 28 | # and "startTLS" flags. 389 for insecure or StartTLS connections, 636 29 | # otherwise. 30 | host: ldap.k8s.example.org:1389 31 | 32 | # Following field is required if the LDAP host is not using TLS (port 389). 33 | # Because this option inherently leaks passwords to anyone on the same network 34 | # as dex, THIS OPTION MAY BE REMOVED WITHOUT WARNING IN A FUTURE RELEASE. 35 | # 36 | insecureNoSSL: true 37 | # If a custom certificate isn't provide, this option can be used to turn on 38 | # TLS certificate checks. As noted, it is insecure and shouldn't be used outside 39 | # of explorative phases. 40 | # 41 | insecureSkipVerify: true 42 | # When connecting to the server, connect using the ldap:// protocol then issue 43 | # a StartTLS command. If unspecified, connections will use the ldaps:// protocol 44 | # 45 | # startTLS: true 46 | # Path to a trusted root certificate file. Default: use the host's root CA. 47 | #rootCA: /etc/dex/ldap.ca 48 | # A raw certificate file can also be provided inline. 49 | #rootCAData: 50 | # The DN and password for an application service account. The connector uses 51 | # these credentials to search for users and groups. Not required if the LDAP 52 | # server provides access for anonymous auth. 53 | # Please note that if the bind password contains a `$`, it has to be saved in an 54 | # environment variable which should be given as the value to `bindPW`. 55 | bindDN: cn=admin,dc=example,dc=org 56 | bindPW: admin 57 | 58 | # User search maps a username and password entered by a user to a LDAP entry. 59 | userSearch: 60 | # BaseDN to start the search from. It will translate to the query 61 | # "(&(objectClass=person)(uid=))". 62 | baseDN: ou=People,dc=example,dc=org 63 | # Optional filter to apply when searching the directory. 64 | filter: "(objectClass=posixAccount)" 65 | # username attribute used for comparing user entries. This will be translated 66 | # and combine with the other filter as "(=)". 67 | username: mail 68 | # The following three fields are direct mappings of attributes on the user entry. 69 | # String representation of the user. 70 | idAttr: uid 71 | # Required. Attribute to map to Email. 72 | emailAttr: mail 73 | # Maps to display name of users. No default value. 74 | nameAttr: uid 75 | 76 | # Group search queries for groups given a user entry. 77 | groupSearch: 78 | # BaseDN to start the search from. It will translate to the query 79 | # "(&(objectClass=group)(member=))". 80 | baseDN: ou=Groups,dc=example,dc=org 81 | # Optional filter to apply when searching the directory. 82 | filter: "(objectClass=posixGroup)" 83 | # Following two fields are used to match a user to a group. It adds an additional 84 | # requirement to the filter that an attribute in the group must match the user's 85 | # attribute value. 86 | userAttr: uid 87 | groupAttr: memberUid 88 | # Represents group name. 89 | nameAttr: cn 90 | oauth2: 91 | skipApprovalScreen: true 92 | 93 | staticClients: 94 | - id: login 95 | redirectURIs: 96 | - 'https://login.k8s.example.org/callback' 97 | name: 'Login Application' 98 | secret: 4TORGiNV9M54BTk1v7dNuFSaI6hUjfjr 99 | -------------------------------------------------------------------------------- /dex-crd.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apiextensions.k8s.io/v1beta1 2 | kind: CustomResourceDefinition 3 | metadata: 4 | name: authcodes.dex.coreos.com 5 | spec: 6 | group: dex.coreos.com 7 | names: 8 | kind: AuthCode 9 | listKind: AuthCodeList 10 | plural: authcodes 11 | singular: authcode 12 | scope: Namespaced 13 | version: v1 14 | 15 | --- 16 | apiVersion: rbac.authorization.k8s.io/v1beta1 17 | kind: ClusterRole 18 | metadata: 19 | name: dex 20 | rules: 21 | - apiGroups: ["dex.coreos.com"] # API group created by dex 22 | resources: ["*"] 23 | verbs: ["*"] 24 | - apiGroups: ["apiextensions.k8s.io"] 25 | resources: ["customresourcedefinitions"] 26 | verbs: ["create"] # To manage its own resources identity must be able to create customresourcedefinitions. 27 | 28 | --- 29 | apiVersion: rbac.authorization.k8s.io/v1beta1 30 | kind: ClusterRoleBinding 31 | metadata: 32 | name: dex 33 | roleRef: 34 | apiGroup: rbac.authorization.k8s.io 35 | kind: ClusterRole 36 | name: dex 37 | subjects: 38 | - kind: ServiceAccount 39 | name: dex # Service account assigned to the dex pod. 40 | namespace: auth # The namespace dex is running in. 41 | 42 | --- 43 | apiVersion: v1 44 | kind: ServiceAccount 45 | metadata: 46 | name: dex 47 | namespace: auth 48 | -------------------------------------------------------------------------------- /dex-deploy.yml: -------------------------------------------------------------------------------- 1 | apiVersion: extensions/v1beta1 2 | kind: Deployment 3 | metadata: 4 | labels: 5 | app: dex 6 | name: dex 7 | namespace: auth 8 | spec: 9 | replicas: 1 10 | template: 11 | metadata: 12 | labels: 13 | app: dex 14 | spec: 15 | serviceAccountName: dex 16 | containers: 17 | - image: quay.io/coreos/dex:v2.9.0 18 | name: dex 19 | command: ["dex", "serve", "/etc/dex/cfg/config.yaml"] 20 | ports: 21 | - name: http 22 | containerPort: 5556 23 | volumeMounts: 24 | - name: config 25 | mountPath: /etc/dex/cfg 26 | volumes: 27 | - name: config 28 | configMap: 29 | name: dex 30 | items: 31 | - key: config.yaml 32 | path: config.yaml 33 | -------------------------------------------------------------------------------- /dex-ing-svc.yml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: v1 3 | kind: Service 4 | metadata: 5 | name: dex 6 | namespace: auth 7 | spec: 8 | ports: 9 | - name: dex 10 | port: 5556 11 | protocol: TCP 12 | targetPort: 5556 13 | selector: 14 | app: dex 15 | --- 16 | apiVersion: extensions/v1beta1 17 | kind: Ingress 18 | metadata: 19 | name: dex 20 | namespace: auth 21 | annotations: 22 | kubernetes.io/ingress.class: nginx 23 | kubernetes.io/tls-acme: 'true' 24 | ingress.kubernetes.io/force-ssl-redirect: 'true' 25 | spec: 26 | rules: 27 | - host: dex.k8s.example.org 28 | http: 29 | paths: 30 | - backend: 31 | serviceName: dex 32 | servicePort: 5556 33 | path: / 34 | tls: 35 | - hosts: 36 | - dex.k8s.example.org 37 | secretName: dex-tls 38 | -------------------------------------------------------------------------------- /loginapp-cm.yml: -------------------------------------------------------------------------------- 1 | --- 2 | kind: ConfigMap 3 | apiVersion: v1 4 | metadata: 5 | name: loginapp 6 | namespace: auth 7 | data: 8 | config.yaml: | 9 | debug: false 10 | client_id: "login" 11 | client_secret: 4TORGiNV9M54BTk1v7dNuFSaI6hUjfjr 12 | issuer_url: "https://dex.k8s.example.org/dex" 13 | issuer_root_ca: "/etc/ssl/ca.pem" 14 | redirect_url: "https://login.k8s.example.org/callback" 15 | listen: "http://0.0.0.0:5555" 16 | disable_choices: false 17 | extra_scopes: "groups" 18 | app_name: "Kubernetes Auth" 19 | -------------------------------------------------------------------------------- /loginapp-deploy.yml: -------------------------------------------------------------------------------- 1 | apiVersion: extensions/v1beta1 2 | kind: Deployment 3 | metadata: 4 | name: loginapp 5 | namespace: auth 6 | spec: 7 | replicas: 3 8 | template: 9 | metadata: 10 | labels: 11 | app: loginapp 12 | spec: 13 | containers: 14 | - image: objectiflibre/login-app:latest 15 | name: loginapp 16 | ports: 17 | - name: http 18 | containerPort: 5555 19 | volumeMounts: 20 | - name: ca 21 | mountPath: /etc/ssl/ 22 | - name: config 23 | mountPath: /app/ 24 | volumes: 25 | - name: ca 26 | configMap: 27 | name: ca 28 | items: 29 | - key: ca.pem 30 | path: ca.pem 31 | - name: config 32 | configMap: 33 | name: loginapp 34 | items: 35 | - key: config.yaml 36 | path: config.yaml 37 | -------------------------------------------------------------------------------- /loginapp-ing-svc.yml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: v1 3 | kind: Service 4 | metadata: 5 | name: loginapp 6 | namespace: auth 7 | spec: 8 | ports: 9 | - name: loginapp 10 | port: 5555 11 | protocol: TCP 12 | targetPort: 5555 13 | selector: 14 | app: loginapp 15 | 16 | --- 17 | apiVersion: extensions/v1beta1 18 | kind: Ingress 19 | metadata: 20 | name: loginapp 21 | namespace: auth 22 | annotations: 23 | kubernetes.io/ingress.class: nginx 24 | kubernetes.io/tls-acme: 'true' 25 | ingress.kubernetes.io/force-ssl-redirect: 'true' 26 | spec: 27 | rules: 28 | - host: login.k8s.example.org 29 | http: 30 | paths: 31 | - backend: 32 | serviceName: loginapp 33 | servicePort: 5555 34 | path: / 35 | tls: 36 | - hosts: 37 | - login.k8s.example.org 38 | secretName: login-tls 39 | -------------------------------------------------------------------------------- /rbac.yml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: rbac.authorization.k8s.io/v1beta1 3 | kind: ClusterRoleBinding 4 | metadata: 5 | name: ldap_cluster_admin 6 | namespace: kube-system 7 | roleRef: 8 | apiGroup: rbac.authorization.k8s.io 9 | kind: ClusterRole 10 | name: cluster-admin 11 | subjects: 12 | - kind: Group 13 | name: admins 14 | --------------------------------------------------------------------------------