Change:
What happened: follow on to Need to comment and avoid checking UID on windows. requires some research into what we should be checking so that we can add appropriate TODO. What you expected to happen: Lets also check this at the call site, Anything else we need to know?: Environment: Kubernetes version (use ): master OS (e.g: ): windows
/assign
/assign
/good-first-issue
This request has been marked as suitable for new contributors. Please ensure the request meets the requirements listed . If this request no longer meets these requirements, the label can be removed by commenting with the command. <detailsIn response to : /good-first-issue Instructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details
/sig windows
Hi are you working on this issue already? If not I'd like to tackle this issue :)
Hi yeah I am already working on this :)
Started branch for this here
thanks
Hey guys is there anything I can do here?
If you want to test perks patch that would be great ?
That sounds great Where do I get started?
Hey ! is there anything I can help with? and how?
I dont think there is anything left to do anything more that you think we need to do to get this merged?
Tested this with containerd as well, I think its good to test
/triage accepted

Discussion:
/* <del> Copyright 2015 The Kubernetes Authors. </del> <ins> Copyright 2021 The Kubernetes Authors. </ins> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.

"math" "net" "net/http" <del> "os" </del> "path" "path/filepath" "strconv"

// add the kubelet config controller to kubeletDeps kubeletDeps.KubeletConfigController = kubeletConfigController <ins> if err := checkPermissions(); err != nil { klog.ErrorS(err, "kubelet running with insufficient permissions") } </ins> // set up signal context here in order to be reused by kubelet and docker shim ctx := genericapiserver.SetupSignalContext()

return nil } <del> func checkPermissions() error { if uid := os.Getuid(); uid != 0 { return fmt.Errorf("kubelet needs to run as uid `0`. It is being run as %d", uid) } // TODO: Check if kubelet is running in the `initial` user namespace. // http://man7.org/linux/man-pages/man7/user_namespaces.7.html return nil } </del> func setConfigz(cz *configz.Config, kc *kubeletconfiginternal.KubeletConfiguration) error { scheme, _, err := kubeletscheme.NewSchemeAndCodecs() if err != nil {

} } <del> if err := checkPermissions(); err != nil { klog.Error(err) } </del> utilruntime.ReallyCrash = s.ReallyCrashForTesting // TODO(vmarmol): Do this through container config.

<ins> // +build !windows /* Copyright 2021 The Kubernetes 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 app import ( "fmt" "os" ) func checkPermissions() error { if uid := os.Getuid(); uid != 0 { return fmt.Errorf("kubelet needs to run as uid `0`. It is being run as %d", uid) } // TODO: Check if kubelet is running in the `initial` user namespace. // http://man7.org/linux/man-pages/man7/user_namespaces.7.html return nil } </ins>

<ins> // +build windows /* Copyright 2021 The Kubernetes 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 app import ( "fmt" "os/user" "golang.org/x/sys/windows" ) func isAdmin() (bool, error) { // Get current user u, err := user.Current() if err != nil { return false, fmt.Errorf("Error retrieving current user: %s", err) } // Get IDs of group user is a member of ids, err := u.GroupIds() if err != nil { return false, fmt.Errorf("Error retrieving group ids: %s", err) } // Check for existence of BUILTINADMINISTRATORS group id for i := range ids { // BUILTINADMINISTRATORS if "S-1-5-32-544" == ids[i] { return true, nil } } return false, nil } func checkPermissions() error { //https://github.com/golang/go/issues/28804#issuecomment-505326268 var sid *windows.SID var userIsAdmin bool // https://docs.microsoft.com/en-us/windows/desktop/api/securitybaseapi/nf-securitybaseapi-checktokenmembership err := windows.AllocateAndInitializeSid( &windows.SECURITY_NT_AUTHORITY, 2, windows.SECURITY_BUILTIN_DOMAIN_RID, windows.DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &sid) if err != nil { return fmt.Errorf("Error while checking for elevated permissions: %s", err) } //We must free the sid to prevent security token leaks defer windows.FreeSid(sid) token := windows.Token(0) userIsAdmin, err = isAdmin() if err != nil { return fmt.Errorf("Error while checking admin group membership: %s", err) } member, err := token.IsMember(sid) if err != nil { return fmt.Errorf("Error while checking for elevated permissions: %s", err) } if !member { return fmt.Errorf("kubelet needs to run with administrator permissions. Run as admin is: %t, User in admin group: %t", member, userIsAdmin) } return nil } </ins>