Skip to content

Commit 127f477

Browse files
aungertechknowlogick
authored andcommitted
MySQL TLS (#4642)
1 parent 0dac1ff commit 127f477

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

custom/conf/app.ini.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ NAME = gitea
223223
USER = root
224224
; Use PASSWD = `your password` for quoting if you use special characters in the password.
225225
PASSWD =
226-
; For "postgres" only, either "disable", "require" or "verify-full"
226+
; For Postgres, either "disable" (default), "require", or "verify-full"
227+
; For MySQL, either "false" (default), "true", or "skip-verify"
227228
SSL_MODE = disable
228229
; For "sqlite3" and "tidb", use an absolute path when you start gitea as service
229230
PATH = data/gitea.db

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
138138
- `NAME`: **gitea**: Database name.
139139
- `USER`: **root**: Database username.
140140
- `PASSWD`: **\<empty\>**: Database user password. Use \`your password\` for quoting if you use special characters in the password.
141-
- `SSL_MODE`: **disable**: For PostgreSQL only.
141+
- `SSL_MODE`: **disable**: For PostgreSQL and MySQL only.
142142
- `PATH`: **data/gitea.db**: For SQLite3 only, the database file path.
143143
- `LOG_SQL`: **true**: Log the executed SQL.
144144

models/models.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func LoadConfigs() {
155155
if len(DbCfg.Passwd) == 0 {
156156
DbCfg.Passwd = sec.Key("PASSWD").String()
157157
}
158-
DbCfg.SSLMode = sec.Key("SSL_MODE").String()
158+
DbCfg.SSLMode = sec.Key("SSL_MODE").MustString("disable")
159159
DbCfg.Path = sec.Key("PATH").MustString("data/gitea.db")
160160
DbCfg.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500)
161161

@@ -222,13 +222,16 @@ func getEngine() (*xorm.Engine, error) {
222222
}
223223
switch DbCfg.Type {
224224
case "mysql":
225+
connType := "tcp"
225226
if DbCfg.Host[0] == '/' { // looks like a unix socket
226-
connStr = fmt.Sprintf("%s:%s@unix(%s)/%s%scharset=utf8&parseTime=true",
227-
DbCfg.User, DbCfg.Passwd, DbCfg.Host, DbCfg.Name, Param)
228-
} else {
229-
connStr = fmt.Sprintf("%s:%s@tcp(%s)/%s%scharset=utf8&parseTime=true",
230-
DbCfg.User, DbCfg.Passwd, DbCfg.Host, DbCfg.Name, Param)
227+
connType = "unix"
231228
}
229+
tls := DbCfg.SSLMode
230+
if tls == "disable" { // allow (Postgres-inspired) default value to work in MySQL
231+
tls = "false"
232+
}
233+
connStr = fmt.Sprintf("%s:%s@%s(%s)/%s%scharset=utf8&parseTime=true&tls=%s",
234+
DbCfg.User, DbCfg.Passwd, connType, DbCfg.Host, DbCfg.Name, Param, tls)
232235
case "postgres":
233236
connStr = getPostgreSQLConnectionString(DbCfg.Host, DbCfg.User, DbCfg.Passwd, DbCfg.Name, Param, DbCfg.SSLMode)
234237
case "mssql":

0 commit comments

Comments
 (0)