@@ -24,14 +24,21 @@ import (
24
24
"unsafe"
25
25
26
26
"github.com/aws/amazon-ecs-agent/agent/utils"
27
+
27
28
"github.com/cihub/seelog"
29
+ "golang.org/x/sys/windows/registry"
28
30
)
29
31
30
32
const (
31
33
// envSkipWindowsServerVersionCheck is an environment setting that can be used
32
34
// to skip the windows server version check. This is useful for testing and
33
35
// should not be set for any non-test use-case.
34
36
envSkipWindowsServerVersionCheck = "ZZZ_SKIP_WINDOWS_SERVER_VERSION_CHECK_NOT_SUPPORTED_IN_PRODUCTION"
37
+ gmsaPluginGUID = "{859E1386-BDB4-49E8-85C7-3070B13920E1}"
38
+ )
39
+
40
+ var (
41
+ fnQueryDomainlessGmsaPluginSubKeys = queryDomainlessGmsaPluginSubKeys
35
42
)
36
43
37
44
// parseGMSACapability is used to determine if gMSA support can be enabled
@@ -40,6 +47,26 @@ func parseGMSACapability() BooleanDefaultFalse {
40
47
return checkDomainJoinWithEnvOverride (envStatus )
41
48
}
42
49
50
+ // parseGMSADomainlessCapability is used to determine if gMSA domainless support can be enabled
51
+ func parseGMSADomainlessCapability () BooleanDefaultFalse {
52
+ envStatus := utils .ParseBool (os .Getenv ("ECS_GMSA_SUPPORTED" ), false )
53
+ if envStatus {
54
+ // gmsaDomainless is not supported on Windows 2016
55
+ isWindows2016 , err := IsWindows2016 ()
56
+ if err != nil || isWindows2016 {
57
+ return BooleanDefaultFalse {Value : ExplicitlyDisabled }
58
+ }
59
+
60
+ // gmsaDomainless is not supported if the plugin is not installed on the instance
61
+ installed , err := isDomainlessGmsaPluginInstalled ()
62
+ if err != nil || ! installed {
63
+ return BooleanDefaultFalse {Value : ExplicitlyDisabled }
64
+ }
65
+ return BooleanDefaultFalse {Value : ExplicitlyEnabled }
66
+ }
67
+ return BooleanDefaultFalse {Value : ExplicitlyDisabled }
68
+ }
69
+
43
70
// parseFSxWindowsFileServerCapability is used to determine if fsxWindowsFileServer support can be enabled
44
71
func parseFSxWindowsFileServerCapability () BooleanDefaultFalse {
45
72
// fsxwindowsfileserver is not supported on Windows 2016 and non-domain-joined container instances
@@ -114,3 +141,42 @@ var IsWindows2016 = func() (bool, error) {
114
141
115
142
return isWS2016 , nil
116
143
}
144
+
145
+ var queryDomainlessGmsaPluginSubKeys = func () ([]string , error ) {
146
+ k , err := registry .OpenKey (registry .LOCAL_MACHINE , `SYSTEM\CurrentControlSet\Control\CCG\COMClasses\` , registry .READ )
147
+ if err != nil {
148
+ seelog .Errorf ("Failed to open registry key SYSTEM\\ CurrentControlSet\\ Control\\ CCG\\ COMClasses with error: %v" , err )
149
+ return nil , err
150
+ }
151
+ defer k .Close ()
152
+ stat , err := k .Stat ()
153
+ if err != nil {
154
+ seelog .Errorf ("Failed to stat registry key SYSTEM\\ CurrentControlSet\\ Control\\ CCG\\ COMClasses with error: %v" , err )
155
+ return nil , err
156
+ }
157
+ subKeys , err := k .ReadSubKeyNames (int (stat .SubKeyCount ))
158
+ if err != nil {
159
+ seelog .Errorf ("Failed to read subkeys of SYSTEM\\ CurrentControlSet\\ Control\\ CCG\\ COMClasses with error: %v" , err )
160
+ return nil , err
161
+ }
162
+
163
+ seelog .Debugf ("gMSA Subkeys are %+v" , subKeys )
164
+ return subKeys , nil
165
+ }
166
+
167
+ // This function queries all gmsa plugin subkeys to check whether the Amazon ECS Plugin GUID is present.
168
+ func isDomainlessGmsaPluginInstalled () (bool , error ) {
169
+ subKeys , err := fnQueryDomainlessGmsaPluginSubKeys ()
170
+ if err != nil {
171
+ seelog .Errorf ("Failed to query gmsa plugin subkeys" )
172
+ return false , err
173
+ }
174
+
175
+ for _ , subKey := range subKeys {
176
+ if subKey == gmsaPluginGUID {
177
+ return true , nil
178
+ }
179
+ }
180
+
181
+ return false , nil
182
+ }
0 commit comments