Skip to content

Commit 4fec6dc

Browse files
Merge pull request #3728 from saikiranakula-amzn/add_gmsa_integration_test
Added integration test gMSA domainless
2 parents 446970c + 06674b2 commit 4fec6dc

File tree

2 files changed

+93
-3
lines changed

2 files changed

+93
-3
lines changed

agent/config/parse_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
func parseGMSACapability() BooleanDefaultFalse {
30-
envStatus := utils.ParseBool(os.Getenv(envGmsaEcsSupport), true)
30+
envStatus := utils.ParseBool(os.Getenv(envGmsaEcsSupport), false)
3131
if envStatus {
3232
// Check if domain join check override is present
3333
skipDomainJoinCheck := utils.ParseBool(os.Getenv(envSkipDomainJoinCheck), false)

agent/engine/engine_sudo_linux_integ_test.go

+92-2
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,8 @@ func TestGMSATaskFile(t *testing.T) {
808808
err = ioutil.WriteFile(testCredSpecFilePath, testCredSpecData, 0755)
809809
require.NoError(t, err)
810810

811+
defer os.RemoveAll(testCredSpecFilePath)
812+
811813
testContainer := createTestContainer()
812814
testContainer.Name = "testGMSATaskFile"
813815

@@ -842,11 +844,99 @@ func TestGMSATaskFile(t *testing.T) {
842844
assert.NoError(t, err, "Could not kill container")
843845

844846
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)
845906

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)
848933
assert.NoError(t, err)
849934

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)
850940
}
851941

852942
func verifyContainerBindMount(client *sdkClient.Client, id, expectedBind string) error {

0 commit comments

Comments
 (0)