-
Notifications
You must be signed in to change notification settings - Fork 613
/
parse_windows.go
115 lines (96 loc) · 3.57 KB
/
parse_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//go:build windows
// +build windows
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file 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 config
import (
"os"
"os/exec"
"strings"
"syscall"
"unsafe"
"github.com/aws/amazon-ecs-agent/agent/utils"
"github.com/cihub/seelog"
)
const (
// envSkipWindowsServerVersionCheck is an environment setting that can be used
// to skip the windows server version check. This is useful for testing and
// should not be set for any non-test use-case.
envSkipWindowsServerVersionCheck = "ZZZ_SKIP_WINDOWS_SERVER_VERSION_CHECK_NOT_SUPPORTED_IN_PRODUCTION"
)
// parseGMSACapability is used to determine if gMSA support can be enabled
func parseGMSACapability() bool {
envStatus := utils.ParseBool(os.Getenv("ECS_GMSA_SUPPORTED"), true)
return checkDomainJoinWithEnvOverride(envStatus)
}
// parseFSxWindowsFileServerCapability is used to determine if fsxWindowsFileServer support can be enabled
func parseFSxWindowsFileServerCapability() bool {
// fsxwindowsfileserver is not supported on Windows 2016 and non-domain-joined container instances
status, err := IsWindows2016()
if err != nil || status == true {
return false
}
envStatus := utils.ParseBool(os.Getenv("ECS_FSX_WINDOWS_FILE_SERVER_SUPPORTED"), true)
return checkDomainJoinWithEnvOverride(envStatus)
}
func checkDomainJoinWithEnvOverride(envStatus bool) bool {
if envStatus {
// Check if domain join check override is present
skipDomainJoinCheck := utils.ParseBool(os.Getenv(envSkipDomainJoinCheck), false)
if skipDomainJoinCheck {
seelog.Debug("Skipping domain join validation based on environment override")
return true
}
// check if container instance is domain joined.
// If container instance is not domain joined, explicitly disable feature configuration.
status, err := isDomainJoined()
if err == nil && status == true {
return true
}
seelog.Errorf("Unable to determine valid domain join: %v", err)
}
return false
}
// isDomainJoined is used to validate if container instance is part of a valid active directory.
// Reference: https://golang.org/src/os/user/lookup_windows.go
func isDomainJoined() (bool, error) {
var domain *uint16
var status uint32
err := syscall.NetGetJoinInformation(nil, &domain, &status)
if err != nil {
return false, err
}
err = syscall.NetApiBufferFree((*byte)(unsafe.Pointer(domain)))
if err != nil {
return false, err
}
return status == syscall.NetSetupDomainName, nil
}
// Making it visible for unit testing
var execCommand = exec.Command
var IsWindows2016 = func() (bool, error) {
// Check for environment override before proceeding.
envSkipWindowsServerVersionCheck := utils.ParseBool(os.Getenv(envSkipWindowsServerVersionCheck), false)
if envSkipWindowsServerVersionCheck {
seelog.Debug("Skipping windows server version check based on environment override")
return false, nil
}
cmd := "systeminfo | findstr /B /C:\"OS Name\""
out, err := execCommand("powershell", "-Command", cmd).CombinedOutput()
if err != nil {
return false, err
}
str := string(out)
isWS2016 := strings.Contains(str, "Microsoft Windows Server 2016 Datacenter")
return isWS2016, nil
}