Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
aa8efc5b
Commit
aa8efc5b
authored
May 16, 2019
by
ksubrmnn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check User SIDs via os package
parent
71bbabc3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
11 deletions
+21
-11
checks_windows.go
cmd/kubeadm/app/preflight/checks_windows.go
+21
-11
No files found.
cmd/kubeadm/app/preflight/checks_windows.go
View file @
aa8efc5b
...
...
@@ -19,28 +19,38 @@ limitations under the License.
package
preflight
import
(
"os/exec"
"strings"
"os/user"
"github.com/pkg/errors"
)
// Check validates if an user has elevated (administrator) privileges.
// The "Well-known SID" of Administrator group
// https://support.microsoft.com/en-us/help/243330/well-known-security-identifiers-in-windows-operating-systems
const
administratorSID
=
"S-1-5-32-544"
// Check validates if a user has elevated (administrator) privileges.
func
(
ipuc
IsPrivilegedUserCheck
)
Check
()
(
warnings
,
errorList
[]
error
)
{
errorList
=
[]
error
{}
// The "Well-known SID" of Administrator group is S-1-5-32-544
// The following powershell will return "True" if run as an administrator, "False" otherwise
// See https://msdn.microsoft.com/en-us/library/cc980032.aspx
args
:=
[]
string
{
"[bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match
\"
S-1-5-32-544
\"
)"
}
isAdmin
,
err
:=
exec
.
Command
(
"powershell"
,
args
...
)
.
Output
()
currUser
,
err
:=
user
.
Current
()
if
err
!=
nil
{
errorList
=
append
(
errorList
,
errors
.
New
(
"cannot get current user"
))
return
nil
,
errorList
}
groupIds
,
err
:=
currUser
.
GroupIds
()
if
err
!=
nil
{
errorList
=
append
(
errorList
,
errors
.
Wrap
(
err
,
"unable to determine if user is running as administrator"
))
}
else
if
strings
.
EqualFold
(
strings
.
TrimSpace
(
string
(
isAdmin
)),
"false"
)
{
errorList
=
append
(
errorList
,
errors
.
New
(
"user is not running as administrator"
))
errorList
=
append
(
errorList
,
errors
.
New
(
"cannot get group IDs for current user"
))
return
nil
,
errorList
}
for
_
,
sid
:=
range
groupIds
{
if
sid
==
administratorSID
{
return
nil
,
errorList
}
}
errorList
=
append
(
errorList
,
errors
.
New
(
"user is not running as administrator"
))
return
nil
,
errorList
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment