diff --git a/cmd/git-sync/main.go b/cmd/git-sync/main.go index 7832b00..3a7d757 100644 --- a/cmd/git-sync/main.go +++ b/cmd/git-sync/main.go @@ -472,6 +472,7 @@ func setupGitSSH() error { log.V(1).Infof("setting up git SSH credentials") var pathToSSHSecret = "/etc/git-secret/ssh" + var pathToSSHKnownHosts = "/etc/git-secret/known_hosts" fileInfo, err := os.Stat(pathToSSHSecret) if err != nil { @@ -483,7 +484,7 @@ func setupGitSSH() error { } //set env variable GIT_SSH_COMMAND to force git use customized ssh command - err = os.Setenv("GIT_SSH_COMMAND", fmt.Sprintf("ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i %s", pathToSSHSecret)) + err = os.Setenv("GIT_SSH_COMMAND", fmt.Sprintf("ssh -q -o UserKnownHostsFile=%s -i %s", pathToSSHKnownHosts, pathToSSHSecret)) if err != nil { return fmt.Errorf("Failed to set the GIT_SSH_COMMAND env var: %v", err) } diff --git a/docs/ssh.md b/docs/ssh.md index a97eff7..fca85bd 100644 --- a/docs/ssh.md +++ b/docs/ssh.md @@ -6,15 +6,21 @@ Git-sync supports using the SSH protocol for pulling git content. Create a Secret to store your SSH private key, with the Secret keyed as "ssh". This can be done one of two ways: ***Method 1:*** +Obtain the host keys for your git server: + +``` +ssh-keyscan $YOUR_GIT_HOST > /tmp/known_hosts +``` Use the ``kubectl create secret`` command and point to the file on your filesystem that stores the key. Ensure that the file is mapped to "ssh" as shown (the file can be located anywhere). + ``` -kubectl create secret generic git-creds --from-file=ssh=~/.ssh/id_rsa +kubectl create secret generic git-creds --from-file=ssh=~/.ssh/id_rsa --from-file=known_hosts=/tmp/known_hosts ``` ***Method 2:*** -Write a config file for a Secret that holds your SSH private key, with the key (pasted as plaintext) mapped to the "ssh" field. +Write a config file for a Secret that holds your SSH private key, with the key (pasted in base64 encoded plaintext) mapped to the "ssh" field. ``` { "kind": "Secret", @@ -23,7 +29,8 @@ Write a config file for a Secret that holds your SSH private key, with the key ( "name": "git-creds" }, "data": { - "ssh": + "ssh": + "known_hosts": } ```