serverless-aws-alias icon indicating copy to clipboard operation
serverless-aws-alias copied to clipboard

Alias Authorizers

Open zachboyd opened this issue 7 years ago • 11 comments

When deploying an alias I have noticed that the old authorizers defined in API gateway are removed and a new set of authorizers are created that includes the alias name. I was wondering if this was intended behavior as I would think the authorizers could always have the same name, but then the stage vars on the authorizer definition would be leveraged so that the correct version was executed.

zachboyd avatar Feb 06 '18 14:02 zachboyd

It is intended behavior, because the authorizer name must be unique, and a different alias can define the authorizer with different settings (not only a different target). E.g. you can change the type of an authorizer to "REQUEST" instead of "TOKEN" in your development branch and deploy your branch as alias.

Having only the stage vars approach would force the authorizer definition itself the same on all aliases and any deploy will have an effect on all other already deployed aliases. As far as I know authorizers are not even deployed to a stage within APIG but stay globally cross stage there (but I might be wrong).

HyperBrain avatar Feb 06 '18 14:02 HyperBrain

Thanks for the clarification and I believe you are correct on the authorizers being cross stage. The authorizer name is referenced on the base resource definition in APIG so when you deploy an alias it looks like all existing aliases are now using the new alias authorizer definitions.

zachboyd avatar Feb 09 '18 14:02 zachboyd

If authorizers are cross-stage, might that be a reason to maintain the original authorizer names? Renaming them to include the authorizer name made me think that these authorizers were specific to the stage / alias, which doesn't appear to be possible in APIG.

BrandonEvansAsurion avatar Mar 27 '18 20:03 BrandonEvansAsurion

The renaming is on purpose because authorizer X can be deployed to alias A1 with a different configuration than in alias A2. Imagine that you have a stable alias that contains the stable deployment. Then you have developer A who rewrites the authorizer and applies a different configuration (like changing TOKEN to REQUEST or changing the internal validation). Now the developer deploys it to his own alias (e.g. feature-1). If the name would not be changed by the plugin, the developer would just screw the stable deployment because the authorizer will be replaced. The isolation that the plugin offers can only work properly if APIG global resources (stage independent) are renamed automatically. The plugin aims to overcome the APIG behavior and provide an isolation in the best way possible.

HyperBrain avatar Mar 28 '18 09:03 HyperBrain

I don't think I understand how one would deploy two authorizers with different configurations with this plugin. In my experience, deploying an alias overwrites the existing authorizers to contain the alias name. I agree that having separate copies would be useful if that's possible.

BrandonEvansAsurion avatar Mar 28 '18 17:03 BrandonEvansAsurion

My experience is the same as @BrandonEvansAsurion in that the authorizers are overwritten when deploying an alias as opposed to creating new ones. Based on what you are describing above I am assuming that is not intended behavior?

zachboyd avatar Mar 29 '18 01:03 zachboyd

@zachboyd Yes. They should be separate per alias deployment. I remember that I implemented it that way, but there might be a bug. I'll have to check.

HyperBrain avatar Mar 29 '18 08:03 HyperBrain

Thanks. Based on what you find I don't mind helping fix the issue if it does happen to be a bug. Just want to better understand the intended behavior as I haven't dug into authorizers a whole lot.

zachboyd avatar Mar 29 '18 14:03 zachboyd

Same here. Thanks @HyperBrain !

BrandonEvansAsurion avatar Mar 29 '18 15:03 BrandonEvansAsurion

Hi @HyperBrain @zachboyd, have any updates on it?

johnwongapi avatar Nov 22 '18 12:11 johnwongapi

Hello @HyperBrain @zachboyd any updates on this ? On my side the aliases seems to work (when i hit a stage i reach the associated authorizer) but they doesn't appear inside API Gateway console on AWS, they seems to be deleted.

monisnap-julien avatar May 04 '19 20:05 monisnap-julien