Skip to content

Commit

Permalink
Misc README updates
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Oct 14, 2021
1 parent d40e2cb commit f7f195c
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,33 @@ Prior to JupyterHub 2.0, the `jupyterhub-idle-culler` required full administrati
in order to have sufficient permissions to stop servers on behalf of users.

JupyterHub 2.0 introduces [scopes][] to allow for more fine-grained permission control.
This means that the cull-idle service does not need full administrative privileges anymore.
This means that the configured culler service does not need full administrative privileges anymore.
It can be assigned only the permissions it needs.

[scopes]: https://jupyterhub.readthedocs.io/en/latest/rbac/scopes.html#available-scopes

`jupyterhub-idle-culler` requires the following scopes to function:

- `read:hub` - access to the hub's version information
- `list:users` - access to the user list API, our source of information about who to cull
- `read:users:activity` - read the last_activity field of the user
- `servers` - management of servers (this includes stopping servers and reading the server model)
- `delete:servers` - management of servers (this includes stopping servers)
- `admin:users` (**optional**) - only needed if using `--cull-users`

To assign the service the appropriate permissions, declare a role in your `jupyterhub_config.py`:

```python
c.JupyterHub.load_roles = [
{
"name": "cull-idle",
"name": "jupyterhub-idle-culler",
"scopes": [
"read:hub",
"list:users",
"read:users:activity",
"delete:servers",
# "admin:users", # if using --cull-users
],
"services": ["idle-culler"], # assign our service to this role, so it has these permissions
"services": ["jupyterhub-idle-culler"], # assign the role's permission to this service
}
]
```
Expand All @@ -62,57 +63,55 @@ Service to the `c.JupyterHub.services` list:
```python
c.JupyterHub.services = [
{
'name': 'idle-culler',
# 'admin': True,
'command': [
"name": "jupyterhub-idle-culler",
"command": [
sys.executable,
'-m', 'jupyterhub_idle_culler',
'--timeout=3600'
"-m", "jupyterhub_idle_culler",
"--timeout=3600",
],
# "admin": True,
}
]
```

where:

- `'admin': True` indicates that the Service requires admin permissions so
it can shut down arbitrary user notebooks
(only for jupyterhub < 2.0; see [above][permissions]), and
- `'command'` indicates that the Service will be managed by the Hub.
- `"command"` indicates that the Service will be managed by the Hub, and
- `"admin": True` grants admin permissions to this Service and is only meant for
use with jupyterhub < 2.0; see [above][permissions].

### As a standalone script

`jupyterhub-idle-culler` can also be run as a standalone script. It can
access the hub's api with a service token.

Register the service token with JupyterHub in jupyterhub_config.py:
Register the service token with JupyterHub in `jupyterhub_config.py`:

```python
c.JupyterHub.services = [
{
'name': 'idle-culler',
# 'admin': True,
'api_token': '...',
"name": "jupyterhub-idle-culler",
"api_token": "...",
# "admin": True,
}
]
```

where:

- `'admin': True` indicates that the Service requires admin permissions so
it can shut down arbitrary user notebooks
(only for jupyterhub < 2.0; see [above][permissions]), and
- `'api_token'` contains a secret token, e.g. generated by `openssl rand -hex 32`
- `'api_token'` contains a secret token, e.g. generated by `openssl rand -hex 32`, and
- `"admin": True` grants admin permissions to this Service and is only meant for
use with jupyterhub < 2.0; see [above][permissions].

and store the same token in a `JUPYTERHUB_API_TOKEN` environment variable.
Then start `jupyterhub-idle-culler` manually
Then start `jupyterhub-idle-culler` manually.

```bash
export JUPYTERHUB_API_TOKEN=api_token_above...
python3 -m jupyterhub-idle-culler [--timeout=900] [--url=http://localhost:8081/hub/api]
```

The command line interface also gives a quick overview of the different options for configuration.
## Command line flags

```
--api-page-size Number of users to request per page, when
Expand All @@ -124,6 +123,8 @@ The command line interface also gives a quick overview of the different options
same time can slow down the Hub, so limit
the number of API requests we have
outstanding at any given time. (default 10)
--cull-admin-users Whether admin users should be culled (only
if --cull-users=true). (default True)
--cull-every The interval (in seconds) for checking for
idle servers to cull. (default 0)
--cull-users Cull users in addition to servers. This is
Expand Down

0 comments on commit f7f195c

Please sign in to comment.