无法使用IAM用户的访问密钥承担第三方AWS账户的角色

时间:2020-06-19 21:41:40

标签: java amazon-web-services sts-securitytokenservice assume-role

我正尝试使用具有SecurityAudit角色的承担角色功能(类似于here)来授予第三方AWS账户对我的AWS账户的访问权限。我按照this的解释为第三方帐户分配了名为test的角色,在该角色中我将获得类似的信任关系(我还添加了第三方的IAM用户,因为它将使用以下命令访问我的AWS账户他的访问密钥):

private int resLayout;
private Context context;
private List<Prescriptions> prescList;

public PrescAdapter(Context context,int res,List<Prescriptions> preList){
    super(context,res,preList);
    this.context=context;
    this.prescList=preList;
    this.resLayout=res;
}

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    View v=convertView;
    if(v==null){
        LayoutInflater vi;
        vi = LayoutInflater.from(context);
        v = vi.inflate(resLayout, null);
    }
    Prescriptions Item=prescList.get(position);
    if(Item!=null)
    {

        TextView Note=v.findViewById(R.id.noteTxt);
        TextView boldMed=v.findViewById(R.id.boldMedTxt);
        TextView med=v.findViewById(R.id.medi);
        TextView Date =v.findViewById(R.id.dateTxt);
        Note.setText(Item.getCondition());
        Date.setText(Item.getPrescription_Date());
        ImageView photo =v.findViewById(R.id.speImg);
        photo.setBackgroundResource(getImage(Item.getClassification_Name()));
        List<Medicins> medicins=Item.getMedicins();
        for (Medicins m:medicins) {

            if(m.getIsBold().equals("1"))boldMed.setText(boldMed.getText().toString()+"\n"+m.getName());
            else med.setText(boldMed.getText().toString()+"\n"+m.getName());
        }

    }
    return v;
}

public int getImage(String c){
    int v;
    switch (c){
        case "Eye":v=R.drawable.ic_eye;break;
        case "Ear":v=R.drawable.ic_ear;break;
        case"Brain":v=R.drawable.ic_brain;break;
        case"Sex":v=R.drawable.ic_sex;break;
        case"Kidney":v=R.drawable.ic_kidney;break;
        case"Stomach":v=R.drawable.ic_stomach;break;
        case"Tooth":v=R.drawable.ic_tooth;break;
        case"Lungs":v=R.drawable.ic_lungs;break;
        case"Gland":v=R.drawable.ic_gland;break;
        case"Heart":v=R.drawable.ic_heart;break;
        case"Skin":v=R.drawable.ic_skin;break;
        case"Bone":v=R.drawable.ic_bone2;break;
        default:v=0;break;
    }
    return v;

然后,我按照here中的代码进行操作,如下所示:

var initialValues = $('#your-fieldset :input').serialize();

$('form').submit(function(e) {
  e.preventDefault();
  var currentValues = $('#your-fieldset :input').serialize();
  if (currentValues == initialValues) {
    // Nothing has changed
    alert('Nothing was changed');
  }
  else {
    this.submit();
  }
});

但是当第三方运行代码时,会收到如下错误:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::thirdparty:root"
      },
      "Action": "sts:AssumeRole",
      "Condition": {}
    }
  ]
}

因此,如果第三方AWS账户想要使用其访问密钥对我的账户进行安全审核,应该如何正确配置它?

1 个答案:

答案 0 :(得分:2)

错误表明

arn:aws:iam::thirdparty:user/TestOne

无法承担角色。

在您的问题中,您正确地允许arn:aws:iam::thirdparty:root担任角色。但这仍然是不授予 TestOne IAM用户权限来做到这一点。

要解决此问题,thirdparty帐户的管理员/根用户必须明确允许 IAM用户TestOne到您帐户中的sts:AssumeRole

例如,thirdparty帐户可以向TestOne用户添加诸如内联策略之类的权限。显然,它也可以使用客户管理的策略或其他IAM机制来完成。但是内联策略似乎是最快,最容易测试的。

相关问题