cloudfoundry / cf-crd-explorations

Apache License 2.0
3 stars 2 forks source link

Explore: authenticating `cf-java-client` #80

Closed kieron-dev closed 3 years ago

kieron-dev commented 3 years ago

With the CF CLI, we found we could use pieces of client-go to authenticate exactly the same was as kubectl does.

Explore whether an analogue is possible using the cf-java-client, borrowing authentication mechanisms from the official java k8s client.

Outcomes:

kieron-dev commented 3 years ago

Getting the workstation ready, assuming we don't want this in eirini-station:

  1. sudo apt get default-jdk - going for the default of java v11, as this is in LTS and things don't compile in v16, it seems...
  2. sudo apt get maven
  3. git clone https://github.com/cloudfoundry/cf-java-client
    • cd cf-java-client
    • gsu
    • export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
    • ./mvnw clean install -DskipTests
    • ./mvnw dependency:resolve
    • ./mvnw dependency:resolve -Dclassifier=sources
  4. git clone https://github.com/kubernetes-client/java k8s-java-client
    • cd k8s-java-client
    • ./mvnw clean install -DskipTests
    • ./mvnw dependency:resolve
    • ./mvnw dependency:resolve -Dclassifier=sources

Then in nvim, :CocInstall coc-java will install a java LSP. Might be based on running eclipse in the background though! I've had better performance from using the build-in lsp: https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#java_language_server.

kieron-dev commented 3 years ago

Some notes on k8s java client. Importantly, pinniped is NOT supported, as it uses a client-go Exec Credentials plugin that returns a client certificate / key pair.

kieron-dev commented 3 years ago

Some notes on cf-java-client.

kieron-dev commented 3 years ago

Back to the k8s client:

This is used by the KubeConfigAuthentication object mentioned above, but has the benefit of not wrapping up the token up with the apiClient, meaning we can use this directly in a new cf-java-client TokenProvider.

It still has the problem mentioned above that exec credential plugins returning certificates will not be supported.

kieron-dev commented 3 years ago

Closing this exploration now.

Findings:

  1. cf-java-client uses a mix of v2 and v3 endpoints. Our example app chose to list apps, and this uses v2 endpoints. This is not in scope currently for cf-on-k8s.
  2. It is simple enough to use the official k8s java client to access the kubeconfig. See https://github.com/eirini-forks/cf-java-client/commit/90076e74cb15577e3d927e0426253af7020eafab. However, the logic of checking $KUBECONFIG, then $HOME/.kube/config, then in cluster configuration is hidden in private methods which need to be duplicated.
  3. We have access to statically defined client certificates/keys and tokens, and tokens via auth-provider and exec-credential plugins. However, the k8s client does not yet support getting certificate/key from an exec-credential plugin. This is a deal-breaker for pinniped, say, which returns a certificate/key from an exec-credential plugin.
  4. For the cf-java-client library to support cf-on-k8s, we would need to upgrade all relevant operations to use v3 endpoints, and look at other means to extract certificates/keys from an exec-credential plugin.