serverless-operations / serverless-operations/serverless-step-functions

Opt-out flag for auto-generated IAM role permissions

Open
#770 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: iam enhancement
Dominant language
JavaScript
Stars
1k
Forks
220
PR merge metrics
No merged PRs in 30d

Description

Background

The plugin auto-generates IAM execution role permissions based on the service-integration ARNs in a state machine's definition (see `lib/deploy/stepFunctions/iamStrategies/`). For most services this produces 1–3 statements of narrowly-scoped actions, which works well as a default.

For Athena specifically (added in #450), the auto-generated role mirrors AWS's documented template and includes ~30 actions across four statements (Athena + S3 + Glue + Lake Formation), with broad resources like `arn:aws:s3:::` and `glue:database/`. This is correct per AWS docs — Athena uses the caller's IAM identity for catalog and storage access — but the breadth makes scope-down harder than it should be.

The gap

There is currently no clean way for a user to subtract from the auto-generated permissions:

  • `iamRoleStatements` adds statements alongside the auto-generated ones; it cannot narrow them.
  • `role:` replaces the entire role (and turns off auto-generation), which is an all-or-nothing escape hatch — the user loses auto-generation for every service they use, not just Athena.

A user who wants Athena to work but needs `s3:GetObject` scoped to `arn:aws:s3:::my-data-lake/` instead of `arn:aws:s3:::` has to either copy the full role themselves (losing the plugin's value) or accept overpermissive grants.

Proposed solutions

A few shapes worth discussing:

A) Boolean opt-out per state machine

```yaml
stepFunctions:
stateMachines:
myMachine:
autoIamRole: false # default true; when false, no auto-generated statements at all
iamRoleStatements:
- Effect: Allow
Action: [athena:startQueryExecution, athena:getDataCatalog]
Resource: arn:aws:athena:us-east-1:123456789012:workgroup/analytics
# ...user-provided narrowly-scoped statements
```

Simplest. Combines with `iamRoleStatements` to give users a fully manual role without having to use `role:` (which also disables logging config defaults, etc.).

B) Per-service opt-out

```yaml
autoIamRole:
athena: false
s3: false
```

Finer control — the user keeps auto-IAM for Lambda invokes, Step Functions startExecution, etc., but takes manual control for Athena. More moving parts.

C) Override-mode `iamRoleStatements`

A flag that changes `iamRoleStatements` from additive to replacing the auto-generated set. Conceptually similar to (A) but reuses an existing field.

Recommendation

(A) feels right for v1: minimum surface area, addresses the actual user need, easy to layer (B) on later if demand exists. Default stays `true` — backwards-compatible.

Out of scope

  • Narrowing the defaults themselves. AWS docs prescribe the broad set; we follow AWS docs.
  • Changing the semantics of `iamRoleStatements`. Additive behaviour is established and changing it would be a breaking change.

Related: when to split rather than narrow

Scope-down is one mitigation; splitting the workload across multiple Serverless services with Serverless Compose is another. CloudFormation has hard limits on policy/template size, and a single state machine that touches Athena + Glue + DynamoDB + Lambda + S3 + Step Functions can drive the auto-generated role past those limits even with this opt-out.

When the issue is role too large rather than role too broad, the correct fix is often:

  • One Serverless service per logical workload (each gets its own CF stack and its own state-machine role)
  • An osls-compose.yml orchestrating them so deploys stay coordinated

This issue's opt-out flag complements that pattern — use compose to split when you've outgrown a single stack, and autoIamRole: false to take manual control of any individual machine that still needs scope-down. The README should mention both options in the IAM section.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the auto-generation code under lib/deploy/stepFunctions/iamStrategies/ and the IAM section of the README. Trace how state-machine configuration selects generated statements and how iamRoleStatements and role currently behave. Done means implementing the recommended default-true autoIamRole opt-out, documenting it alongside the Serverless Compose guidance, and adding coverage for manual and default behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript
Domain
cloud, security
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.