MChorfa / porter-helm3

porter-helm3
Apache License 2.0
8 stars 10 forks source link

Support reading the kubeconfig file from any location #41

Closed carolynvs closed 2 years ago

carolynvs commented 2 years ago

Porter is changing the user that the container runs as from root to a lower privileged user "nonroot". I quickly realized that this mixin has /root/.kube/config hard coded.

The kubernetes library we are using does support automatically detecting the KUBECONFIG environment variable, and looking up the kubeconfig file from $HOME/.kube/config. It would be great if this mixin supported that as well because otherwise it will immediately stop working with new releases of porter v1.

I have a patch that I'll submit for this shortly.

eexwhyzee commented 2 years ago

+1 for this, this is also an issue for macos users where the /root dir is a read only file system by default, so we can't throw a kubeconfig in there

carolynvs commented 2 years ago

@eexwhyzee This change in particular is about reading the kubeconfig inside the bundle from a configurable location. On a client, you can use a parameter set to tell porter where to find the kubeconfig on your local machine.

eexwhyzee commented 2 years ago

hmm interesting, so i tried to run the airgap example on a k8s cluster running locally on my machine, and it errors out saying it can't find a kubeconfig at /root/.kube/config, even when i set the kubeconfig location to the one on my local machine:

❯ porter credentials show whalegap                                                    
Name: whalegap
Created: 7 minutes ago
Modified: 7 minutes ago

-----------------------------------------------------------
  Name        Local Source                    Source Type
-----------------------------------------------------------
  kubeconfig  /<LOCAL_PATH>/.kube/config  path

❯ porter install -c whalegap                                                            
installing whalegap...
executing install action from whalegap (installation: whalegap)
Install WhaleGap
Error: couldn't get kubernetes client: couldn't build kubernetes config: stat /root/.kube/config: no such file or directory
err: couldn't get kubernetes client: couldn't build kubernetes config: stat /root/.kube/config: no such file or directory
Error: mixin execution failed: exit status 1
Error: 1 error occurred:
    * container exit code: 1, message: <nil>

any suggestions/input on how to get this working would be much appreciated!

(also my bad for piggy backing onto this thread, i can create a separate issues thread if needed)

carolynvs commented 2 years ago

Oh shoot yes this is totally caused by the latest version of porter injecting the kubeconfig into /home/nonroot/.kube/config instead of /root/.kube/config because new versions of porter assume the bundle was built with nonroot support (instead of assuming it will be running as root).

I'm working on fixing this and will report back when I have steps to get things working again. Unfortunately, I didn't do a great job rolling out that change and as you have seen, there are a few more problems to work out first before we can use it.

Basically the examples all use nonroot now, but the helm3 mixin doesn't yet have #42 merged to work with nonroot. I don't think there's a good workaround at the moment, so hang tight and I'll try to get the published examples, porter and helm3 in agreement again.

Thanks for reporting this!

eexwhyzee commented 2 years ago

no worries at all and thank you for the update! looking forward for the fix getting in

carolynvs commented 2 years ago

I just moved the v1 examples to a new docker registry, can you try again with the whalegap bundle at ghcr.io/getporter/examples/whalegap:v0.2.0?

eexwhyzee commented 2 years ago

@carolynvs hmmm just tried and got the same error:

$ porter install -c whalegap
installing whalegap...
executing install action from whalegap (installation: whalegap)
Install WhaleGap
Error: couldn't get kubernetes client: couldn't build kubernetes config: stat /root/.kube/config: no such file or directory
err: couldn't get kubernetes client: couldn't build kubernetes config: stat /root/.kube/config: no such file or directory
Error: mixin execution failed: exit status 1
Error: 1 error occurred:
    * container exit code: 1, message: <nil>
carolynvs commented 2 years ago

I can't tell from what you posted if it actually used the new bundle. The following command would ensure that you have the most recent version:

porter install -c whalegap -r ghcr.io/getporter/examples/whalegap:v0.2.0 --force
carolynvs commented 2 years ago

This was fixed in #42