用于调用 Sagemaker InvokeEndpoint 的 STS 凭证不起作用,尽管从同一策略生成的 IAM 凭证确实有效

问题描述 投票:0回答:1

我尝试使用通过 STS 生成的凭据调用 Sagemaker 端点,但收到权限错误:

botocore.exceptions.ClientError: An error occurred (AccessDeniedException) when calling the InvokeEndpoint operation: User: arn:aws:sts::{REDACTED_AWS_ACCOUNT_ID}:federated-user/{REDACTED_USER_SUFFIX} is not authorized to perform: sagemaker:InvokeEndpoint on resource: arn:aws:sagemaker:us-west-2:{REDACTED_AWS_ACCOUNT_ID}:endpoint/{REDACTED_ENDPOINT} because no identity-based policy allows the sagemaker:InvokeEndpoint action

奇怪的是,如果使用相同的策略生成 IAM 凭证(而不是 STS 凭证),我可以毫无问题地调用 Sagemaker 端点。

我已经仔细检查了该策略,它看起来是正确的(并且实际上适用于 IAM 案例,如上所述)。政策如下:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "sagemaker:InvokeEndpoint"
      ],
      "Resource": [
        "arn:${ .aws_partition }:sagemaker:${ .aws_region }:${ .aws_account_id }:endpoint/${ .endpoint }",
      ]
    }
  ]
}

我还检查了 STS 凭证生成过程中所承担的角色的信任关系,它也看起来是正确的。我的一个想法是,我们正在使用 Vault 来代理 STS 凭证生成请求,并且也许信任关系需要指定 Vault?但我会感到惊讶,因为我认为过去在为其他 AWS 服务生成 STS 凭证时不必这样做。这是信任关系:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Principal": {
                "Service": "sagemaker.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}

什么可能导致 IAM 凭证有效时 STS 凭证失败?

amazon-iam amazon-sagemaker hashicorp-vault aws-sts
1个回答
0
投票

答案可能取决于您是否使用 STS 的 AssumedRole 或联合令牌模式,但问题的根源是用于生成 STS 凭证的 IAM 用户没有具有

sagemaker:*
权限的策略,或者它可以假设(假定的角色)或附加到角色(联邦令牌)。

请参阅 https://developer.hashicorp.com/vault/docs/secrets/aws#sts-federation-tokens 了解更多详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.