gpt4 book ai didi

aws-cloudformation - 状态机 IAM 角色无权访问日志目标

转载 作者:行者123 更新时间:2023-12-03 07:26:17 25 4
gpt4 key购买 nike

我正在尝试部署 CF 堆栈,但由于 IAM 权限问题而失败。此问题堆栈中的相关资源是:

  1. 状态机(阶跃函数)

  2. Cloudwatch 日志组

  3. 日志组的订阅过滤器

此订阅过滤器将日志转发到 Kenesis,日志将在其中流式传输到 splunk。回到我的问题,当我尝试部署上述 CF 堆栈时,出现以下错误:状态机 IAM 角色无权访问日志目标

我已向附加到状态机的角色授予以下权限

StateMachineRole:
Type: AWS::IAM::Role
DeletionPolicy: Retain
Properties:
RoleName: StateMachineRole-${self:custom.env.stage}
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: states.amazonaws.com
Action: sts:AssumeRole

LambdaPolicy:
Type: AWS::IAM::Policy
DeletionPolicy: Retain
DependsOn: CustomLogGroup
Properties:
PolicyName: LambdaPolicy-${self:custom.env.stage}
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'lambda:InvokeFunction'
Resource: lambdaArn
- Effect: Allow
Action:
- 'logs:CreateLogDelivery'
- 'logs:GetLogDelivery'
- 'logs:UpdateLogDelivery'
- 'logs:DeleteLogDelivery'
- 'logs:ListLogDeliveries'
- 'logs:PutLogEvents'
- 'logs:PutResourcePolicy'
- 'logs:DescribeResourcePolicies'
- 'logs:DescribeLogGroups'
- 'logs:PutDestination'
- 'logs:PutSubscriptionFilter'
- 'logs:PutDestinationPolicy'
Resource: !GetAtt CustomLogGroup.Arn


/*CustomLogGroup*/
CustomLogGroup:
Type: AWS::Logs::LogGroup
Properties:
KmsKeyId: !ImportValue XXXXXXX
LogGroupName: CustomLogGroupName
RetentionInDays: ${file(./.env.${self:custom.env.stage}.yaml):cloudwatchLogs.retentionDays

引用了以下SO问题:Aws step function deployment log access issue

最佳答案

某些操作不支持资源类型,因此使用通配符 * 将解决您的权限问题。

Resource: '*'

如果要遵循最小权限访问原则,您需要检查有关 CloudWatch 权限的一些要点:

  • LogDeliveryResourcePolicy 操作不支持资源类型,因此它们必须在资源上使用通配符 *

     - Effect: Allow
    Action:
    - 'logs:CreateLogDelivery'
    - 'logs:GetLogDelivery'
    - 'logs:UpdateLogDelivery'
    - 'logs:DeleteLogDelivery'
    - 'logs:ListLogDeliveries'
    - 'logs:PutResourcePolicy'
    - 'logs:DescribeResourcePolicies'
    Resource: '*'
  • PutLogEvents 操作位于 log-stream* 中所以如果想限制,你需要遵循这样的操作:

     - Effect: Allow
    Action:
    - 'logs:PutLogEvents'
    Resource: 'arn:aws:logs:${Region}:${Account}:log-group:${LogGroupName}:log-stream:${LogStreamName}
  • Destination 相关操作位于 destination* level,所以如果想限制,你需要遵循这样的操作:

     - Effect: Allow
    Action:
    - 'logs:PutDestination'
    - 'logs:PutDestinationPolicy'
    Resource: 'arn:aws:logs:${Region}:${Account}:log-group:${LogGroupName}:destination:${DestinationName}'
  • PutSubscriptionFilter 操作位于 log-group 中和 destination*水平。

有关 CloudWatch Logs 操作和权限的更多信息,请参阅此处:

Actions, resources, and condition keys for Amazon CloudWatch Logs

关于aws-cloudformation - 状态机 IAM 角色无权访问日志目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73889792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com