openunison-k8s-login-oidc

by marc.boorshtein

Helm chartv1.0.24App 1.0.24

Use OpnID Connect to authenticate to your cluster with kubectl and dashboard using OpenUnison Orchestra. oidc kubernetes authentication.

About this chart

Orchestra Login Portal for OpenID Connect

:warning:

Please go to https://openunison.github.io/ to integrate your cluster with OpenUnison. This repo has been deprecated. It will continue to be updated until 12/30/2022, however new features will not be added to this repo.

:warning:

Short video of logging into Kubernetes and using kubectl using OpenID Connect and Keycloak

Orchestra Login Portal provides a login portal for Kubernetes that allows you to authenticate with your OpenID Connect credentials, use the identity provider's groups for RBAC authorizations and provides integration for both kubectl and the Kubernetes Dashboard (https://github.com/kubernetes/dashboard). The portal runs inside of Kubernetes, leveraging Kubernetes for scalability, secret management and deployment.

When a user accesses Kubernetes using Orchestra, they'll access both the login portal and the dashboard through OpenUnison (instead of directly via an ingress). OpenUnison will inject the user's identity into each request, allowing the dashboard to act on their behalf. The login portal has no external dependencies outside of your OpenID Connect identity provider and Kubernetes. All objects for session state are stored as CRDs.

Deployment

What You Need To Start

Prior to deploying Orchestra you will need:

  1. Kubernetes 1.10 or higher
  2. The Nginx Ingress Controller deployed (https://kubernetes.github.io/ingress-nginx/deploy/)
  3. Information from your OpenID Connect Identity Provider per Prepare Deployment in the next section. When registering OpenUnison with your identity provider, use the hostname and /auth/oidc as the redirect. For instance if OpenUnison will be running on k8sou.tremolo.lan.com then the redirect_uri will be https://k8sou.tremolo.lan/auth/oidc
  4. Deploy the dashboard to your cluster
  5. helm 3.0+

Required Attributes for Your Identity Provider

In order to integrate your identity provide make sure the following attributes are in the id_token:

  • sub
  • email
  • given_name
  • family_name
  • name
  • groups (optional)

These are then mapped into the user's object in OpenUnison for personalization and authorization. These attributes are often available with the profile scope.

Add Tremolo Security's Helm Repo

helm repo add tremolo https://nexus.tremolo.io/repository/helm/
helm repo update

Deploy The OpenUnison Operator

Create your namespace

kubectl create ns openunison

Deploy the operator

helm install openunison tremolo/openunison-operator --namespace openunison

Wait for the operator pod to be available

watch kubectl get pods -n openunison

Create A Secret For Your OpenID Connect Secret

Create a secret in the openunison namespace:

apiVersion: v1
type: Opaque
metadata:
  name: orchestra-secrets-source
  namespace: openunison
data:
  OIDC_CLIENT_SECRET: aW0gYSBzZWNyZXQ=
  K8S_DB_SECRET: aW0gYSBzZWNyZXQ=
  unisonKeystorePassword: aW0gYSBzZWNyZXQ=
kind: Secret
PropertyDescription
OIDC_CLIENT_SECRETThe secret provided by your identity provider
unisonKeystorePasswordThe password for OpenUnison's keystore, should NOT contain an ampersand (&)
K8S_DB_SECRETA random string of characters used to secure the SSO process with the dashboard. This should be long and random, with no ampersands (&)

Deploy OpenUnison

Copy values.yaml (https://raw.githubusercontent.com/OpenUnison/helm-charts/master/openunison-k8s-login-oidc/values.yaml) and update as appropriate:

PropertyDescription
network.openunison_hostThe host name for OpenUnison. This is what user's will put into their browser to login to Kubernetes
network.dashboard_hostThe host name for the dashboard. This is what users will put into the browser to access to the dashboard. NOTE: network.openunison_host and network.dashboard_host Both network.openunison_host and network.dashboard_host MUST point to OpenUnison
network.api_server_hostThe host name to use for the api server reverse proxy. This is what kubectl will interact with to access your cluster. NOTE: network.openunison_host and network.dashboard_host
network.k8s_urlThe URL for the Kubernetes API server
network.session_inactivity_timeout_secondsThe number of seconds of inactivity before the session is terminated, also the length of the refresh token's session
network.createIngressCertificateIf true (default), the operator will create a self signed Ingress certificate. Set to false if using an existing certificate or LetsEncrypt
network.force_redirect_to_tlsIf true, all traffic that reaches OpenUnison over http will be redirected to https. Defaults to true. Set to false when using an external TLS termination point, such as an istio sidecar proxy
network.ingress_typeThe type of Ingress object to create. nginx and istio is supported
network.ingress_annotationsAnnotations to add to the Ingress object
network.ingress_certificateThe certificate that the Ingress object should reference
network.istio.selectorsLabels that the istio Gateway object will be applied to. Default is istio: ingressgateway
cert_template.ouThe OU attribute for the forward facing certificate
cert_template.oThe O attribute for the forward facing certificate
cert_template.lThe L attribute for the forward facing certificate
cert_template.stThe ST attribute for the forward facing certificate
cert_template.cThe C attribute for the forward facing certificate
certs.use_k8s_cmTells the deployment system if you should use k8s' built in certificate manager. If your distribution doesn't support this (such as Canonical and Rancher), set this to false
myvd_config_pathThe path to the MyVD configuration file, unless being customized, use WEB-INF/myvd.conf
dashboard.namespaceThe namespace for the dashboard. For the 1.x dashboard this is kube-system, for the 2.x dashboard this is kubernetes-dashboard
dashboard.cert_nameThe name of the secret in the dashboard's namespace that stores the certificate for the dashboard
dashboard.labelThe label of the dashboard pod, this is used to delete the pod once new certificates are generated
dashboard.service_nameThe name of the service object for the dashboard
k8s_cluster_nameThe name of the cluster to use in the ./kube-config. Defaults to kubernetes
imageThe name of the image to use
enable_impersonationIf true, OpenUnison will run in impersonation mode. Instead of OpenUnison being integrated with Kubernetes via OIDC, OpenUnison will be a reverse proxy and impersonate users. This is useful with cloud deployments where oidc is not an option
monitoring.prometheus_service_accountThe prometheus service account to authorize access to the /monitoring endpoint
oidc.client_idThe client ID registered with your identity provider
oidc.auth_urlYour identity provider's authorization url
oidc.token_urlYour identity provider's token url
oidc.domainAn email domain to limit access to
oidc.user_in_idtokenSet to true if the user's attributes (such as name and groups), is contained in the user's id_token. Set to false if a call to the identity provider's user info endpoint is required to load the full profile
oidc.userinfo_urlIf oidc.user_in_idtoken is false, the user_info endpoint for your identity provider
oidc.scopesThe list of scopes to include, may change based on your identity provider
oidc.claims.subIf specified, the claim from the id_token to use for the sub attribute
oidc.claims.emailIf specified, the claim from the id_token to use for the mail attribute
oidc.claims.givenNameIf specified, the claim from the id_token to use for the givenName attribute
oidc.claims.familyNameIf specified, the claim from the id_token to use for the sn attribute
oidc.claims.displayNameIf specified, the claim from the id_token to use for the dipslayName attribute
oidc.claims.groupsIf specified, the claim from the id_token to use for the groups attribute
network_policies.enabledIf true, creates a deny-all network policy and additional policies based on below configurations
network_policies.ingress.enabledif true, a policy will be created that allows access from the Namespace identified by the labels
network_policies.ingress.labelsLabels for the Namespace hosting the Ingress
network_policies.monitoring.enabledif true, a policy will be created that allows access from the Namespace identified by the labels to support monitoring
network_policies.monitoring.labelsLabels for the Namespace hosting monitoring
network_policies.apiserver.enabledif true, a policy will be created that allows access from the kube-ns Namespace identified by the labels
network_policies.apiserver.labelsLabels for the Namespace hosting the api server
services.enable_tokenrequestIf true, the OpenUnison Deployment will use the TokenRequest API instead of static ServiceAccount tokens. *** NOT AVAILABLE UNTIL OPENUNISON 1.0.21 ***
services.token_request_audienceThe audience expected by the API server *** NOT AVAILABLE UNTIL OPENUNISON 1.0.21 ***
services.token_request_expiration_secondsThe number of seconds TokenRequest tokens should be valid for, minimum 600 seconds *** NOT AVAILABLE UNTIL OPENUNISON 1.0.21 ***
services.node_selectorsannotations to use when choosing nodes to run OpenUnison, maps to the Deployment nodeSelector
services.pullSecretThe name of the Secret that stores the pull secret for pulling the OpenUnison image
services.resources.requests.memoryMemory requested by OpenUnison
services.resources.requests.cpuCPU requested by OpenUnison
services.resources.limits.memoryMaximum memory allocated to OpenUnison
services.resources.limits.cpuMaximum CPU allocated to OpenUnison
openunison.replicasThe number of OpenUnison replicas to run, defaults to 1
openunison.non_secret_dataAdd additional non-secret configuration options, added to the non_secret_data secrtion of the OpenUnison object
openunison.secretsAdd additional keys from the orchestra-secrets-source Secret
impersonation.use_jetstackif true, the operator will deploy an instance of JetStack's OIDC Proxy (https://github.com/jetstack/kube-oidc-proxy). Default is false
impersonation.jetstack_oidc_proxy_imageThe name of the image to use
impersonation.explicit_certificate_trustIf true, oidc-proxy will explicitly trust the tls.crt key of the Secret named in impersonation.ca_secret_name. Defaults to true
impersonation.ca_secret_nameIf impersonation.explicit_certificate_trust is true, the name of the tls Secret that stores the certificate for OpenUnison that the oidc proxy needs to trust. Defaults to ou-tls-secret
impersonation.resources.requests.memoryMemory requested by oidc proxy
impersonation.resources.requests.cpuCPU requested by oidc proxy
impersonation.resources.limits.memoryMaximum memory allocated to oidc proxy
impersonation.resources.limits.cpuMaximum CPU allocated to oidc proxy
myvd_configmapThe name of a ConfigMap with a key called myvd.conf that will override the MyVD configuration

Additionally, you can add your identity provider's TLS base64 encoded PEM certificate to your values under trusted_certs for pem_b64. This will allow OpenUnison to talk to your identity provider using TLS if it doesn't use a commercially signed certificate. If you don't need a certificate to talk to your identity provider, replace the trusted_certs section with trusted_certs: [].

Finally, run the helm chart:

helm install orchestra tremolo/openunison-k8s-login-oidc --namespace openunison -f /path/to/values.yaml

Complete SSO Integration with Kubernetes

Run kubectl describe configmap api-server-config -n openunison to get the SSO integration artifacts. The output will give you both the API server flags that need to be configured on your API servers. The certificate that needs to be trusted is in the ou-tls-certificate secret in the openunison namespace.

First Login

To login, open your browser and go to the host you specified for OU_HOST in your input.props. For instance if OU_HOST is k8sou.tremolo.lan then navigate to https://k8sou.tremolo.lan. You'll be prompted for your Active Directory username and password. Once authenticated you'll be able login to the portal and generate your .kube/config from the Tokens screen.

CLI Login

You can bypass manually launching a browser with the oulogin kubectl plugin - https://github.com/TremoloSecurity/kubectl-login. This plugin will launch a browser for you, authenticate you then configure your kubectl configuration without any pre-configuration on your clients.

Enabling JetStack OIDC Proxy for Impersonation

OpenUnison's built in reverse proxy doesn't support the SPDY protocol which kubectl, and the client-go sdk, uses for exec, cp, and port-forward. If you require these options, and are using impersonation, you can now enable the JetStack OIDC proxy (https://github.com/jetstack/kube-oidc-proxy) instead of using OpenUnison's built in reverse proxy. To enable it, add the impersonation options from the helm chart configuration to your chart.

Deploy openunison-k8s-login-oidc with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has openunison-k8s-login-oidc on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartopenunison-k8s-login-oidc is pinned at v1.0.24 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply