Broad privileges in a Serverless Framework IAM role

A function execution role allows all actions on all resources

Description

An Allow statement with Action: "*" and Resource: "*" permits every AWS action on every resource unless another policy restricts it.

Potential impact

A bug or compromise in a function using the role could expose, change or delete unrelated data.

Remediation

In provider.iam.role.statements, limit the shared role to the actions and resources its functions need. Use separate roles when their needs differ. Grant actions that require Resource: "*" separately, with conditions where supported.

Examples

The revised statement allows s3:GetObject on objects in example-bucket. Supply your functions and any other permissions they need, including logging.

Before

yaml
service: service
frameworkVersion: "4"
provider:
  name: aws
  runtime: nodejs22.x
  iam:
    role:
      statements:
        - Effect: Allow
          Resource: "*"
          Action: "*"

After

yaml
service: service
frameworkVersion: "4"
provider:
  name: aws
  runtime: nodejs22.x
  iam:
    role:
      statements:
        - Effect: Allow
          Resource: arn:aws:s3:::example-bucket/*
          Action:
            - s3:GetObject

References