Skip to content

Commit c203fd2

Browse files
committed
MB-46113: New RBAC roles and privileges for sync gateway
Added roles for use by sync gateway. Ns_server will NOT enforce these in any way, nor will they match any objects ns_server cares about. It is largely inert data held for sync-gateway to utilize. They are all visible on the UI and are all (but sync_gateway_dev_ops) parameterized by [bucket, scope, collection]. This feature is only available initially on developer preview. Change-Id: I1035849602991281c59d0a59d8f0d3a688c1adad Reviewed-on: http://review.couchbase.org/c/ns_server/+/157210 Tested-by: Bryan McCoid <[email protected]> Tested-by: Build Bot <[email protected]> Well-Formed: Build Bot <[email protected]> Reviewed-by: Artem Stemkovski <[email protected]>
1 parent f39c039 commit c203fd2

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

src/memcached_permissions.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,9 @@ permissions_for_user_test_() ->
467467
meck:expect(cluster_compat_mode, is_enterprise,
468468
fun () -> true end),
469469
meck:expect(cluster_compat_mode, get_compat_version,
470-
fun (_) -> ?VERSION_70 end)
470+
fun (_) -> ?VERSION_70 end),
471+
meck:expect(cluster_compat_mode, is_developer_preview,
472+
fun() -> false end)
471473
end,
472474
fun (_) ->
473475
meck:unload(cluster_compat_mode)

src/menelaus_roles.erl

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,53 @@ ui_folders() ->
582582
{backup, "Backup"},
583583
{mobile, "Mobile"}].
584584

585+
maybe_add_developer_preview_roles() ->
586+
DP = cluster_compat_mode:is_developer_preview(),
587+
sync_gateway_roles(DP).
588+
589+
sync_gateway_roles(true) ->
590+
[{sync_gateway_configurator, ?RBAC_COLLECTION_PARAMS,
591+
[{name, <<"Sync Gateway Architect">>},
592+
{folder, mobile},
593+
{desc, <<"Can manage Sync Gateway databases and users, "
594+
"and access Sync Gateway's /metrics endpoint. "
595+
"This user cannot read application data.">>}],
596+
[{[{collection, ?RBAC_COLLECTION_PARAMS}, sgw], all}]},
597+
{sync_gateway_app, ?RBAC_COLLECTION_PARAMS,
598+
[{name, <<"Sync Gateway Application">>},
599+
{folder, mobile},
600+
{desc, <<"Can manage Sync Gateway users and roles, and "
601+
"read and write application data through Sync "
602+
"Gateway.">>}],
603+
[{[{collection, ?RBAC_COLLECTION_PARAMS}, sgw, auth], [configure]},
604+
{[{collection, ?RBAC_COLLECTION_PARAMS}, sgw, principal], [read, write]},
605+
{[{collection, ?RBAC_COLLECTION_PARAMS}, sgw, appdata], [read, write]},
606+
{[{collection, ?RBAC_COLLECTION_PARAMS}, sgw, principal_appdata], [read]}]},
607+
{sync_gateway_app_ro, ?RBAC_COLLECTION_PARAMS,
608+
[{name, <<"Sync Gateway Application Read Only">>},
609+
{folder, mobile},
610+
{desc, <<"Can read Sync Gateway users and roles, and "
611+
"read application data through Sync Gateway.">>}],
612+
[{[{collection, ?RBAC_COLLECTION_PARAMS}, sgw, appdata], [read]},
613+
{[{collection, ?RBAC_COLLECTION_PARAMS}, sgw, principal], [read]},
614+
{[{collection, ?RBAC_COLLECTION_PARAMS}, sgw, principal_appdata], [read]}]},
615+
{sync_gateway_replicator, ?RBAC_COLLECTION_PARAMS,
616+
[{name, <<"Sync Gateway Replicator">>},
617+
{folder, mobile},
618+
{desc, <<"Can manage Inter-Sync Gateway Replications. "
619+
"This user cannot read application data.">>}],
620+
[{[{collection, ?RBAC_COLLECTION_PARAMS}, sgw, replications], all}]},
621+
{sync_gateway_dev_ops, [],
622+
[{name, <<"Sync Gateway Dev Ops">>},
623+
{folder, mobile},
624+
{desc, <<"Can manage Sync Gateway node-level configuration, "
625+
"and access Sync Gateway's /metrics endpoint "
626+
"for Prometheus integration.">>}],
627+
[{[{collection, ?RBAC_COLLECTION_PARAMS}, sgw, dev_ops], all},
628+
{[admin, stats_export], [read]}]}];
629+
sync_gateway_roles(false) ->
630+
[].
631+
585632
internal_roles() ->
586633
[{stats_reader, [], [],
587634
[{[admin, internal, stats], [read]}]}].
@@ -602,7 +649,7 @@ get_public_definitions(Version) when Version < ?VERSION_66 ->
602649
get_public_definitions(Version) when Version < ?VERSION_70 ->
603650
menelaus_old_roles:roles_pre_70();
604651
get_public_definitions(_) ->
605-
roles().
652+
roles() ++ maybe_add_developer_preview_roles().
606653

607654
-spec object_match(
608655
rbac_permission_object(), rbac_permission_pattern_object()) ->
@@ -1521,7 +1568,9 @@ produce_roles_by_permission_test_() ->
15211568
meck:expect(cluster_compat_mode, is_enterprise,
15221569
fun () -> true end),
15231570
meck:expect(cluster_compat_mode, get_compat_version,
1524-
fun (_) -> ?VERSION_70 end)
1571+
fun (_) -> ?VERSION_70 end),
1572+
meck:expect(cluster_compat_mode, is_developer_preview,
1573+
fun() -> false end)
15251574
end,
15261575
fun (_) ->
15271576
meck:unload(cluster_compat_mode)

src/menelaus_users.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,10 +922,13 @@ upgrade_test_() ->
922922
meck:new(replicated_dets, [passthrough]),
923923
meck:expect(replicated_dets, select_with_update,
924924
fun replicated_dets:toy_select_with_update/4),
925+
meck:expect(cluster_compat_mode, is_developer_preview,
926+
fun() -> false end),
925927
replicated_dets:toy_init(storage_name())
926928
end,
927929
fun (_) ->
928930
meck:unload(replicated_dets),
931+
meck:unload(cluster_compat_mode),
929932
ets:delete(storage_name())
930933
end,
931934
[Test(?VERSION_66,

src/menelaus_web_rbac.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,9 @@ t_wrap(Tests) ->
18721872
meck:expect(cluster_compat_mode, is_enterprise,
18731873
fun () -> true end),
18741874
meck:expect(cluster_compat_mode, get_compat_version,
1875-
fun (_) -> ?VERSION_70 end)
1875+
fun (_) -> ?VERSION_70 end),
1876+
meck:expect(cluster_compat_mode, is_developer_preview,
1877+
fun() -> false end)
18761878
end,
18771879
fun (_) ->
18781880
meck:unload(cluster_compat_mode)

0 commit comments

Comments
 (0)