Pull request 2656: AG-54304-path-traversal-vuln

Squashed commit of the following:

commit 33991debf6893bbfef320be5363bc83e11859039
Merge: 3f88261a5 83d8d6595
Author: f.setrakov <f.setrakov@adguard.com>
Date:   Fri May 22 16:10:53 2026 +0300

    Merge branch 'master' into AG-54304-path-traversal-vuln

commit 3f88261a5bba60243c8fd25fcf898789765e80eb
Author: f.setrakov <f.setrakov@adguard.com>
Date:   Thu May 21 17:13:37 2026 +0300

    home: imp code

commit 589589f4f241bcdb5d0c94b5837299b8685443f2
Author: f.setrakov <f.setrakov@adguard.com>
Date:   Wed May 20 15:42:34 2026 +0300

    all: fix race, imp code

commit 762f073facc451e6bc160a21e068352b14806620
Author: f.setrakov <f.setrakov@adguard.com>
Date:   Tue May 19 18:13:24 2026 +0300

    all: fix path-traversal vuln
This commit is contained in:
Fedor Setrakov committed 2026-05-22 13:22:59 +00:00
1 parent 83d8d65950
commit 249a3a1615
9 files changed
+175 -110

No files matched your search

+2
View File
@@ -54,6 +54,8 @@ See also the [v0.107.75 GitHub milestone][ms-v0.107.75].
### Security ### Security
- Authorization in GLiNET mode is no longer vulnerable to path traversal attacks.
- Go version has been updated to prevent the possibility of exploiting the Go vulnerabilities fixed in [1.26.3][go-1.26.3]. - Go version has been updated to prevent the possibility of exploiting the Go vulnerabilities fixed in [1.26.3][go-1.26.3].
- IDs of requests received over DoH and DoQ and forwarded to plain-DNS upstreams are now set to non-zero values to improve security. - IDs of requests received over DoH and DoQ and forwarded to plain-DNS upstreams are now set to non-zero values to improve security.
+26 -16
View File
@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"log/slog" "log/slog"
"net/http" "net/http"
"os"
"time" "time"
"github.com/AdguardTeam/AdGuardHome/internal/aghuser" "github.com/AdguardTeam/AdGuardHome/internal/aghuser"
@@ -56,6 +57,10 @@ type authConfig struct {
// mux is the server's multiplexer. It must not be nil. // mux is the server's multiplexer. It must not be nil.
mux *http.ServeMux mux *http.ServeMux
// gliNetTokenRoot is the root where GLiNet tokens are stored. It must not
// be nil if isGLiNet is true.
gliNetTokenRoot *os.Root
// rateLimiter manages the rate limiting for login attempts. It must not be // rateLimiter manages the rate limiting for login attempts. It must not be
// nil. // nil.
rateLimiter loginRateLimiter rateLimiter loginRateLimiter
@@ -88,6 +93,10 @@ type auth struct {
// mux is the server's multiplexer. // mux is the server's multiplexer.
mux *http.ServeMux mux *http.ServeMux
// gliNetTokenRoot is the root where GLiNet tokens are stored. It must not
// be nil if isGLiNet is true.
gliNetTokenRoot *os.Root
// rateLimiter manages rate limiting for login attempts. // rateLimiter manages rate limiting for login attempts.
rateLimiter loginRateLimiter rateLimiter loginRateLimiter
@@ -133,15 +142,16 @@ func newAuth(ctx context.Context, conf *authConfig) (a *auth, err error) {
} }
return &auth{ return &auth{
logger: conf.baseLogger.With(slogutil.KeyPrefix, "auth"), logger: conf.baseLogger.With(slogutil.KeyPrefix, "auth"),
mux: conf.mux, mux: conf.mux,
rateLimiter: conf.rateLimiter, rateLimiter: conf.rateLimiter,
trustedProxies: conf.trustedProxies, trustedProxies: conf.trustedProxies,
sessions: s, gliNetTokenRoot: conf.gliNetTokenRoot,
users: userDB, sessions: s,
doHRoutes: conf.doHRoutes, users: userDB,
isGLiNet: conf.isGLiNet, doHRoutes: conf.doHRoutes,
isUserless: len(conf.users) == 0, isGLiNet: conf.isGLiNet,
isUserless: len(conf.users) == 0,
}, nil }, nil
} }
@@ -149,13 +159,13 @@ func newAuth(ctx context.Context, conf *authConfig) (a *auth, err error) {
func (a *auth) middleware() (mw httputil.Middleware) { func (a *auth) middleware() (mw httputil.Middleware) {
if a.isGLiNet { if a.isGLiNet {
return newAuthMiddlewareGLiNet(&authMiddlewareGLiNetConfig{ return newAuthMiddlewareGLiNet(&authMiddlewareGLiNetConfig{
logger: a.logger, logger: a.logger,
mux: a.mux, mux: a.mux,
clock: timeutil.SystemClock{}, clock: timeutil.SystemClock{},
doHRoutes: a.doHRoutes, doHRoutes: a.doHRoutes,
tokenFilePrefix: glFilePrefix, tokenFileRoot: a.gliNetTokenRoot,
ttl: glTokenTimeout, ttl: glTokenTimeout,
maxTokenSize: MaxFileSize, maxTokenSize: MaxFileSize,
}) })
} }
+22 -25
View File
@@ -18,11 +18,9 @@ import (
"github.com/AdguardTeam/golibs/timeutil" "github.com/AdguardTeam/golibs/timeutil"
) )
// glFilePrefix is the prefix of the filepath where the authentication token is // glFilePrefix is the prefix of the file where the authentication token is
// stored. Note that it is variable so it can be edited in tests. // stored.
// const glFilePrefix = "gl_token_"
// TODO(s.chzhen): Make it a constant.
var glFilePrefix = "/tmp/gl_token_"
const ( const (
// glTokenTimeout is the TTL (Time To Live) of the authentication token. // glTokenTimeout is the TTL (Time To Live) of the authentication token.
@@ -54,9 +52,9 @@ type authMiddlewareGLiNetConfig struct {
// doHRoutes is a list of DoH routes for public access. // doHRoutes is a list of DoH routes for public access.
doHRoutes []string doHRoutes []string
// tokenFilePrefix is the prefix of the filepath where the authentication // tokenFileRoot is the root where GLiNet tokens are stored. It must not be
// token is stored. It must not be empty. // nil.
tokenFilePrefix string tokenFileRoot *os.Root
// ttl is the TTL (Time To Live) of the authentication token. It must be // ttl is the TTL (Time To Live) of the authentication token. It must be
// greater than zero. // greater than zero.
@@ -70,26 +68,26 @@ type authMiddlewareGLiNetConfig struct {
// authMiddlewareGLiNet is the GLiNet authentication middleware. It checks if // authMiddlewareGLiNet is the GLiNet authentication middleware. It checks if
// the request is authenticated using a cookie. // the request is authenticated using a cookie.
type authMiddlewareGLiNet struct { type authMiddlewareGLiNet struct {
logger *slog.Logger logger *slog.Logger
mux *http.ServeMux mux *http.ServeMux
clock timeutil.Clock clock timeutil.Clock
doHRoutes []string doHRoutes []string
tokenFilePrefix string tokenFileRoot *os.Root
ttl time.Duration ttl time.Duration
maxTokenSize uint maxTokenSize uint
} }
// newAuthMiddlewareGLiNet returns the new properly initialized // newAuthMiddlewareGLiNet returns the new properly initialized
// *authMiddlewareGLiNet. // *authMiddlewareGLiNet.
func newAuthMiddlewareGLiNet(c *authMiddlewareGLiNetConfig) (mw *authMiddlewareGLiNet) { func newAuthMiddlewareGLiNet(c *authMiddlewareGLiNetConfig) (mw *authMiddlewareGLiNet) {
return &authMiddlewareGLiNet{ return &authMiddlewareGLiNet{
logger: c.logger, logger: c.logger,
mux: c.mux, mux: c.mux,
clock: c.clock, clock: c.clock,
doHRoutes: c.doHRoutes, doHRoutes: c.doHRoutes,
tokenFilePrefix: c.tokenFilePrefix, tokenFileRoot: c.tokenFileRoot,
ttl: c.ttl, ttl: c.ttl,
maxTokenSize: c.maxTokenSize, maxTokenSize: c.maxTokenSize,
} }
} }
@@ -158,8 +156,7 @@ func (mw *authMiddlewareGLiNet) isAuthenticated(ctx context.Context, r *http.Req
// the time stored in a file named after the token and checks if the token has // the time stored in a file named after the token and checks if the token has
// expired based on that time. // expired based on that time.
func (mw *authMiddlewareGLiNet) checkToken(ctx context.Context, token string) (ok bool) { func (mw *authMiddlewareGLiNet) checkToken(ctx context.Context, token string) (ok bool) {
tokenFile := mw.tokenFilePrefix + token tokenDate := mw.tokenDate(ctx, glFilePrefix+token)
tokenDate := mw.tokenDate(ctx, tokenFile)
now := mw.clock.Now() now := mw.clock.Now()
if now.Before(tokenDate.Add(mw.ttl)) { if now.Before(tokenDate.Add(mw.ttl)) {
return true return true
@@ -173,7 +170,7 @@ func (mw *authMiddlewareGLiNet) checkToken(ctx context.Context, token string) (o
// tokenDate returns the time stored in the authentication token file. If there // tokenDate returns the time stored in the authentication token file. If there
// is an error, it logs the error and returns the zero time. // is an error, it logs the error and returns the zero time.
func (mw *authMiddlewareGLiNet) tokenDate(ctx context.Context, tokenFile string) (t time.Time) { func (mw *authMiddlewareGLiNet) tokenDate(ctx context.Context, tokenFile string) (t time.Time) {
f, err := os.Open(tokenFile) f, err := mw.tokenFileRoot.Open(tokenFile)
if err != nil { if err != nil {
mw.logger.ErrorContext(ctx, "opening token file", slogutil.KeyError, err) mw.logger.ErrorContext(ctx, "opening token file", slogutil.KeyError, err)
+39 -9
View File
@@ -2,12 +2,15 @@ package home
import ( import (
"encoding/binary" "encoding/binary"
"io/fs"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os" "os"
"path/filepath"
"testing" "testing"
"time" "time"
"github.com/AdguardTeam/golibs/testutil"
"github.com/AdguardTeam/golibs/timeutil" "github.com/AdguardTeam/golibs/timeutil"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@@ -20,25 +23,42 @@ func TestAuthMiddlewareGLiNet(t *testing.T) {
testTTL = 60 * time.Second testTTL = 60 * time.Second
glTokenFileSuffix = "test" glTokenFileSuffix = "test"
testPerm fs.FileMode = 0o644
) )
tempDir := t.TempDir() tempDir := t.TempDir()
glFilePrefix = tempDir + "/gl_token_" glTokenFolder := filepath.Join(tempDir, "foo")
glTokenFile := glFilePrefix + glTokenFileSuffix err := os.MkdirAll(glTokenFolder, 0o755)
require.NoError(t, err)
tokenFileRoot, err := os.OpenRoot(glTokenFolder)
require.NoError(t, err)
testutil.CleanupAndRequireSuccess(t, tokenFileRoot.Close)
err = os.MkdirAll(filepath.Join(glTokenFolder, glFilePrefix), testPerm)
require.NoError(t, err)
glTokenFile := filepath.Join(glTokenFolder, glFilePrefix+glTokenFileSuffix)
glFileData := make([]byte, 4) glFileData := make([]byte, 4)
binary.NativeEndian.PutUint32(glFileData, uint32(time.Now().Add(testTTL).Unix())) binary.NativeEndian.PutUint32(glFileData, uint32(time.Now().Add(testTTL).Unix()))
err := os.WriteFile(glTokenFile, glFileData, 0o644) err = os.WriteFile(glTokenFile, glFileData, testPerm)
require.NoError(t, err)
// Mock token file for testing path traversal vulnerability. See AG-54304.
passwdFile := filepath.Join(tempDir, "path_traversal_token")
err = os.WriteFile(passwdFile, glFileData, testPerm)
require.NoError(t, err) require.NoError(t, err)
mw := newAuthMiddlewareGLiNet(&authMiddlewareGLiNetConfig{ mw := newAuthMiddlewareGLiNet(&authMiddlewareGLiNetConfig{
logger: testLogger, logger: testLogger,
mux: http.NewServeMux(), mux: http.NewServeMux(),
clock: timeutil.SystemClock{}, clock: timeutil.SystemClock{},
tokenFilePrefix: glFilePrefix, tokenFileRoot: tokenFileRoot,
maxTokenSize: MaxFileSize, maxTokenSize: MaxFileSize,
ttl: testTTL, ttl: testTTL,
}) })
h := &testAuthHandler{} h := &testAuthHandler{}
@@ -50,6 +70,12 @@ func TestAuthMiddlewareGLiNet(t *testing.T) {
reqInvalidCookie := httptest.NewRequest(http.MethodGet, "/", nil) reqInvalidCookie := httptest.NewRequest(http.MethodGet, "/", nil)
reqInvalidCookie.AddCookie(&http.Cookie{Name: glCookieName, Value: "invalid_cookie"}) reqInvalidCookie.AddCookie(&http.Cookie{Name: glCookieName, Value: "invalid_cookie"})
reqPathTraversalToken := httptest.NewRequest(http.MethodGet, "/", nil)
reqPathTraversalToken.AddCookie(&http.Cookie{
Name: glCookieName,
Value: "/../../path_traversal_token",
})
testCases := []struct { testCases := []struct {
req *http.Request req *http.Request
name string name string
@@ -66,6 +92,10 @@ func TestAuthMiddlewareGLiNet(t *testing.T) {
req: reqInvalidCookie, req: reqInvalidCookie,
name: "invalid_cookie", name: "invalid_cookie",
wantCode: http.StatusFound, wantCode: http.StatusFound,
}, {
req: reqPathTraversalToken,
name: "path_traversal_token",
wantCode: http.StatusFound,
}} }}
for _, tc := range testCases { for _, tc := range testCases {
+14 -10
View File
@@ -517,6 +517,10 @@ func TestAuth_ServeHTTP_auth(t *testing.T) {
writeGLFile(t, tempDir, testTTL) writeGLFile(t, tempDir, testTTL)
sessionsDB := filepath.Join(tempDir, "sessions.db") sessionsDB := filepath.Join(tempDir, "sessions.db")
gliNetRoot, err := os.OpenRoot(tempDir)
require.NoError(t, err)
testutil.CleanupAndRequireSuccess(t, gliNetRoot.Close)
mw := &webMw{} mw := &webMw{}
baseMux := http.NewServeMux() baseMux := http.NewServeMux()
httpReg := aghhttp.NewDefaultRegistrar(baseMux, mw.wrap) httpReg := aghhttp.NewDefaultRegistrar(baseMux, mw.wrap)
@@ -529,14 +533,15 @@ func TestAuth_ServeHTTP_auth(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
auth, err := newAuth(testutil.ContextWithTimeout(t, testTimeout), &authConfig{ auth, err := newAuth(testutil.ContextWithTimeout(t, testTimeout), &authConfig{
baseLogger: testLogger, baseLogger: testLogger,
mux: baseMux, mux: baseMux,
rateLimiter: emptyRateLimiter{}, rateLimiter: emptyRateLimiter{},
trustedProxies: testTrustedProxies, trustedProxies: testTrustedProxies,
dbFilename: sessionsDB, gliNetTokenRoot: gliNetRoot,
users: users, dbFilename: sessionsDB,
sessionTTL: testTTL * time.Second, users: users,
isGLiNet: false, sessionTTL: testTTL * time.Second,
isGLiNet: false,
}) })
require.NoError(t, err) require.NoError(t, err)
@@ -620,8 +625,7 @@ func TestAuth_ServeHTTP_auth(t *testing.T) {
func writeGLFile(t *testing.T, tempDir string, testTTL int64) { func writeGLFile(t *testing.T, tempDir string, testTTL int64) {
t.Helper() t.Helper()
glFilePrefix = tempDir + "/gl_token_" glTokenFile := filepath.Join(tempDir, glFilePrefix+"test")
glTokenFile := glFilePrefix + "test"
glFileData := make([]byte, 4) glFileData := make([]byte, 4)
binary.NativeEndian.PutUint32(glFileData, uint32(time.Now().Unix()+testTTL)) binary.NativeEndian.PutUint32(glFileData, uint32(time.Now().Unix()+testTTL))
+38 -14
View File
@@ -119,6 +119,12 @@ func Main(clientBuildFS fs.FS) {
baseLogger.InfoContext(ctx, "adguard home is running as a service") baseLogger.InfoContext(ctx, "adguard home is running as a service")
} }
var glTokenFileRoot *os.Root
if opts.glinetMode {
glTokenFileRoot, err = os.OpenRoot("/tmp/")
fatalOnError(err)
}
done := make(chan struct{}) done := make(chan struct{})
signals := make(chan os.Signal, 1) signals := make(chan os.Signal, 1)
@@ -126,9 +132,20 @@ func Main(clientBuildFS fs.FS) {
sigHdlrLogger := baseLogger.With(slogutil.KeyPrefix, "signalhdlr") sigHdlrLogger := baseLogger.With(slogutil.KeyPrefix, "signalhdlr")
sigHdlr := newSignalHandler(sigHdlrLogger, signals, func(ctx context.Context) { sigHdlr := newSignalHandler(sigHdlrLogger, signals, func(ctx context.Context) {
defer close(done)
cleanup(ctx) cleanup(ctx)
cleanupAlways() cleanupAlways()
close(done)
if !opts.glinetMode {
return
}
closeErr := glTokenFileRoot.Close()
if closeErr != nil {
baseLogger.ErrorContext(ctx, "closing glinet token root", slogutil.KeyError, closeErr)
os.Exit(osutil.ExitCodeFailure)
}
}) })
go sigHdlr.handle(ctx) go sigHdlr.handle(ctx)
@@ -139,6 +156,7 @@ func Main(clientBuildFS fs.FS) {
ctx, ctx,
baseLogger, baseLogger,
svcLogger, svcLogger,
glTokenFileRoot,
opts, opts,
clientBuildFS, clientBuildFS,
signals, signals,
@@ -156,7 +174,7 @@ func Main(clientBuildFS fs.FS) {
} }
// run the protection // run the protection
run(ctx, baseLogger, opts, clientBuildFS, done, sigHdlr, workDir, confPath) run(ctx, baseLogger, opts, clientBuildFS, glTokenFileRoot, done, sigHdlr, workDir, confPath)
} }
// setupContext initializes [globalContext] fields. It also reads and upgrades // setupContext initializes [globalContext] fields. It also reads and upgrades
@@ -731,7 +749,9 @@ func fatalOnError(err error) {
} }
} }
// run configures and starts AdGuard Home. // run configures and starts AdGuard Home. base and sigHdlr must not be nil.
// glTokenFileRoot must not be nil if opts.glinetMode is true. clientBuildFS
// must not be nil if opts.localFrontend is false.
// //
// TODO(e.burkov): Make opts a pointer. // TODO(e.burkov): Make opts a pointer.
func run( func run(
@@ -739,6 +759,7 @@ func run(
baseLogger *slog.Logger, baseLogger *slog.Logger,
opts options, opts options,
clientBuildFS fs.FS, clientBuildFS fs.FS,
glTokenFileRoot *os.Root,
done chan struct{}, done chan struct{},
sigHdlr *signalHandler, sigHdlr *signalHandler,
workDir string, workDir string,
@@ -796,7 +817,7 @@ func run(
err = os.MkdirAll(dataDirPath, aghos.DefaultPermDir) err = os.MkdirAll(dataDirPath, aghos.DefaultPermDir)
fatalOnError(errors.Annotate(err, "creating DNS data dir at %s: %w", dataDirPath)) fatalOnError(errors.Annotate(err, "creating DNS data dir at %s: %w", dataDirPath))
auth, err := initUsers(ctx, baseLogger, workDir, mux, opts.glinetMode) auth, err := initUsers(ctx, baseLogger, workDir, mux, opts.glinetMode, glTokenFileRoot)
fatalOnError(err) fatalOnError(err)
confModifier.setAuth(auth) confModifier.setAuth(auth)
@@ -1040,13 +1061,15 @@ func checkPermissions(
} }
// initUsers initializes authentication module and clears the [config.Users] // initUsers initializes authentication module and clears the [config.Users]
// field. // field. baseLogger and mux must not be nil. glTokenRoot must not be nil if
// isGLiNet is true.
func initUsers( func initUsers(
ctx context.Context, ctx context.Context,
baseLogger *slog.Logger, baseLogger *slog.Logger,
workDir string, workDir string,
mux *http.ServeMux, mux *http.ServeMux,
isGLiNet bool, isGLiNet bool,
glTokenRoot *os.Root,
) (auth *auth, err error) { ) (auth *auth, err error) {
var rateLimiter loginRateLimiter var rateLimiter loginRateLimiter
if config.AuthAttempts > 0 && config.AuthBlockMin > 0 { if config.AuthAttempts > 0 && config.AuthBlockMin > 0 {
@@ -1059,15 +1082,16 @@ func initUsers(
dataDirPath := filepath.Join(workDir, dataDir) dataDirPath := filepath.Join(workDir, dataDir)
auth, err = newAuth(ctx, &authConfig{ auth, err = newAuth(ctx, &authConfig{
baseLogger: baseLogger, baseLogger: baseLogger,
mux: mux, mux: mux,
rateLimiter: rateLimiter, rateLimiter: rateLimiter,
trustedProxies: netutil.SliceSubnetSet(netutil.UnembedPrefixes(config.DNS.TrustedProxies)), trustedProxies: netutil.SliceSubnetSet(netutil.UnembedPrefixes(config.DNS.TrustedProxies)),
dbFilename: filepath.Join(dataDirPath, sessionsDBName), dbFilename: filepath.Join(dataDirPath, sessionsDBName),
doHRoutes: config.HTTPConfig.DoH.Routes, doHRoutes: config.HTTPConfig.DoH.Routes,
users: config.Users, users: config.Users,
sessionTTL: time.Duration(config.HTTPConfig.SessionTTL), sessionTTL: time.Duration(config.HTTPConfig.SessionTTL),
isGLiNet: isGLiNet, isGLiNet: isGLiNet,
gliNetTokenRoot: glTokenRoot,
}) })
if err != nil { if err != nil {
return nil, fmt.Errorf("initializing auth module: %w", err) return nil, fmt.Errorf("initializing auth module: %w", err)
-3
View File
@@ -61,7 +61,6 @@ func newTestWeb(
// //
// The global variables are: // The global variables are:
// - [config] // - [config]
// - [glFilePrefix]
// - [globalContext.clients.storage] // - [globalContext.clients.storage]
// - [globalContext.dnsServer] // - [globalContext.dnsServer]
// - [globalContext.web] // - [globalContext.web]
@@ -72,14 +71,12 @@ func storeGlobals(tb testing.TB) {
tb.Helper() tb.Helper()
prevConfig := config prevConfig := config
prefGLFilePrefix := glFilePrefix
storage := globalContext.clients.storage storage := globalContext.clients.storage
dnsServer := globalContext.dnsServer dnsServer := globalContext.dnsServer
web := globalContext.web web := globalContext.web
tb.Cleanup(func() { tb.Cleanup(func() {
config = prevConfig config = prevConfig
glFilePrefix = prefGLFilePrefix
globalContext.clients.storage = storage globalContext.clients.storage = storage
globalContext.dnsServer = dnsServer globalContext.dnsServer = dnsServer
globalContext.web = web globalContext.web = web
@@ -3,12 +3,10 @@ package home
import ( import (
"bytes" "bytes"
"context" "context"
"encoding/binary"
"encoding/json" "encoding/json"
"io" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os"
"path/filepath" "path/filepath"
"testing" "testing"
"time" "time"
@@ -31,8 +29,6 @@ func TestWeb_HandleGetProfile(t *testing.T) {
const ( const (
testTTL = 60 testTTL = 60
glTokenFileSuffix = "test"
userName = "name" userName = "name"
userPassword = "password" userPassword = "password"
@@ -43,14 +39,6 @@ func TestWeb_HandleGetProfile(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
tempDir := t.TempDir() tempDir := t.TempDir()
glFilePrefix = tempDir + "/gl_token_"
glTokenFile := glFilePrefix + glTokenFileSuffix
glFileData := make([]byte, 4)
binary.NativeEndian.PutUint32(glFileData, uint32(time.Now().Unix()+testTTL))
err = os.WriteFile(glTokenFile, glFileData, 0o644)
require.NoError(t, err)
sessionsDB := filepath.Join(tempDir, "sessions.db") sessionsDB := filepath.Join(tempDir, "sessions.db")
+34 -21
View File
@@ -33,16 +33,17 @@ const svcLogPrefix = "service_manager"
// constructing a service instance and running it. Perhaps, deprecate the // constructing a service instance and running it. Perhaps, deprecate the
// action. // action.
type program struct { type program struct {
ctx context.Context ctx context.Context
clientBuildFS fs.FS clientBuildFS fs.FS
signals chan os.Signal signals chan os.Signal
done chan struct{} done chan struct{}
opts options opts options
baseLogger *slog.Logger baseLogger *slog.Logger
logger *slog.Logger logger *slog.Logger
sigHdlr *signalHandler sigHdlr *signalHandler
workDir string gliNetTokenRoot *os.Root
confPath string workDir string
confPath string
} }
// type check // type check
@@ -54,7 +55,17 @@ func (p *program) Start(_ service.Service) (err error) {
args := p.opts args := p.opts
args.runningAsService = true args.runningAsService = true
go run(p.ctx, p.baseLogger, args, p.clientBuildFS, p.done, p.sigHdlr, p.workDir, p.confPath) go run(
p.ctx,
p.baseLogger,
args,
p.clientBuildFS,
p.gliNetTokenRoot,
p.done,
p.sigHdlr,
p.workDir,
p.confPath,
)
return nil return nil
} }
@@ -140,6 +151,7 @@ func handleServiceControlAction(
ctx context.Context, ctx context.Context,
baseLogger *slog.Logger, baseLogger *slog.Logger,
l *slog.Logger, l *slog.Logger,
gliNetTokenRoot *os.Root,
opts options, opts options,
clientBuildFS fs.FS, clientBuildFS fs.FS,
signals chan os.Signal, signals chan os.Signal,
@@ -167,16 +179,17 @@ func handleServiceControlAction(
runOpts.serviceControlAction = "run" runOpts.serviceControlAction = "run"
p := &program{ p := &program{
ctx: ctx, ctx: ctx,
clientBuildFS: clientBuildFS, clientBuildFS: clientBuildFS,
signals: signals, signals: signals,
done: done, done: done,
opts: runOpts, opts: runOpts,
baseLogger: baseLogger, baseLogger: baseLogger,
logger: baseLogger.With(slogutil.KeyPrefix, "service"), logger: baseLogger.With(slogutil.KeyPrefix, "service"),
sigHdlr: sigHdlr, sigHdlr: sigHdlr,
workDir: workDir, gliNetTokenRoot: gliNetTokenRoot,
confPath: confPath, workDir: workDir,
confPath: confPath,
} }
return p.handleRun(ctx, baseLogger, runOpts) return p.handleRun(ctx, baseLogger, runOpts)