π₯ Make videos programmatically with React
disable possibility for unauthenticated renders
Jonny Burger8a48bd515285
diff --git a/packages/cloudrun/package.json b/packages/cloudrun/package.jsonindex 84a5e780dc..100659c27a 100644--- a/packages/cloudrun/package.json+++ b/packages/cloudrun/package.json@@ -20,7 +20,6 @@"@remotion/cli": "workspace:*","@remotion/renderer": "workspace:*","google-auth-library": "^8.7.0",- "got": "11.8.2","remotion": "workspace:*"},"devDependencies": {@@ -49,4 +48,4 @@]}}-}\ No newline at end of file+}diff --git a/packages/cloudrun/readme.md b/packages/cloudrun/readme.mdindex c7b105ba42..96243f202c 100644--- a/packages/cloudrun/readme.md+++ b/packages/cloudrun/readme.md@@ -135,9 +135,9 @@ For information only, here are the reasons for the above permissions- storage.objects.list- ToDo...- run.services.getIamPolicy- - used to check the existing IAM policy on a service, before modifying it for (un)authenticated invoking.+ - used to check the existing IAM policy on a service- run.services.setIamPolicy- - used to set the IAM policy on a service, to allow unauthenticated invoking, or remove unauthenticated invoking.+ - used to set the IAM policy on a service### 2. Create a service account in the Google Cloud Console@@ -187,20 +187,17 @@ Options:- --service-name (required):- the name of the Cloud Run service to deploy or update. Service names must be 49 characters or less and must be unique per region and project. A service name cannot be changed later and is publicly visible. The service does not need to exist yet. If it does exist, a new revision will be deployed.- --region: the region of the service-- --allow-unauthenticated (optional, default to false):- - whether to allow unauthenticated requests to the service. For now, I would suggest setting this to true, to avoid having to create a service account and grant it access to the service. In the future, it would be recommended to not set this tru.- --overwrite-service (optional, default to false):- if an existing service is found with the same name, a prompt will come up asking if a new revision should be deployed. If this flag is set to true, the prompt will be skipped and a new revision will be deployed automatically.Taking the above into account, a valid command would be:-`npx remotion gcp cloud-run deploy --service-name=cloud-run-render --project-id=new-remotion-project --allow-unauthenticated`+`npx remotion gcp cloud-run deploy --service-name=cloud-run-render --project-id=new-remotion-project`To view the deployed service, navigate to the [Cloud Run](https://console.cloud.google.com/run) screen in Google Cloud Console, and selecting the project from the drop-down menu in the top left corner.- The URL is visible at the top of the screen. This is where to send POST requests for rendering.- Revisions are listed under the revisions tab. You can also manage traffic splitting, and view resource limits for each revision.- Logs are available under the logs tab. For troubleshooting, it is best to click on the new tab icon to open the Logs Explorer, and then click on Stream Logs in the top right to have a live view of logs.-- The security tab allows you to manage authentication and authorization for the service. If you set `--allow-unauthenticated` to true, you will see that unauthenticated invocations are allowed.<br><br>diff --git a/packages/cloudrun/src/api/cloud-run-allow-unauthenticated-access.ts b/packages/cloudrun/src/api/cloud-run-allow-unauthenticated-access.tsdeleted file mode 100644index 08f666711d..0000000000--- a/packages/cloudrun/src/api/cloud-run-allow-unauthenticated-access.ts+++ /dev/null@@ -1,92 +0,0 @@-import {getCloudRunClient} from './helpers/get-cloud-run-client';--/**- * @description Allow unauthenticated access to the Cloud Run service.- * @link https://remotion.dev/docs/lambda/deployfunction- * @param options.serviceName The name of the Cloud Run service.- * @returns {Promise<Boolean>} True if operation was successful. False if not.- */-export const allowUnauthenticatedAccess = async (- serviceName: string,- allow: boolean-): Promise<Boolean> => {- const cloudRunClient = getCloudRunClient();-- const existingPolicy = await cloudRunClient.getIamPolicy({- resource: serviceName,- });-- const existingBindings = existingPolicy[0].bindings || [];-- const invokerBindings = existingPolicy[0].bindings?.filter(- (binding) => binding.role === 'roles/run.invoker'- );- if (allow) {- /* allow allUsers to invoke cloud run */-- let finalMembers: string[] = [];-- if (invokerBindings?.[0]) {- if (invokerBindings?.[0].members?.indexOf('allUsers') === -1) {- // allUsers not present for roles/run.invoker- finalMembers = invokerBindings[0].members.concat(['allUsers']);- } else {- // allUsers already present for roles/run.invoker- return true;- }- } else {- // no existing bindings found for roles/run.invoker- finalMembers = ['allUsers'];- }-- await cloudRunClient.setIamPolicy({- resource: serviceName,- policy: {- bindings: [- ...existingBindings,- {- role: 'roles/run.invoker',- members: finalMembers,- },- ],- },- });- } else {- /* Ensure allUsers is not on permitted to invoke cloud run */-- if (!existingBindings.length) {- // there are no bindings on this service- return true;- }-- if (invokerBindings?.[0]) {- if (invokerBindings[0].members?.indexOf('allUsers') === -1) {- // allUsers not present for roles/run.invoker- return true;- }-- invokerBindings[0].members?.splice(- invokerBindings[0].members.indexOf('allUsers'),- 1- );- } else {- // no existing bindings found for roles/run.invoker- return true;- }-- await cloudRunClient.setIamPolicy({- resource: serviceName,- policy: {- bindings: [- ...existingBindings,- {- role: 'roles/run.invoker',- members: invokerBindings[0].members,- },- ],- },- });- }-- return true;-};diff --git a/packages/cloudrun/src/api/render-media-on-cloudrun.ts b/packages/cloudrun/src/api/render-media-on-cloudrun.tsindex d4b8a99bd7..6e324d8c76 100644--- a/packages/cloudrun/src/api/render-media-on-cloudrun.ts+++ b/packages/cloudrun/src/api/render-media-on-cloudrun.ts@@ -1,5 +1,4 @@import type {ChromiumOptions, FrameRange} from '@remotion/renderer';-import got from 'got/dist/source';import type {CloudrunCodec} from '../shared/validate-gcp-codec';import {validateCloudrunCodec} from '../shared/validate-gcp-codec';import {validatePrivacy} from '../shared/validate-privacy';@@ -8,7 +7,6 @@ import {getAuthClientForUrl} from './helpers/get-auth-client-for-url';import {getCloudrunEndpoint} from './helpers/get-cloudrun-endpoint';export type RenderMediaOnCloudrunInput = {- authenticatedRequest: boolean;cloudRunUrl?: string;serviceName?: string;region?: string;@@ -84,7 +82,6 @@ export type RenderMediaOnCloudrunOutput = {*/export const renderMediaOnCloudrun = async ({- authenticatedRequest,cloudRunUrl,serviceName,region,@@ -152,62 +149,39 @@ export const renderMediaOnCloudrun = async ({type: 'media',};- if (authenticatedRequest) {- const client = await getAuthClientForUrl(cloudRunEndpoint);+ const client = await getAuthClientForUrl(cloudRunEndpoint);- const authenticatedDataPromise = new Promise((resolve, reject) => {- client- .request({- url: cloudRunEndpoint,- method: 'POST',- data,- responseType: 'stream',- })- .then((postResponse) => {- const stream: any = postResponse.data;+ const postResponse = await client.request({+ url: cloudRunEndpoint,+ method: 'POST',+ data,+ responseType: 'stream',+ });- stream.on('data', (chunk: Buffer) => {- const chunkResponse = JSON.parse(chunk.toString());- if (chunkResponse.response) {- authenticatedResponse = chunkResponse.response;- } else if (chunkResponse.onProgress) {- updateRenderProgress?.(chunkResponse.onProgress);- }- });+ const authenticatedDataPromise = new Promise((resolve, reject) => {+ // TODO: Add any sort of type safety+ let response: any;- stream.on('end', () => {- resolve(response);- });+ const stream: any = postResponse.data;- stream.on('error', (error: any) => {- reject(error);- });- });+ stream.on('data', (chunk: Buffer) => {+ const chunkResponse = JSON.parse(chunk.toString());+ if (chunkResponse.response) {+ authenticatedResponse = chunkResponse.response;+ } else if (chunkResponse.onProgress) {+ updateRenderProgress?.(chunkResponse.onProgress);+ }});- let authenticatedResponse = await authenticatedDataPromise;- return authenticatedResponse as RenderMediaOnCloudrunOutput;- }+ stream.on('end', () => {+ resolve(response);+ });- const dataPromise = new Promise((resolve, reject) => {- got.stream- .post(cloudRunEndpoint, {json: data})- .on('data', (chunk) => {- const chunkResponse = JSON.parse(chunk.toString());- if (chunkResponse.response) {- response = chunkResponse.response;- } else if (chunkResponse.onProgress) {- updateRenderProgress?.(chunkResponse.onProgress);- }- })- .on('end', () => {- resolve(response);- })- .on('error', (error) => {- reject(error);- });+ stream.on('error', (error: any) => {+ reject(error);+ });});- let response = await dataPromise;- return response as RenderMediaOnCloudrunOutput;+ let authenticatedResponse = await authenticatedDataPromise;+ return authenticatedResponse as RenderMediaOnCloudrunOutput;};diff --git a/packages/cloudrun/src/api/render-still-on-cloudrun.ts b/packages/cloudrun/src/api/render-still-on-cloudrun.tsindex 61b4e288db..7e333151b3 100644--- a/packages/cloudrun/src/api/render-still-on-cloudrun.ts+++ b/packages/cloudrun/src/api/render-still-on-cloudrun.ts@@ -1,12 +1,10 @@import type {ChromiumOptions, StillImageFormat} from '@remotion/renderer';-import got from 'got';import {validatePrivacy} from '../shared/validate-privacy';import {validateServeUrl} from '../shared/validate-serveurl';import {getAuthClientForUrl} from './helpers/get-auth-client-for-url';import {getCloudrunEndpoint} from './helpers/get-cloudrun-endpoint';export type RenderStillOnCloudrunInput = {- authenticatedRequest: boolean;cloudRunUrl?: string;serviceName?: string;region?: string;@@ -54,7 +52,6 @@ export type RenderStillOnCloudrunOutput = {*/export const renderStillOnCloudrun = async ({- authenticatedRequest,cloudRunUrl,serviceName,region,@@ -100,19 +97,12 @@ export const renderStillOnCloudrun = async ({type: 'still',};- if (authenticatedRequest) {- const client = await getAuthClientForUrl(cloudRunEndpoint);+ const client = await getAuthClientForUrl(cloudRunEndpoint);- const authenticatedResponse = await client.request({- url: cloudRunUrl,- method: 'POST',- data,- });- return authenticatedResponse.data as RenderStillOnCloudrunOutput;- }-- const response: RenderStillOnCloudrunOutput = await got- .post(cloudRunEndpoint, {json: data})- .json();- return response;+ const authenticatedResponse = await client.request({+ url: cloudRunUrl,+ method: 'POST',+ data,+ });+ return authenticatedResponse.data as RenderStillOnCloudrunOutput;};diff --git a/packages/cloudrun/src/cli/args.ts b/packages/cloudrun/src/cli/args.tsindex 2d5dc11afb..4767880cc2 100644--- a/packages/cloudrun/src/cli/args.ts+++ b/packages/cloudrun/src/cli/args.ts@@ -7,7 +7,6 @@ type servicesCommandLineOptions = {region: GcpRegion;['project-id']: string;['service-name']: string;- ['allow-unauthenticated']: boolean | undefined;y: boolean;yes: boolean;force: boolean;diff --git a/packages/cloudrun/src/cli/commands/render/helpers/renderArgsCheck.ts b/packages/cloudrun/src/cli/commands/render/helpers/renderArgsCheck.tsindex a3a957f659..13338d5367 100644--- a/packages/cloudrun/src/cli/commands/render/helpers/renderArgsCheck.ts+++ b/packages/cloudrun/src/cli/commands/render/helpers/renderArgsCheck.ts@@ -104,8 +104,6 @@ export const renderArgsCheck = async (subcommand: string, args: string[]) => {cloudRunUrl = uri;}- const authenticatedRequest = !parsedCloudrunCli['unauthenticated-request'];-return {serveUrl,cloudRunUrl,@@ -113,7 +111,6 @@ export const renderArgsCheck = async (subcommand: string, args: string[]) => {outName,outputBucket,privacy,- authenticatedRequest,downloadName,};};diff --git a/packages/cloudrun/src/cli/commands/render/renderMedia.ts b/packages/cloudrun/src/cli/commands/render/renderMedia.tsindex 54f173f0f4..110fd92b87 100644--- a/packages/cloudrun/src/cli/commands/render/renderMedia.ts+++ b/packages/cloudrun/src/cli/commands/render/renderMedia.ts@@ -23,7 +23,6 @@ export const renderMediaSubcommand = async (outputBucket,downloadName,privacy,- authenticatedRequest,} = await renderArgsCheck(RENDER_MEDIA_SUBCOMMAND, args);const {codec, reason: codecReason} = CliInternals.getFinalOutputCodec({@@ -68,7 +67,6 @@ export const renderMediaSubcommand = async (Sending request to Cloud Run:Cloud Run Service URL = ${cloudRunUrl}- Authenticated Request = ${authenticatedRequest}Type = mediaComposition = ${composition}Codec = ${codec}@@ -140,7 +138,6 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}forceHeight: height,forceWidth: width,audioCodec,- authenticatedRequest,outputBucket,updateRenderProgress,});diff --git a/packages/cloudrun/src/cli/commands/render/renderStill.ts b/packages/cloudrun/src/cli/commands/render/renderStill.tsindex 2094e0189d..af0b9f72d7 100644--- a/packages/cloudrun/src/cli/commands/render/renderStill.ts+++ b/packages/cloudrun/src/cli/commands/render/renderStill.ts@@ -19,7 +19,6 @@ export const renderStillSubcommand = async (outName,outputBucket,privacy,- authenticatedRequest,downloadName,} = await renderArgsCheck(RENDER_STILL_SUBCOMMAND, args);@@ -55,7 +54,6 @@ export const renderStillSubcommand = async (Sending request to Cloud Run:Cloud Run Service URL = ${cloudRunUrl}- Authenticated Request = ${authenticatedRequest}Type = stillComposition = ${composition}Output Bucket = ${outputBucket}@@ -103,7 +101,6 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}scale,forceHeight: height,forceWidth: width,- authenticatedRequest,outputBucket,outputFile: outName,});diff --git a/packages/cloudrun/src/cli/commands/services/deploy.ts b/packages/cloudrun/src/cli/commands/services/deploy.tsindex ea3211d572..8b0d574f62 100644--- a/packages/cloudrun/src/cli/commands/services/deploy.ts+++ b/packages/cloudrun/src/cli/commands/services/deploy.ts@@ -1,6 +1,5 @@import {CliInternals} from '@remotion/cli';import {VERSION} from 'remotion/version';-import {allowUnauthenticatedAccess} from '../../../api/cloud-run-allow-unauthenticated-access';import {deployService} from '../../../api/deploy-service';import {generateServiceName} from '../../../shared/generate-service-name';import {validateGcpRegion} from '../../../shared/validate-gcp-region';@@ -15,8 +14,6 @@ export const CLOUD_RUN_DEPLOY_SUBCOMMAND = 'deploy';export const cloudRunDeploySubcommand = async () => {const region = getGcpRegion();const projectID = process.env.REMOTION_GCP_PROJECT_ID as string;- const allowUnauthenticated =- parsedCloudrunCli['allow-unauthenticated'] ?? false;let memoryLimit = parsedCloudrunCli.memoryLimit ?? '2Gi';let cpuLimit = parsedCloudrunCli.cpuLimit ?? '1.0';const timeoutSeconds = parsedCloudrunCli.timeoutSeconds ?? 300;@@ -36,7 +33,6 @@ Validating Deployment of Cloud Run Service:Service Timeout In Seconds = ${timeoutSeconds}Project Name = ${projectID}Region = ${region}- Allow Unauthenticated Access = ${allowUnauthenticated}`.trim()));@@ -120,11 +116,6 @@ Service Already Deployed! Check GCP Console for Cloud Run URL.);}}-- await allowUnauthenticatedAccessToService(- deployResult.fullName,- allowUnauthenticated- );} catch (e) {Log.error(CliInternals.chalk.red(@@ -138,74 +129,3 @@ Service Already Deployed! Check GCP Console for Cloud Run URL.throw e;}};--async function allowUnauthenticatedAccessToService(- serviceName: string,- allowUnauthenticated: boolean-) {- if (allowUnauthenticated) {- try {- if (!CliInternals.quietFlagProvided()) {- Log.info(- CliInternals.chalk.white(- '\nAllowing unauthenticated access to the Cloud Run service...'- )- );- }-- await allowUnauthenticatedAccess(serviceName, allowUnauthenticated);-- if (CliInternals.quietFlagProvided()) {- Log.info('Unauthenticated access granted');- } else {- Log.info();-- Log.info(- CliInternals.chalk.blueBright(- ` β Unauthenticated access granted on ${serviceName}`- )- );- }- } catch (e) {- Log.error(- CliInternals.chalk.red(- ` Failed to allow unauthenticated access to the Cloud Run service.`- )- );- throw e;- }- } else {- try {- if (!CliInternals.quietFlagProvided()) {- Log.info();-- Log.info(- CliInternals.chalk.white(- 'Ensuring only authenticated access to the Cloud Run service...'- )- );- }-- await allowUnauthenticatedAccess(serviceName, allowUnauthenticated);-- if (CliInternals.quietFlagProvided()) {- Log.info('Authenticated access granted');- } else {- Log.info();-- Log.info(- CliInternals.chalk.blueBright(- ` π Only authenticated access granted on ${serviceName}`- )- );- }- } catch (e) {- Log.error(- CliInternals.chalk.red(- ` Failed to allow unauthenticated access to the Cloud Run service.`- )- );- throw e;- }- }-}diff --git a/packages/docs/docs/cloudrun/cli/render.md b/packages/docs/docs/cloudrun/cli/render.mdindex 2067cd0e8c..e04f8cfc25 100644--- a/packages/docs/docs/cloudrun/cli/render.md+++ b/packages/docs/docs/cloudrun/cli/render.md@@ -94,10 +94,6 @@ Specify the url of the service which should be used to perform the render. You mSpecify the name of the service which should be used to perform the render. This is used in conjunction with the region to determine the service endpoint, as the same service name can exist across multiple regions. You must set either `cloud-run-url` _or_ `service-name`, but not both-### `--unauthenticated-request`--When this flag is set, the endpoint will be called without making use of credentials in the .env file. This requires the service to allow unauthenticated invocations. This can be set with the [--allow-unauthenticated](/docs/cloudrun/cli/services#--allow-unauthenticated) flag through the CLI, or through the [allowUnauthenticatedAccess](/docs/cloudrun/allowunauthenticatedaccess) method in the Node API.-## Media Rendering Specific FlagsThe above flags can be used for rendering both Still and Media. These flags are specific for Media rendering.diff --git a/packages/docs/docs/cloudrun/cli/services.md b/packages/docs/docs/cloudrun/cli/services.mdindex 4a56e7faaa..9c8616145c 100644--- a/packages/docs/docs/cloudrun/cli/services.md+++ b/packages/docs/docs/cloudrun/cli/services.md@@ -37,7 +37,6 @@ Validating Deployment of Cloud Run Service:Service Timeout In Seconds = 300Project Name = remotion-6Region = us-east1- Allow Unauthenticated Access = falseDeploying Cloud Run Service...@@ -74,13 +73,9 @@ Timeout of the Cloud Run service. Default: 300 seconds.Not to be confused with the [`--timeout` flag when rendering which defines the timeout for `delayRender()`](/docs/cli/render#--timeout).:::-### `--allow-unauthenticated`--If passed this allows anyone, including unauthenticated users, to access and interact with the deployed service's endpoint.-### `--quiet`, `-q`-Only logs the service name, and 'Authenticated access granted' or 'Unauthenticated access granted'.+Only logs the service name, and 'Authenticated access granted'.## lsdiff --git a/packages/docs/docs/cloudrun/setup.md b/packages/docs/docs/cloudrun/setup.mdindex cb00f662e3..1588ec552d 100644--- a/packages/docs/docs/cloudrun/setup.md+++ b/packages/docs/docs/cloudrun/setup.md@@ -297,7 +297,6 @@ const serviceName = services[0].serviceName;// ---cut---const { renderId, bucketName } = await renderMediaOnCloudrun({- authenticatedRequest: false, // unauthenticated request - requires cloud run service to be publiccloudRunUrl,serveUrl: url,composition: "HelloWorld",@@ -353,7 +352,6 @@ const outputFile = "string";// ---cut---const { renderId, publicUrl } = await renderStillOnCloudrun({- authenticatedRequest: false, // unauthenticated request - requires cloud run service to be publiccloudRunUrl,serveUrl: url,composition: "HelloWorld",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 77d8e44191..13c1ec5023 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -240,7 +240,6 @@ importers:'@types/minimist': 1.2.2eslint: 8.25.0google-auth-library: ^8.7.0- got: 11.8.2prettier: ^2.7.1prettier-plugin-organize-imports: ^3.2.2remotion: workspace:*@@ -256,7 +255,6 @@ importers:'@remotion/cli': link:../cli'@remotion/renderer': link:../renderergoogle-auth-library: 8.8.0- got: 11.8.2remotion: link:../coredevDependencies:'@jonny/eslint-config': 3.0.266_t54va6jeo5lf3vtqih5uiyrm5e@@ -15079,23 +15077,6 @@ packages:dependencies:get-intrinsic: 1.2.0- /got/11.8.2:- resolution: {integrity: sha512-D0QywKgIe30ODs+fm8wMZiAcZjypcCodPNuMz5H9Mny7RJ+IjJ10BdmGW7OM7fHXP+O7r6ZwapQ/YQmMSvB0UQ==}- engines: {node: '>=10.19.0'}- dependencies:- '@sindresorhus/is': 4.6.0- '@szmarczak/http-timer': 4.0.6- '@types/cacheable-request': 6.0.2- '@types/responselike': 1.0.0- cacheable-lookup: 5.0.4- cacheable-request: 7.0.2- decompress-response: 6.0.0- http2-wrapper: 1.0.3- lowercase-keys: 2.0.0- p-cancelable: 2.1.1- responselike: 2.0.1- dev: false-/got/11.8.5:resolution: {integrity: sha512-o0Je4NvQObAuZPHLFoRSkdG2lTgtcynqymzg2Vupdx6PorhaT5MCbIyXG6d4D94kk8ZG57QeosgdiqfJWhEhlQ==}engines: {node: '>=10.19.0'}