Skip to content

Commit

Permalink
Merge pull request #179 from vre-hub/flux_jhub
Browse files Browse the repository at this point in the history
Migrate jhub from tf ro flux
  • Loading branch information
goseind authored Jul 24, 2023
2 parents 90bf1df + fa95e8c commit 06dd0fb
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 307 deletions.
9 changes: 9 additions & 0 deletions infrastructure/cluster/flux-v2/jhub/jhub-charts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: HelmRepository
metadata:
name: jhub
namespace: jhub
spec:
interval: 10m
url: https://hub.jupyter.org/helm-chart/

6 changes: 6 additions & 0 deletions infrastructure/cluster/flux-v2/jhub/jhub-ns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# kind: Namespace
# apiVersion: v1
# metadata:
# name: jhub
# labels:
# name: jhub
13 changes: 13 additions & 0 deletions infrastructure/cluster/flux-v2/jhub/jhub-profiles-cm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: jhub-profiles
namespace: jhub
data:
values.yaml: |
singleuser:
profileList:
- display_name: "Default profile"
description: "A jupyter/scipy-notebook env with python-3.9, the rucio-jupyterlab extension and the reana-client installed."
default: True
281 changes: 281 additions & 0 deletions infrastructure/cluster/flux-v2/jhub/jhub-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: jhub-cvre
namespace: jhub
spec:
releaseName: jhub-cvre
interval: 5m
chart:
spec:
sourceRef:
kind: HelmRepository
name: jhub
namespace: jhub
chart: jupyterhub
interval: 5m
version: 2.0.0
valuesFrom:
- kind: Secret
name: jhub-cvre-iam-secrets
valuesKey: client_id
targetPath: hub.config.RucioAuthenticator.client_id
- kind: Secret
name: jhub-cvre-iam-secrets
valuesKey: client_secret
targetPath: hub.config.RucioAuthenticator.client_secret
- kind: Secret
name: jhub-cvre-dbconnectstring
valuesKey: dbconnectstring
targetPath: hub.db.url
- kind: ConfigMap
name: jupyter-profiles
valuesKey: values.yaml
values:
proxy:
service:
type: ClusterIP
hub:
service:
type: ClusterIP
# network policy needs to be modified to allow access to the Rucio server
# (disabling it for now as a workaround, see also the ones for singeluser and proxy below)
networkPolicy:
enabled: false
db:
type: postgres # secret dbconnect string set in main-helm.tf
config:
RucioAuthenticator:
# client_id: "" # set through secret
# client_secret: "" # set through secret
authorize_url: https://iam-escape.cloud.cnaf.infn.it/authorize
token_url: https://iam-escape.cloud.cnaf.infn.it/token
userdata_url: https://iam-escape.cloud.cnaf.infn.it/userinfo
username_key: preferred_username
scope:
- openid
- profile
- email
extraConfig:
token-exchange: |
import pprint
import os
import warnings
import requests
from oauthenticator.generic import GenericOAuthenticator
# custom authenticator to exchange the access token for a refresh token for rucio OIDC to work
class RucioAuthenticator(GenericOAuthenticator):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.enable_auth_state = True
def exchange_token(self, token):
params = {
'client_id': self.client_id,
'client_secret': self.client_secret,
'grant_type': 'urn:ietf:params:oauth:grant-type:token-exchange',
'subject_token': token,
'scope': 'openid email profile',
'audience': 'rucio'
}
response = requests.post(self.token_url, data=params)
refresh_token = response.json()['access_token']
return refresh_token
async def pre_spawn_start(self, user, spawner):
auth_state = await user.get_auth_state()
pprint.pprint(auth_state)
if not auth_state:
# user has no auth state
return
# define token environment variable from auth_state
spawner.environment['REFRESH_TOKEN'] = self.exchange_token(auth_state['access_token'])
# set the above authenticator as the default
c.JupyterHub.authenticator_class = RucioAuthenticator
# enable authentication state
c.GenericOAuthenticator.enable_auth_state = True
if 'JUPYTERHUB_CRYPT_KEY' not in os.environ:
warnings.warn(
"Need JUPYTERHUB_CRYPT_KEY env for persistent auth_state.\n"
" export JUPYTERHUB_CRYPT_KEY=$(openssl rand -hex 32)"
)
c.CryptKeeper.keys = [os.urandom(32)]
singleuser:
defaultUrl: "/lab"
# The liefcycle hooks are used to create the Rucio configuration file,
# and the token file by copying the REFRESH_TOKEN from the environment variable to the token file.
lifecycleHooks:
postStart:
exec:
command:
- "sh"
- "-c"
- >
echo -n $REFRESH_TOKEN > /home/jovyan/token;
mkdir -p /opt/rucio/etc;
echo "[client]" >> /opt/rucio/etc/rucio.cfg;
echo "rucio_host = https://vre-rucio.cern.ch" >> /opt/rucio/etc/rucio.cfg;
echo "auth_host = https://vre-rucio-auth.cern.ch" >> /opt/rucio/etc/rucio.cfg;
echo "ca_cert = /opt/cert.pem" >> /opt/rucio/etc/rucio.cfg;
echo "account = $JUPYTERHUB_USER" >> /opt/rucio/etc/rucio.cfg;
echo "auth_type = oidc" >> /opt/rucio/etc/rucio.cfg;
echo "oidc_audience = rucio" >> /opt/rucio/etc/rucio.cfg;
echo "auth_token_file_path = /home/jovyan/token" >> /opt/rucio/etc/rucio.cfg;
networkPolicy:
enabled: false
storage:
type: static
static:
pvcName: jhub-singleuser # manually created StorageClass with Retain policy and PVC with 800Gi (refer to main-k8s.tf)
extraVolumes:
# - name: cvfms-from-vre # commented out not working
# persistentVolumeClaim:
# claimName: cvfms
- name: eulake-escape-data # mounts the EOS RSE needed for the Rucio JupiterLab extension
hostPath:
path: /var/eos-eulake-home/eulake/escape/data
extraVolumeMounts:
# - name: cvfms-from-vre # commented out not working
# mountPath: /cvfms
# # CVMFS automount volumes must be mounted with HostToContainer mount propagation.
# mountPropagation: HostToContainer
- name: eulake-escape-data # mounts the EOS RSE needed for the Rucio JupiterLab extension
mountPath: /eos/escape/
mountPropagation: HostToContainer
readOnly: true
image:
name: ghcr.io/vre-hub/vre-singleuser:sha-7210810
tag: latest
pullPolicy: Always
extraFiles:
ca:
mountPath: /opt/cert.pem
stringData: |
-----BEGIN CERTIFICATE-----
MIIGqTCCBJGgAwIBAgIQAojDcLlcbrhBX0qrEka4mzANBgkqhkiG9w0BAQ0FADBK
MQswCQYDVQQGEwJjaDENMAsGA1UEChMEQ0VSTjEsMCoGA1UEAxMjQ0VST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pt+H
n30awoaDoMuHcGS5B6NOZLfwE+suTxMw8pjHhKXx7RkSoeZy72PinlbWn1tWLiPa
UMdkrb/WHOdMKaadQTDO/VyibBL49iJ8BAlERgIl9QaRDLjAIdD45rLdBe95HxSl
zpZqsxuI09eJ8+iLFJhTDH2BODoEuqbn6PB/5z2d5zuG5sr85Vzn81ddapuUT9Ra
/dB5eJQeFZ0WjtUOO3gS/A==
-----END CERTIFICATE-----
cmd: null
extraEnv:
JUPYTERHUB_SINGLEUSER_APP: "notebook.notebookapp.NotebookApp"
RUCIO_MODE: "replica"
RUCIO_WILDCARD_ENABLED: "1"
RUCIO_BASE_URL: "https://vre-rucio.cern.ch"
RUCIO_AUTH_URL: "https://vre-rucio-auth.cern.ch"
RUCIO_DISPLAY_NAME: "VRE-RUCIO"
RUCIO_NAME: "vre-rucio.cern.ch"
RUCIO_SITE_NAME: "ROAMING"
RUCIO_OIDC_AUTH: "env"
RUCIO_OIDC_ENV_NAME: "REFRESH_TOKEN"
RUCIO_DEFAULT_AUTH_TYPE: "oidc"
RUCIO_OAUTH_ID: "rucio"
RUCIO_DEFAULT_INSTANCE: "vre-rucio.cern.ch"
RUCIO_DESTINATION_RSE: "CERN-EOS"
RUCIO_RSE_MOUNT_PATH: "/eos/escape"
RUCIO_PATH_BEGINS_AT: "5"
RUCIO_CA_CERT: "/opt/cert.pem" # this could be set in the image as well
ingress:
enabled: true
ingressClassName: nginx
annotations:
cert-manager.io/cluster-issuer: "letsencrypt" # this issues a certificate for the domain through cert-manager automatically
hosts:
- jhub-vre.cern.ch
tls:
- hosts:
- jhub-vre.cern.ch
secretName: cert-manager-tls-ingress-secret-jhub

Loading

0 comments on commit 06dd0fb

Please sign in to comment.