K3os: SSH authorized keys are appended instead of being overwritten

Created on 12 May 2020  路  2Comments  路  Source: rancher/k3os

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

  1. Have /system/k3os/config.yaml contain one SSH key.
  2. Then, create /var/lib/rancher/k3os/config.yaml with a new SSH key.
  3. Reboot
  4. Check the contents of ~/.ssh/authorized_keys

Expected 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).

kinbug

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:

# 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

All 2 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Moep90 picture Moep90  路  5Comments

svefors picture svefors  路  8Comments

mortenlj picture mortenlj  路  6Comments

PhilsLab picture PhilsLab  路  6Comments

runningman84 picture runningman84  路  3Comments