Skip to content

Commit 1ff555e

Browse files
test(studio): clarify default admin access (#705)
1 parent bdea1af commit 1ff555e

6 files changed

Lines changed: 122 additions & 11 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,10 @@ veadk studio deploy \
220220
--developer "alice@example.com,bob@example.com"
221221
```
222222

223-
Supplying either role list enables role-based access control; users not in a
224-
list are regular users, and `admin` wins when an identity appears in both
225-
lists. Admins have all Studio capabilities and can see every Runtime.
223+
Omitting both role lists makes every signed-in user an `admin`. Supplying
224+
either list enables role-based access control; users not in a list are regular
225+
users, and `admin` wins when an identity appears in both lists. Admins have all
226+
Studio capabilities and can see every Runtime.
226227
Developers can add and manage agents but can see and manage only their own
227228
Runtimes. Regular users can see only their own Runtimes; the add/manage-agent
228229
sidebar items are hidden. The sidebar account footer shows the OAuth email

‎docs/content/docs/framework/frontend.en.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ veadk studio deploy \
231231
--developer "alice@example.com,bob@example.com"
232232
```
233233

234-
Supplying either list enables role-based access control. An identity that does
235-
not match either list is a regular user. Omitting both options preserves the
236-
existing unrestricted Studio behavior.
234+
Omitting both options treats every signed-in user as an `admin`. Supplying
235+
either list enables role-based access control. An identity that does not match
236+
either list is a regular user.
237237

238238
| Capability | admin | developer | Regular user |
239239
| :-- | :-- | :-- | :-- |

‎docs/content/docs/framework/frontend.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ veadk studio deploy \
209209
--developer "alice@example.com,bob@example.com"
210210
```
211211

212-
只要传入任一名单就会启用角色权限;未命中名单的身份是普通用户。两项都不传时
213-
保留原有行为,不限制 Studio 功能。
212+
两项都不传时,所有登录用户都按管理员(`admin`)处理。只要传入任一名单就会启用
213+
角色权限;未命中名单的身份是普通用户。
214214

215215
| 功能 | admin | developer | 普通用户 |
216216
| :-- | :-- | :-- | :-- |

‎tests/cli/test_studio_deploy_target.py‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ def register_callback_for_user_pool_client(self, **kwargs: object) -> None:
118118
assert captured["region"] == expected_region
119119
assert captured["project"] == expected_project
120120
assert veadk_environments["VEIDENTITY_REGION"] == expected_identity_region
121+
assert "VEADK_STUDIO_ADMINS" not in veadk_environments
122+
assert "VEADK_STUDIO_DEVELOPERS" not in veadk_environments
121123
assert f"{expected_region}/{expected_project}" in result.output
122124
assert ("Warning:" in result.output) == (
123125
expected_identity_region != expected_region
@@ -128,6 +130,78 @@ def register_callback_for_user_pool_client(self, **kwargs: object) -> None:
128130
assert callback["skip_consent_enabled"] is True
129131

130132

133+
@pytest.mark.parametrize(
134+
("role_args", "expected_environment"),
135+
[
136+
(
137+
["--admin", "admin@example.com"],
138+
{"VEADK_STUDIO_ADMINS": "admin@example.com"},
139+
),
140+
(
141+
["--developer", "dev@example.com"],
142+
{"VEADK_STUDIO_DEVELOPERS": "dev@example.com"},
143+
),
144+
],
145+
)
146+
def test_studio_deploy_enables_rbac_when_either_role_is_configured(
147+
monkeypatch: pytest.MonkeyPatch,
148+
role_args: list[str],
149+
expected_environment: dict[str, str],
150+
) -> None:
151+
class _FakeCloudAgentEngine:
152+
def __init__(self, **_: object) -> None:
153+
pass
154+
155+
def deploy(self, **_: object) -> SimpleNamespace:
156+
return SimpleNamespace(
157+
vefaas_endpoint="https://studio.example.com",
158+
vefaas_application_id="app-id",
159+
vefaas_function_id="",
160+
)
161+
162+
monkeypatch.setattr(
163+
"veadk.cloud.cloud_agent_engine.CloudAgentEngine", _FakeCloudAgentEngine
164+
)
165+
monkeypatch.setattr(
166+
"veadk.cli.cli_frontend._resolve_studio_identity_region",
167+
lambda **_: "cn-beijing",
168+
)
169+
monkeypatch.setattr(
170+
"veadk.integrations.ve_identity.identity_client.IdentityClient.register_callback_for_user_pool_client",
171+
lambda *_args, **_kwargs: None,
172+
)
173+
174+
result = CliRunner().invoke(
175+
studio,
176+
[
177+
"deploy",
178+
"--user-pool-id",
179+
"pool-id",
180+
"--allowed-client-id",
181+
"client-id",
182+
"--vefaas-app-name",
183+
"studio-app",
184+
"--iam-role",
185+
"trn:iam::role/test",
186+
"--gateway-name",
187+
"gateway",
188+
"--volcengine-access-key",
189+
"ak",
190+
"--volcengine-secret-key",
191+
"sk",
192+
*role_args,
193+
],
194+
)
195+
196+
assert result.exit_code == 0, result.output
197+
configured_roles = {
198+
key: value
199+
for key, value in veadk_environments.items()
200+
if key in {"VEADK_STUDIO_ADMINS", "VEADK_STUDIO_DEVELOPERS"}
201+
}
202+
assert configured_roles == expected_environment
203+
204+
131205
def test_studio_identity_region_searches_deployment_region_first(
132206
monkeypatch: pytest.MonkeyPatch,
133207
) -> None:

‎tests/cli/test_studio_rbac.py‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,40 @@ def test_role_matching_uses_all_trusted_identifiers_and_admin_wins() -> None:
141141

142142
def test_unconfigured_policy_preserves_legacy_full_access() -> None:
143143
policy = StudioAccessPolicy.from_csv(None, "")
144+
principal = StudioPrincipal.local("any-user")
144145

145146
assert not policy.enabled
146-
assert policy.role_for(None) == StudioRole.ADMIN
147+
assert policy.role_for(principal) == StudioRole.ADMIN
148+
assert policy.access_payload(principal) == {
149+
"role": "admin",
150+
"username": "any-user",
151+
"rbacEnabled": False,
152+
"capabilities": {
153+
"createAgents": True,
154+
"manageAgents": True,
155+
"runtimeScope": "all",
156+
},
157+
}
158+
159+
160+
@pytest.mark.parametrize(
161+
("admins", "developers", "listed_user", "listed_role"),
162+
[
163+
("admin", None, "admin", StudioRole.ADMIN),
164+
(None, "developer", "developer", StudioRole.DEVELOPER),
165+
],
166+
)
167+
def test_either_role_list_enables_rbac(
168+
admins: str | None,
169+
developers: str | None,
170+
listed_user: str,
171+
listed_role: StudioRole,
172+
) -> None:
173+
policy = StudioAccessPolicy.from_csv(admins, developers)
174+
175+
assert policy.enabled
176+
assert policy.role_for(StudioPrincipal.local(listed_user)) == listed_role
177+
assert policy.role_for(StudioPrincipal.local("unlisted")) == StudioRole.USER
147178

148179

149180
def test_unlisted_identity_is_a_regular_user() -> None:
@@ -195,6 +226,9 @@ def test_studio_deploy_exposes_role_options() -> None:
195226
assert result.exit_code == 0
196227
assert "--admin" in result.output
197228
assert "--developer" in result.output
229+
assert "Omit both role options to grant every user admin access" in " ".join(
230+
result.output.split()
231+
)
198232

199233

200234
def test_access_endpoint_resolves_local_roles_and_blocks_user_management(

‎veadk/cli/cli_frontend.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,8 @@ def _serve_options(f):
485485
default=None,
486486
envvar="VEADK_STUDIO_ADMINS",
487487
help="Comma-separated Studio admin usernames or OAuth emails "
488-
"(env: VEADK_STUDIO_ADMINS).",
488+
"(env: VEADK_STUDIO_ADMINS). Omit both role options to grant "
489+
"every user admin access.",
489490
),
490491
click.option(
491492
"--developer",
@@ -3378,7 +3379,8 @@ def _resolve_studio_identity_region(
33783379
"studio_admins",
33793380
default=None,
33803381
envvar="VEADK_STUDIO_ADMINS",
3381-
help="Comma-separated Studio admin usernames or OAuth emails.",
3382+
help="Comma-separated Studio admin usernames or OAuth emails. Omit both "
3383+
"role options to grant every user admin access.",
33823384
)
33833385
@click.option(
33843386
"--developer",

0 commit comments

Comments
 (0)