kubernetes: Missing test coverage for OIDC code

/sig auth

xref #108794


I have been thinking about this change and the associated code, especially in regards to the on-going quality discussion.

While I think this change is at least partially a move in the right direction, I believe further refactors are required to actually make this code understandable and maintainable (and correct in all configurations).

Thus before making changes to this code, I would like to see the following integration test coverage:

  • Build a mock OIDC test server with the JWKs, well-known, and token endpoints
  • Run a test API server
  • Configure it to use a the mock OIDC test server (process local)
  • Configure the client(s) based on the specific test scenario
  • Make calls to the CSR API and the token review API (with and without correct audience) and assert the user info is correct

Some scenarios that come to mind (this is not meant to be a complete list, and I suspect some will fail on the existing code):

  1. ID token not expired
  2. ID token expired
  3. Refresh token does not change
  4. Refresh token does change
  5. Other aspects of the config change (i.e. client secret, CA data, etc)
  6. Auth config persister does not actually persist
  7. Refresh flow does not return ID token
  8. ID token expires early due to JWK rotation
  9. Distributed claim fetching for group data
  10. …

The above will likely need multiple permutations, in particular I would like to see both kubeconfig files as input (maybe even the same file concurrently across different round trippers) and rest.Config as inputs (with every weird config a code integrator could come up with).

In an ideal world we would have e2e tests in a similar vain as the above against an OIDC provider like Dex or Keycloak or UAA, but we can leave that off for now.

The API server OIDC support and the client-go OIDC support are two halves of the same feature, and both sides have no real integration test coverage when used in conjunction with an API server. Lets fix that so that we can make changes with confidence.

_Originally posted by @enj in https://github.com/kubernetes/kubernetes/issues/108794#issuecomment-1126162050_

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 16 (14 by maintainers)

Most upvoted comments

@r-erema sure but I would replace that claims server in a different PR. Small and separate PRs are much easier to review and limit the chance that we regress anything / lose any test coverage.

@stlaz and @r-erema I see that you both have PRs open for this. Can we make sure we are not duplicating code / effort here? #115059 #115122

cc @aramase

Also, these unit, integration and e2e tests should not add any new go dependencies to the project. e2e tests may run new container images as needed.

@r-erema coordinate with @aramase who had mentioned taking this issue a while back.