一、機制

詳見:
https://help.aliyun.com/document_detail/74971.html二、操作
2.1 子賬号操作(主賬号身份操作)
- 登陸ram控制台,建立子賬号。
- 給子賬号授予 AliyunSTSAssumeRoleAccess 權限。

- 建立子賬号ak,并儲存。

2.2 建立操作角色(主賬号身份)
- 主賬号下建立角色,授予目前賬号AliyunLogReadOnlyAccess權限。




- 在主賬号下建立出具有sls讀權限讀slsreadrole角色,具有 AliyunLogReadOnlyAccess
-
- 這裡的arn拷貝下來,後續代碼使用。

信任政策,表示子賬号具有assume權限。
{
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"RAM": [
"acs:ram::主賬号uid:root"
]
}
}
],
"Version": "1"
}
2.3 代碼擷取免登頁面
代碼連結:
https://samplecode.oss-cn-hangzhou.aliyuncs.com/slsconsole.py?spm=a2c4g.11186623.2.17.71337019d4IbX1&file=slsconsole.py需要修改的配置:
- SigninHost: 國内站賬号'https://signin-intl.aliyun.com',國際站賬号:'https://signin.aliyun.com'
- accessKeyId/accessKeySecret 子賬号ak,即2.1建的ak
- roleArn:主賬号下建的role,即2.2建的role
- destination:要通路的目的地
// destination取值樣例:
// 完整查詢分析頁面:
https://sls4service.console.aliyun.com/lognext/project/<Project名稱>/logsearch/<日志庫名稱>?hideTopbar=true&hideSidebar=true
## 查詢頁面
https://sls4service.console.aliyun.com/lognext/project/<Project名稱>/logsearch/<日志庫名稱>?isShare=true&hideTopbar=true&hideSidebar=true
// 儀表盤頁面
https://sls4service.console.aliyun.com/lognext/project/<Project名稱>/dashboard/<儀表盤ID>?isShare=true&hideTopbar=true&hideSidebar=true