Pull request 2751: AGDNS-3720-terminate-dependecy-of-tlsMgr-from-web

Squashed commit of the following:

commit e45ebca7b68e771774bb7e3e940369ed16e29d29
Merge: 519f8870d 090f75d79
Author: Maksim Kazantsev <m.kazantsev@adguard.com>
Date:   Mon Aug 17 14:51:21 2026 +0300

    Merge branch 'master' into AGDNS-3720-terminate-dependecy-of-tlsMgr-from-web

commit 519f8870d67b887527369fc0a2d16955264acdcf
Author: Maksim Kazantsev <m.kazantsev@adguard.com>
Date:   Fri Aug 14 13:53:44 2026 +0300

    home: imp code;

commit 59d294d9651d073bb8da171e08d4e5733b009e54
Author: Maksim Kazantsev <m.kazantsev@adguard.com>
Date:   Thu Aug 13 15:41:22 2026 +0300

    home: completely terminate the dependency of tlsMgr from web;
This commit is contained in:
Maksim Kazantsev 2026-08-17 14:17:40 +00:00
parent 090f75d79f
commit c5c8623318
5 changed files with 10 additions and 35 deletions

View file

@ -870,8 +870,6 @@ func run(
sigHdlr.addWeb(web)
tlsMgr.setWebAPI(web)
statsDir, querylogDir, err := checkStatsAndQuerylogDirs(config, workDir)
fatalOnError(ctx, baseLogger, err)

View file

@ -56,12 +56,6 @@ type tlsManager struct {
// nil.
extTLSConf *aghtls.ExtendedTLSConfig
// web is the web UI and API server. It must not be nil.
//
// TODO(s.chzhen): Temporary cyclic dependency due to ongoing refactoring.
// Resolve it.
web *webAPI
// rootCerts is a pool of root CAs for TLSv1.2.
rootCerts *x509.CertPool
@ -106,8 +100,7 @@ type tlsManagerConfig struct {
// newTLSManager initializes the manager of TLS configuration. m is always
// non-nil while any returned error indicates that the TLS configuration isn't
// valid. Thus TLS may be initialized later, e.g. via the web UI. conf must
// not be nil. Note that [tlsManager.web] must be initialized later on by using
// [tlsManager.setWebAPI].
// not be nil.
func newTLSManager(ctx context.Context, conf *tlsManagerConfig) (m *tlsManager, err error) {
m = &tlsManager{
logger: conf.logger,
@ -185,14 +178,6 @@ func newTLSManager(ctx context.Context, conf *tlsManagerConfig) (m *tlsManager,
return m, nil
}
// setWebAPI stores the provided web API. It must be called before
// [tlsManager.Start], [tlsManager.reload] or [webAPI.validateTLSSettings].
//
// TODO(s.chzhen): Remove it once cyclic dependency is resolved.
func (m *tlsManager) setWebAPI(webAPI *webAPI) {
m.web = webAPI
}
// setCertFileTime sets [tlsManager.certLastMod] from the certificate. If there
// are errors, setCertFileTime logs them. m.mu is expected to be locked.
func (m *tlsManager) setCertFileTime(ctx context.Context) {
@ -1031,14 +1016,6 @@ var _ service.Interface = (*tlsManager)(nil)
// Start implements the [service.Interface] interface for *tlsManager. It
// starts the TLS manager.
func (m *tlsManager) Start(ctx context.Context) (err error) {
m.mu.Lock()
defer m.mu.Unlock()
// The background context is used because the TLSConfigChanged wraps context
// with timeout on its own and shuts down the server, which handles current
// request.
m.web.tlsConfigChanged(context.Background(), m.extTLSConf)
go m.handleCertFileChange(ctx)
return nil

View file

@ -358,9 +358,6 @@ func TestTLSManager_Reload(t *testing.T) {
})
require.NoError(t, err)
web := newTestWeb(t, &webConfig{tlsManager: m})
m.setWebAPI(web)
extTLSConf := m.ExtendedTLSConfig()
assertCertSerialNumber(t, extTLSConf, snBefore)

View file

@ -340,8 +340,15 @@ func (web *webAPI) start(ctx context.Context) {
web.logger.InfoContext(ctx, "AdGuard Home is available at the following addresses:")
// For https, we have a separate goroutine loop.
go web.tlsServerLoop(ctx)
go func() {
// Apply the initial TLS configuration. The background context is used
// because tlsConfigChanged wraps context with timeout on its own and shuts
// down the server, which handles current request.
web.tlsConfigChanged(context.Background(), web.tlsConfProvider.ExtendedTLSConfig())
// For https, we have a separate goroutine loop.
web.tlsServerLoop(ctx)
}()
// This loop is used as an ability to change listening host and/or port.
for !web.httpsServer.inShutdown() {

View file

@ -91,7 +91,6 @@ func TestWebAPI_HandleTLSConfigure(t *testing.T) {
require.NoError(t, err)
web := newTestWeb(t, &webConfig{tlsManager: m})
m.setWebAPI(web)
extTLSConf := m.ExtendedTLSConfig()
assertCertSerialNumber(t, extTLSConf, wantSerialNumber)
@ -176,7 +175,6 @@ func TestWebAPI_HandleTLSStatus(t *testing.T) {
require.NoError(t, err)
web := newTestWeb(t, &webConfig{tlsManager: m})
m.setWebAPI(web)
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/control/tls/status", nil)
@ -209,7 +207,6 @@ func TestWebAPI_ValidateTLSSettings(t *testing.T) {
require.NoError(t, err)
web := newTestWeb(t, &webConfig{tlsManager: m})
m.setWebAPI(web)
tcpLn, err := net.Listen("tcp", ":0")
require.NoError(t, err)
@ -310,7 +307,6 @@ func TestWebAPI_HandleTLSValidate(t *testing.T) {
require.NoError(t, err)
web := newTestWeb(t, &webConfig{tlsManager: m})
m.setWebAPI(web)
setts := &tlsConfigSettingsExt{
tlsConfigSettings: tlsConfigSettings{