Files
Craig Gumbley 40c6ab6d53 runtime/v2: avoid symlink for bundle work dir on Windows
Creating symlinks on Windows requires administrator privileges or
Developer Mode, so NewBundle fails with "A required privilege is not
held by the client" when containerd creates a task without them.

Replace the direct os.Symlink and os.Readlink calls with platform
specific helpers. On non-Windows platforms they keep the existing
symlink behaviour. On Windows, createWorkLink creates a directory
junction using go-winio's reparse point encoding, which does not need
elevated privileges. os.Readlink resolves both symlinks and junctions,
so resolveWorkLink uses it on both platforms.

createWorkLink closes the directory handle before removing the
half-created junction directory on failure. The handle is opened
without sharing, so removing the directory while it is still open would
fail.

Signed-off-by: Craig Gumbley <craiggumbley@gmail.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
Assisted-by: OpenCode (anthropic/claude-sonnet-5-5)
2026-11-02 14:04:39 +00:00

36 lines
1.0 KiB
Go

//go:build !windows
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v2
import (
"os"
"path/filepath"
)
// createWorkLink creates a symlink from bundlePath/work -> work.
func createWorkLink(work, bundlePath string) error {
return os.Symlink(work, filepath.Join(bundlePath, "work"))
}
// resolveWorkLink reads the symlink at bundlePath/work to recover the
// working directory path.
func resolveWorkLink(bundlePath string) (string, error) {
return os.Readlink(filepath.Join(bundlePath, "work"))
}