cloudflare/cloudflared · error
set token file security info: %w
Error message
set token file security info: %w
What it means
Finally, createTokenFile calls Win32 SetSecurityInformation (with OWNER_SECURITY_INFORMATION and DACL_SECURITY_INFORMATION) to stamp the owner and restrictive DACL onto the freshly created token file. If that Win32 call fails, cloudflared wraps the error with this message, and the service install aborts (the caller cleans up the token file).
Source
Thrown at cmd/cloudflared/windows_service.go:209
// -> Set file owner
// DACL_SECURITY_INFORMATION
// -> Set ACEs
// PROTECTED_DACL_SECURITY_INFORMATION
// -> Update DACL to be "protected' such that it cannot inherit entries from its parent
const securityInfo = windows.OWNER_SECURITY_INFORMATION |
windows.DACL_SECURITY_INFORMATION |
windows.PROTECTED_DACL_SECURITY_INFORMATION
if err := windows.SetNamedSecurityInfo(
path,
windows.SE_FILE_OBJECT,
securityInfo,
owner,
nil,
dacl,
nil,
); err != nil {
return fmt.Errorf("set token file security info: %w", err)
}
return nil
}
type windowsService struct {
app *cli.App
graceShutdownC chan struct{}
}
// Execute is called by the service manager when service starts, the state
// of the service will be set to Stopped when this function returns.
func (s *windowsService) Execute(serviceArgs []string, r <-chan svc.ChangeRequest, statusChan chan<- svc.Status) (ssec bool, errno uint32) {
log := logger.Create(nil)
elog, err := eventlog.Open(windowsServiceName)
if err != nil {
log.Err(err).Msgf("Cannot open event log for %s", windowsServiceName)
returnView on GitHub (pinned to 2253eeeb25)
Solutions
- Run `cloudflared service install` from an elevated (Run as Administrator) prompt
- Check for Group Policy/AV software resetting ACLs on %PROGRAMDATA% paths
- Verify the CreateFile handle is opened with the access rights needed to write security info (e.g. include WRITE_DAC/WRITE_OWNER in desired access)
- Check the wrapped Win32 code in the message (e.g. 'Access is denied') and address the specific denial
Example fix
// before f, err := windows.CreateFile(pathRaw, windows.GENERIC_WRITE, 0, nil, windows.CREATE_ALWAYS, windows.FILE_ATTRIBUTE_NORMAL, 0) // after const desiredAccess = windows.GENERIC_WRITE | windows.WRITE_DAC | windows.WRITE_OWNER f, err := windows.CreateFile(pathRaw, desiredAccess, 0, nil, windows.CREATE_ALWAYS, windows.FILE_ATTRIBUTE_NORMAL, 0)
Defensive patterns
Strategy: try-catch
Validate before calling
# PowerShell pre-check: is the session elevated?
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-Not $isAdmin) { Write-Error 'Run cloudflared service install as Administrator'; exit 1 } Try / catch
if err := installWindowsService(ctx); err != nil {
if strings.Contains(err.Error(), "set token file security info") {
log.Error().Msg("could not stamp ACL on token file; run as Administrator and check GPO/AV interference")
}
return err
} Prevention
- Always run service install elevated
- Verify no Group Policy or AV resets ACLs under %PROGRAMDATA%
- Open the file handle with WRITE_DAC/WRITE_OWNER access when setting security info
- Read the wrapped Win32 code to target the specific denial
When it happens
Trigger: windows.SetSecurityInformation fails on the token file handle after CreateFile succeeded — the caller lacks WRITE_OWNER/WRITE_DAC rights on the file, or the handle lacks the needed access bits.
Common situations: Running the service install without elevation so the process cannot set owner to BUILTIN\Administrators; Group Policy or antivirus interfering with ACL changes under %PROGRAMDATA%; the file handle was opened without sufficient desired-access flags.
Understand the failure class
Background: "You do not have permission" / 403 Forbidden errors: authenticated but not allowed — causes and fixes across open-source libraries — this error's family across 31 libraries.
Related errors
- The file-writing error is: %v / The delete tunnel error is:
- cloudflared service is already installed at ${service}; if y
- create config dir at %s: %w
- create token file at %s: %w
- chmod token file at %s: %w
AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06).
Data as JSON: /api/errors/1c591077dee10f49.
Report an issue: GitHub.