From 97e5ce4344e5f37393089f7dc904b0c528499375 Mon Sep 17 00:00:00 2001 From: streambinder Date: Thu, 26 Sep 2019 12:23:31 +0200 Subject: [PATCH 1/3] internal: backend: sftp: support user@domain parsing as user --- internal/backend/sftp/config.go | 7 +++++-- internal/backend/sftp/config_test.go | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/backend/sftp/config.go b/internal/backend/sftp/config.go index 90fe52c39..2860a479e 100644 --- a/internal/backend/sftp/config.go +++ b/internal/backend/sftp/config.go @@ -56,8 +56,11 @@ func ParseConfig(s string) (interface{}, error) { host = data[0] dir = data[1] // split user and host at the "@" - data = strings.SplitN(host, "@", 2) - if len(data) == 2 { + data = strings.SplitN(host, "@", 3) + if len(data) == 3 { + user = data[0] + "@" + data[1] + host = data[2] + } else if len(data) == 2 { user = data[0] host = data[1] } diff --git a/internal/backend/sftp/config_test.go b/internal/backend/sftp/config_test.go index 44439005e..acf07e4e7 100644 --- a/internal/backend/sftp/config_test.go +++ b/internal/backend/sftp/config_test.go @@ -1,6 +1,8 @@ package sftp -import "testing" +import ( + "testing" +) var configTests = []struct { in string @@ -41,6 +43,10 @@ var configTests = []struct { "sftp:user@host:/dir/subdir", Config{User: "user", Host: "host", Path: "/dir/subdir"}, }, + { + "sftp:user@domain@host:/dir/subdir", + Config{User: "user@domain", Host: "host", Path: "/dir/subdir"}, + }, { "sftp:host:../dir/subdir", Config{Host: "host", Path: "../dir/subdir"}, From c56cbfe95be5e6f8656f9da24b81d8baf101e4ed Mon Sep 17 00:00:00 2001 From: streambinder Date: Thu, 19 Dec 2019 11:58:33 +0100 Subject: [PATCH 2/3] changelog: add pull-2423 --- changelog/unreleased/pull-2423 | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/unreleased/pull-2423 diff --git a/changelog/unreleased/pull-2423 b/changelog/unreleased/pull-2423 new file mode 100644 index 000000000..16487a8fe --- /dev/null +++ b/changelog/unreleased/pull-2423 @@ -0,0 +1,5 @@ +Enhancement: support user@domain parsing as user + +Added the ability for user@domain-like users to be authenticated over SFTP servers. + +https://github.com/restic/restic/pull/2423 From 9b5d069ade7809a29a01d8ff48127062971a60d2 Mon Sep 17 00:00:00 2001 From: streambinder Date: Thu, 19 Dec 2019 12:02:48 +0100 Subject: [PATCH 3/3] doc: 030: sfpt: hint for domain-confined users --- doc/030_preparing_a_new_repo.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/030_preparing_a_new_repo.rst b/doc/030_preparing_a_new_repo.rst index 3cadf78a5..9133c70a3 100644 --- a/doc/030_preparing_a_new_repo.rst +++ b/doc/030_preparing_a_new_repo.rst @@ -78,6 +78,9 @@ You can also specify a relative (read: no slash (``/``) character at the beginning) directory, in this case the dir is relative to the remote user's home directory. +Also, if the SFTP server is enforcing domain-confined users, you can +specify the user this way: ``user@domain@host``. + .. note:: Please be aware that sftp servers do not expand the tilde character (``~``) normally used as an alias for a user's home directory. If you want to specify a path relative to the user's home directory, pass a