diff --git a/options/locale/locale_en-US.json b/options/locale/locale_en-US.json index ede582627a..4498502703 100644 --- a/options/locale/locale_en-US.json +++ b/options/locale/locale_en-US.json @@ -1119,6 +1119,7 @@ "repo.migrate.clone_address_desc": "The HTTP(S), Git, or SSH 'clone' URL of an existing repository", "repo.migrate.github_token_desc": "You can put one or more tokens here, separated by commas, to make migrating faster by circumventing the GitHub API rate limit. WARNING: Abusing this feature may violate the service provider's policy and may lead to getting your account(s) blocked.", "repo.migrate.clone_local_path": "or a local server path", + "repo.migrate.ssh_not_supported_for_forge": "SSH clone URLs are only supported for the plain Git migration. To use SSH against this forge, switch to the Git service.", "repo.migrate.ssh_helper_title": "SSH URLs", "repo.migrate.ssh_helper_desc": "Upload your SSH mirror keys to the remote SSH server for authentication.", "repo.migrate.ssh_helper_link": "View your SSH keys (if migrating to an organization, you may need to upload the organization's SSH keys).", diff --git a/routers/web/repo/migrate.go b/routers/web/repo/migrate.go index 0f094fcb81..446cbac8a6 100644 --- a/routers/web/repo/migrate.go +++ b/routers/web/repo/migrate.go @@ -69,7 +69,9 @@ func Migrate(ctx *context.Context) { return } ctx.Data["ContextUser"] = ctxUser - setManagedSSHKeyFingerprints(ctx, ctxUser) + if serviceType == structs.PlainGitService { + setManagedSSHKeyFingerprints(ctx, ctxUser) + } ctx.HTML(http.StatusOK, templates.TplName("repo/migrate/"+serviceType.Name())) } @@ -204,7 +206,9 @@ func MigratePost(ctx *context.Context) { return } ctx.Data["ContextUser"] = ctxUser - setManagedSSHKeyFingerprints(ctx, ctxUser) + if form.Service == structs.PlainGitService { + setManagedSSHKeyFingerprints(ctx, ctxUser) + } tpl := templates.TplName("repo/migrate/" + form.Service.Name()) @@ -213,6 +217,15 @@ func MigratePost(ctx *context.Context) { return } + // Managed SSH keys are only wired up for the plain Git migration form. + // Forge migrations (GitHub/GitLab/etc.) authenticate against both the + // git remote and the forge API with a token, so reject ssh:// here. + if form.Service != structs.PlainGitService && ssh_module.IsSSHURL(strings.TrimSpace(form.CloneAddr)) { + ctx.Data["Err_CloneAddr"] = true + ctx.RenderWithErrDeprecated(ctx.Tr("repo.migrate.ssh_not_supported_for_forge"), tpl, form) + return + } + remoteAddr, err := git.ParseRemoteAddr(form.CloneAddr, form.AuthUsername, form.AuthPassword) if err == nil { err = migrations.IsMigrateURLAllowed(remoteAddr, ctx.Doer) diff --git a/templates/repo/migrate/codebase.tmpl b/templates/repo/migrate/codebase.tmpl index d5497e10bc..33fd9a2e8c 100644 --- a/templates/repo/migrate/codebase.tmpl +++ b/templates/repo/migrate/codebase.tmpl @@ -19,15 +19,14 @@ -