Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Crans Passwords
Manage
Activity
Members
Labels
Plan
Issues
5
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nounous
Crans Passwords
Commits
fa4e8acf
Commit
fa4e8acf
authored
4 years ago
by
Maxime Bombar
Browse files
Options
Downloads
Patches
Plain Diff
[remote] Correctly handles Include directive in SSH config
parent
b9ef74ef
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#3281
passed with warnings with stages
in 3 minutes and 15 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cpasswords/remote.py
+27
-7
27 additions, 7 deletions
cpasswords/remote.py
with
27 additions
and
7 deletions
cpasswords/remote.py
+
27
−
7
View file @
fa4e8acf
...
@@ -11,8 +11,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
...
@@ -11,8 +11,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
import
base64
import
base64
import
json
import
json
import
logging
import
logging
import
re
from
configparser
import
ConfigParser
from
functools
import
lru_cache
from
functools
import
lru_cache
from
getpass
import
getpass
from
getpass
import
getpass
,
getuser
from
hashlib
import
sha1
,
sha256
from
hashlib
import
sha1
,
sha256
from
pathlib
import
Path
from
pathlib
import
Path
...
@@ -117,12 +119,30 @@ def create_ssh_client(host, password=None):
...
@@ -117,12 +119,30 @@ def create_ssh_client(host, password=None):
client
.
set_missing_host_key_policy
(
AskUserOrDNSPolicy
)
client
.
set_missing_host_key_policy
(
AskUserOrDNSPolicy
)
# Load config file and use the right username
# Load config file and use the right username
try
:
# As of June 2020, paramiko doesn't support `Include` directive ...
config
=
SSHConfig
()
# See https://github.com/paramiko/paramiko/issues/1609
config
.
parse
(
Path
.
home
().
joinpath
(
"
.ssh/config
"
).
open
())
config_path
=
Path
.
home
().
joinpath
(
"
.ssh/config
"
)
username
=
config
.
lookup
(
host
).
get
(
"
user
"
,
None
)
# Match anything right after `Include` directive in a non commented line.
except
FileNotFoundError
:
include_regex
=
re
.
compile
(
"
^(?!#).*(?<=Include )([^\s]+)
"
)
username
=
None
config_files
=
[
config_path
]
with
open
(
config_path
)
as
cpath
:
for
line
in
cpath
.
readlines
():
m
=
include_regex
.
match
(
line
)
if
m
:
config_files
.
append
(
Path
(
m
.
group
(
1
)))
username
=
None
for
conf
in
config_files
:
try
:
config
=
SSHConfig
()
config
.
parse
(
conf
.
expanduser
().
open
())
except
FileNotFoundError
:
continue
username
=
config
.
lookup
(
host
).
get
(
"
user
"
)
if
username
:
break
if
not
username
:
username
=
getuser
()
log
.
debug
(
f
"
Will connect to
{
host
}
as
{
username
}
"
)
# Load system private keys
# Load system private keys
client
.
load_system_host_keys
()
client
.
load_system_host_keys
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment