Skip to content

Commit e6d46ee

Browse files
authored
Make migrations SKIP_TLS_VERIFY apply to git too (#19132) (#19141)
Backport #19132 Make SKIP_TLS_VERIFY apply to git data migrations too through adding the `-c http.sslVerify=false` option to the git clone command. Fix #18998 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 5bb0c92 commit e6d46ee

File tree

3 files changed

+39
-32
lines changed

3 files changed

+39
-32
lines changed

modules/git/repo.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,16 @@ func (repo *Repository) IsEmpty() (bool, error) {
9797

9898
// CloneRepoOptions options when clone a repository
9999
type CloneRepoOptions struct {
100-
Timeout time.Duration
101-
Mirror bool
102-
Bare bool
103-
Quiet bool
104-
Branch string
105-
Shared bool
106-
NoCheckout bool
107-
Depth int
108-
Filter string
100+
Timeout time.Duration
101+
Mirror bool
102+
Bare bool
103+
Quiet bool
104+
Branch string
105+
Shared bool
106+
NoCheckout bool
107+
Depth int
108+
Filter string
109+
SkipTLSVerify bool
109110
}
110111

111112
// Clone clones original repository to target path.
@@ -128,6 +129,9 @@ func CloneWithArgs(ctx context.Context, from, to string, args []string, opts Clo
128129
}
129130

130131
cmd := NewCommandContextNoGlobals(ctx, args...).AddArguments("clone")
132+
if opts.SkipTLSVerify {
133+
cmd.AddArguments("-c", "http.sslVerify=false")
134+
}
131135
if opts.Mirror {
132136
cmd.AddArguments("--mirror")
133137
}

modules/repository/repo.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
7272
}
7373

7474
if err = git.CloneWithContext(ctx, opts.CloneAddr, repoPath, git.CloneRepoOptions{
75-
Mirror: true,
76-
Quiet: true,
77-
Timeout: migrateTimeout,
75+
Mirror: true,
76+
Quiet: true,
77+
Timeout: migrateTimeout,
78+
SkipTLSVerify: setting.Migrations.SkipTLSVerify,
7879
}); err != nil {
7980
return repo, fmt.Errorf("Clone: %v", err)
8081
}
@@ -88,10 +89,11 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
8889
}
8990

9091
if err = git.CloneWithContext(ctx, wikiRemotePath, wikiPath, git.CloneRepoOptions{
91-
Mirror: true,
92-
Quiet: true,
93-
Timeout: migrateTimeout,
94-
Branch: "master",
92+
Mirror: true,
93+
Quiet: true,
94+
Timeout: migrateTimeout,
95+
Branch: "master",
96+
SkipTLSVerify: setting.Migrations.SkipTLSVerify,
9597
}); err != nil {
9698
log.Warn("Clone wiki: %v", err)
9799
if err := util.RemoveAll(wikiPath); err != nil {
@@ -310,7 +312,7 @@ func PushUpdateAddTag(repo *repo_model.Repository, gitRepo *git.Repository, tagN
310312
}
311313

312314
var author *user_model.User
313-
var createdAt = time.Unix(1, 0)
315+
createdAt := time.Unix(1, 0)
314316

315317
if sig != nil {
316318
author, err = user_model.GetUserByEmail(sig.Email)
@@ -325,7 +327,7 @@ func PushUpdateAddTag(repo *repo_model.Repository, gitRepo *git.Repository, tagN
325327
return fmt.Errorf("unable to get CommitsCount: %w", err)
326328
}
327329

328-
var rel = models.Release{
330+
rel := models.Release{
329331
RepoID: repo.ID,
330332
TagName: tagName,
331333
LowerTagName: strings.ToLower(tagName),

services/migrations/dump.go

+15-14
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ import (
2222
"code.gitea.io/gitea/modules/log"
2323
base "code.gitea.io/gitea/modules/migration"
2424
"code.gitea.io/gitea/modules/repository"
25+
"code.gitea.io/gitea/modules/setting"
2526
"code.gitea.io/gitea/modules/structs"
2627

2728
"gopkg.in/yaml.v2"
2829
)
2930

30-
var (
31-
_ base.Uploader = &RepositoryDumper{}
32-
)
31+
var _ base.Uploader = &RepositoryDumper{}
3332

3433
// RepositoryDumper implements an Uploader to the local directory
3534
type RepositoryDumper struct {
@@ -151,9 +150,10 @@ func (g *RepositoryDumper) CreateRepo(repo *base.Repository, opts base.MigrateOp
151150
}
152151

153152
err = git.Clone(remoteAddr, repoPath, git.CloneRepoOptions{
154-
Mirror: true,
155-
Quiet: true,
156-
Timeout: migrateTimeout,
153+
Mirror: true,
154+
Quiet: true,
155+
Timeout: migrateTimeout,
156+
SkipTLSVerify: setting.Migrations.SkipTLSVerify,
157157
})
158158
if err != nil {
159159
return fmt.Errorf("Clone: %v", err)
@@ -168,10 +168,11 @@ func (g *RepositoryDumper) CreateRepo(repo *base.Repository, opts base.MigrateOp
168168
}
169169

170170
if err := git.Clone(wikiRemotePath, wikiPath, git.CloneRepoOptions{
171-
Mirror: true,
172-
Quiet: true,
173-
Timeout: migrateTimeout,
174-
Branch: "master",
171+
Mirror: true,
172+
Quiet: true,
173+
Timeout: migrateTimeout,
174+
Branch: "master",
175+
SkipTLSVerify: setting.Migrations.SkipTLSVerify,
175176
}); err != nil {
176177
log.Warn("Clone wiki: %v", err)
177178
if err := os.RemoveAll(wikiPath); err != nil {
@@ -403,7 +404,7 @@ func (g *RepositoryDumper) createItems(dir string, itemFiles map[int64]*os.File,
403404

404405
// CreateComments creates comments of issues
405406
func (g *RepositoryDumper) CreateComments(comments ...*base.Comment) error {
406-
var commentsMap = make(map[int64][]interface{}, len(comments))
407+
commentsMap := make(map[int64][]interface{}, len(comments))
407408
for _, comment := range comments {
408409
commentsMap[comment.IssueIndex] = append(commentsMap[comment.IssueIndex], comment)
409410
}
@@ -532,7 +533,7 @@ func (g *RepositoryDumper) CreatePullRequests(prs ...*base.PullRequest) error {
532533

533534
// CreateReviews create pull request reviews
534535
func (g *RepositoryDumper) CreateReviews(reviews ...*base.Review) error {
535-
var reviewsMap = make(map[int64][]interface{}, len(reviews))
536+
reviewsMap := make(map[int64][]interface{}, len(reviews))
536537
for _, review := range reviews {
537538
reviewsMap[review.IssueIndex] = append(reviewsMap[review.IssueIndex], review)
538539
}
@@ -611,7 +612,7 @@ func RestoreRepository(ctx context.Context, baseDir, ownerName, repoName string,
611612
if err != nil {
612613
return err
613614
}
614-
var uploader = NewGiteaLocalUploader(ctx, doer, ownerName, repoName)
615+
uploader := NewGiteaLocalUploader(ctx, doer, ownerName, repoName)
615616
downloader, err := NewRepositoryRestorer(ctx, baseDir, ownerName, repoName)
616617
if err != nil {
617618
return err
@@ -622,7 +623,7 @@ func RestoreRepository(ctx context.Context, baseDir, ownerName, repoName string,
622623
}
623624
tp, _ := strconv.Atoi(opts["service_type"])
624625

625-
var migrateOpts = base.MigrateOptions{
626+
migrateOpts := base.MigrateOptions{
626627
GitServiceType: structs.GitServiceType(tp),
627628
}
628629
updateOptionsUnits(&migrateOpts, units)

0 commit comments

Comments
 (0)