ipn/auditlog: store the audit log in the backend's state directory

The store path was hardcoded to %ProgramData%\Tailscale\audit-log.json on
Windows, so a tailscaled run by a regular user with its own --statedir
logged "[unexpected] failed to create audit log store ... Access is denied"
on every profile switch. Use the backend's TailscaleVarRoot when it is
known, falling back to the platform default otherwise. For the Windows
service the state directory is %ProgramData%\Tailscale, so its path is
unchanged; an explicit SetStoreFilePath still wins.

Updates #2791

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I5d7f9b1c3e5a7c9e1b3d5f7a9c1e3b5d7f9a1c3e
This commit is contained in:
Brad Fitzpatrick authored and Brad Fitzpatrick committed 2026-09-24 11:52:21 -07:00
1 parent 6612bed24d
commit e87076a378
2 files changed
+25 -6

No files matched your search

+11 -3
View File
@@ -37,6 +37,11 @@ func init() {
type extension struct {
logf logger.Logf
// sb is the backend, consulted for its state directory when the
// store is created. The directory is not known yet when the
// extension is constructed.
sb ipnext.SafeBackend
// store is the log store shared by all loggers.
// It is created when the first logger is started.
store lazy.SyncValue[LogStore]
@@ -53,8 +58,11 @@ type extension struct {
// newExtension is an [ipnext.NewExtensionFn] that creates a new audit log extension.
// It is registered with [ipnext.RegisterExtension] if the package is imported.
func newExtension(logf logger.Logf, _ ipnext.SafeBackend) (ipnext.Extension, error) {
return &extension{logf: logger.WithPrefix(logf, featureName+": ")}, nil
func newExtension(logf logger.Logf, sb ipnext.SafeBackend) (ipnext.Extension, error) {
return &extension{
logf: logger.WithPrefix(logf, featureName+": "),
sb: sb,
}, nil
}
// Name implements [ipnext.Extension].
@@ -86,7 +94,7 @@ func (e *extension) startNewLogger(cc controlclient.Client, profileID ipn.Profil
// Create a new log store if this is the first logger.
// Otherwise, get the existing log store.
store, err := e.store.GetErr(func() (LogStore, error) {
return newDefaultLogStore(e.logf)
return newDefaultLogStore(e.logf, e.sb.TailscaleVarRoot())
})
if err != nil {
return nil, fmt.Errorf("failed to create audit log store: %w", err)
+14 -3
View File
@@ -41,9 +41,20 @@ func DefaultStoreFilePath() (string, error) {
}
}
// newDefaultLogStore returns a new [LogStore] for the current platform.
func newDefaultLogStore(logf logger.Logf) (LogStore, error) {
path, err := storeFilePath.GetErr(DefaultStoreFilePath)
// newDefaultLogStore returns a new [LogStore] for the current platform. Its
// file is the path set with [SetStoreFilePath] if any, else audit-log.json in
// varRoot (the backend's state directory) if that is known, else the platform
// default from [DefaultStoreFilePath]. For the Windows service the state
// directory is the platform default's directory anyway; the difference is for
// a tailscaled run by a user with their own --statedir, which cannot write
// under %ProgramData%.
func newDefaultLogStore(logf logger.Logf, varRoot string) (LogStore, error) {
path, err := storeFilePath.GetErr(func() (string, error) {
if varRoot != "" {
return filepath.Join(varRoot, "audit-log.json"), nil
}
return DefaultStoreFilePath()
})
if err != nil {
// This indicates that the auditlog package was not omitted from the build
// on a platform without a default store path and that [SetStoreFilePath]