faas icon indicating copy to clipboard operation
faas copied to clipboard

[Question] Pass API key in URL?

Open nelfer opened this issue 8 years ago • 5 comments

Hi,

I just learned from the guides about the docker secrets and passing the header with the key to grant access to a function. My question is, can this key be passed in a query string parameter? There are some programs that can post to the functions but have no option to add additional HTTP headers.

I learned about OpenFaaS because I was working Azure Functions and I thought there must be an open source version. In Azure Functions, the gateway keys can be created and then the function can be flagged to be called anonymously or with a key. If flagged with a key, it can be passed in the URL as a query string which is very convenient for consumption by other systems.

On a related note: Are there any plans to manage keys/secrets from the gateway UI, as not to have to access the physical server in order to create docker secrets? Thanks!

nelfer avatar Jun 20 '18 01:06 nelfer

I think this seems like two questions - you can use query strings, check out the workshop repo and docs site for more information on that. We've documented it in detail.

You may want to look at OpenFaaS Cloud on Kubernetes which has support for SealedSecrets enabling a "git push, get functions" experience.

alexellis avatar Jun 20 '18 08:06 alexellis

Thanks for the quick response.

It seems I got confused with this:

https://github.com/openfaas/faas/blob/master/guide/secure_secret_management.md

The link to the APIKeyProtected function is not working. So I thought that the gateway (somehow) can automatically filter/validate secrets. But now reading more into it, it seems like each individual function has to handle it.

Any plans to make the gateway to validate secrets? Allowing or denying function execution unless the right associated secret has been given (as a form value, query string or json property)?

This becomes important when doing integration with Slack/Mattermost/Jira where the function can potentially expose private information. Making sure the call is coming from the right place (validating the secret given to that webhook) by means of a query string value. Slack and Mattermost automatically give you a token that will be passed to the URL (the faas function) when posting. It will be nice if the gateway could have a mechanism to validate the such tokens so that each function doesn't have to do it.

For now, I think what I'll do is chain 2 functions to every call. I'll make a function that will validate tokens (in whichever form are passed) and have my other functions always call that one for validation. This is kinda the AWS way with lambda function, except that you can specify in the gateway which function is your authorization function, so the gateway makes the call chain automatically.

Thanks!

nelfer avatar Jun 20 '18 11:06 nelfer

Any plans to make the gateway to validate secrets? Allowing or denying function execution unless the right associated secret has been given (as a form value, query string or json property)?

I don't know what you mean by this.

We have documented how to use secrets here https://docs.openfaas.com/reference/secrets/ - what about this isn't working for you?

alexellis avatar Jun 20 '18 12:06 alexellis

The secrets work. But I have to implement it on each function (validation).

What I'm asking is if the gateway in some future, can handle secret validation. For example when configuring deployment of a function, tell it the secret name and where we expect the secret to come in the call (query string or form variable)

Then the gateway could block the function execution if the wrong parameter is passed. The function code doesn't have to worry about validating secrets.

nelfer avatar Jun 20 '18 12:06 nelfer

So I'm going to close this for now, because I figure out how to handle re-using a function with multiple secrets (a different secret for each integration point). For each point, I create a new secret, given a name like secret0, secret1, etc. and then I pass the name of the secret as parameter to the function.

This solves the issue of multiple endpoints that require a different secret each.

Thanks

P.S. I have a different question now, but I'll start a new thread

nelfer avatar Jun 22 '18 03:06 nelfer