Skip to content

Commit 8e4c4ef

Browse files
authored
Merge branch 'aws:master' into master
2 parents 4206ad7 + 2ddc859 commit 8e4c4ef

File tree

111 files changed

+4715
-1354
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+4715
-1354
lines changed

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
# Changelog
22

3+
## 1.67.2
4+
* Bug - Fix the generation of network bindings for Service Connect container [#3513](https://github.com/aws/amazon-ecs-agent/pull/3513)
5+
* Bug - Prevent resetting valid agent state db when IMDS fails on startup [#3509](https://github.com/aws/amazon-ecs-agent/pull/3509)
6+
7+
## 1.67.1
8+
* Bug - Read git hash from RELEASE_COMMIT file if possible [#3508](https://github.com/aws/amazon-ecs-agent/pull/3508)
9+
10+
## 1.67.0
11+
* Bug - Don't log errors on instances not using GMSA [#3489](https://github.com/aws/amazon-ecs-agent/pull/3489)
12+
* Enhancement - Update packaging Readme files with updated instructions to build init files [#3490](https://github.com/aws/amazon-ecs-agent/pull/3490)
13+
* Bug - Fix unit tests for cgroup v2 [#3491](https://github.com/aws/amazon-ecs-agent/pull/3491)
14+
* Enhancement - Update readme for ECS_SELINUX_CAPABLE to clarify Z-mode mount only and limited support [#3496](https://github.com/aws/amazon-ecs-agent/pull/3496)
15+
* Bug - Fix agent short hash version bug [#3497](https://github.com/aws/amazon-ecs-agent/pull/3497)
16+
* Bug - Use Ubuntu 20.04 for linux GH Unit tests [#3501](https://github.com/aws/amazon-ecs-agent/pull/3501)
17+
* Feature - Container port range mapping [#3506](https://github.com/aws/amazon-ecs-agent/pull/3506)
18+
19+
## 1.66.2
20+
* Bug - Add ecs-serviceconnect to CNI and Agent build scripts [#3482](https://github.com/aws/amazon-ecs-agent/pull/3482)
21+
* Bug - add call to update-version.sh to dockerfree-agent-image [#3484](https://github.com/aws/amazon-ecs-agent/pull/3484)
22+
23+
## 1.66.1
24+
* Bug - Update ecs agent version short hash to point to built head [#3476](https://github.com/aws/amazon-ecs-agent/pull/3476)
25+
* Bug - Remove CAP_CHOWN [#3480](https://github.com/aws/amazon-ecs-agent/pull/3480)
26+
27+
## 1.66.0
28+
* Feature - gMSA on Linux support [#3464](https://github.com/aws/amazon-ecs-agent/pull/3464)
29+
* Enhancement - Restart AppNet Relay on failure [#3469](Restart AppNet Relay on failure)
30+
331
## 1.65.1
432
* Enhancement - Add grpc vendor dependencies [#3439](https://github.com/aws/amazon-ecs-agent/pull/3439)
533
* Bug - Workaround git-secrets scan issue: awslabs/git-secrets#221 [#3442](https://github.com/aws/amazon-ecs-agent/pull/3442)

Makefile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static:
5252
./scripts/build
5353

5454
static-with-pause:
55-
./scripts/build true "" false true
55+
./scripts/build true "" true true
5656

5757
# Cross-platform build target for static checks
5858
xplatform-build:
@@ -377,11 +377,11 @@ amazon-linux-sources.tgz:
377377
cp packaging/amazon-linux-ami-integrated/amazon-ecs-volume-plugin.conf amazon-ecs-volume-plugin.conf
378378
cp packaging/amazon-linux-ami-integrated/amazon-ecs-volume-plugin.service amazon-ecs-volume-plugin.service
379379
cp packaging/amazon-linux-ami-integrated/amazon-ecs-volume-plugin.socket amazon-ecs-volume-plugin.socket
380-
tar -czf ./sources.tgz ecs-init scripts misc agent amazon-ecs-cni-plugins amazon-vpc-cni-plugins agent-container VERSION
380+
tar -czf ./sources.tgz ecs-init scripts misc agent amazon-ecs-cni-plugins amazon-vpc-cni-plugins agent-container VERSION RELEASE_COMMIT
381381

382382
.amazon-linux-rpm-integrated-done: amazon-linux-sources.tgz
383383
test -e SOURCES || ln -s . SOURCES
384-
rpmbuild --define "%_topdir $(PWD)" -bb ecs-init.spec
384+
rpmbuild --define "%_topdir $(PWD)" -bb ecs-agent.spec
385385
find RPMS/ -type f -exec cp {} . \;
386386
touch .amazon-linux-rpm-integrated-done
387387

@@ -404,8 +404,8 @@ generic-rpm-integrated: .generic-rpm-integrated-done
404404
VERSION = $(shell cat ecs-init/ECSVERSION)
405405

406406
.generic-deb-integrated-done: get-cni-sources
407-
mkdir -p BUILDROOT
408407
./scripts/update-version.sh
408+
mkdir -p BUILDROOT
409409
tar -czf ./amazon-ecs-init_${VERSION}.orig.tar.gz ecs-init scripts README.md
410410
cp -r packaging/generic-deb-integrated/debian Makefile ecs-init scripts misc agent agent-container amazon-ecs-cni-plugins amazon-vpc-cni-plugins README.md VERSION GO_VERSION BUILDROOT
411411
cd BUILDROOT && dpkg-buildpackage -uc -b
@@ -459,16 +459,17 @@ generic-rpm: .generic-rpm-done
459459
deb: .deb-done
460460

461461
clean:
462-
rm -f misc/certs/host-certs.crt &> /dev/null
463-
rm -rf misc/pause-container/image/
464-
rm -rf misc/pause-container/rootfs/
465-
rm -rf misc/plugins/
466-
rm -rf out/
467-
rm -rf rootfs/
462+
-rm -f misc/certs/host-certs.crt &> /dev/null
463+
-rm -rf misc/pause-container/image/
464+
-rm -rf misc/pause-container/rootfs/
465+
-rm -rf misc/plugins/
466+
-rm -rf out/
467+
-rm -rf rootfs/
468468
-$(MAKE) -C $(ECS_CNI_REPOSITORY_SRC_DIR) clean
469469
-rm -f .get-deps-stamp
470470
-rm -f .builder-image-stamp
471471
-rm -f .out-stamp
472+
-rm -f ecs-agent.spec
472473
-rm -rf $(PWD)/bin
473474
-rm -rf cover.out
474475
-rm -rf coverprofile.out

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ additional details on each available environment variable.
146146
| `ECS_RESERVED_MEMORY` | 32 | Reduction, in MiB, of the memory capacity of the instance that is reported to Amazon ECS. Used by Amazon ECS when placing tasks on container instances. This doesn't reserve memory usage on the instance. | 0 | 0 |
147147
| `ECS_AVAILABLE_LOGGING_DRIVERS` | `["awslogs","fluentd","gelf","json-file","journald","logentries","splunk","syslog"]` | Which logging drivers are available on the container instance. | `["json-file","none"]` | `["json-file","none"]` |
148148
| `ECS_DISABLE_PRIVILEGED` | `true` | Whether launching privileged containers is disabled on the container instance. | `false` | `false` |
149-
| `ECS_SELINUX_CAPABLE` | `true` | Whether SELinux is available on the container instance. | `false` | `false` |
149+
| `ECS_SELINUX_CAPABLE` | `true` | Whether SELinux is available on the container instance. (Limited support; Z-mode mounts only.) | `false` | `false` |
150150
| `ECS_APPARMOR_CAPABLE` | `true` | Whether AppArmor is available on the container instance. | `false` | `false` |
151-
| `ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION` | 10m | Default time to wait to delete containers for a stopped task (see also `ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION_JITTER`). If set to less than 1 minute, the value is ignored. | 3h | 3h |
151+
| `ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION` | 10m | Default time to wait to delete containers for a stopped task (see also `ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION_JITTER`). If set to less than 1 second, the value is ignored. | 3h | 3h |
152152
| `ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION_JITTER` | 1h | Jitter value for the task engine cleanup wait duration. When specified, the actual cleanup wait duration time for each task will be the duration specified in `ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION` plus a random duration between 0 and the jitter duration. | blank | blank |
153153
| `ECS_CONTAINER_STOP_TIMEOUT` | 10m | Instance scoped configuration for time to wait for the container to exit normally before being forcibly killed. | 30s | 30s |
154154
| `ECS_CONTAINER_START_TIMEOUT` | 10m | Timeout before giving up on starting a container. | 3m | 8m |
@@ -204,7 +204,8 @@ additional details on each available environment variable.
204204
| `ECS_ENABLE_GPU_SUPPORT` | `true` | Whether you use container instances with GPU support. This parameter is specified for the agent. You must also configure your task definitions for GPU. For more information | `false` | `Not applicable` |
205205
| `HTTP_PROXY` | `10.0.0.131:3128` | The hostname (or IP address) and port number of an HTTP proxy to use for the Amazon ECS agent to connect to the internet. For example, this proxy will be used if your container instances do not have external network access through an Amazon VPC internet gateway or NAT gateway or instance. If this variable is set, you must also set the NO_PROXY variable to filter Amazon EC2 instance metadata and Docker daemon traffic from the proxy. | `null` | `null` |
206206
| `NO_PROXY` | <For Linux: 169.254.169.254,169.254.170.2,/var/run/docker.sock &#124; For Windows: 169.254.169.254,169.254.170.2,\\.\pipe\docker_engine> | The HTTP traffic that should not be forwarded to the specified HTTP_PROXY. You must specify 169.254.169.254,/var/run/docker.sock to filter Amazon EC2 instance metadata and Docker daemon traffic from the proxy. | `null` | `null` |
207-
207+
| `CREDENTIALS_FETCHER_HOST` | `unix:///var/credentials-fetcher/socket/credentials_fetcher.sock` | Used to create a connection to the [credentials-fetcher daemon](https://github.com/aws/credentials-fetcher); to support gMSA on Linux. The default is fine for most users, only needs to be modified if user is configuring a custom credentials-fetcher socket path, ie, [CF_UNIX_DOMAIN_SOCKET_DIR](https://github.com/aws/credentials-fetcher#default-environment-variables). | `unix:///var/credentials-fetcher/socket/credentials_fetcher.sock` | Not Applicable |
208+
| `CREDENTIALS_FETCHER_SECRET_NAME_FOR_DOMAINLESS_GMSA` | `secretmanager-secretname` | Used to support scaling option for gMSA on Linux [credentials-fetcher daemon](https://github.com/aws/credentials-fetcher). If user is configuring gMSA on a non-domain joined instance, they need to create an Active Directory user with access to retrieve principals for the gMSA account and store it in secrets manager | `secretmanager-secretname` | Not Applicable |
208209
### Persistence
209210

210211
When you run the Amazon ECS Container Agent in production, its `datadir` should be persisted between runs of the Docker

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.65.1
1+
1.67.2

agent/acs/model/api/api-2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@
618618
"type":"structure",
619619
"members":{
620620
"containerPort":{"shape":"Integer"},
621+
"containerPortRange":{"shape":"String"},
621622
"hostPort":{"shape":"Integer"},
622623
"protocol":{"shape":"TransportProtocol"}
623624
}

agent/acs/model/ecsacs/api.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agent/api/container/container.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ package container
1515

1616
import (
1717
"encoding/json"
18+
"errors"
1819
"fmt"
1920
"strconv"
21+
"strings"
2022
"sync"
2123
"time"
2224

@@ -317,6 +319,13 @@ type Container struct {
317319
finishedAt time.Time
318320

319321
labels map[string]string
322+
323+
// ContainerHasPortRange is set to true when the container has at least 1 port range requested.
324+
ContainerHasPortRange bool
325+
// ContainerPortSet is a set of singular container ports that don't belong to a containerPortRange request
326+
ContainerPortSet map[int]struct{}
327+
// ContainerPortRangeMap is a map of containerPortRange to its associated hostPortRange
328+
ContainerPortRangeMap map[string]string
320329
}
321330

322331
type DependsOn struct {
@@ -1325,6 +1334,44 @@ func (c *Container) UpdateManagedAgentSentStatus(agentName string, status apicon
13251334
return false
13261335
}
13271336

1337+
// RequiresCredentialSpec checks if container needs a credentialspec resource
1338+
func (c *Container) RequiresCredentialSpec() bool {
1339+
credSpec, err := c.getCredentialSpec()
1340+
if err != nil || credSpec == "" {
1341+
return false
1342+
}
1343+
1344+
return true
1345+
}
1346+
1347+
// GetCredentialSpec is used to retrieve the current credentialspec resource
1348+
func (c *Container) GetCredentialSpec() (string, error) {
1349+
return c.getCredentialSpec()
1350+
}
1351+
1352+
func (c *Container) getCredentialSpec() (string, error) {
1353+
c.lock.RLock()
1354+
defer c.lock.RUnlock()
1355+
1356+
if c.DockerConfig.HostConfig == nil {
1357+
return "", errors.New("empty container hostConfig")
1358+
}
1359+
1360+
hostConfig := &dockercontainer.HostConfig{}
1361+
err := json.Unmarshal([]byte(*c.DockerConfig.HostConfig), hostConfig)
1362+
if err != nil || len(hostConfig.SecurityOpt) == 0 {
1363+
return "", errors.New("unable to obtain security options from container hostConfig")
1364+
}
1365+
1366+
for _, opt := range hostConfig.SecurityOpt {
1367+
if strings.HasPrefix(opt, "credentialspec") {
1368+
return opt, nil
1369+
}
1370+
}
1371+
1372+
return "", errors.New("unable to obtain credentialspec")
1373+
}
1374+
13281375
func (c *Container) GetManagedAgentStatus(agentName string) apicontainerstatus.ManagedAgentStatus {
13291376
c.lock.RLock()
13301377
defer c.lock.RUnlock()
@@ -1360,3 +1407,39 @@ func (c *Container) IsContainerTornDown() bool {
13601407
defer c.lock.RUnlock()
13611408
return c.ContainerTornDownUnsafe
13621409
}
1410+
1411+
func (c *Container) SetContainerHasPortRange(containerHasPortRange bool) {
1412+
c.lock.Lock()
1413+
defer c.lock.Unlock()
1414+
c.ContainerHasPortRange = containerHasPortRange
1415+
}
1416+
1417+
func (c *Container) HasPortRange() bool {
1418+
c.lock.RLock()
1419+
defer c.lock.RUnlock()
1420+
return c.ContainerHasPortRange
1421+
}
1422+
1423+
func (c *Container) SetContainerPortSet(containerPortSet map[int]struct{}) {
1424+
c.lock.Lock()
1425+
defer c.lock.Unlock()
1426+
c.ContainerPortSet = containerPortSet
1427+
}
1428+
1429+
func (c *Container) GetContainerPortSet() map[int]struct{} {
1430+
c.lock.RLock()
1431+
defer c.lock.RUnlock()
1432+
return c.ContainerPortSet
1433+
}
1434+
1435+
func (c *Container) SetContainerPortRangeMap(portRangeMap map[string]string) {
1436+
c.lock.Lock()
1437+
defer c.lock.Unlock()
1438+
c.ContainerPortRangeMap = portRangeMap
1439+
}
1440+
1441+
func (c *Container) GetContainerPortRangeMap() map[string]string {
1442+
c.lock.RLock()
1443+
defer c.lock.RUnlock()
1444+
return c.ContainerPortRangeMap
1445+
}

agent/api/container/container_test.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,3 +970,113 @@ func TestUpdateManagedAgentSentStatus(t *testing.T) {
970970
})
971971
}
972972
}
973+
974+
func TestRequiresCredentialSpec(t *testing.T) {
975+
testCases := []struct {
976+
name string
977+
container *Container
978+
expectedOutput bool
979+
}{
980+
{
981+
name: "hostconfig_nil",
982+
container: &Container{},
983+
expectedOutput: false,
984+
},
985+
{
986+
name: "invalid_case",
987+
container: getContainer("invalid"),
988+
expectedOutput: false,
989+
},
990+
{
991+
name: "empty_sec_opt",
992+
container: getContainer("{\"NetworkMode\":\"bridge\"}"),
993+
expectedOutput: false,
994+
},
995+
{
996+
name: "missing_credentialspec",
997+
container: getContainer("{\"SecurityOpt\": [\"invalid-sec-opt\"]}"),
998+
expectedOutput: false,
999+
},
1000+
{
1001+
name: "valid_credentialspec_file",
1002+
container: getContainer("{\"SecurityOpt\": [\"credentialspec:file://gmsa_gmsa-acct.json\"]}"),
1003+
expectedOutput: true,
1004+
},
1005+
{
1006+
name: "valid_credentialspec_s3",
1007+
container: getContainer("{\"SecurityOpt\": [\"credentialspec:arn:aws:s3:::${BucketName}/${ObjectName}\"]}"),
1008+
expectedOutput: true,
1009+
},
1010+
{
1011+
name: "valid_credentialspec_ssm",
1012+
container: getContainer("{\"SecurityOpt\": [\"credentialspec:arn:aws:ssm:region:aws_account_id:parameter/parameter_name\"]}"),
1013+
expectedOutput: true,
1014+
},
1015+
}
1016+
1017+
for _, tc := range testCases {
1018+
t.Run(tc.name, func(t *testing.T) {
1019+
assert.Equal(t, tc.expectedOutput, tc.container.RequiresCredentialSpec())
1020+
})
1021+
}
1022+
}
1023+
1024+
func TestGetCredentialSpecErr(t *testing.T) {
1025+
testCases := []struct {
1026+
name string
1027+
container *Container
1028+
expectedOutputString string
1029+
expectedErrorString string
1030+
}{
1031+
{
1032+
name: "hostconfig_nil",
1033+
container: &Container{},
1034+
expectedOutputString: "",
1035+
expectedErrorString: "empty container hostConfig",
1036+
},
1037+
{
1038+
name: "invalid_case",
1039+
container: getContainer("invalid"),
1040+
expectedOutputString: "",
1041+
expectedErrorString: "unable to obtain security options from container hostConfig",
1042+
},
1043+
{
1044+
name: "empty_sec_opt",
1045+
container: getContainer("{\"NetworkMode\":\"bridge\"}"),
1046+
expectedOutputString: "",
1047+
expectedErrorString: "unable to obtain security options from container hostConfig",
1048+
},
1049+
{
1050+
name: "missing_credentialspec",
1051+
container: getContainer("{\"SecurityOpt\": [\"invalid-sec-opt\"]}"),
1052+
expectedOutputString: "",
1053+
expectedErrorString: "unable to obtain credentialspec",
1054+
},
1055+
}
1056+
1057+
for _, tc := range testCases {
1058+
t.Run(tc.name, func(t *testing.T) {
1059+
expectedOutputStr, err := tc.container.GetCredentialSpec()
1060+
assert.Equal(t, tc.expectedOutputString, expectedOutputStr)
1061+
assert.EqualError(t, err, tc.expectedErrorString)
1062+
})
1063+
}
1064+
}
1065+
1066+
func TestGetCredentialSpecHappyPath(t *testing.T) {
1067+
c := getContainer("{\"SecurityOpt\": [\"credentialspec:file://gmsa_gmsa-acct.json\"]}")
1068+
1069+
expectedCredentialSpec := "credentialspec:file://gmsa_gmsa-acct.json"
1070+
1071+
credentialspec, err := c.GetCredentialSpec()
1072+
assert.NoError(t, err)
1073+
assert.EqualValues(t, expectedCredentialSpec, credentialspec)
1074+
}
1075+
1076+
func getContainer(hostConfig string) *Container {
1077+
c := &Container{
1078+
Name: "c",
1079+
}
1080+
c.DockerConfig.HostConfig = &hostConfig
1081+
return c
1082+
}

agent/api/container/container_unix.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,8 @@
1616

1717
package container
1818

19-
import (
20-
"github.com/pkg/errors"
21-
)
22-
2319
const (
2420
// DockerContainerMinimumMemoryInBytes is the minimum amount of
2521
// memory to be allocated to a docker container
2622
DockerContainerMinimumMemoryInBytes = 4 * 1024 * 1024 // 4MB
2723
)
28-
29-
// RequiresCredentialSpec checks if container needs a credentialspec resource
30-
func (c *Container) RequiresCredentialSpec() bool {
31-
return false
32-
}
33-
34-
// GetCredentialSpec is used to retrieve the current credentialspec resource
35-
func (c *Container) GetCredentialSpec() (string, error) {
36-
return "", errors.New("unsupported platform")
37-
}

0 commit comments

Comments
 (0)