{"record":{"id":"14258326d7322b2d","repo":"GoogleContainerTools/skaffold","slug":"getting-relative-path-of-s","errorCode":null,"errorMessage":"getting relative path of %s","messagePattern":"getting relative path of (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/docker/parse.go","lineNumber":233,"sourceCode":"\t\t\tpath := filepath.Join(workspace, p)\n\t\t\tif _, err := os.Stat(path); err == nil {\n\t\t\t\tfts = append(fts, FromTo{From: filepath.Clean(p), To: cpCmd.dest, ToIsDir: cpCmd.destIsDir, StartLine: cpCmd.startLine, EndLine: cpCmd.endLine})\n\t\t\t\tmatchesOne = true\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tfiles, err := filepath.Glob(path)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid glob pattern: %w\", err)\n\t\t\t}\n\t\t\tif files == nil {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tfor _, f := range files {\n\t\t\t\trel, err := filepath.Rel(workspace, f)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"getting relative path of %s\", f)\n\t\t\t\t}\n\n\t\t\t\tfts = append(fts, FromTo{From: rel, To: cpCmd.dest, ToIsDir: cpCmd.destIsDir, StartLine: cpCmd.startLine, EndLine: cpCmd.endLine})\n\t\t\t}\n\t\t\tmatchesOne = true\n\t\t}\n\n\t\tif !matchesOne {\n\t\t\treturn nil, fmt.Errorf(\"file pattern %s must match at least one file\", cpCmd.srcs)\n\t\t}\n\t}\n\n\tlog.Entry(context.TODO()).Debugf(\"Found dependencies for dockerfile: %v\", fts)\n\n\treturn fts, nil\n}\n\nfunc extractCopyCommands(ctx context.Context, nodes []*parser.Node, onlyLastImage bool, cfg Config) ([]*copyCommand, error) {","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/docker/parse.go#L215-L251","documentation":"After glob matching succeeds, expandSrcGlobPatterns converts each matched absolute path to a workspace-relative path with filepath.Rel(workspace, f). If a matched file lies outside the workspace (making a relative path impossible/meaningless) Rel fails and Skaffold wraps it as 'getting relative path of <file>'. Docker COPY sources must live inside the build context, so this signals a pattern that escapes the workspace.","triggerScenarios":"A glob in a COPY source matches files under a parent directory (e.g. '../shared/x*' resolving outside workspace), or the workspace root passed to the API does not contain the matched files.","commonSituations":"Dockerfiles copying from sibling directories via '..' paths; a workspace/workspaceRoot misconfiguration in skaffold.yaml pointing at a subdirectory; symlinks in the build context resolving outside the workspace.","solutions":["Ensure all COPY sources are inside the configured workspace/build context — remove '..' traversal from patterns","Correct the workspace root in skaffold.yaml (context field) so it is the common ancestor of all copied files","Replace '..'-style references by restructuring the project or using an additional artifact with its own context","Check for symlinks inside the workspace that point outside and remove or relocate them"],"exampleFix":"// before (Dockerfile, workspace=./svc)\nCOPY ../shared/lib /lib\n// after (set context: . and)\nCOPY svc/main ./main\nCOPY shared/lib /lib","handlingStrategy":"try-catch","validationCode":"func sourcesInsideWorkspace(workspace string, srcs []string) error {\n    absWs, err := filepath.Abs(workspace)\n    if err != nil { return err }\n    for _, s := range srcs {\n        matches, _ := filepath.Glob(filepath.Join(absWs, s))\n        for _, m := range matches {\n            if !strings.HasPrefix(m, absWs+string(os.PathSeparator)) {\n                return fmt.Errorf(\"pattern %q resolves outside workspace: %s\", s, m)\n            }\n        }\n    }\n    return nil\n}","typeGuard":"func withinWorkspace(workspace, file string) bool {\n    absWs, err := filepath.Abs(workspace)\n    if err != nil { return false }\n    abs, err := filepath.Abs(file)\n    return err == nil && strings.HasPrefix(abs, absWs+string(os.PathSeparator))\n}","tryCatchPattern":"fts, err := skaffold.ReadCopyCmdsFromDockerfile(path, args, cfg, false)\nif err != nil && strings.Contains(err.Error(), \"getting relative path of\") {\n    return fmt.Errorf(\"a COPY source escapes the workspace; fix pattern or context: %w\", err)\n}","preventionTips":["Never use '..' traversal in COPY sources; restructure contexts instead","Set skaffold.yaml context/workspace to the common ancestor of all copied files","Audit symlinks in the build context that point outside the workspace","Keep artifact workspaces aligned with the Dockerfile's assumed layout"],"tags":["filepath","workspace","dockerfile-copy"],"backgroundTag":"dockerfile-copy-source-not-found","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}