...

Source file src/k8s.io/kubernetes/cmd/kubelet/app/server_windows.go

Documentation: k8s.io/kubernetes/cmd/kubelet/app

     1  //go:build windows
     2  // +build windows
     3  
     4  /*
     5  Copyright 2021 The Kubernetes Authors.
     6  
     7  Licensed under the Apache License, Version 2.0 (the "License");
     8  you may not use this file except in compliance with the License.
     9  You may obtain a copy of the License at
    10  
    11      http://www.apache.org/licenses/LICENSE-2.0
    12  
    13  Unless required by applicable law or agreed to in writing, software
    14  distributed under the License is distributed on an "AS IS" BASIS,
    15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  See the License for the specific language governing permissions and
    17  limitations under the License.
    18  */
    19  
    20  package app
    21  
    22  import (
    23  	"errors"
    24  	"os/user"
    25  
    26  	"golang.org/x/sys/windows"
    27  	"k8s.io/klog/v2"
    28  )
    29  
    30  func checkPermissions() error {
    31  
    32  	u, err := user.Current()
    33  	if err != nil {
    34  		klog.ErrorS(err, "Unable to get current user")
    35  		return err
    36  	}
    37  
    38  	// For Windows user.UserName contains the login name and user.Name contains
    39  	// the user's display name - https://pkg.go.dev/os/user#User
    40  	klog.InfoS("Kubelet is running as", "login name", u.Username, "dispaly name", u.Name)
    41  
    42  	if !windows.GetCurrentProcessToken().IsElevated() {
    43  		return errors.New("kubelet needs to run with elevated permissions!")
    44  	}
    45  
    46  	return nil
    47  }
    48  

View as plain text