Skip to content

Commit 8afaa24

Browse files
committed
Revert "Try to fix ACME path when renew (go-gitea#33668) (go-gitea#33693)"
This reverts commit 039924a.
1 parent 92f2d90 commit 8afaa24

File tree

2 files changed

+15
-26
lines changed

2 files changed

+15
-26
lines changed

cmd/web_acme.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ func runACME(listenAddr string, m http.Handler) error {
5454
altTLSALPNPort = p
5555
}
5656

57+
// FIXME: this path is not right, it uses "AppWorkPath" incorrectly, and writes the data into "AppWorkPath/https"
58+
// Ideally it should migrate to AppDataPath write to "AppDataPath/https"
59+
certmagic.Default.Storage = &certmagic.FileStorage{Path: setting.AcmeLiveDirectory}
60+
magic := certmagic.NewDefault()
5761
// Try to use private CA root if provided, otherwise defaults to system's trust
5862
var certPool *x509.CertPool
5963
if setting.AcmeCARoot != "" {
@@ -63,13 +67,7 @@ func runACME(listenAddr string, m http.Handler) error {
6367
log.Warn("Failed to parse CA Root certificate, using default CA trust: %v", err)
6468
}
6569
}
66-
// FIXME: this path is not right, it uses "AppWorkPath" incorrectly, and writes the data into "AppWorkPath/https"
67-
// Ideally it should migrate to AppDataPath write to "AppDataPath/https"
68-
// And one more thing, no idea why we should set the global default variables here
69-
// But it seems that the current ACME code needs these global variables to make renew work.
70-
// Otherwise, "renew" will use incorrect storage path
71-
certmagic.Default.Storage = &certmagic.FileStorage{Path: setting.AcmeLiveDirectory}
72-
certmagic.DefaultACME = certmagic.ACMEIssuer{
70+
myACME := certmagic.NewACMEIssuer(magic, certmagic.ACMEIssuer{
7371
CA: setting.AcmeURL,
7472
TrustedRoots: certPool,
7573
Email: setting.AcmeEmail,
@@ -79,10 +77,8 @@ func runACME(listenAddr string, m http.Handler) error {
7977
ListenHost: setting.HTTPAddr,
8078
AltTLSALPNPort: altTLSALPNPort,
8179
AltHTTPPort: altHTTPPort,
82-
}
80+
})
8381

84-
magic := certmagic.NewDefault()
85-
myACME := certmagic.NewACMEIssuer(magic, certmagic.DefaultACME)
8682
magic.Issuers = []certmagic.Issuer{myACME}
8783

8884
// this obtains certificates or renews them if necessary

modules/setting/server.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,24 +169,20 @@ func loadServerFrom(rootCfg ConfigProvider) {
169169
HTTPAddr = sec.Key("HTTP_ADDR").MustString("0.0.0.0")
170170
HTTPPort = sec.Key("HTTP_PORT").MustString("3000")
171171

172-
// DEPRECATED should not be removed because users maybe upgrade from lower version to the latest version
173-
// if these are removed, the warning will not be shown
174-
if sec.HasKey("ENABLE_ACME") {
175-
EnableAcme = sec.Key("ENABLE_ACME").MustBool(false)
176-
} else {
177-
deprecatedSetting(rootCfg, "server", "ENABLE_LETSENCRYPT", "server", "ENABLE_ACME", "v1.19.0")
178-
EnableAcme = sec.Key("ENABLE_LETSENCRYPT").MustBool(false)
179-
}
180-
181172
Protocol = HTTP
182173
protocolCfg := sec.Key("PROTOCOL").String()
183-
if protocolCfg != "https" && EnableAcme {
184-
log.Fatal("ACME could only be used with HTTPS protocol")
185-
}
186-
187174
switch protocolCfg {
188175
case "https":
189176
Protocol = HTTPS
177+
178+
// DEPRECATED should not be removed because users maybe upgrade from lower version to the latest version
179+
// if these are removed, the warning will not be shown
180+
if sec.HasKey("ENABLE_ACME") {
181+
EnableAcme = sec.Key("ENABLE_ACME").MustBool(false)
182+
} else {
183+
deprecatedSetting(rootCfg, "server", "ENABLE_LETSENCRYPT", "server", "ENABLE_ACME", "v1.19.0")
184+
EnableAcme = sec.Key("ENABLE_LETSENCRYPT").MustBool(false)
185+
}
190186
if EnableAcme {
191187
AcmeURL = sec.Key("ACME_URL").MustString("")
192188
AcmeCARoot = sec.Key("ACME_CA_ROOT").MustString("")
@@ -214,9 +210,6 @@ func loadServerFrom(rootCfg ConfigProvider) {
214210
deprecatedSetting(rootCfg, "server", "LETSENCRYPT_EMAIL", "server", "ACME_EMAIL", "v1.19.0")
215211
AcmeEmail = sec.Key("LETSENCRYPT_EMAIL").MustString("")
216212
}
217-
if AcmeEmail == "" {
218-
log.Fatal("ACME Email is not set (ACME_EMAIL).")
219-
}
220213
} else {
221214
CertFile = sec.Key("CERT_FILE").String()
222215
KeyFile = sec.Key("KEY_FILE").String()

0 commit comments

Comments
 (0)