@@ -808,6 +808,8 @@ func TestGMSATaskFile(t *testing.T) {
808
808
err = ioutil .WriteFile (testCredSpecFilePath , testCredSpecData , 0755 )
809
809
require .NoError (t , err )
810
810
811
+ defer os .RemoveAll (testCredSpecFilePath )
812
+
811
813
testContainer := createTestContainer ()
812
814
testContainer .Name = "testGMSATaskFile"
813
815
@@ -842,11 +844,99 @@ func TestGMSATaskFile(t *testing.T) {
842
844
assert .NoError (t , err , "Could not kill container" )
843
845
844
846
verifyTaskIsStopped (stateChangeEvents , testTask )
847
+ }
848
+
849
+ func TestGMSADomainlessTaskFile (t * testing.T ) {
850
+ t .Setenv ("ECS_GMSA_SUPPORTED" , "True" )
851
+ t .Setenv ("ZZZ_SKIP_DOMAIN_JOIN_CHECK_NOT_SUPPORTED_IN_PRODUCTION" , "True" )
852
+ t .Setenv ("ZZZ_SKIP_CREDENTIALS_FETCHER_INVOCATION_CHECK_NOT_SUPPORTED_IN_PRODUCTION" , "True" )
853
+
854
+ cfg := defaultTestConfigIntegTest ()
855
+ cfg .TaskCPUMemLimit .Value = config .ExplicitlyDisabled
856
+ cfg .TaskCleanupWaitDuration = 3 * time .Second
857
+ cfg .GMSACapable = config.BooleanDefaultFalse {Value : config .ExplicitlyEnabled }
858
+ cfg .AWSRegion = "us-west-2"
859
+
860
+ taskEngine , done , _ := setupGMSALinux (cfg , nil , t )
861
+ defer done ()
862
+
863
+ stateChangeEvents := taskEngine .StateChangeEvents ()
864
+
865
+ // Setup test gmsa file
866
+ credentialSpecDataDir := "/tmp"
867
+ testFileName := "test-gmsa.json"
868
+ testCredSpecFilePath := filepath .Join (credentialSpecDataDir , testFileName )
869
+ _ , err := os .Create (testCredSpecFilePath )
870
+ require .NoError (t , err )
871
+
872
+ // add local credentialspec file for domainless gmsa support
873
+ testCredSpecData := []byte (`{
874
+ "CmsPlugins": [
875
+ "ActiveDirectory"
876
+ ],
877
+ "DomainJoinConfig": {
878
+ "Sid": "S-1-5-21-975084816-3050680612-2826754290",
879
+ "MachineAccountName": "gmsa-acct-test",
880
+ "Guid": "92a07e28-bd9f-4bf3-b1f7-0894815a5257",
881
+ "DnsTreeName": "gmsa.test.com",
882
+ "DnsName": "gmsa.test.com",
883
+ "NetBiosName": "gmsa"
884
+ },
885
+ "ActiveDirectoryConfig": {
886
+ "GroupManagedServiceAccounts": [
887
+ {
888
+ "Name": "gmsa-acct-test",
889
+ "Scope": "gmsa.test.com"
890
+ }
891
+ ],
892
+ "HostAccountConfig": {
893
+ "PortableCcgVersion": "1",
894
+ "PluginGUID": "{859E1386-BDB4-49E8-85C7-3070B13920E1}",
895
+ "PluginInput": {
896
+ "CredentialArn": "arn:aws:secretsmanager:us-west-2:123456789:secret:gmsausersecret-xb5Qev"
897
+ }
898
+ }
899
+ }
900
+ }` )
901
+
902
+ err = ioutil .WriteFile (testCredSpecFilePath , testCredSpecData , 0755 )
903
+ require .NoError (t , err )
904
+
905
+ defer os .RemoveAll (testCredSpecFilePath )
845
906
846
- // Cleanup the test file
847
- err = os .RemoveAll (testCredSpecFilePath )
907
+ testContainer := createTestContainer ()
908
+ testContainer .Name = "testGMSADomainlessTaskFile"
909
+
910
+ testContainer .CredentialSpecs = []string {"credentialspecdomainless:file:///tmp/test-gmsa.json" }
911
+
912
+ testTask := & apitask.Task {
913
+ Arn : "testGMSAFileTaskARN" ,
914
+ Family : "family" ,
915
+ Version : "1" ,
916
+ DesiredStatusUnsafe : apitaskstatus .TaskRunning ,
917
+ Containers : []* apicontainer.Container {testContainer },
918
+ }
919
+ testTask .Containers [0 ].TransitionDependenciesMap = make (map [apicontainerstatus.ContainerStatus ]apicontainer.TransitionDependencySet )
920
+ testTask .ResourcesMapUnsafe = make (map [string ][]taskresource.TaskResource )
921
+ testTask .Containers [0 ].Command = getLongRunningCommand ()
922
+
923
+ go taskEngine .AddTask (testTask )
924
+
925
+ verifyTaskIsRunning (stateChangeEvents , testTask )
926
+
927
+ client , _ := sdkClient .NewClientWithOpts (sdkClient .WithHost (endpoint ), sdkClient .WithVersion (sdkclientfactory .GetDefaultVersion ().String ()))
928
+ containerMap , _ := taskEngine .(* DockerTaskEngine ).state .ContainerMapByArn (testTask .Arn )
929
+ cid := containerMap [testTask .Containers [0 ].Name ].DockerID
930
+
931
+ expectedBind := "/tmp/tgt:/var/credentials-fetcher/krbdir:ro"
932
+ err = verifyContainerBindMount (client , cid , expectedBind )
848
933
assert .NoError (t , err )
849
934
935
+ // Kill the existing container now
936
+ err = client .ContainerKill (context .TODO (), cid , "SIGKILL" )
937
+ assert .NoError (t , err , "Could not kill container" )
938
+
939
+ verifyTaskIsStopped (stateChangeEvents , testTask )
850
940
}
851
941
852
942
func verifyContainerBindMount (client * sdkClient.Client , id , expectedBind string ) error {
0 commit comments