Version (k3OS / kernel)
k3OS v0.10.0
5.0.0-43-generic
Architecture
amd64
Describe the bug
If two different config.yaml files each contain a SSH key, they will both be present in ~/.ssh/authorized_keys whereas the merged config (output from sudo k3os config --dump) only contains the second one.
To Reproduce
/system/k3os/config.yaml contain one SSH key./var/lib/rancher/k3os/config.yaml with a new SSH key.~/.ssh/authorized_keysExpected behavior
I would expect ~/.ssh/authorized_keys to only contain what is defined in the merged config.yaml as displayed by sudo k3os config --dump. In my case, it would be the value from /var/lib/...
Actual behavior
It ends up containing both keys (so it appends instead of overwriting the file).
Reviewing the code, keys are intentionally appended to /home/rancher/.ssh/authorized_keys. This is because authorized keys are store on persistent disk, ${root}/k3os/data/home/rancher/.ssh/authorized_keys, allowing for external augmentation.
To get the behavior that you require, a workaround:
# include this in:
# - /var/lib/rancher/k3os/config.yaml, or
# - /var/lib/rancher/k3os/config.d/*.yaml
boot_cmd:
- truncate /home/rancher/.ssh/authorized_keys --reference /dev/null
I tested the boot_cmd you provided and it seems to work very well.
Not sure if this should be documented or not, or maybe just a note that says that ssh keys are appended by default.
Anyhow, since this is expected behaviour on your end, I will go ahead and close the issue.
Thanks!
Most helpful comment
Reviewing the code, keys are intentionally appended to
/home/rancher/.ssh/authorized_keys. This is because authorized keys are store on persistent disk,${root}/k3os/data/home/rancher/.ssh/authorized_keys, allowing for external augmentation.To get the behavior that you require, a workaround: