From 9df35356572e09dc2c0907113bf64479204e46a9 Mon Sep 17 00:00:00 2001 From: Vladimir Shushlin Date: Mon, 3 Jun 2019 11:22:03 +0000 Subject: Redirect unknown ACME challenges to the GitLab instance --- app.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'app.go') diff --git a/app.go b/app.go index 08eff7e7..9d4f5bdb 100644 --- a/app.go +++ b/app.go @@ -17,6 +17,7 @@ import ( log "github.com/sirupsen/logrus" mimedb "gitlab.com/lupine/go-mimedb" + "gitlab.com/gitlab-org/gitlab-pages/internal/acme" "gitlab.com/gitlab-org/gitlab-pages/internal/admin" "gitlab.com/gitlab-org/gitlab-pages/internal/artifact" "gitlab.com/gitlab-org/gitlab-pages/internal/auth" @@ -38,10 +39,11 @@ var ( type theApp struct { appConfig - dm domain.Map - lock sync.RWMutex - Artifact *artifact.Artifact - Auth *auth.Auth + dm domain.Map + lock sync.RWMutex + Artifact *artifact.Artifact + Auth *auth.Auth + AcmeMiddleware *acme.Middleware } func (a *theApp) isReady() bool { @@ -166,6 +168,10 @@ func (a *theApp) serveContent(ww http.ResponseWriter, r *http.Request, https boo host, domain := a.getHostAndDomain(r) + if a.AcmeMiddleware.ServeAcmeChallenges(&w, r, domain) { + return + } + if a.Auth.TryAuthenticate(&w, r, a.dm, &a.lock) { return } @@ -360,6 +366,10 @@ func runApp(config appConfig) { config.RedirectURI, config.GitLabServer) } + if config.GitLabServer != "" { + a.AcmeMiddleware = &acme.Middleware{GitlabURL: config.GitLabServer} + } + configureLogging(config.LogFormat, config.LogVerbose) if err := mimedb.LoadTypes(); err != nil { -- cgit v1.2.3