Skip to content

Conversation

@colerogers
Copy link
Contributor

Description

Creating a way for customers to explicitly set the access control on v2 HTTP functions. The access control is set at the function level, so different functions can have different access policies. The customer can choose to set access control to public, private, or a custom service account. Access control is set in the onRequest({}) options object, by setting the invoker property. To handle multiple service accounts, invoker can accept an array of strings.

Code sample

export const myFunction = v2.https.onRequest({ invoker: 'private' }, (req, res) => { res.send("Done"); });

| string
| Array<options.SupportedRegion | string>;
cors?: string | boolean;
invoker?: Invoker | Invoker[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbleigh Should we make this an HTTPS only option or should we make it also an event trigger option and set the service account of EventArc accordingly? I guess maybe the former since we don't have a clear answer what to do if the user passes two SAs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think let's leave this HTTPS-only for now.

opts = optsOrHandler as HttpsOptions;
}

const invoker = 'invoker' in opts ? opts.invoker : 'public';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we validate these values at deploy time, but what happens when users specify a bad/valid-but-wtf values, e.g.

// Bad settings invoker: ['public', 'private'] invoker: ['private', 'service-account@'] // Valid, but wtf? invoker: ['public', 'service-account@']

Is having the following signature more appropriate?

invoker?: public | private | string[]
Copy link
Member

@inlined inlined Aug 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a fine TS signature (if you also allow string) though the CLI should handle the valid-but-wtf case

Copy link
Contributor Author

@colerogers colerogers Aug 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that all 3 of these cases should be treated as bad and should throw an error. The way I read the type definition is that the user can set 'public', 'private', '$service-account', or [ '$service-account-1', '$service-account-2', ... ]. They should not mix public or private with the array of service accounts.

I've added a helper method to src/common/encoding that will error out of the user sets public or private in the array.

/**
* Invoker to set access control on https functions.
*/
invoker?: Invoker | Invoker[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given your new defensive programming stance I agree with Daniel now that we can/should change our typing.

invoker?: 'public' | 'private' | string | string[]; 

This will make sure code complete doesn't suggest "public" or "private" when the customer enters an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the type definition

@colerogers colerogers merged commit 94414f4 into master Aug 11, 2021
@colerogers colerogers deleted the colerogers.http-access-control-v2 branch August 11, 2021 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 participants