Skip to content

Commit

Permalink
fix: depecrate --ssh-add flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ComradeProgrammer committed Sep 25, 2023
1 parent f23902c commit f41096d
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 34 deletions.
61 changes: 31 additions & 30 deletions cmd/minikube/cmd/docker-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ type DockerShellConfig struct {
var (
noProxy bool
sshHost bool
sshAdd bool
sshAdd bool // depecrated
dockerUnset bool
defaultNoProxyGetter NoProxyGetter
)
Expand Down Expand Up @@ -271,6 +271,10 @@ For example, you can do all docker operations such as docker build, docker run,
Note: You need the docker-cli to be installed on your machine.
docker-cli install instructions: https://minikube.sigs.k8s.io/docs/tutorials/docker_desktop_replacement/#steps`,
Run: func(cmd *cobra.Command, args []string) {

if sshAdd {
out.WarningT("--ssh-add flag has been depecrated, please user --ssh-host instead. Now if you use --ssh-host to enable ssh connection with docker, minikube will automatically add ssh-agent and append hosts to known_hosts")
}
var err error

shl := shell.ForceShell
Expand Down Expand Up @@ -326,7 +330,11 @@ docker-cli install instructions: https://minikube.sigs.k8s.io/docs/tutorials/doc
// so directly set --ssh-host --ssh-add to true, even user didn't specify them
sshAdd = true
sshHost = true
}

d := co.CP.Host.Driver

if sshHost || sshAdd {
// start the ssh-agent
if err := sshagent.Start(cname); err != nil {
exit.Message(reason.SSHAgentStart, err.Error())
Expand All @@ -338,6 +346,27 @@ docker-cli install instructions: https://minikube.sigs.k8s.io/docs/tutorials/doc
// set the ssh-agent envs for current process
os.Setenv("SSH_AUTH_SOCK", co.Config.SSHAuthSock)
os.Setenv("SSH_AGENT_PID", strconv.Itoa(co.Config.SSHAgentPID))

klog.Infof("Adding %v", d.GetSSHKeyPath())

path, err := exec.LookPath("ssh-add")
if err != nil {
exit.Error(reason.IfSSHClient, "Error with ssh-add", err)
}
cmd := exec.Command(path, d.GetSSHKeyPath())
cmd.Stderr = os.Stderr

cmd.Env = append(cmd.Env, fmt.Sprintf("SSH_AUTH_SOCK=%s", co.Config.SSHAuthSock))
cmd.Env = append(cmd.Env, fmt.Sprintf("SSH_AGENT_PID=%d", co.Config.SSHAgentPID))

err = cmd.Run()
if err != nil {
exit.Error(reason.IfSSHClient, "Error with ssh-add", err)
}

// if we use ssh to connect the docker daemon, appending know is always required
// eventually, run something similar to ssh --append-known
appendKnownHelper(nodeName, true)
}

r := co.CP.Runner
Expand All @@ -346,7 +375,6 @@ docker-cli install instructions: https://minikube.sigs.k8s.io/docs/tutorials/doc
ensureDockerd(cname, r)
}

d := co.CP.Host.Driver
port := constants.DockerDaemonPort
if driver.NeedsPortForward(driverName) {
port, err = oci.ForwardedPort(driverName, cname, port)
Expand Down Expand Up @@ -404,33 +432,6 @@ docker-cli install instructions: https://minikube.sigs.k8s.io/docs/tutorials/doc
if err := dockerSetScript(ec, os.Stdout); err != nil {
exit.Error(reason.InternalDockerScript, "Error generating set output", err)
}

if sshAdd {
klog.Infof("Adding %v", d.GetSSHKeyPath())

path, err := exec.LookPath("ssh-add")
if err != nil {
exit.Error(reason.IfSSHClient, "Error with ssh-add", err)
}
cmd := exec.Command(path, d.GetSSHKeyPath())
cmd.Stderr = os.Stderr

// TODO: refactor to work with docker, temp fix to resolve regression
if cr == constants.Containerd {
cmd.Env = append(cmd.Env, fmt.Sprintf("SSH_AUTH_SOCK=%s", co.Config.SSHAuthSock))
cmd.Env = append(cmd.Env, fmt.Sprintf("SSH_AGENT_PID=%d", co.Config.SSHAgentPID))
}
err = cmd.Run()
if err != nil {
exit.Error(reason.IfSSHClient, "Error with ssh-add", err)
}

// TODO: refactor to work with docker, temp fix to resolve regression
if cr == constants.Containerd {
// eventually, run something similar to ssh --append-known
appendKnownHelper(nodeName, true)
}
}
},
}

Expand Down Expand Up @@ -692,7 +693,7 @@ func init() {
defaultNoProxyGetter = &EnvNoProxyGetter{}
dockerEnvCmd.Flags().BoolVar(&noProxy, "no-proxy", false, "Add machine IP to NO_PROXY environment variable")
dockerEnvCmd.Flags().BoolVar(&sshHost, "ssh-host", false, "Use SSH connection instead of HTTPS (port 2376)")
dockerEnvCmd.Flags().BoolVar(&sshAdd, "ssh-add", false, "Add SSH identity key to SSH authentication agent")
dockerEnvCmd.Flags().BoolVar(&sshAdd, "ssh-add", false, "Deprecated: Add SSH identity key to SSH authentication agent")
dockerEnvCmd.Flags().StringVar(&shell.ForceShell, "shell", "", "Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh, bash, zsh], default is auto-detect")
dockerEnvCmd.Flags().StringVarP(&outputFormat, "output", "o", "", "One of 'text', 'yaml' or 'json'.")
dockerEnvCmd.Flags().BoolVarP(&dockerUnset, "unset", "u", false, "Unset variables instead of setting them")
Expand Down
2 changes: 1 addition & 1 deletion site/content/en/docs/commands/docker-env.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ minikube docker-env [flags]
--no-proxy Add machine IP to NO_PROXY environment variable
-o, --output string One of 'text', 'yaml' or 'json'.
--shell string Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh, bash, zsh], default is auto-detect
--ssh-add Add SSH identity key to SSH authentication agent
--ssh-add Depecrated: Add SSH identity key to SSH authentication agent
--ssh-host Use SSH connection instead of HTTPS (port 2376)
-u, --unset Unset variables instead of setting them
```
Expand Down
1 change: 1 addition & 0 deletions translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"Deleting container \"{{.name}}\" ...": "Lösche Container \"{{.name}}\" ...",
"Deleting existing cluster {{.name}} with different driver {{.driver_name}} due to --delete-on-failure flag set by the user. ": "Lösche den existierenden Cluster {{.name}} mit unterschiedlichem Treiber {{.driver_name}} aufgrund des vom Benutzer gesetzten --delete-on-failure Parameters. ",
"Deleting node {{.name}} from cluster {{.cluster}}": "Lösche Node {{.name}} von Cluster {{.cluster}}",
"Depecrated: Add SSH identity key to SSH authentication agent": "",
"Directory to output licenses to": "",
"Disable checking for the availability of hardware virtualization before the vm is started (virtualbox driver only)": "Deaktivieren Sie die Überprüfung der Verfügbarkeit der Hardwarevirtualisierung vor dem Starten der VM (nur Virtualbox-Treiber)",
"Disable dynamic memory in your VM manager, or pass in a larger --memory value": "Deaktiveren Sie die dynmaische Memory-Verwaltung in ihrem VM manager oder verwenden Sie einen größeren --memory Wert",
Expand Down
1 change: 1 addition & 0 deletions translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
"Deleting container \"{{.name}}\" ...": "Eliminando contenedor \"{{.name}}\" ...",
"Deleting existing cluster {{.name}} with different driver {{.driver_name}} due to --delete-on-failure flag set by the user. ": "",
"Deleting node {{.name}} from cluster {{.cluster}}": "Eliminando nodo {{.name}} del clúster {{.cluster}}",
"Depecrated: Add SSH identity key to SSH authentication agent": "",
"Directory to output licenses to": "",
"Disable checking for the availability of hardware virtualization before the vm is started (virtualbox driver only)": "Permite inhabilitar la comprobación de disponibilidad de la virtualización de hardware antes de iniciar la VM (solo con el controlador de Virtualbox)",
"Disable dynamic memory in your VM manager, or pass in a larger --memory value": "Desactivar memoria dinámica in tu administrador de VM, o pasa un mayor valor --memory",
Expand Down
1 change: 1 addition & 0 deletions translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
"Deleting container \"{{.name}}\" ...": "Suppression du conteneur \"{{.name}}\" ...",
"Deleting existing cluster {{.name}} with different driver {{.driver_name}} due to --delete-on-failure flag set by the user. ": "Suppression du cluster existant {{.name}} avec un pilote différent {{.driver_name}} en raison de l'indicateur --delete-on-failure défini par l'utilisateur.",
"Deleting node {{.name}} from cluster {{.cluster}}": "Suppression de noeuds {{.name}} de cluster {{.cluster}}",
"Depecrated: Add SSH identity key to SSH authentication agent": "",
"Directory to output licenses to": "Répertoire de sortie des licences",
"Disable checking for the availability of hardware virtualization before the vm is started (virtualbox driver only)": "Désactive la vérification de la disponibilité de la virtualisation du matériel avant le démarrage de la VM (pilote virtualbox uniquement).",
"Disable dynamic memory in your VM manager, or pass in a larger --memory value": "Désactivez la mémoire dynamique dans votre gestionnaire de machine virtuelle ou transmettez une valeur --memory plus grande",
Expand Down
1 change: 1 addition & 0 deletions translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"Deleting container \"{{.name}}\" ...": "コンテナー「{{.name}}」を削除しています...",
"Deleting existing cluster {{.name}} with different driver {{.driver_name}} due to --delete-on-failure flag set by the user. ": "ユーザーが設定した --delete-on-failure フラグにより、異なるドライバー {{.driver_name}} を持つ既存のクラスター {{.name}} を削除しています。",
"Deleting node {{.name}} from cluster {{.cluster}}": "クラスター {{.cluster}} から、ノード {{.name}} を削除しています",
"Depecrated: Add SSH identity key to SSH authentication agent": "",
"Directory to output licenses to": "ライセンスを出力するディレクトリー",
"Disable checking for the availability of hardware virtualization before the vm is started (virtualbox driver only)": "VM が起動する前にハードウェアの仮想化の可用性チェックを無効にします (virtualbox ドライバーのみ)",
"Disable dynamic memory in your VM manager, or pass in a larger --memory value": "VM マネージャーで動的メモリーを無効にするか、より大きな --memory の値を指定してください",
Expand Down
1 change: 1 addition & 0 deletions translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"Deleting container \"{{.name}}\" ...": "",
"Deleting existing cluster {{.name}} with different driver {{.driver_name}} due to --delete-on-failure flag set by the user. ": "",
"Deleting node {{.name}} from cluster {{.cluster}}": "클러스터 {{.cluster}} 에서 노드 {{.name}} 를 삭제하는 중 ...",
"Depecrated: Add SSH identity key to SSH authentication agent": "",
"Directory to output licenses to": "",
"Disable checking for the availability of hardware virtualization before the vm is started (virtualbox driver only)": "가상 머신 시작 전 하드웨어 가상화 지원 여부 확인 작업을 비활성화합니다 (virtualbox 드라이버 한정)",
"Disable dynamic memory in your VM manager, or pass in a larger --memory value": "",
Expand Down
2 changes: 1 addition & 1 deletion translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"A set of key=value pairs that describe feature gates for alpha/experimental features.": "",
"Access the Kubernetes dashboard running within the minikube cluster": "Dostęp do dashboardu uruchomionego w klastrze kubernetesa w minikube",
"Access to ports below 1024 may fail on Windows with OpenSSH clients older than v8.1. For more information, see: https://minikube.sigs.k8s.io/docs/handbook/accessing/#access-to-ports-1024-on-windows-requires-root-permission": "",
"Add SSH identity key to SSH authentication agent": "",
"Add an image into minikube as a local cache, or delete, reload the cached images": "",
"Add an image to local cache.": "Dodaj obraz do lokalnego cache",
"Add host key to SSH known_hosts file": "Dodaj klucz hosta do pliku known_hosts",
Expand Down Expand Up @@ -160,6 +159,7 @@
"Deleting container \"{{.name}}\" ...": "Usuwanie kontenera \"{{.name}}\" ...",
"Deleting existing cluster {{.name}} with different driver {{.driver_name}} due to --delete-on-failure flag set by the user. ": "",
"Deleting node {{.name}} from cluster {{.cluster}}": "Usuwanie węzła {{.name}} z klastra {{.cluster}}",
"Depecrated: Add SSH identity key to SSH authentication agent": "",
"Directory to output licenses to": "",
"Disable checking for the availability of hardware virtualization before the vm is started (virtualbox driver only)": "",
"Disable dynamic memory in your VM manager, or pass in a larger --memory value": "",
Expand Down
2 changes: 1 addition & 1 deletion translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"A set of key=value pairs that describe feature gates for alpha/experimental features.": "",
"Access the Kubernetes dashboard running within the minikube cluster": "",
"Access to ports below 1024 may fail on Windows with OpenSSH clients older than v8.1. For more information, see: https://minikube.sigs.k8s.io/docs/handbook/accessing/#access-to-ports-1024-on-windows-requires-root-permission": "",
"Add SSH identity key to SSH authentication agent": "",
"Add an image into minikube as a local cache, or delete, reload the cached images": "",
"Add an image to local cache.": "",
"Add host key to SSH known_hosts file": "",
Expand Down Expand Up @@ -142,6 +141,7 @@
"Deleting container \"{{.name}}\" ...": "",
"Deleting existing cluster {{.name}} with different driver {{.driver_name}} due to --delete-on-failure flag set by the user. ": "",
"Deleting node {{.name}} from cluster {{.cluster}}": "",
"Depecrated: Add SSH identity key to SSH authentication agent": "",
"Directory to output licenses to": "",
"Disable checking for the availability of hardware virtualization before the vm is started (virtualbox driver only)": "",
"Disable dynamic memory in your VM manager, or pass in a larger --memory value": "",
Expand Down
2 changes: 1 addition & 1 deletion translations/strings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"A set of key=value pairs that describe feature gates for alpha/experimental features.": "",
"Access the Kubernetes dashboard running within the minikube cluster": "",
"Access to ports below 1024 may fail on Windows with OpenSSH clients older than v8.1. For more information, see: https://minikube.sigs.k8s.io/docs/handbook/accessing/#access-to-ports-1024-on-windows-requires-root-permission": "",
"Add SSH identity key to SSH authentication agent": "",
"Add an image into minikube as a local cache, or delete, reload the cached images": "",
"Add an image to local cache.": "",
"Add host key to SSH known_hosts file": "",
Expand Down Expand Up @@ -142,6 +141,7 @@
"Deleting container \"{{.name}}\" ...": "",
"Deleting existing cluster {{.name}} with different driver {{.driver_name}} due to --delete-on-failure flag set by the user. ": "",
"Deleting node {{.name}} from cluster {{.cluster}}": "",
"Depecrated: Add SSH identity key to SSH authentication agent": "",
"Directory to output licenses to": "",
"Disable checking for the availability of hardware virtualization before the vm is started (virtualbox driver only)": "",
"Disable dynamic memory in your VM manager, or pass in a larger --memory value": "",
Expand Down
1 change: 1 addition & 0 deletions translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
"Deleting container \"{{.name}}\" ...": "正在删除容器 \"{{.name}}\" ...",
"Deleting existing cluster {{.name}} with different driver {{.driver_name}} due to --delete-on-failure flag set by the user. ": "由于用户设置了 --delete-on-failure 标志,正在删除具有不同驱动程序 {{.driver_name}} 的现有集群 {{.name}}。",
"Deleting node {{.name}} from cluster {{.cluster}}": "正在从集群 {{.cluster}} 中删除节点 {{.name}}",
"Depecrated: Add SSH identity key to SSH authentication agent": "",
"Directory to output licenses to": "输出许可证的目录",
"Disable checking for the availability of hardware virtualization before the vm is started (virtualbox driver only)": "禁用在启动虚拟机之前检查硬件虚拟化的可用性(仅限 virtualbox 驱动程序)",
"Disable dynamic memory in your VM manager, or pass in a larger --memory value": "禁用虚拟机管理器中的动态内存,或者使用 --memory 传入更大的值",
Expand Down

0 comments on commit f41096d

Please sign in to comment.