Skip to content

Commit 9b1310b

Browse files
Refactor role creation for upgrade command path (#2795)
Co-authored-by: Adam Lewis <[email protected]>
1 parent 88dfe24 commit 9b1310b

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

src/_nebari/upgrade.py

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,22 @@ class Upgrade_2024_9_1(UpgradeStep):
12141214

12151215
version = "2024.9.1"
12161216

1217+
# Nebari version 2024.9.1 has been marked as broken, and will be skipped:
1218+
# https://github.com/nebari-dev/nebari/issues/2798
1219+
@override
1220+
def _version_specific_upgrade(
1221+
self, config, start_version, config_filename: Path, *args, **kwargs
1222+
):
1223+
return config
1224+
1225+
1226+
class Upgrade_2024_11_1(UpgradeStep):
1227+
"""
1228+
Upgrade step for Nebari version 2024.11.1
1229+
"""
1230+
1231+
version = "2024.11.1"
1232+
12171233
@override
12181234
def _version_specific_upgrade(
12191235
self, config, start_version, config_filename: Path, *args, **kwargs
@@ -1243,16 +1259,16 @@ def _version_specific_upgrade(
12431259
Please ensure no users are currently logged in prior to deploying this
12441260
update.
12451261
1246-
Nebari [green]2024.9.1[/green] introduces changes to how group
1247-
directories are mounted in JupyterLab pods.
1262+
This release introduces changes to how group directories are mounted in
1263+
JupyterLab pods.
12481264
12491265
Previously, every Keycloak group in the Nebari realm automatically created a
12501266
shared directory at ~/shared/<group-name>, accessible to all group members
12511267
in their JupyterLab pods.
12521268
1253-
Starting with Nebari [green]2024.9.1[/green], only groups assigned the
1254-
JupyterHub client role [magenta]allow-group-directory-creation[/magenta] will have their
1255-
directories mounted.
1269+
Moving forward, only groups assigned the JupyterHub client role
1270+
[magenta]allow-group-directory-creation[/magenta] or its affiliated scope
1271+
[magenta]write:shared-mount[/magenta] will have their directories mounted.
12561272
12571273
By default, the admin, analyst, and developer groups will have this
12581274
role assigned during the upgrade. For other groups, you'll now need to
@@ -1268,7 +1284,7 @@ def _version_specific_upgrade(
12681284
# Prompt the user for role assignment (if yes, transforms the response into bool)
12691285
assign_roles = (
12701286
Prompt.ask(
1271-
"[bold]Would you like Nebari to assign the corresponding role to all of your current groups automatically?[/bold]",
1287+
"[bold]Would you like Nebari to assign the corresponding role/scopes to all of your current groups automatically?[/bold]",
12721288
choices=["y", "N"],
12731289
default="N",
12741290
).lower()
@@ -1286,13 +1302,31 @@ def _version_specific_upgrade(
12861302
username="root",
12871303
password=config["security"]["keycloak"]["initial_root_password"],
12881304
)
1289-
1290-
# Proceed with updating group permissions
1305+
# Get client ID as role is bound to the JupyterHub client
12911306
client_id = keycloak_admin.get_client_id("jupyterhub")
1292-
role_name = "allow-group-directory-creation-role"
1307+
role_name = "legacy-group-directory-creation-role"
1308+
1309+
# Create role with shared scopes
1310+
keycloak_admin.create_client_role(
1311+
client_role_id=client_id,
1312+
skip_exists=True,
1313+
payload={
1314+
"name": role_name,
1315+
"attributes": {
1316+
"scopes": ["write:shared-mount"],
1317+
"component": ["shared-directory"],
1318+
},
1319+
"description": (
1320+
"Role to allow group directory creation, created as part of the "
1321+
"Nebari 2024.11.1 upgrade workflow."
1322+
),
1323+
},
1324+
)
1325+
12931326
role_id = keycloak_admin.get_client_role_id(
12941327
client_id=client_id, role_name=role_name
12951328
)
1329+
12961330
role_representation = keycloak_admin.get_role_by_id(role_id=role_id)
12971331

12981332
# Fetch all groups and groups with the role

0 commit comments

Comments
 (0)