Skip to content

Commit 2d21d2a

Browse files
authored
Make migrations SKIP_TLS_VERIFY apply to git too (#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 fb08d2b commit 2d21d2a

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

modules/git/repo.go

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

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

112113
// Clone clones original repository to target path.
@@ -124,6 +125,9 @@ func CloneWithArgs(ctx context.Context, from, to string, args []string, opts Clo
124125
}
125126

126127
cmd := NewCommandContextNoGlobals(ctx, args...).AddArguments("clone")
128+
if opts.SkipTLSVerify {
129+
cmd.AddArguments("-c", "http.sslVerify=false")
130+
}
127131
if opts.Mirror {
128132
cmd.AddArguments("--mirror")
129133
}

modules/repository/repo.go

+9-7
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.Clone(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.Clone(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 {

services/migrations/dump.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ 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"
@@ -149,9 +150,10 @@ func (g *RepositoryDumper) CreateRepo(repo *base.Repository, opts base.MigrateOp
149150
}
150151

151152
err = git.Clone(g.ctx, remoteAddr, repoPath, git.CloneRepoOptions{
152-
Mirror: true,
153-
Quiet: true,
154-
Timeout: migrateTimeout,
153+
Mirror: true,
154+
Quiet: true,
155+
Timeout: migrateTimeout,
156+
SkipTLSVerify: setting.Migrations.SkipTLSVerify,
155157
})
156158
if err != nil {
157159
return fmt.Errorf("Clone: %v", err)
@@ -166,10 +168,11 @@ func (g *RepositoryDumper) CreateRepo(repo *base.Repository, opts base.MigrateOp
166168
}
167169

168170
if err := git.Clone(g.ctx, wikiRemotePath, wikiPath, git.CloneRepoOptions{
169-
Mirror: true,
170-
Quiet: true,
171-
Timeout: migrateTimeout,
172-
Branch: "master",
171+
Mirror: true,
172+
Quiet: true,
173+
Timeout: migrateTimeout,
174+
Branch: "master",
175+
SkipTLSVerify: setting.Migrations.SkipTLSVerify,
173176
}); err != nil {
174177
log.Warn("Clone wiki: %v", err)
175178
if err := os.RemoveAll(wikiPath); err != nil {

0 commit comments

Comments
 (0)