azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

Azure functions ignores entries for CORS allowed origins

Open yakeem opened this issue 8 years ago • 11 comments

I'm trying to deploy Azure with resource templates. In my template.json I want to set up allowed origins to all:

"siteConfig": { "cors": { "allowedOrigins": [ "*" ] },

The problem is that Azure anyway creates by default additional entries:

image

And after that I have problem with CORS, "*" rule seems to be ignored if there are any specific cors entries. So I need to manually delete these three added by Azure. Do you have any idea how I can automatically get rid of them or somehow else setup allowed origins to all?

yakeem avatar Mar 14 '18 09:03 yakeem

Which CLI command are you using and which service are you creating CORS rules for?

tjprescott avatar Mar 14 '18 17:03 tjprescott

I'm creating a resource group with command: az group deployment create --resource-group testrg --template-file template.json --parameters parameters.json --mode Complete

and within this group, i'm creating an Azure Function, triggered by HTTP binding. I want to create CORS rules for this function.

In template.json i'm describing this Azure Function, and as I have shown before, I'm adding one entry for cors allowed origin "*".

Azure however adds three additional allowed origins: https://functions.azure.com https://functions-staging.azure.com https://functions-next.azure.com

And in the end, only these three origins are allowed for CORS, the general rule for all origins is then ignored.

edit: This is also really problematic because Azure CLI currently does not provide an option to manage CORS entries for function apps --> https://github.com/Azure/azure-cli/issues/4565 I would like to have whole setting up an infrastructue in an automated way but I cannot workaround this issue.

yakeem avatar Mar 15 '18 08:03 yakeem

This sounds like a service limitation. @panchagnula can you confirm?

tjprescott avatar Mar 15 '18 16:03 tjprescott

Is there an ETA for an enhancement where the option to disable the default CORS rules will be supplied via ARM template (i.e. non-manual methods) for customers who do not require them?

jrgithub avatar Sep 22 '18 18:09 jrgithub

@jrgithub have you tried this command? https://docs.microsoft.com/en-us/cli/azure/webapp/cors?view=azure-cli-latest , this available for functonapps as well https://docs.microsoft.com/en-us/cli/azure/functionapp/cors?view=azure-cli-latest -

panchagnula avatar Sep 24 '18 17:09 panchagnula

@jrgithub have you tried this command? https://docs.microsoft.com/en-us/cli/azure/webapp/cors?view=azure-cli-latest , this available for functonapps as well https://docs.microsoft.com/en-us/cli/azure/functionapp/cors?view=azure-cli-latest -

Unfortunately this command does not work for me with web apps. The azure terminal outputs an updated allowedOrigins key:value but the host continues to generate a cors error.

lswright avatar Oct 06 '18 18:10 lswright

@ahmelsayed - can you please take a look & help out here please. Are there any special CORS setting that are missing here?

panchagnula avatar Oct 18 '18 19:10 panchagnula

Hi, I'm getting same issue where these three default entries remains and CORS headers don't get reflect in response. I'm using node-js based function and I could temporarily achieve the desired result by removing all CORS rules which were default added ( and did not add a new entry with *) additionally I added CORS headers manually in response object within nodeJS function and then the returning response had these headers reflecting..

so the only question remains is " Can these rules be removed programatically or using ARM template" so no manual intervention required.

R's navin

navinmistry avatar Feb 14 '19 13:02 navinmistry

  • will not remove all the entries, in Arm Template you should use an [] to remove all the rules, you can try by using resources.azure.com, & edit the Site Config CorRules property.

panchagnula avatar Feb 14 '19 16:02 panchagnula

Tried with below setting in template after having a word with azure guys on a service ticket call.

"resources": [{ "apiVersion": "2016-08-01", "name": "[parameters('appName')]", "type": "Microsoft.Web/sites", "properties": { "name": "[parameters('appName')]", "siteConfig": { "cors": { "allowedOrigins": ["*"] }, . . . . . .

This seems to be working, I didn't try it earlier as the very first comment convinced me it wouldn't work. ( Just to mention, I have CORS headers set in my function explicitly and they've started getting honoured after this template change )

looks like a solution to me!!

navinmistry avatar Feb 15 '19 12:02 navinmistry

i am closing this since this - we have a CLI command for this that has been released.

panchagnula avatar Feb 15 '19 19:02 panchagnula