OAuthenticator:使用通用OAuth提供程序验证JupyterHub用户
oauthenticator的Python项目详细描述
OAuthenticator
oauth+jupyterhub authenticator=oauthenticator
OAuthenticator当前支持以下身份验证服务:
a通用实现,可以与 也提供任何提供商。
示例
有关使用OAuthenticator的Docker映像示例,请参见示例 目录。
另一个示例 正在使用github oauth在单独的docker中生成每个用户的服务器 容器。
安装
使用pip安装:
pip3 install oauthenticator
或者克隆repo并进行dev安装:
git clone https://github.com/jupyterhub/oauthenticator.git
cd oauthenticator
pip3 install -e .
一般设置
第一步是告诉jupyterhub使用您选择的oauthenticator。各
authenticator在oauthenticator
的子模块中提供,并且每个
authenticator有一个带有local
的变量(例如localgithuboauthenticator
),
将OAuth用户名映射到本地系统用户名。
设置选定的OAuthenticator
在jupyterhub配置py中,添加:
fromoauthenticator.githubimportGitHubOAuthenticatorc.JupyterHub.authenticator_class=GitHubOAuthenticator
设置回调URL、客户端ID和客户端机密
所有OAuthenticator都需要设置回调URL、客户端ID和客户端 秘密。通常在注册oauth应用程序时会得到这些 与您的oauth提供者。特定于提供程序的详细信息在部分中提供 下面。在向您的提供商注册OAuth应用程序时,您将 可能需要指定回调URL。 回调url应该如下所示:
http[s]://[your-host]/hub/oauth_callback
其中[主机]
是服务器将运行的位置。如
example.com:8000
当jupyterhub运行时,将从环境变量中检索这些值:
$OAUTH_CALLBACK_URL$OAUTH_CLIENT_ID$OAUTH_CLIENT_SECRET
您还可以在配置文件中设置这些值
c.MyOAuthenticator.oauth_callback_url='http[s]://[your-host]/hub/oauth_callback'c.MyOAuthenticator.client_id='your-client-id'c.MyOAuthenticator.client_secret='your-client-secret'
azure设置
先决条件- 要求:
pyjwt>;=1.5.3
> pip3 install PyJWT
- 请确保设置环境变量
> export AAD_TENANT_ID='{AAD-TENANT-ID}'
- 示例代码在
examples>;azuread>;sample_jupyter_config.py中提供
- 只需将下面的代码添加到您的
jupyterhub\u config.py
文件中- 确保将
'{}'
中的值替换为应用程序、租户、域等的值 - 只需将下面的代码添加到您的
然后,将以下内容添加到您的jupyterhub_config.py
文件中:
pip3 install oauthenticator
1
您还可以使用localgithuboauthenticator
将github帐户映射到本地用户。
通过设置环境变量,您可以使用自己的github企业实例。
如果您的github企业只支持http,则可以将环境变量设置为true或任何设置。
Github允许通过 将特定于github的作用域添加到请求的令牌。
Gitlab设置
首先,您需要创建一个gitlab oauth 应用程序
然后,将以下内容添加到您的jupyterhub_config.py
文件中:
pip3 install oauthenticator
2
您还可以使用localgitlaboauthenticator
将gitlab帐户映射到本地用户。
您可以通过设置gitlab_host
环境来使用自己的gitlab ce/ee实例
旗.
谷歌设置
访问https://console.developers.google.com" rel="nofollow">https://console.developers.google.com设置OAuth客户端ID和机密。有关如何创建OAuth 2.0客户端凭据,请参见谷歌文档。授权的javascript源代码
应设置为集线器的公共地址,而授权的重定向uri
应设置为相同,但后面紧跟/hub/oauth_回调
然后,将以下内容添加到您的jupyterhub_config.py
文件中:
pip3 install oauthenticator
3
默认情况下,允许任何域登录,但您可以使用列表(推荐)限制授权域:
pip3 install oauthenticator
4
您可以自定义登录按钮文本(可选):
pip3 install oauthenticator
5
打开换档设置
如果您使用正确配置的oauth进行openshift部署(请参见
下面几节是快速参考),您应该设置客户机ID和
环境变量的secretoauth_client_id
,oauth_client_secret
和
oauth_callback_url
在openshift 4.0之前,oauth提供者和rest api url端点可以
通过设置单个环境变量openshift_url
来指定。从
openshift 4.0以后,这两个端点位于不同的主机上。你需要
将openshift-auth-api-url设置为oauth提供程序url,然后
openshift_rest_api_url
到rest api url端点。
oauth_回调url应该匹配http[s]://[your app route]/hub/oauth_回调
全球OAuth(管理员)
作为集群管理员,您可以创建一个全局的oauth客户端 在openshift集群中,使用api创建新的oauthclient对象:
pip3 install oauthenticator
6
作为OAuth客户端的服务帐户
作为项目成员,您可以将服务帐户用作oauth客户机" rel="nofollow">服务帐户用作oauth客户机 脚本。这使您可以定义与 服务帐户。您只需要使用 正确的注释:
pip3 install oauthenticator
7
在这种情况下,您的oauth_client_id将是系统:ServiceAccount:<;ServiceAccount_namespace>;:<;ServiceAccount_name&< /代码>
oauth_client_secret是服务帐户的api令牌(
oc sa get token<;service account_name>;
)
而oauth_callback_url是注释serviceaccounts.openshift.io/oauth redirecturi.1的值。
更多详细信息请参见上游文档。
okpyauthenticator
okpy是一个自动评分工具
广泛应用于加州大学伯克利分校的eecs和数据科学课程。这个验证者
通过使学生能够通过
首先保存相关的用户状态
到env
(在开发安全状态保存机制之前,该功能将被编辑)。
配置
如果要使用okpyauthenticator对集线器进行身份验证,则需要指定 jupyterhub config.py文件中的authenticator类:
pip3 install oauthenticator
8
并设置环境变量。
globus设置
访问https://developers.globus.org/" rel="nofollow">https://developers.globus.org/设置应用程序。确保本机应用程序 取消选中并确保回调url如下所示:
pip3 install oauthenticator
9
设置授权和传输的作用域。默认值包括:
git clone https://github.com/jupyterhub/oauthenticator.git
cd oauthenticator
pip3 install -e .
0
在 或者,您可以为以下对象设置env变量:jupyterhub配置中设置上述设置
。需要设置jupyterhub_crypt_key,并且可以生成
使用openssl:
1
git clone https://github.com/jupyterhub/oauthenticator.git
cd oauthenticator
pip3 install -e .
oauth_callback_url
,oauth_client_id
,
以及oauth_client_secretopenssl rand-hex 32
你们都被这一点给定了!一定要检查下面的调整设置 与用户身份、传输和附加安全性相关。
用户身份
默认情况下,所有用户都被限制在其globus id(example@globusid.org) 使用默认的jupyterhub配置:
git clone https://github.com/jupyterhub/oauthenticator.git
cd oauthenticator
pip3 install -e .
2
如果要使用链接标识,例如malcolm@universityofindependence.edu
,
转到您的应用程序开发人员页面并设置
您的应用程序所需的身份提供程序设置为<;your university>;
,并设置
配置如下:
git clone https://github.com/jupyterhub/oauthenticator.git
cd oauthenticator
pip3 install -e .
3
全球范围和转移
默认配置将使用令牌自动设置用户环境,
允许他们启动python笔记本并启动globus传输。如果你
要将数据传输到jupyterhub服务器,建议您安装
globus connect server并在下面添加globus戋u local戋端点
uuid。如果你想要
要更改其他行为,可以修改以下默认设置:
git clone https://github.com/jupyterhub/oauthenticator.git
cd oauthenticator
pip3 install -e .
4
如果您只想用globus id验证用户,但不想
允许他们进行传输,您可以删除urn:globus:auth:scope:transfer.api.globus.org:all
。
相反,如果愿意,可以为另一个传输服务器添加一个附加作用域。
使用c.globusoauthenticator.exclude
防止令牌传递到
用户环境。默认情况下,auth.globus.org
被排除在外,但transfer.api.globus.org
是允许的。如果要禁用传输,请修改c.globusoauthenticator.scope
而不是c.globusoauthenticator.exclude来避免获取不必要的令牌。
moodle设置
首先为moodle安装oauth2服务器插件。
为jupyterhub使用genericoauthenticator
,方法是相应地编辑jupyterhub配置py
:
git clone https://github.com/jupyterhub/oauthenticator.git
cd oauthenticator
pip3 install -e .
5
并将环境变量oauth2\u authorize\u url
设置为:
http://your-moodle-domain.com/local/oauth/login.php?客户ID=moodle-client-id&response\u type=code