aws / aws/serverless-application-model

Auto-created role for Lambda could scope down logs policy

Open
#395 5 comments 3 reactions 0 assignees View on GitHub
breaking-change stage/pm-review type/feature
Dominant language
Python
Stars
9.6k
Forks
2.5k
Avg merge
1d 11h
Merged PRs (30d)
7

Description

When specifying an `AWS::Serverless::Function` without a role, SAM creates a role and attaches the `AWSLambdaBasicExecutionRole` managed policy to it. This provides write permissions for CloudWatch Logs, in particular:
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "*"
}
]
}
```
However, since this is part of a CloudFormation template, SAM could instead attach a non-managed policy that is specifically scoped to the log group for the function:
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": {"Fn::Join": [
"", [
"arn:",
{"Ref": "AWS::Partition"},
":logs",
{"Ref": "AWS::Region"},
":",
{"Ref": "AWS::AccountId"},
":log-group:/aws/lambda/",
{"Ref": "SAMFunctionLogicalId"},
":*"
],
]}
}
]
}
```
This is a least-privilege policy, unlike the managed policy. If this is desirable, I can create a PR.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.