Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/27147.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
dynamic host volumes: fix Windows compatibility
```
24 changes: 13 additions & 11 deletions client/hostvolumemanager/host_volume_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,20 @@ func (p *HostVolumePluginMkdir) Create(_ context.Context,
}

// Chown note: A uid or gid of -1 means to not change that value.
if err = os.Chown(path, params.Uid, params.Gid); err != nil {
log.Error("error changing owner/group", "error", err, "uid", params.Uid, "gid", params.Gid)

// Failing to change ownership is fatal for this plugin. Since we have
// already created the directory, we should attempt to clean it.
// Otherwise, the operator must do this manually.
if err := os.RemoveAll(path); err != nil {
log.Error("failed to remove directory after create failure",
"error", err)
if params.Uid != -1 || params.Gid != -1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If os.Chown always returns an error on windows, should we just wrap the chown in a if runtime.GOOS != "windows"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would works too but isn't that bad that user might expect to set permissions which is not actually done?

Based on code -1 means change nothing so current logic would works exactly same way in both Linux and Windows as long user do not configure permissions but any other value would still give error not supported by windows

Copy link
Member

@mismithhisler mismithhisler Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Also, I apologize for belaboring this, but I was curious how this was handled elsewhere in the codebase (it's not the only place we use os.Chown(). It looks we only chown when the euid from syscall.Geteuid() is 0. I wonder if, for consistency sake, we should do something similar here? This syscall returns -1 on Windows. See here for reference.

Either way, I think it's probably useful for someone on the Nomad team (I can do this) to update the mkdir plugin docs to let Windows users know that ownership changing is not available on Windows.

if err = os.Chown(path, params.Uid, params.Gid); err != nil {
log.Error("error changing owner/group", "error", err, "uid", params.Uid, "gid", params.Gid)

// Failing to change ownership is fatal for this plugin. Since we have
// already created the directory, we should attempt to clean it.
// Otherwise, the operator must do this manually.
if err := os.RemoveAll(path); err != nil {
log.Error("failed to remove directory after create failure",
"error", err)
}

return nil, fmt.Errorf("error changing owner/group: %w", err)
}

return nil, fmt.Errorf("error changing owner/group: %w", err)
}

log.Debug("plugin ran successfully")
Expand Down
Loading