Commit Graph

11 Commits

Author SHA1 Message Date
Paulo Gomes 3ab95a4bf0
libgit2: close discarded connections
Cached connections can be shared across concurrent
operations, and their disposal must take that into
account to avoid closing a connection that is stale for
one goroutine, but is still valid for another.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-04-07 18:37:40 +01:00
Paulo Gomes add07745f3
libgit2: restrict smart creds to Type SSH Memory
Avoid asking for SSH credential in files, as they won't be
used. The cacheKeyAndConfig func already enforces this
behaviour.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-04-07 18:37:39 +01:00
Paulo Gomes d86f0a280a
libgit2: validate URL max length
The major Git SaaS providers have repository URLs
for both HTTP and SSH that tops around 250
characters in length.

The limits chosen were a lot higher to align with use
cases in which users may have on-premise servers with
long domain names and paths.

For SSH the validation is around path length only,
which is now limited to 4096 characters, which is
at the higher end of the range in Linux.

For HTTP the validation is around the full URL
provided by the caller.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-04-07 18:37:38 +01:00
Paulo Gomes 54d0794d19
libgit2: handle the closing of stale connections
Internal and upstream calls to sshSmartSubtransport.Close()
when dealing with an stale connection, may lead to misleading
errors.

Focus should instead be redirected to ensuring that Close()
releases resources and ensures that a new SubTransport can be
created, so new operations can succeed.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-04-07 18:37:38 +01:00
Paulo Gomes 69c3f00172
libgit2: retry on stale connections
SSH servers that block the reuse of SSH connections for
multiple SSH sessions may lead to EOF when a new session
is being created.

This fixes the issue of long-running connections resulting
in EOF for GitLab servers.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-04-07 18:37:37 +01:00
Sanskar Jaiswal 5c84ea7e96 add flag to allow configuration of SSH kex algos
Adds a flag `ssh-kex-algos` which configures the gogit and libgit2
managed clients to use the specified list of kex algos for ssh. If not
used the default list in `golang/x/crypto/ssh` is used.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2022-04-07 16:43:15 +05:30
Paulo Gomes 36fcdeeb5e
libgit2: fix access to nil t.stdin and improve observability
All errors that were previously not handled are now logged through
traceLog, to further help during transport investigations.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-03-30 14:44:41 +01:00
Paulo Gomes 92ad1f813b
Cache SSH connections
The underlying SSH connections are kept open and are reused
across several SSH sessions. This is due to upstream issues in
which concurrent/parallel SSH connections may lead to instability.

https://github.com/golang/go/issues/51926
https://github.com/golang/go/issues/27140
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-03-28 11:58:10 +01:00
Paulo Gomes 017707a71c
Improve managed transport observability
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-03-25 19:08:54 +00:00
Paulo Gomes 5091b69ad5
Force ssh.Dial timeout
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-03-25 19:08:52 +00:00
Paulo Gomes aa3288112e
Implement Managed Transport for libgit2
libgit2 network operations are blocking and do not provide timeout nor context capabilities,
leading for several reports by users of the controllers hanging indefinitely.

By using managed transport, golang primitives such as http.Transport and net.Dial can be used
to ensure timeouts are enforced.

Co-Authored-by: Sunny <darkowlzz@protonmail.com>
Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
2022-03-16 16:22:20 +05:30