π₯ Make videos programmatically with React
user permissions
Jonny Burgerf1e4e56fc869
diff --git a/packages/docs/docs/lambda-permissions.md b/packages/docs/docs/lambda-permissions.mdindex 45e8ad9714..ea0aa367c6 100644--- a/packages/docs/docs/lambda-permissions.md+++ b/packages/docs/docs/lambda-permissions.md@@ -9,7 +9,7 @@ import {RolePolicy} from '../components/lambda/role-permissions.tsx';This document describes the necessary permissions for Remotion Lambda and explains to those interested why the permissions are necessary.-Before configuring permissions, [follow the setup guide first](/docs/lambda/setup).+For a step by step guide on how to set up permissions, [follow the setup guide](/docs/lambda/setup).## User permissions@@ -41,11 +41,21 @@ To assign, go to [AWS console](https://console.aws.amazon.com/console/home) βYou can always get the suitable permission file for your Remotion Lambda version by typing `npx remotion lambda policies role`.:::+## Validation++There are two ways in which you can test if the permissions have been correctly set up. Either you execute the following command:++```bash+npx remotion lambda policies validate+```++or if you want to validate it programmatically, the [`simulatePermissions()`](/docs/lambda/simulatepermissions).+## Explanation-:::info-Currently the permissions are too loose. They will be made stricter to only require as minimal access as possible.-:::+The following table is a breakdown of why Remotion Lambda requires the permissions it does.++### User policies<table><tr>@@ -76,23 +86,37 @@ Currently the permissions are too loose. They will be made stricter to only requ</td><td><code>*</code></td><td>- Allows for verification that all the policies are properly set.+ Allows for <code>npx remotion lambda permissions validate</code>.+ </td>+ </tr>+ <tr>+ <td>+ <code>iam:PassRole</code>+ </td>+ <td><code>arn:aws:iam::*:role/remotion-lambda-role</code></td>+ <td>+ Allows the Lambda function to assume a role with sufficient permissions.</td></tr><tr><td><code>s3:GetObject</code> <br /><code>s3:DeleteObject</code> <br />+ <code>s3:PutObjectAcl</code> <br />+ <code>s3:PutObject</code> <br />+ <code>s3:CreateBucket</code> <br/>+ <code>s3:ListBucket</code> <br />+ <code>s3:GetBucketLocation</code> <br />+ <code>s3:PutBucketAcl</code> <br /><code>s3:DeleteBucket</code> <br /><code>s3:PutBucketWebsite</code> <br />- <code>s3:ListBucket</code> <br />- <code>s3:DeleteBucketWebsite</code>+ <code>s3:DeleteBucketWebsite</code> <br /></td><td>- <code>{'arn:aws:s3:::remotion-*'}</code>+ <code>{'arn:aws:s3:::remotionlambda-*'}</code></td><td>- Allows for executing basic CRUD operations on all S3 buckets in your account that start with <code>remotion-</code>+ Allows to create and delete buckets and objects in your account, make objects public and configure them as websites. Only buckets that start with <code>remotionlambda-</code> can be accessed.</td></tr><tr>@@ -106,32 +130,131 @@ Currently the permissions are too loose. They will be made stricter to only requAllows listing the names of all buckets in your account, in order to detect an already existing Remotion bucket.</td></tr>+<tr><td>- <code>lambda:CreateFunction</code> <br/>- <code>lambda:InvokeFunction</code> <br/>- <code>lambda:DeleteFunction</code> <br/>- <code>lambda:PublishLayerVersion</code> <br/>- <code>lambda:DeleteLayerVersion</code> <br/><code>lambda:GetLayerVersion</code></td><td>- <code>{'arn:aws:lambda:*::remotion-*'}</code>+ <code>{"arn:aws:lambda:*:678892195805:layer:remotion-binaries-*"}</code></td><td>- Allows for creating, deleting and deleting Lambda functions starting with <code>remotion-</code>. Allows for managing layers (responsible for delivering FFMPEG and Puppeteer binaries).+ Allows to read Chromium and FFMPEG binaries. These binaries are hosted in an account hosted by Remotion specifically dedicated to hosting those layers in all supported regions.</td></tr><tr><td>- <code>lambda:ListLayers</code> <br />- <code>lambda:ListFunctions</code>+ <code>lambda:ListFunctions</code> <br/>+ <code>lambda:GetFunction</code> <br/></td><td>- <code>{'*'}</code>+ <code>{"*"}</code></td><td>- Allows for reading the metadata of all Lambdas and Lambda Layers in your account for finding Remotion-related resources.+ Allows to read the functions in your AWS account in order to find the correct function to invoke. The loose <code>*</code> permission is because AWS doesn't allow this permission to be tightened.+ </td>+ </tr>+ <tr>+ <td>+ <code>logs:InvokeAsync</code> <br/>+ <code>logs:InvokeFunction</code> <br/>+ <code>logs:DeleteFunction</code> <br/>+ <code>logs:PutFunctionEventInvokeConfig</code> <br/>+ <code>logs:CreateFunction</code> <br/>+ </td>+ <td>+ <code>{"arn:aws:lambda:*:*:function:remotion-render-*"}</code>+ </td>+ <td>+ Allows to create, delete, invoke and configure functions (such as disabling automatic retries). Used by the CLI and the Node.JS APIS to set up, execute and teardown the infrastructure.+ </td>+ </tr>+ <tr>+ <td>+ <code>logs:CreateLogGroup</code> <br/>+ <code>logs:PutRetentionPolicy</code>+ </td>+ <td>+ <code>{"arn:aws:logs:*:*:log-group:/aws/lambda/remotion-render-*"}</code>+ </td>+ <td>+ Allows to create CloudWatch group, so logs can be saved in there later. Simplifies debugging.</td></tr></table>++### Role policies++<table>+ <tr>+ <th>+ Permission+ </th>+ <th>+ Scope+ </th>+ <th>+ Reason+ </th>+ </tr>+ <tr>+ <td>+ <code>s3.ListAllMyBuckets</code>+ </td>+ <td>+ <code>{"*"}</code>+ </td>+ <td>+ Get a list of Remotion buckets in order to find existing buckets that start with <code>remotionlambda-</code>.+ </td>+ </tr>+ <tr>+ <td>+ <code>s3:CreateBucket</code> <br/>+ <code>s3:ListBucket</code> <br/>+ <code>s3:PutBucketAcl</code> <br/>+ <code>s3:GetObject</code> <br/>+ <code>s3:DeleteObject</code> <br/>+ <code>s3:PutObjectAcl</code> <br/>+ <code>s3:PutObject</code> <br/>+ <code>s3:GetBucketLocation</code>+ </td>+ <td>+ <code>{"arn:aws:s3:::remotionlambda-*"}</code>+ </td>+ <td>+ Create and delete buckets and items, make them public or private and fetch their location. Since Remotion stores the videos in an S3 bucket, it needs basic CRUD capabilities over those buckets. The permission only applies to buckets that start with <code>remotionlambda-</code>+ </td>+ </tr>+ <tr>+ <td>+ <code>lambda:InvokeFunction</code> <br/>+ </td>+ <td>+ <code>{"arn:aws:lambda:*:*:function:remotion-render*"}</code>+ </td>+ <td>+Allow the function to recursively invoke itself. A render involves multiple function calls, which is to be orchestrated by the first function call.+ </td>++ </tr>+ <tr>+ <td>+ <code>lambda:CreateLogStream</code> <br/>+ <code>lambda:PutLogEvents</code> <br/>+ </td>+ <td>+ <code>{"arn:aws:logs:*:*:log-group:/aws/lambda/remotion-render*"}</code>+ </td>+ <td>+Allows to write the function logs to CloudWatch for easier debugging.+ </td>++ </tr>++</table>++## See also++- [Set up guide](/docs/lambda/setup)+- [`simulatePermissions()`](/docs/lambda/simulatepermissions)diff --git a/packages/docs/docs/lambda-setup.md b/packages/docs/docs/lambda-setup.mdindex b770558b2c..4343a18340 100644--- a/packages/docs/docs/lambda-setup.md+++ b/packages/docs/docs/lambda-setup.md@@ -324,4 +324,4 @@ This code will poll every second to check the progress of the video and exit the- Select [which region(s)](/docs/lambda/region-selection) you want to run Remotion Lambda in.- Familiarize yourself with the CLI and the Node.JS APIs (list in sidebar).- Before going live, go through the [Production checklist](/docs/lambda/checklist).-- If you have any questions, go through the [FAQ](/docs/lambda/faq) or ask in our [Discord channel](https://discord.gg/PzjkKS8S5S))+- If you have any questions, go through the [FAQ](/docs/lambda/faq) or ask in our [Discord channel](https://discord.gg/PzjkKS8S5S)diff --git a/packages/lambda/src/api/iam-validation/role-permissions.ts b/packages/lambda/src/api/iam-validation/role-permissions.tsindex 977d5006fd..3c301ef0f6 100644--- a/packages/lambda/src/api/iam-validation/role-permissions.ts+++ b/packages/lambda/src/api/iam-validation/role-permissions.ts@@ -13,12 +13,11 @@ export const rolePermissions: {actions: [s3.ListAllMyBuckets],resource: ['*'],},- {- actions: [s3.CreateBucket, s3.ListBucket, s3.PutBucketAcl],- resource: [`arn:aws:s3:::${REMOTION_BUCKET_PREFIX}*`],- },{actions: [+ s3.CreateBucket,+ s3.ListBucket,+ s3.PutBucketAcl,s3.GetObject,s3.DeleteObject,s3.PutObjectAcl,diff --git a/packages/lambda/src/api/iam-validation/user-permissions.ts b/packages/lambda/src/api/iam-validation/user-permissions.tsindex 90cb49e850..64529e3bc8 100644--- a/packages/lambda/src/api/iam-validation/user-permissions.ts+++ b/packages/lambda/src/api/iam-validation/user-permissions.ts@@ -6,7 +6,6 @@ import {} from '../../shared/constants';import {REMOTION_HOSTED_LAYER_ARN} from '../../shared/hosted-layers';-// TODO: Update docs before releaseexport const requiredPermissions: {actions: (s3 | iam | lambda | logs)[];resource: string[];@@ -33,12 +32,15 @@ export const requiredPermissions: {actions: [s3.GetObject,s3.DeleteObject,- s3.DeleteBucket,- s3.PutBucketWebsite,- s3.DeleteBucketWebsite,s3.PutObjectAcl,s3.PutObject,+ s3.CreateBucket,+ s3.ListBucket,s3.GetBucketLocation,+ s3.PutBucketAcl,+ s3.DeleteBucket,+ s3.PutBucketWebsite,+ s3.DeleteBucketWebsite,],resource: [`arn:aws:s3:::${REMOTION_BUCKET_PREFIX}*`],},@@ -47,11 +49,6 @@ export const requiredPermissions: {actions: [s3.ListAllMyBuckets],resource: ['*'],},- {- id: 'BucketManagement',- actions: [s3.CreateBucket, s3.ListBucket, s3.PutBucketAcl],- resource: [`arn:aws:s3:::${REMOTION_BUCKET_PREFIX}*`],- },{id: 'FunctionListing',actions: [lambda.ListFunctions, lambda.GetFunction],@@ -69,15 +66,8 @@ export const requiredPermissions: {resource: [`arn:aws:lambda:*:*:function:${RENDER_FN_PREFIX}*`],},{- id: 'LogCreation',- actions: [logs.CreateLogGroup],- resource: [- `arn:aws:logs:*:*:log-group:${LOG_GROUP_PREFIX}${RENDER_FN_PREFIX}*`,- ],- },- {- id: 'LogManagement',- actions: [logs.PutRetentionPolicy],+ id: 'logs.PutRetentionPolicy',+ actions: [logs.CreateLogGroup, logs.PutRetentionPolicy],resource: [`arn:aws:logs:*:*:log-group:${LOG_GROUP_PREFIX}${RENDER_FN_PREFIX}*`,],