Skip to content

Commit e701cac

Browse files
authored
Merge pull request #1828 from pendo324/vsock-fix
fix: allow non-admin users to run limactl start
2 parents 2a1feb2 + f19a060 commit e701cac

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

pkg/windows/registry_windows.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222

2323
// AddVSockRegistryKey makes a vsock server running on the host acceessible in guests.
2424
func AddVSockRegistryKey(port int) error {
25-
rootKey, err := getGuestCommunicationServicesKey()
25+
rootKey, err := getGuestCommunicationServicesKey(true)
2626
if err != nil {
2727
return err
2828
}
@@ -58,7 +58,7 @@ func AddVSockRegistryKey(port int) error {
5858

5959
// RemoveVSockRegistryKey removes entries created by AddVSockRegistryKey.
6060
func RemoveVSockRegistryKey(port int) error {
61-
rootKey, err := getGuestCommunicationServicesKey()
61+
rootKey, err := getGuestCommunicationServicesKey(true)
6262
if err != nil {
6363
return err
6464
}
@@ -79,7 +79,7 @@ func RemoveVSockRegistryKey(port int) error {
7979

8080
// IsVSockPortFree determines if a VSock port has been registiered already.
8181
func IsVSockPortFree(port int) (bool, error) {
82-
rootKey, err := getGuestCommunicationServicesKey()
82+
rootKey, err := getGuestCommunicationServicesKey(false)
8383
if err != nil {
8484
return false, err
8585
}
@@ -148,7 +148,7 @@ func GetDistroID(name string) (string, error) {
148148

149149
// GetRandomFreeVSockPort gets a list of all registered VSock ports and returns a non-registered port.
150150
func GetRandomFreeVSockPort(min, max int) (int, error) {
151-
rootKey, err := getGuestCommunicationServicesKey()
151+
rootKey, err := getGuestCommunicationServicesKey(false)
152152
if err != nil {
153153
return 0, err
154154
}
@@ -186,11 +186,19 @@ func GetRandomFreeVSockPort(min, max int) (int, error) {
186186
return tree[0].offset + v, nil
187187
}
188188

189-
func getGuestCommunicationServicesKey() (registry.Key, error) {
189+
// getGuestCommunicationServicesKey returns the HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization\GuestCommunicationServices
190+
// registry key for use in other operations.
191+
//
192+
// allowWrite is configurable because setting it to true requires Administrator access.
193+
func getGuestCommunicationServicesKey(allowWrite bool) (registry.Key, error) {
194+
var registryPermissions uint32 = registry.READ
195+
if allowWrite {
196+
registryPermissions = registry.WRITE | registry.READ
197+
}
190198
rootKey, err := registry.OpenKey(
191199
registry.LOCAL_MACHINE,
192200
guestCommunicationsPrefix,
193-
registry.WRITE|registry.READ,
201+
registryPermissions,
194202
)
195203
if err != nil {
196204
return 0, fmt.Errorf(

0 commit comments

Comments
 (0)