Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double check CloneURL is acceptable #20869

Merged
merged 5 commits into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions services/migrations/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,10 @@ func DumpRepository(ctx context.Context, baseDir, ownerName string, opts base.Mi
return err
}

if err := migrateRepository(downloader, uploader, opts, nil); err != nil {
ghost := user_model.NewGhostUser()
ghost.IsAdmin = true

if err := migrateRepository(ghost, downloader, uploader, opts, nil); err != nil {
if err1 := uploader.Rollback(); err1 != nil {
log.Error("rollback failed: %v", err1)
}
Expand Down Expand Up @@ -641,7 +644,10 @@ func RestoreRepository(ctx context.Context, baseDir, ownerName, repoName string,
return err
}

if err = migrateRepository(downloader, uploader, migrateOpts, nil); err != nil {
ghost := user_model.NewGhostUser()
ghost.IsAdmin = true

if err = migrateRepository(ghost, downloader, uploader, migrateOpts, nil); err != nil {
if err1 := uploader.Rollback(); err1 != nil {
log.Error("rollback failed: %v", err1)
}
Expand Down
2 changes: 1 addition & 1 deletion services/migrations/gitea_uploader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestGiteaUploadRepo(t *testing.T) {
uploader = NewGiteaLocalUploader(graceful.GetManager().HammerContext(), user, user.Name, repoName)
)

err := migrateRepository(downloader, uploader, base.MigrateOptions{
err := migrateRepository(user, downloader, uploader, base.MigrateOptions{
CloneAddr: "https://github.com/go-xorm/builder",
RepoName: repoName,
AuthUsername: "",
Expand Down
16 changes: 14 additions & 2 deletions services/migrations/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func MigrateRepository(ctx context.Context, doer *user_model.User, ownerName str
uploader := NewGiteaLocalUploader(ctx, doer, ownerName, opts.RepoName)
uploader.gitServiceType = opts.GitServiceType

if err := migrateRepository(downloader, uploader, opts, messenger); err != nil {
if err := migrateRepository(doer, downloader, uploader, opts, messenger); err != nil {
if err1 := uploader.Rollback(); err1 != nil {
log.Error("rollback failed: %v", err1)
}
Expand Down Expand Up @@ -177,7 +177,7 @@ func newDownloader(ctx context.Context, ownerName string, opts base.MigrateOptio
// migrateRepository will download information and then upload it to Uploader, this is a simple
// process for small repository. For a big repository, save all the data to disk
// before upload is better
func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts base.MigrateOptions, messenger base.Messenger) error {
func migrateRepository(doer *user_model.User, downloader base.Downloader, uploader base.Uploader, opts base.MigrateOptions, messenger base.Messenger) error {
if messenger == nil {
messenger = base.NilMessenger
}
Expand All @@ -198,6 +198,18 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
return err
}

// Now the clone URL can be rewritten by the downloader so we must recheck
if err := IsMigrateURLAllowed(repo.CloneURL, doer); err != nil {
return err
}

// And so can the original URL too so again we must recheck
if repo.OriginalURL != "" {
if err := IsMigrateURLAllowed(repo.OriginalURL, doer); err != nil {
return err
}
}

log.Trace("migrating git data from %s", repo.CloneURL)
messenger("repo.migrate.migrating_git")
if err = uploader.CreateRepo(repo, opts); err != nil {
Expand Down