fn icon indicating copy to clipboard operation
fn copied to clipboard

Basic Authentication

Open Daniel15 opened this issue 5 years ago • 8 comments

Description I'm trying to work out how to secure Fn when hosting it 'standalone' (without Kubernetes), given the ext-auth middleware is broken.

Even if I stick Fn behind an Nginx reverse proxy that performs authentication for all the administrative actions (deploying functions, etc), someone on the server itself could still directly hit the IP address for the Fn Docker container, bypassing the Nginx reverse proxy. It would be nice to support basic auth or a Bearer auth token out-of-the-box, similar to what OpenFaaS does: https://docs.openfaas.com/reference/authentication/. Then I could at least use this auth token in the Nginx configuration.

Daniel15 avatar Apr 18 '19 07:04 Daniel15

Hey @Daniel15 - I am going to try to get the auth and dns middleware examples working again this/next week, I suspect this is just a few minor compile bugs but may use the opportunity to clean up extensions stuff in general.

we do have support for an auth token in the cli I think by happenstance, as far as supporting it out of the box in fn, I suppose we could support it by allowing a token to be configured on server startup, but I think our hope in general is that if this is desired it's easy enough to build and use fn with auth extensions - have not thought out specifically supporting auth out of the box and intersection with any additional middleware authentication, specifically schemes that are not basic auth (and how to configure this to override basic, abstraction, etc).

rdallman avatar Apr 24 '19 17:04 rdallman

Thanks @rdallman! I did have a very brief look at trying to work out how to fix it, but didn't get too far, and you'll likely be able to do a better job. These are the compilation errors I hit when building ext-auth (https://github.com/fnproject/ext-auth/issues/4):

../../fnproject/ext-auth/app_listener.go:27:23: l.simple.ds.GetDatabase undefined (type models.Datastore has no field or method GetDatabase)
../../fnproject/ext-auth/app_listener.go:56:23: l.simple.ds.GetDatabase undefined (type models.Datastore has no field or method GetDatabase)
../../fnproject/ext-auth/app_listener.go:78:20: l.simple.ds.GetDatabase undefined (type models.Datastore has no field or method GetDatabase)
../../fnproject/ext-auth/app_listener.go:89:8: filter.NameIn undefined (type *models.AppFilter has no field or method NameIn)
../../fnproject/ext-auth/middleware.go:80:27: m.simple.ds.GetApp undefined (type models.Datastore has no field or method GetApp)
../../fnproject/ext-auth/simple.go:91:12: s.ds.GetDatabase undefined (type models.Datastore has no field or method GetDatabase)
../../fnproject/ext-auth/simple.go:107:12: s.ds.GetDatabase undefined (type models.Datastore has no field or method GetDatabase)
../../fnproject/ext-auth/simple.go:126:12: s.ds.GetDatabase undefined (type models.Datastore has no field or method GetDatabase)
../../fnproject/ext-auth/simple.go:146:13: s.ds.GetDatabase undefined (type models.Datastore has no field or method GetDatabase)

#1060 removed the GetDatabase method from models.Datastore, and I wasn't quite sure what to replace it with. Perhaps the solution is for ext-auth to have its own database object (instead of reusing fn's one), but given I don't actually know Golang and don't have time to properly learn it, I stopped looking into it 😅

I suspect when Fn hits 1.0, the API/ABI will be less susceptible to breaking changes like this.

The other functionality that'd be useful is the ability to disable creating new users (https://github.com/fnproject/ext-auth/issues/3) and allow multiple users for one app (https://github.com/fnproject/ext-auth/issues/2).

Daniel15 avatar Apr 25 '19 17:04 Daniel15

@rdallman - Any luck with the middleware?

Daniel15 avatar Jun 03 '19 18:06 Daniel15

hey @Daniel15 - first step of updating https://github.com/fnproject/fn/pull/1481 (pending review) - I think I'm going to rework the example's main to set up the datastore itself, grab the db out of there, and use it, rather than all the additional plumbing to get the datastore out. sorry for delay here, wedged getting reviews for a bit now.

rdallman avatar Jun 03 '19 22:06 rdallman

Any way to help here?

dgutson avatar Jun 24 '19 10:06 dgutson

@dgutson https://github.com/fnproject/fn/issues/1476#issuecomment-498455578 is the plan, it's going to take some time to add some methods to fn and then make the changes in the ext-auth repo to use them. if you have an existing auth solution you need to integrate with, ext-auth is a decent template as is and the changes I'm making won't help much - just remove all the db usage and change it to client calls to your auth service (/ caching).

rdallman avatar Jun 25 '19 18:06 rdallman

I am going with standalone fn option, @Daniel15 , have you made any progress to authenticate fn? i am thinking of going by iptables access, only few apps are given access to hit fn server.

praveendk avatar Sep 16 '19 07:09 praveendk

i put nginx infront of fn api but the fn api client cant handle basic auth

K0IN avatar Jan 06 '21 23:01 K0IN