Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions doesn't allow function name or route /api/admin #1781

Open
omkarmore83 opened this issue Aug 11, 2017 · 8 comments
Open

Functions doesn't allow function name or route /api/admin #1781

omkarmore83 opened this issue Aug 11, 2017 · 8 comments
Labels
Milestone

Comments

@omkarmore83
Copy link
Member

omkarmore83 commented Aug 11, 2017

By default functions has a route prefix of "/api". When I try to create a function with the name "admin", Function gives an error saying

Error:

Function ($admin) Error: The specified route conflicts with one or more built in routes.
Session Id: 19b72d6133b2489987185f757f8c1fe2

Timestamp: 2017-08-11T18:18:36.311Z

Functions built in route uses /admin. Its understandable that this is reserved. However functions with route /api/admin or with any other route prefix should be allowed.

Infact it doesnt even allow function names like administrator or anything that starts with admin.

@christopheranderson
Copy link
Contributor

This likely needs to stay blocked because you can change the base route to "/" and then you'd have "/admin" with you function named admin. We'd need a safer way to evaluate this.

@christopheranderson christopheranderson added this to the Next milestone Aug 14, 2017
@jyn514
Copy link

jyn514 commented Jun 20, 2019

This doesn't give a warning if you have it in a regex constraint, it took me a while even to figure out that this was intentional. If I change it to say "route": "admin" it gives a warning. Sample code:

{
"bindings": [
     {
        "route": "{url:regex(admin)}"
     }
]
}

@CastleArg
Copy link

I'm having a problem here with getStatusQueryUris, eg
http://myApp/runtime/webhooks/durabletask/instances/xxxxxxx

I have a catch all proxy to route to SPA UI and have more specific proxies e.g /api/myFunc for actual backend stuff.
However it is now impossible to query status.

Hitting the statusQueryUri will be routed to SPA UI, and I cannot make a proxy to force tit to the backend due to this issue.

@rithinch
Copy link

rithinch commented Nov 2, 2019

Workaround

You can change the route name from /admin to something likev2/admin in your function code.

Example:

[FunctionName("ExampleAdminRoute")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "v2/admin")]HttpRequest req, ILogger log)
{
    //your function code
}

Then, you can add a proxy to the route (more info on azure function proxies here). Proxies are stored in proxies.json.

Make sure this file is copied to the build output directory i.e. including in .csproj file.

Example proxies.json:

{
  "$schema": "http://json.schemastore.org/proxies",
  "proxies": {
    "AdminProxy": {
      "matchCondition": {
        "methods": [ "GET" ],
        "route": "/api/admin"
      },
      "backendUri": "https://localhost/api/v2/admin"
    }
  }
}

Now, when you run the functions app, you should see console output like:

Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.
Listening on http://0.0.0.0:7071/
Hit CTRL-C to exit...

Http Functions:

	AdminProxy: http://localhost:7071/api/admin

	ExampleAdminRoute: http://localhost:7071/api/v2/admin

Any requests coming to api/admin will automatically be redirected to api/v2/admin.

Proxies are flexible enough to match different types of requests (GET/POST) with parameters etc.

The same applies to functions app written in any language i.e. Node.js, Python etc.

More info in the stackoverflow question here.

@ggailey777
Copy link

Do we plan to address this, or should we just document it? I have a related doc issue where the customer wants to name the function admin-results-email. https://github.com/MicrosoftDocs/azure-docs/issues/80267

I understand blocking admin but not admin-*

@gabr1elt-arc
Copy link

admin-* should be allowed to group admin apis!

@briandunnington
Copy link

This likely needs to stay blocked because you can change the base route to "/" and then you'd have "/admin" with you function named admin. We'd need a safer way to evaluate this.

you could also change your function name from "notadmin" to "admin" and it would also break, but it shouldnt try to protect you from something you havent done yet.

if the resolved routes arent in conflict when the app is built, it shouldnt cause an error.

we got bit by this going the other way. originally, we had a routePrefix of api and some routes like "something/admin/whatever" which worked fine. then we changed our routePrefix to "api/something" and the route to "admin/whatever" (so the net effect was that the final route didnt change at all) and it started erroring out, even though 1) the actual route didnt change and 2) api/something/admin is not in conflict with any built-in routes.

@aeromac
Copy link

aeromac commented Jan 23, 2025

shouldn't built-in routes have a prefix like /.admin or /_admin instead? SWA uses /_ah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants