From abec17f8f28c46d803764d6d9bbd5b63d8f2d52d Mon Sep 17 00:00:00 2001 From: Julio Montes Date: Fri, 11 Oct 2019 15:25:54 +0000 Subject: [PATCH] virtcontainers/store: make VCStoreUUIDPath rootless The uuid file shouldn't be created at `/var` if running rootless. Modify `VMUUIDStoragePath` to get a path accessible for non-root users if running rootless. fixes #2133 Signed-off-by: Julio Montes --- virtcontainers/store/filesystem_backend.go | 9 ++++++++- virtcontainers/store/vc.go | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/virtcontainers/store/filesystem_backend.go b/virtcontainers/store/filesystem_backend.go index 200e42e474..b74699f666 100644 --- a/virtcontainers/store/filesystem_backend.go +++ b/virtcontainers/store/filesystem_backend.go @@ -105,7 +105,14 @@ var RunVMStoragePath = func() string { // VMUUIDStoragePath is the uuid directory. // It will contain all uuid info used by guest vm. -var VMUUIDStoragePath = filepath.Join("/var/lib", StoragePathSuffix, UUIDPathSuffix) +var VMUUIDStoragePath = func() string { + path := filepath.Join("/var/lib", StoragePathSuffix, UUIDPathSuffix) + if rootless.IsRootless() { + return filepath.Join(rootless.GetRootlessDir(), path) + } + return path + +} func itemToFile(item Item) (string, error) { switch item { diff --git a/virtcontainers/store/vc.go b/virtcontainers/store/vc.go index f69827b351..79642b0593 100644 --- a/virtcontainers/store/vc.go +++ b/virtcontainers/store/vc.go @@ -271,7 +271,7 @@ func SandboxConfigurationItemPath(id string, item Item) (string, error) { // VCStoreUUIDPath returns a virtcontainers runtime uuid URL. func VCStoreUUIDPath() string { - return filesystemScheme + "://" + filepath.Join(VCStorePrefix, VMUUIDStoragePath) + return filesystemScheme + "://" + filepath.Join(VCStorePrefix, VMUUIDStoragePath()) } // SandboxRuntimeRoot returns a virtcontainers sandbox runtime root URL.