ssh: use specified proxy when importing SSH keys
When fetching SSH keys, the proxy settings specified by the user were not used. This resulted in the inability to import keys in networks where a HTTP proxy is mandatory. We now explicitly set the https_proxy environment variable when calling ssh-import-id if a proxy was configured by the user. Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
parent
e107504748
commit
aa4a674352
|
@ -14,6 +14,7 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
@ -77,8 +78,13 @@ class SSHController(SubiquityController):
|
||||||
identities: List[SSHIdentity] = []
|
identities: List[SSHIdentity] = []
|
||||||
|
|
||||||
import_command = ('ssh-import-id', '--output', '-', '--', user_id)
|
import_command = ('ssh-import-id', '--output', '-', '--', user_id)
|
||||||
|
env = None
|
||||||
|
if self.app.base_model.proxy.proxy:
|
||||||
|
env = os.environ.copy()
|
||||||
|
env["https_proxy"] = self.app.base_model.proxy.proxy
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cp = await arun_command(import_command, check=True)
|
cp = await arun_command(import_command, check=True, env=env)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
log.exception("ssh-import-id failed. stderr: %s", e.stderr)
|
log.exception("ssh-import-id failed. stderr: %s", e.stderr)
|
||||||
return SSHFetchIdResponse(status=SSHFetchIdStatus.IMPORT_ERROR,
|
return SSHFetchIdResponse(status=SSHFetchIdStatus.IMPORT_ERROR,
|
||||||
|
|
Loading…
Reference in New Issue