{"record":{"id":"f98ead25dd9c6d0c","repo":"hashicorp/nomad","slug":"work-dir-must-be-an-absolute-path","errorCode":null,"errorMessage":"work_dir must be an absolute path","messagePattern":"work_dir must be an absolute path","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/rawexec/driver.go","lineNumber":201,"sourceCode":"\t// WorkDir sets the working directory of the task\n\tWorkDir string `codec:\"work_dir\"`\n\n\t//DeniedEnvvars enables the removal of specified environment variables from a given job environment\n\tDeniedEnvvars []string `codec:\"denied_envvars\"`\n}\n\nfunc (t *TaskConfig) validate() error {\n\t// ensure only one of cgroups_v1_override and cgroups_v2_override have been\n\t// configured; must check here because task config validation cannot happen\n\t// on the server.\n\tif len(t.OverrideCgroupV1) > 0 && t.OverrideCgroupV2 != \"\" {\n\t\treturn errors.New(\"only one of cgroups_v1_override and cgroups_v2_override may be set\")\n\t}\n\tif t.OOMScoreAdj < 0 {\n\t\treturn errors.New(\"oom_score_adj must not be negative\")\n\t}\n\tif t.WorkDir != \"\" && !filepath.IsAbs(t.WorkDir) {\n\t\treturn errors.New(\"work_dir must be an absolute path\")\n\t}\n\treturn nil\n}\n\n// TaskState is the state which is encoded in the handle returned in\n// StartTask. This information is needed to rebuild the task state and handler\n// during recovery.\ntype TaskState struct {\n\tReattachConfig *pstructs.ReattachConfig\n\tTaskConfig     *drivers.TaskConfig\n\tPid            int\n\tStartedAt      time.Time\n}\n\n// NewRawExecDriver returns a new DriverPlugin implementation\nfunc NewRawExecDriver(ctx context.Context, logger hclog.Logger) drivers.DriverPlugin {\n\tlogger = logger.Named(pluginName)\n\treturn &Driver{","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/rawexec/driver.go#L183-L219","documentation":"rawexec's TaskConfig.validate() requires work_dir, when set, to be an absolute filesystem path, because the driver chdir()s the spawned process into it directly; a relative path has no meaningful anchor since the working directory of the Nomad client process is arbitrary.","triggerScenarios":"Submitting a rawexec task with work_dir = \"subdir\" or any path not starting with \"/\" (on Windows, not matching a root like C:\\\\); validate() rejects it before the task starts.","commonSituations":"Porting configs that used relative paths with a different executor; templates interpolating a relative directory name; assuming the driver resolves work_dir relative to the task's allocation dir.","solutions":["Prefix the path with \"/\" or the Windows drive root, e.g. work_dir = \"/opt/myapp\"","Use the allocation directory variable (NOMAD_ALLOC_DIR or driver-relative env) to build an absolute path in the template","Omit work_dir to run with the executor default working directory","Verify the path exists and is accessible to the Nomad client user"],"exampleFix":"// before\nconfig {\n  command = \"/bin/app\"\n  work_dir = \"appdir\"\n}\n// after\nconfig {\n  command = \"/bin/app\"\n  work_dir = \"/opt/appdir\"\n}","handlingStrategy":"validation","validationCode":"func checkWorkDir(wd string) error {\n    if wd != \"\" && !filepath.IsAbs(wd) {\n        return fmt.Errorf(\"work_dir %q must be absolute\", wd)\n    }\n    return nil\n}","typeGuard":"func isAbsWorkDir(wd string) bool { return wd == \"\" || filepath.IsAbs(wd) }","tryCatchPattern":null,"preventionTips":["Always write absolute paths in work_dir","Build paths from NOMAD_ALLOC_DIR or explicit roots in templates","Add work_dir checks to your job-spec lint pipeline"],"tags":["rawexec","paths","config-validation","nomad"],"backgroundTag":"path-must-be-absolute","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}