Serverless-Devs / Serverless-Devs

:fire::fire::fire: Serverless Devs developer tool ( Serverless Devs 开发者工具 )
https://www.serverless-devs.com
Apache License 2.0
1.74k stars 165 forks source link

关于设置阿里云 AK/SK格式校验 #375

Closed heimanba closed 2 years ago

heimanba commented 2 years ago
  1. 阿里云的accountid是不是正确的(例如他就是数字,不能有字母)
  2. secretId/Key,前后是不是有特殊字符,我记得我们前后没有特殊字符,但是用户复制的时候经常会带有一个\t

image

lowkeyrd commented 2 years ago

ak/sk、sts校验要用RAM提供的接口,不要自己用正则,太不规范了。贴一段其他项目中校验cred的代码,可以用ts翻译下 image

heimanba commented 2 years ago

refer: https://github.com/devsapp/fc/issues/536

heimanba commented 2 years ago

https://next.api.aliyun.com/api/Sts/2015-04-01/GetCallerIdentity?sdkStyle=dara&params={}&lang=TYPESCRIPT&tab=DEMO

{"IdentityType":"RAMUser","AccountId":"1740298130743624","RequestId":"F7C09E25-0C6C-5BD3-B744-949414CB0CC6","PrincipalId":"215654737666918818","UserId":"215654737666918818","Arn":"acs:ram::1740298130743624:user/fc-private"}
heimanba commented 2 years ago
heimanba commented 2 years ago
const Core = require('@alicloud/pop-core');

var client = new Core({
 accessKeyId: process.env['ACCESS_KEY_ID'],
 accessKeySecret: process.env['ACCESS_KEY_SECRET'],
 securityToken: process.env['SECURITY_TOKEN'],
 endpoint: 'https://sts.cn-hangzhou.aliyuncs.com',
 apiVersion: '2015-04-01'
});

var params = {}

var requestOption = {
 method: 'POST'
};

client.request('GetCallerIdentity', params, requestOption).then((result) => {
 console.log(JSON.stringify(result));
}, (ex) => {
 console.log(ex);
})
anycodes commented 2 years ago

您可能在配置一个错误的阿里云密钥,请检查密钥信息的准确性。如果您配置并非阿里云密钥,可以通过增加-f参数,强行写入。或执行s config add *** -f

You may be configuring an incorrect Alibaba Cloud SecretKey. Please check the accuracy of them. If your configuration is not an Alibaba Cloud SecretKey, you can force writing by adding the -f parameter. Or execute s config add *** -f

heimanba commented 2 years ago

已支持添加AK/SK时候无需填写主账号AccountID