Serverless Plugin for easily defining IAM roles per function via the use of iamRoleStatements at the function level.
Installations
npm install serverless-iam-roles-per-function
Score
98.5
Supply Chain
99.6
Quality
76
Maintenance
100
Vulnerability
99.6
License
Releases
Unable to fetch releases
Developer
functionalone
Developer Guide
Module System
CommonJS
Min. Node Version
>=10
Typescript Support
No
Node Version
14.17.0
NPM Version
6.14.13
Statistics
412 Stars
119 Commits
57 Forks
17 Watching
22 Branches
15 Contributors
Updated on 10 Oct 2024
Bundle Size
76.49 kB
Minified
26.65 kB
Minified + Gzipped
Languages
TypeScript (89.39%)
JavaScript (6.49%)
Shell (4.11%)
Total Downloads
Cumulative downloads
Total Downloads
21,948,497
Last day
5.3%
23,469
Compared to previous day
Last week
6%
121,574
Compared to previous week
Last month
-0.2%
511,742
Compared to previous month
Last year
14.3%
6,154,779
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Serverless IAM Roles Per Function Plugin
A Serverless plugin to easily define IAM roles per function via the use of iamRoleStatements
at the function definition block.
Installation
npm install --save-dev serverless-iam-roles-per-function
Or if you want to try out the next
upcoming version:
npm install --save-dev serverless-iam-roles-per-function@next
Add the plugin to serverless.yml:
1plugins: 2 - serverless-iam-roles-per-function
Note: Node 6.10 or higher runtime required.
Usage
Define iamRoleStatements
definitions at the function level:
1functions: 2 func1: 3 handler: handler.get 4 iamRoleStatementsName: my-custom-role-name #optional custom role name setting instead of the default generated one 5 iamRoleStatements: 6 - Effect: "Allow" 7 Action: 8 - dynamodb:GetItem 9 Resource: "arn:aws:dynamodb:${self:provider.region}:*:table/mytable" 10 ... 11 func2: 12 handler: handler.put 13 iamRoleStatements: 14 - Effect: "Allow" 15 Action: 16 - dynamodb:PutItem 17 Resource: "arn:aws:dynamodb:${self:provider.region}:*:table/mytable" 18 ...
The plugin will create a dedicated role for each function that has an iamRoleStatements
definition. It will include the permissions for create and write to CloudWatch logs, stream events and if VPC is defined: AWSLambdaVPCAccessExecutionRole
will be included (as is done when using iamRoleStatements
at the provider level).
if iamRoleStatements
are not defined at the function level default behavior is maintained and the function will receive the global IAM role. It is possible to define an empty iamRoleStatements
for a function and then the function will receive a dedicated role with only the permissions needed for CloudWatch and (if needed) stream events and VPC. Example of defining a function with empty iamRoleStatements
and configured VPC. The function will receive a custom role with CloudWatch logs permissions and the policy AWSLambdaVPCAccessExecutionRole
:
1functions: 2 func1: 3 handler: handler.get 4 iamRoleStatements: [] 5 vpc: 6 securityGroupIds: 7 - sg-xxxxxx 8 subnetIds: 9 - subnet-xxxx 10 - subnet-xxxxx
By default, function level iamRoleStatements
override the provider level definition. It is also possible to inherit the provider level definition by specifying the option iamRoleStatementsInherit: true
:
serverless >= v2.24.0
1provider: 2 name: aws 3 iam: 4 role: 5 statements: 6 - Effect: "Allow" 7 Action: 8 - xray:PutTelemetryRecords 9 - xray:PutTraceSegments 10 Resource: "*" 11 ... 12functions: 13 func1: 14 handler: handler.get 15 iamRoleStatementsInherit: true 16 iamRoleStatements: 17 - Effect: "Allow" 18 Action: 19 - dynamodb:GetItem 20 Resource: "arn:aws:dynamodb:${self:provider.region}:*:table/mytable"
serverless < v2.24.0
1provider: 2 name: aws 3 iamRoleStatements: 4 - Effect: "Allow" 5 Action: 6 - xray:PutTelemetryRecords 7 - xray:PutTraceSegments 8 Resource: "*" 9 ... 10functions: 11 func1: 12 handler: handler.get 13 iamRoleStatementsInherit: true 14 iamRoleStatements: 15 - Effect: "Allow" 16 Action: 17 - dynamodb:GetItem 18 Resource: "arn:aws:dynamodb:${self:provider.region}:*:table/mytable"
The generated role for func1
will contain both the statements defined at the provider level and the ones defined at the function level.
If you wish to change the default behavior to inherit
instead of override
it is possible to specify the following custom configuration:
1custom: 2 serverless-iam-roles-per-function: 3 defaultInherit: true
Role Names
The plugin uses a naming convention for function roles which is similar to the naming convention used by the Serverless Framework. Function roles are named with the following convention:
<service-name>-<stage>-<function-name>-<region>-lambdaRole
AWS has a 64 character limit on role names. If the default naming exceeds 64 chars the plugin will remove the suffix: -lambdaRole
to shorten the name. If it still exceeds 64 chars an error will be thrown containing a message of the form:
auto generated role name for function: ${functionName} is too long (over 64 chars).
Try setting a custom role name using the property: iamRoleStatementsName.
In this case you should set the role name using the property iamRoleStatementsName
. For example:
1functions: 2 func1: 3 handler: handler.get 4 iamRoleStatementsName: my-custom-role-name 5 iamRoleStatements: 6 - Effect: "Allow" 7 Action: 8 - dynamodb:GetItem 9 Resource: "arn:aws:dynamodb:${self:provider.region}:*:table/mytable" 10 ...
PermissionsBoundary
Define iamPermissionsBoundary definitions at the function level:
1functions: 2 func1: 3 handler: handler.get 4 iamPermissionsBoundary: !Sub arn:aws:iam::xxxxx:policy/your_permissions_boundary_policy 5 iamRoleStatementsName: my-custom-role-name 6 iamRoleStatements: 7 - Effect: "Allow" 8 Action: 9 - sqs:* 10 Resource: "*" 11 ...
You can set permissionsBoundary for all roles with iamGlobalPermissionsBoundary in custom:
1custom: 2 serverless-iam-roles-per-function: 3 iamGlobalPermissionsBoundary: !Sub arn:aws:iam::xxxx:policy/permissions-boundary-policy
For more information, see Permissions Boundaries.
Contributing
Contributions are welcome and appreciated.
- Before opening a PR it is best to first open an issue. Describe in the issue what you want you plan to implement/fix. Based on the feedback in the issue, you should be able to plan how to implement your PR.
- Once ready, open a PR to contribute your code.
- To help updating the CHANGELOG.md file, we use standard-version. Make sure to use conventional commit messages as specified at: https://www.conventionalcommits.org/en/v1.0.0/.
- Update the release notes at CHANGELOG.md and bump the version by running:
npm run release
- Examine the CHANGELOG.md and update if still required.
- Don't forget to commit the files modified by
npm run release
(we have the auto-commit option disabled by default). - Once the PR is approved and merged into master, travis-ci will automatically tag the version you created and deploy to npmjs under the
next
tag. You will see your version deployed at: https://www.npmjs.com/package/serverless-iam-roles-per-function?activeTab=versions. - Test your deployed version by installing with the
next
tag. For example:npm install --save-dev serverless-iam-roles-per-function@next
Publishing a Production Release (Maintainers)
Once a contributed PR (or multiple PRs) have been merged into master
, there is need to publish a production release, after we are sure that the release is stable. Maintainers with commit access to the repository can publish a release by merging into the release
branch. Steps to follow:
-
Verify that the current deployed pre-release version under the
next
tag in npmjs is working properly. Usually, it is best to allow thenext
version to gain traction a week or two before releasing. Also, if the version solves a specific reported issue, ask the community on the issue to test out thenext
version. -
Make sure the version being used in master hasn't been released. This can happen if a PR was merged without bumping the version by running
npm run release
. If the version needs to be advanced, open a PR to advance the version as specified here. -
Open a PR to merge into the
release
branch. Use as a base therelease
branch and compare thetag
version torelease
. For example: -
Once approved by another maintainer, merge the PR.
-
Make sure to check after the Travis CI build completes that the release has been published to the
latest
tag on nmpjs.
More Info
Introduction post: Serverless Framework: Defining Per-Function IAM Roles
Note: Serverless Framework provides support for defining custom IAM roles on a per function level through the use of the role
property and creating CloudFormation resources, as documented here. This plugin doesn't support defining both the role
property and iamRoleStatements
at the function level.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 6/19 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 19 are checked with a SAST tool
Reason
67 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-rrc9-gqf8-8rwg
- Warn: Project is vulnerable to: GHSA-4w2v-q235-vp99
- Warn: Project is vulnerable to: GHSA-cph5-m8f7-6c5x
- Warn: Project is vulnerable to: GHSA-wf5p-g6vw-rhxx
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-257v-vj4p-3w2h
- Warn: Project is vulnerable to: GHSA-h452-7996-h45h
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h
- Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q
- Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-jg8v-48h5-wgxg
- Warn: Project is vulnerable to: GHSA-36fh-84j7-cv5h
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-8hfj-j24r-96c4
- Warn: Project is vulnerable to: GHSA-wc69-rhjr-hc9g
- Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-px4h-xg32-q955
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-g6ww-v8xp-vmwg
- Warn: Project is vulnerable to: GHSA-g954-5hwp-pp24
- Warn: Project is vulnerable to: GHSA-h755-8qp9-cq85
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6
- Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj
- Warn: Project is vulnerable to: GHSA-wpg7-2c88-r8xv
- Warn: Project is vulnerable to: GHSA-3f95-r44v-8mrg
- Warn: Project is vulnerable to: GHSA-28xr-mwxg-3qc8
- Warn: Project is vulnerable to: GHSA-9p95-fxvg-qgq2
- Warn: Project is vulnerable to: GHSA-9w5j-4mwv-2wj8
- Warn: Project is vulnerable to: GHSA-xfhh-g9f5-x4m4
- Warn: Project is vulnerable to: GHSA-qm95-pgcg-qqfq
- Warn: Project is vulnerable to: GHSA-cqmj-92xf-r6r9
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-38fc-wpqx-33j7
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-776f-qx25-q3cc
- Warn: Project is vulnerable to: GHSA-72mh-269x-7mh5
- Warn: Project is vulnerable to: GHSA-h4j5-c7cj-74xg
Score
2.5
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to serverless-iam-roles-per-function
serverless-logging-config
Lets you configure custom log group, JSON logging, and other recent logging changes announce in Nov 2023.
serverless-plugin-custom-roles
A Serverless plugin that makes creation of per function IAM roles easier
@maaraanas/randomhash-serverless-iam-roles-per-function
Forked Serverless plugin to define IAM Role statements as part of the function definition block. Base: https://github.com/functionalone/serverless-iam-roles-per-function
serverless-custom-iam-roles-per-function
A Serverless plugin to make sure function role names are always valid, ie: