diff options
author | Amit Rathi <amit.juschill@gmail.com> | 2019-05-22 20:16:17 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2019-05-22 20:16:17 +0000 |
commit | 158a14ec202b5001dd84f24a691ae32a8895ca0c (patch) | |
tree | 4bb0df40766964add92e079cfde7def117cbd88a | |
parent | 728ddeb6ae3e7112f027696d0d54ddb5375bb907 (diff) | |
download | gitlab-ce-158a14ec202b5001dd84f24a691ae32a8895ca0c.tar.gz |
JupyterHub Repo Integration
-rw-r--r-- | app/models/clusters/applications/jupyter.rb | 9 | ||||
-rw-r--r-- | changelogs/unreleased/jupyter_pre_spawn_hook_v2.yml | 5 | ||||
-rw-r--r-- | vendor/jupyter/values.yaml | 20 |
3 files changed, 34 insertions, 0 deletions
diff --git a/app/models/clusters/applications/jupyter.rb b/app/models/clusters/applications/jupyter.rb index 36c51522089..bd9c453e2a4 100644 --- a/app/models/clusters/applications/jupyter.rb +++ b/app/models/clusters/applications/jupyter.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'securerandom' + module Clusters module Applications class Jupyter < ApplicationRecord @@ -80,6 +82,9 @@ module Clusters "secretToken" => secret_token }, "auth" => { + "state" => { + "cryptoKey" => crypto_key + }, "gitlab" => { "clientId" => oauth_application.uid, "clientSecret" => oauth_application.secret, @@ -95,6 +100,10 @@ module Clusters } end + def crypto_key + @crypto_key ||= SecureRandom.hex(32) + end + def project_id cluster&.project&.id end diff --git a/changelogs/unreleased/jupyter_pre_spawn_hook_v2.yml b/changelogs/unreleased/jupyter_pre_spawn_hook_v2.yml new file mode 100644 index 00000000000..c5918df8193 --- /dev/null +++ b/changelogs/unreleased/jupyter_pre_spawn_hook_v2.yml @@ -0,0 +1,5 @@ +--- +title: Pass user's identity and token from JupyterHub to user's Jupyter environment +merge_request: 27314 +author: Amit Rathi +type: added diff --git a/vendor/jupyter/values.yaml b/vendor/jupyter/values.yaml index 781d6e3042f..a5e13fdc104 100644 --- a/vendor/jupyter/values.yaml +++ b/vendor/jupyter/values.yaml @@ -8,8 +8,28 @@ hub: extraConfig: | c.KubeSpawner.cmd = ['jupyter-labhub'] + async def add_auth_env(spawner): + ''' + We set user's id, login and access token on single user image to + enable repository integration for JupyterHub. + See: https://gitlab.com/gitlab-org/gitlab-ce/issues/47138#note_154294790 + ''' + auth_state = await spawner.user.get_auth_state() + + if not auth_state: + spawner.log.warning("No auth state for %s", spawner.user) + return + + spawner.environment['GITLAB_ACCESS_TOKEN'] = auth_state['access_token'] + spawner.environment['GITLAB_USER_LOGIN'] = auth_state['gitlab_user']['username'] + spawner.environment['GITLAB_USER_ID'] = str(auth_state['gitlab_user']['id']) + + c.KubeSpawner.pre_spawn_hook = add_auth_env + auth: type: gitlab + state: + enabled: true singleuser: defaultUrl: "/lab" |