diff --git a/source/Calamari.Tests/ArgoCD/Git/AuthenticatingRepositoryFactoryTests.cs b/source/Calamari.Tests/ArgoCD/Git/AuthenticatingRepositoryFactoryTests.cs index 3d4593717..5d559298f 100644 --- a/source/Calamari.Tests/ArgoCD/Git/AuthenticatingRepositoryFactoryTests.cs +++ b/source/Calamari.Tests/ArgoCD/Git/AuthenticatingRepositoryFactoryTests.cs @@ -81,6 +81,8 @@ public void AnonymousCloneWhenNoCredentialsMatch() public class SshUrlTests : AuthenticatingRepositoryFactoryTestBase { [Test] + // SSH not currently functional on Windows + [Category(TestCategory.CompatibleOS.OnlyNixOrMac)] public void SshCredentialBranch_IsSelectedAndDispatchesSshKeyGitConnection() { // Use an ssh:// URL so the new strict validation allows it, and mock the factory @@ -108,6 +110,8 @@ public void HttpsCredentialTakesPriorityOverSshWhenBothMatchAnSshUrl() } [Test] + // SSH not currently functional on Windows + [Category(TestCategory.CompatibleOS.OnlyNixOrMac)] public void KnownHostsFromDtoAreCarriedOntoSshKeyGitConnection() { const string sshUrl = "ssh://git@github.com/org/repo.git"; diff --git a/source/Calamari.Tests/ArgoCD/Git/RepositoryFactoryTests.cs b/source/Calamari.Tests/ArgoCD/Git/RepositoryFactoryTests.cs index d9103a546..f52231a15 100644 --- a/source/Calamari.Tests/ArgoCD/Git/RepositoryFactoryTests.cs +++ b/source/Calamari.Tests/ArgoCD/Git/RepositoryFactoryTests.cs @@ -96,6 +96,8 @@ public void CanCloneAnExistingRepositoryAtHEADAndAssociatedFiles() } [Test] + // SSH not currently functional on Windows + [Category(TestCategory.CompatibleOS.OnlyNixOrMac)] public void CloningSshKeyGitConnectionDoesNotResolveAPullRequestClientAndLogsVerboseMessage() { var filename = "sshTest.txt"; diff --git a/source/Calamari/ArgoCD/Git/RepositoryFactory.cs b/source/Calamari/ArgoCD/Git/RepositoryFactory.cs index 6b70ec16b..771c9b83b 100644 --- a/source/Calamari/ArgoCD/Git/RepositoryFactory.cs +++ b/source/Calamari/ArgoCD/Git/RepositoryFactory.cs @@ -1,10 +1,10 @@ using System; using System.IO; using System.Linq; -using System.Text; using System.Threading; using Calamari.ArgoCD.Git.PullRequests; using Calamari.Common.Commands; +using Calamari.Common.Plumbing; using Calamari.Common.Plumbing.Extensions; using Calamari.Common.Plumbing.FileSystem; using Calamari.Common.Plumbing.Logging; @@ -48,6 +48,8 @@ public RepositoryFactory(ILog log, ICalamariFileSystem fileSystem, string reposi public RepositoryWrapper CloneRepository(string repositoryName, IGitConnection gitConnection) { + WindowsSshKeys.AssertSupported(gitConnection); + var repositoryPath = Path.Combine(repositoryParentDirectory, repositoryName); fileSystem.CreateDirectory(repositoryPath); diff --git a/source/Calamari/ArgoCD/Git/WindowsSshKeys.cs b/source/Calamari/ArgoCD/Git/WindowsSshKeys.cs new file mode 100644 index 000000000..e84bb5208 --- /dev/null +++ b/source/Calamari/ArgoCD/Git/WindowsSshKeys.cs @@ -0,0 +1,20 @@ +using System; +using Calamari.Common.Plumbing; +using NuGet.Commands; + +namespace Calamari.ArgoCD.Git; + +// Our fork LibGit2Sharp uses WinCNG for it's SSH support, and WinCNG does not support some keys. +// This first implementation blocks on all as we want to get the feature out for Linux first and +// we'll come back to attempt to handle it more gracefully at a later date. +public class WindowsSshKeys +{ + public static void AssertSupported(IGitConnection? connection) + { + if (!CalamariEnvironment.IsRunningOnWindows) return; + if (connection is not SshKeyGitConnection) return; + + throw new CommandException( + "SSH credentials are not currently supported for Git operations running on Windows. Use HTTPS credentials (username + password or PAT) instead or run the deployment on a Linux worker."); + } +} \ No newline at end of file