Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dangerous command in k3s.sh #62

Open
mas-kon opened this issue Feb 25, 2024 · 3 comments
Open

Dangerous command in k3s.sh #62

mas-kon opened this issue Feb 25, 2024 · 3 comments

Comments

@mas-kon
Copy link

mas-kon commented Feb 25, 2024

Command in script
echo "StrictHostKeyChecking no" > ~/.ssh/config
destroying your config file for SSH. :(

Please change to
sed -i '1s/^/StrictHostKeyChecking no\n/' ~/.ssh/config

@zatricky
Copy link

zatricky commented Mar 11, 2024

Luckily I searched existing issues before suggesting the same change. Of note is that this same line is actually in multiple scripts, sometimes twice (local machine - and then sometimes run on the remote machine too):

./Docker-Swarm/swarm-3-nodes.sh
./Docker-Swarm/swarm.sh
./Kubernetes/K3S-Deploy/k3s.sh
./Kubernetes/Kubernetes-Lite/k3s.sh
./Kubernetes/RKE2-Cilium/rke2.sh
./Kubernetes/RKE2/rke2.sh

@JamesTurland
Copy link
Owner

Good spot, I'll amend that now. Thanks

@zatricky
Copy link

I see there were some updates. I realised that technically there is still a potential problem introduced by the change. If the file exists, the old behaviour would wipe it. If the file doesn't exist, the new behaviour results in an error. 🫣

I don't know how complex or edge-case-proof you want the scripts to be - but perhaps putting these security-reducing lines into the ssh config is actually a bad idea compared to just importing the keys:

mkdir -p ~/.ssh
for node in "${all[@]}"; do
  ssh-keyscan ${remote_host} >> ~/.ssh/known_hosts
done
perl -i -ne 'print if ! $x{$_}++' ~/.ssh/known_hosts

The first line makes sure the .ssh folder exists. It gives no output or errors unless the folder didn't exist and it was unable to create it.
The line inside the for loop connects to the remote host and saves the host's keys into known_hosts.
The last line assumes we have perl installed and is only there to remove duplicated entries out of the known_hosts file in case we happened to run the script a second time. There are many other ways to do the same thing however:
https://stackoverflow.com/questions/11532157/remove-duplicate-lines-without-sorting
https://stackoverflow.com/questions/1444406/how-to-delete-duplicate-lines-in-a-file-without-sorting-it-in-unix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants