snail007/goproxy · error

auth-file ERR:%s

Error message

auth-file ERR:%s

What it means

InitBasicAuth loads HTTP basic-auth credentials for the service. When an auth file is configured it calls basicAuth.AddFromFile, and if reading/parsing that file fails, the underlying error is wrapped as "auth-file ERR:%s" and returned, aborting service startup via InitService.

Source

Thrown at services/http.go:174

		//parent string, timeout int, InitialCap int, MaxCap int
		s.outPool = utils.NewOutPool(
			*s.cfg.CheckParentInterval,
			*s.cfg.ParentType == TYPE_TLS,
			s.cfg.CertBytes, s.cfg.KeyBytes,
			*s.cfg.Parent,
			*s.cfg.Timeout,
			*s.cfg.PoolSize,
			*s.cfg.PoolSize*2,
		)
	}
}
func (s *HTTP) InitBasicAuth() (err error) {
	s.basicAuth = utils.NewBasicAuth()
	if *s.cfg.AuthFile != "" {
		var n = 0
		n, err = s.basicAuth.AddFromFile(*s.cfg.AuthFile)
		if err != nil {
			err = fmt.Errorf("auth-file ERR:%s", err)
			return
		}
		log.Printf("auth data added from file %d , total:%d", n, s.basicAuth.Total())
	}
	if len(*s.cfg.Auth) > 0 {
		n := s.basicAuth.Add(*s.cfg.Auth)
		log.Printf("auth data added %d, total:%d", n, s.basicAuth.Total())
	}
	return
}
func (s *HTTP) IsBasicAuth() bool {
	return *s.cfg.AuthFile != "" || len(*s.cfg.Auth) > 0
}
func (s *HTTP) IsDeadLoop(inLocalAddr string, host string) bool {
	inIP, inPort, err := net.SplitHostPort(inLocalAddr)
	if err != nil {
		return false
	}

View on GitHub (pinned to e6d6a821db)

Solutions

  1. Check the error wrapped after 'auth-file ERR:' and fix the underlying cause (missing file, bad permission, malformed line)
  2. Use an absolute path for the auth file in the config so it is independent of the working directory
  3. Validate each line is 'user:password' (one per line) with no stray whitespace or BOM
  4. Alternatively configure credentials inline via the auth config option instead of a file

Example fix

// before
// auth_file=./user.conf   (file not present in container)
// after
// auth_file=/etc/nps/user.conf  (absolute path, exists, chmod 600)
Defensive patterns

Strategy: validation

Validate before calling

func validateAuthFile(path string) error {
    f, err := os.Open(path)
    if err != nil { return err }
    defer f.Close()
    sc := bufio.NewScanner(f)
    for i := 1; sc.Scan(); i++ {
        line := strings.TrimSpace(sc.Text())
        if line == "" { continue }
        if !strings.Contains(line, ":") {
            return fmt.Errorf("line %d: expected user:password", i)
        }
    }
    return sc.Err()
}

Try / catch

if err := svc.Init(); err != nil {
    var authFileErr bool
    if strings.HasPrefix(err.Error(), "auth-file ERR:") { authFileErr = true }
    if authFileErr {
        log.Fatalf("fix auth file config: %v", err)
    }
}

Prevention

When it happens

Trigger: *cfg.AuthFile is set to a path that does not exist, is unreadable (permissions), or whose contents do not match the expected user:password line format, causing AddFromFile to return an error which gets wrapped.

Common situations: Wrong relative path after changing working directory (systemd/docker working dir differs); file missing in the container image; malformed lines (missing colon, whitespace, wrong charset); file mounted without read permission.

Related errors


AI-assisted analysis of snail007/goproxy@e6d6a821db (2026-09-03). Data as JSON: /api/errors/d7dc1db80d959349. Report an issue: GitHub.