fix(middleware): added client credential login to middleware#1844
fix(middleware): added client credential login to middleware#1844kian99 merged 1 commit intocanonical:v3from
Conversation
internal/middleware/authn.go
Outdated
| if err == nil { | ||
| next.ServeHTTP(w, r.WithContext(withIdentity(ctx, user))) | ||
| } | ||
| // then try client credentials authentication |
There was a problem hiding this comment.
I'd prefer an explicit method for client creds, I wouldn't consider them basic auth as that implies it is a person. It also doesn't read well as the method is called AuthenticateWithSessionTokenViaBasicAuth, so oyou could call it AuthenticateWithSessionTokenViaBasicAuthOrClientCredentials or just make a new method.
d9becbf to
34d35c6
Compare
| ctx := r.Context() | ||
| // extract auth token | ||
| _, password, ok := r.BasicAuth() | ||
| username, password, ok := r.BasicAuth() |
There was a problem hiding this comment.
Agreed with Alex that we are overloading things here. It would make more sense to parse the Authorization header. If it's basic auth, i.e. Basic <base64value> we treat it as a client-id/secret, and if it's Bearer <token> we treat it as a session token. The auth schemes are covered here. Unfortunately we can't change the handling for tokens since that would break backwards compatibility.
We could change the format for the ClientCredentials login provider since only JIMM parses it and clearly that doesn't work yet. I.e. on the Juju client side use a different scheme rather than Basic. There aren't any good schemes that cover this though. And it also takes me back to the idea that JIMM "technically" shouldn't receive a client-id/secret, the client should exchange those with the identity server for a token, then it's always bearer auth.
A long term option would be to change the Juju client's SessionTokenLoginProvider to send a Bearer <token> header and support both for a time. A bunch of effort for not much gain though.
In the end, what you've done is fine. To avoid the try option 1 then try option 2, you could choose to check if username != "" and do the client-credentials login else do SessionToken login but that's a nit imo.
internal/middleware/authn.go
Outdated
| // AuthenticateViaBasicAuth performs basic auth authentication and puts an identity in the request's context. | ||
| // The basic-auth is composed of an empty user, and as a password a jwt token that we parse and use to authenticate the user. |
There was a problem hiding this comment.
I'd expand the docstring to explain why we have to try one option then another.
Enables client credential login to http endpoints we proxy.
34d35c6 to
52e8b5d
Compare
Description
Enables client credential login to http endpoints we proxy.
Engineering checklist
Test instructions