cloudfoundry / cf-crd-explorations

Apache License 2.0
3 stars 2 forks source link

Explore: evaluate OIDC/OAuth2 authentication flows #33

Closed gcapizzi closed 3 years ago

gcapizzi commented 3 years ago

Background

OpenID Connect 1.0, which is built on top of OAuth 2.0, supports three authentication flows:

We want to understand which one is the best suited for our oidc-login implementation. Some notes:

Questions

Resources

Dev Notes

georgethebeatle commented 3 years ago

So far we have managed to implement 2 oidc flows

We have tested both against dex (instructions here)

Both flows are supported by the same cf cli plugin based on whether you pass in a client secret or not.

We wanted to test the implicit grant flow as well, but it looks like it is not supported by kubernetes, since when you configure the apiserver to work with oidc, the oidc-client-id is a required parameter: https://kubernetes.io/docs/reference/access-authn-authz/authentication/#configuring-the-api-server

gcapizzi commented 3 years ago

We wanted to test the implicit grant flow as well, but it looks like it is not supported by kubernetes

@georgethebeatle the Implicit flow still requires client_id ID to be passed in the authorization request.

mnitchev commented 3 years ago

We implemented the implicit flow for the cli plugin which had a few caveats:

To solve the last problem, we serve a static HTML page with some javascript to extract the token and send it as a query param to the server.

References:

  1. https://openid.net/specs/openid-connect-core-1_0.html#NonceNotes
  2. https://openid.net/specs/openid-connect-core-1_0.html#ImplicitCallback
  3. https://openid.net/specs/openid-connect-core-1_0.html#ImplicitAuthResponse
  4. https://datatracker.ietf.org/doc/html/rfc3986#section-3.5
mnitchev commented 3 years ago

As a conclusion - we think that the PKCE flow is the best one and the most suited to use in the cli. However we can also have all of the other flows implemented in the plugin for whoever needs them, and have PKCE as default.

kieron-dev commented 3 years ago

It is recommended for IDPs to issue short-lived tokens with refresh tokens for better security. This gives the IDP the opportunity to stop access for a given user, effectively revoking the token. Okta suggests a short lived token might be issued for several hours. It also points out the bad user experience using short-lived tokens without refresh tokens, while noting long-lived tokens are problematic for security.

The expiry time of a token is up to configuration in the IDP, i.e. outside of our control. Therefore we should definitely support refresh tokens to avoid a bad user experience when IDP configuration provides short-lived tokens.

If we want to support the implicit flow, tokens will need to be longer-lived, and we should document the potential security issues with harder revocation and more damage on leakage.