控制对任务日志的访问
使用 Marathon 群组管理用户对任务日志的访问
您可以通过使用 Marathon 群组进行作业和服务,控制用户对任务日志的访问。然后,您可以分配访问这些群组的权限,从而让您可以控制用户可以访问哪些日志。
重要信息:本文档所述的功能仅在严格安全模式下可用。
在此过程中,您将在单独的 Marathon 群组中部署服务,并授予用户权限以查看这些 Marathon 群组的任务。
以下是对所需 权限 的概述:
前提条件:
- DC/OS 和 DC/OS CLI ,您以超级用户身份登录。
通过 DC/OS Web 界面
选择组织并选择组。
图 1. 新用户组
新建一个组。
图 2. 创建新组屏幕
选择组名,并从权限选项卡上单击添加权限。
单击插入权限字符串以切换对话框,然后粘贴到以下权限中,单击添加权限。
图 4. 权限字符串已添加
创建用户和授予权限
选择组织并选择用户。选择现有用户或创建一个新用户。
图 5. 用户屏幕
从组成员选项卡,在搜索框中输入并选择组名。这将向单个用户授予组权限。
图 6. 将用户添加到安全组
本节介绍如何在组中部署简单的应用程序。
选择服务 > 运行服务。
选择单个容器,并将您的服务定义为:
- 服务 ID指定
/<gid>/<service-name>
。这会在服务组内创建一个服务。 - 容器运行时选择通用容器运行时 (UCR)。
- 服务 ID指定
单击查看并运行和运行服务以完成安装。您现在应该能看到一个在组中运行的服务。
图 8. 在组中运行的服务
现在您可以 验证访问权限。
通过 IAM API
前提条件: 您必须 获取根证书 才能发布此部分的 curl 命令。
提示
- 服务资源通常包括
/
必须在%252F
请求中以curl
替换的字符,如下例所示。 - 使用 API 管理权限时,您必须在授予之前先创建权限。如果权限已存在,API 将返回提示信息,您可以继续分配权限。
使用以下命令创建一个 Marathon 组 (
<gid>
).curl -X POST --cacert dcos-ca.crt \
$(dcos config show core.dcos_url)/service/marathon/v2/groups \
-d '{"id":"<gid>"}' \
-H "Authorization: token=$(dcos config show core.dcos_acs_token)"
使用以下命令在
<service-name>
内部部署一个简单的应用程序 (<gid>
.curl -X POST --cacert dcos-ca.crt \
$(dcos config show core.dcos_url)/service/marathon/v2/apps \
-d '{"id":"/<gid>/<service-name>","cmd":"sleep 1000000000"}' \
-H "Content-type: application/json" \
-H "Authorization: token=$(dcos config show core.dcos_acs_token)"
创建和授予权限
使用以下命令为您的组创建权限 (
<gid>
).使用以下命令向用户授予权限 (
<username>
). 这些将允许她在 中查看任务日志。<gid>
.curl -X PUT --cacert dcos-ca.crt \
-H "Authorization: token=$(dcos config show core.dcos_acs_token)" $(dcos config show core.dcos_url)/acs/api/v1/acls/dcos:adminrouter:ops:mesos/users/<username>/full
-H "Authorization: token=$(dcos config show core.dcos_acs_token)" $(dcos config show core.dcos_url)/acs/api/v1/acls/dcos:adminrouter:ops:slave/users/<username>/full
curl -X PUT --cacert dcos-ca.crt \
-H "Authorization: token=$(dcos config show core.dcos_acs_token)" $(dcos config show core.dcos_url)/acs/api/v1/acls/dcos:mesos:master:framework:role:slave_public/users/<username>/read
-H "Authorization: token=$(dcos config show core.dcos_acs_token)" $(dcos config show core.dcos_url)/acs/api/v1/acls/dcos:mesos:master:executor:app_id:%252F<gid>/users/<username>/read
curl -X PUT --cacert dcos-ca.crt \
-H "Authorization: token=$(dcos config show core.dcos_acs_token)" $(dcos config show core.dcos_url)/acs/api/v1/acls/dcos:mesos:master:task:app_id:%252F<gid>/users/<username>/read
curl -X PUT --cacert dcos-ca.crt \
-H "Authorization: token=$(dcos config show core.dcos_acs_token)" $(dcos config show core.dcos_url)/acs/api/v1/acls/dcos:mesos:agent:framework:role:slave_public/users/<username>/read
curl -X PUT --cacert dcos-ca.crt \
-H "Authorization: token=$(dcos config show core.dcos_acs_token)" $(dcos config show core.dcos_url)/acs/api/v1/acls/dcos:mesos:agent:executor:app_id:%252F<gid>/users/<username>/read
curl -X PUT --cacert dcos-ca.crt \
-H "Authorization: token=$(dcos config show core.dcos_acs_token)" $(dcos config show core.dcos_url)/acs/api/v1/acls/dcos:mesos:agent:task:app_id:%252F<gid>/users/<username>/read
curl -X PUT --cacert dcos-ca.crt \
-H "Authorization: token=$(dcos config show core.dcos_acs_token)" $(dcos config show core.dcos_url)/acs/api/v1/acls/dcos:mesos:agent:sandbox:app_id:%252F<gid>/users/<username>/read
现在您可以 。
验证访问权限
以用户身份登录到 DC/OS CLI。
dcos auth login
运行此命令以访问用户有权访问的服务的日志。
例如,如果您的服务名是
alice-service
:dcos task log --follow alice-service
Executing pre-exec command '{"arguments":["mesos-containerizer","mount","--help=false","--operation=make-rslave","--path=\/"],"shell":false,"value":"\/opt\/mesosphere\/active\/mesos\/libexec\/mesos\/mesos-containerizer"}'
Executing pre-exec command '{"arguments":["mount","-n","-t","ramfs","ramfs","\/var\/lib\/mesos\/slave\/slaves\/151ee739-d2b9-4024-8dbd-1345148774df-S1\/frameworks\/151ee739-d2b9-4024-8dbd-1345148774df-0001\/executors\/dev-group_alice-service.363072a5-65b5-11e7-a133-1a6ac27c9efe\/runs\/b46bea37-f3bb-4d9b-b0b9-00b1215c8404\/.secret-48e7541e-6634-4c25-9185-986255249439"],"shell":false,"value":"mount"}'
如果您没有正确的权限,您将看到以下输出: