python程序刷新CDN用的是腾讯云账户的SecretID,理论上能对账号下全部资源进行操作,这么做的话风险很大,将可能影响整个腾讯云账号。为减少此风险,可通过子账户的方式来刷新CDN,这样使API只有操作刷新CDN的权限,而不能访问其他云上资源。
具体操作方法如下:
1,登录到腾讯云控制台
2,点击右上角头像,选择访问管理。
![](https://danteng.org/wp-content/uploads/2020/03/1584630288622.png)
3.1,策略–>新建自定义策略,按产品功能或项目权限创建。
![](https://danteng.org/wp-content/uploads/2020/03/1584630288628.png)
![](https://danteng.org/wp-content/uploads/2020/03/1584630288634.png)
3.2,定义策略名,服务类型选择内容分发网络。
![](https://danteng.org/wp-content/uploads/2020/03/1584630288639.png)
3.3,权限配置中选择刷新预热。
![](https://danteng.org/wp-content/uploads/2020/03/1584630288644.png)
3.4,策略关联对象。这里需要选择正确的项目,否则不会生效。
![](https://danteng.org/wp-content/uploads/2020/03/1584630288647.png)
![](https://danteng.org/wp-content/uploads/2020/03/1584630288649.png)
4.1,用户–>影虎列表–>新建用户,创建子账户。
![](https://danteng.org/wp-content/uploads/2020/03/1584630288651.png)
4.2,选择自定义创建。
![](https://danteng.org/wp-content/uploads/2020/03/1584630288654.png)
4.3,进入子账号配置流程,选择可访问资源并接收消息。如果选择仅用于接收消息则账号不能访问腾讯云。
![](https://danteng.org/wp-content/uploads/2020/03/1584630288657.png)
4.4,填写用户名,勾选编程访问,其它随意。默认情况下,该账号只能通过API访问,不能通过控制台访问。
![](https://danteng.org/wp-content/uploads/2020/03/1584630288661.png)
4.5,完成身份验证。
![](https://danteng.org/wp-content/uploads/2020/03/1584630288664.png)
4.6,勾选第三步创建的策略。
![](https://danteng.org/wp-content/uploads/2020/03/1584630288668.png)
如需自行变更Secret信息,需勾选自主管理API密钥。
![](https://danteng.org/wp-content/uploads/2020/03/1584630288671.png)
4.7,查看并确认信息。
![](https://danteng.org/wp-content/uploads/2020/03/1584630288672.png)
5,创建完成后,即可看到子账户的SecretID和SecretKey。
用这组SecretID替换python刷新腾讯云CDN程序里面的信息。
![](https://danteng.org/wp-content/uploads/2020/03/1584630288674.png)
6,回到API密钥管理中,禁用账户SecretID。
![](https://danteng.org/wp-content/uploads/2020/03/1584630288676.png)
至此全部配置完成,python刷新CDN时将使用子账户访问,且原有主账户SecretID将会立刻失效。
本文链接地址: https://danteng.org/how-to-flush-qcloud-cdn-by-sub-account/