Skip to content

Commit

Permalink
feat(twin): add oidc user support
Browse files Browse the repository at this point in the history
  • Loading branch information
HoKim98 committed Aug 28, 2024
1 parent 0371e55 commit c25bf3c
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/oidc-login/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
13 changes: 13 additions & 0 deletions charts/oidc-login/.schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
input:
- values.yaml

draft: 2020
indent: 2
output: values.schema.json

schemaRoot:
id: https://smartx-team.github.io/mobilex-api/charts/nvidia-isaac-sim
title: NVIDIA Issac-Sim Schema
description: Schema for NVIDIA Issac-Sim Helm Chart
additionalProperties: true
25 changes: 25 additions & 0 deletions charts/oidc-login/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
apiVersion: v2
name: oidc-login
description: Convenient OIDC authorization tool per user

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: latest
30 changes: 30 additions & 0 deletions charts/oidc-login/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# OIDC Login

## Usage

```bash
# Register the MobileX API repository
helm repo add mobilex "https://smartx-team.github.io/mobilex-api"

# Deploy authorization rules
NAME="my-user-name" # TODO: Change it to your oidc username
helm install $NAME "mobilex/oidc-login" \
--namespace "name-twin"
```

## Uninstall

```bash
NAME="my-user-name" # TODO: Change it to your oidc username
helm uninstall $NAME --namespace "oidc-login"
```

## Validating

```bash
# Install json schema generator
helm plugin install "https://github.com/losisin/helm-values-schema-json.git"

# Create a json schema
helm schema
```
58 changes: 58 additions & 0 deletions charts/oidc-login/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "oidc-login.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "oidc-login.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Expand the name of the user.
*/}}
{{- define "oidc-login.userName" -}}
{{- default .Chart.Name .Values.account.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "oidc-login.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "oidc-login.labels" -}}
helm.sh/chart: {{ include "oidc-login.chart" . }}
{{ include "oidc-login.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "oidc-login.selectorLabels" -}}
app.kubernetes.io/name: {{ include "oidc-login.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
15 changes: 15 additions & 0 deletions charts/oidc-login/templates/clusterrolebinding.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: "oidc:{{ include "oidc-login.userName" . }}:{{ include "oidc-login.fullname" . }}"
labels:
{{- include "oidc-login.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: "{{ .Values.account.clusterRoleName }}"
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name: "oidc:{{ include "oidc-login.userName" . }}"
15 changes: 15 additions & 0 deletions charts/oidc-login/templates/rolebinding.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ include "oidc-login.fullname" . }}
labels:
{{- include "oidc-login.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: "{{ .Values.account.roleName }}"
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name: "oidc:{{ include "oidc-login.userName" . }}"
6 changes: 6 additions & 0 deletions charts/oidc-login/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
account:
clusterRoleName: twin-admin
roleName: twin-admin

nameOverride: null

0 comments on commit c25bf3c

Please sign in to comment.