Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into centos
Browse files Browse the repository at this point in the history
  • Loading branch information
psiniemi committed Mar 12, 2021
2 parents 63cb24b + 71bc304 commit 9e001ec
Show file tree
Hide file tree
Showing 97 changed files with 13,586 additions and 2,259 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: go
go_import_path: github.com/aws/amazon-ecs-init
sudo: false
go:
- 1.12
- 1.15

matrix:
include:
Expand Down
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# Changelog

## 1.50.2-1
* Cache Agent version 1.50.2

## 1.50.1-1
* Cache Agent version 1.50.1
* Does not restart ECS Agent when it exits with exit code 5

## 1.50.0-1
* Cache Agent version 1.50.0
* Allows ECS customers to execute interactive commands inside containers.

## 1.49.0-1
* Cache Agent version 1.49.0
* Removes iptable rule that drops packets to port 51678 unconditionally on ecs service stop

## 1.48.1-1
* Cache Agent version 1.48.1

## 1.48.0-2
* Cache Agent version 1.48.0

## 1.47.0-1
* Cache Agent version 1.47.0

## 1.46.0-1
* Cache Agent version 1.46.0

## 1.45.0-1
* Cache Agent version 1.45.0
* Block offhost access to agent's introspection port by default. Configurable via env ECS\_ALLOW\_OFFHOST\_INTROSPECTION\_ACCESS

## 1.44.4-1
* Cache Agent version 1.44.4

Expand Down
19 changes: 18 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ dev:
generate:
PATH=$(PATH):$(shell pwd)/scripts go generate -v ./...

PLATFORM:=$(shell uname -s)
ifeq (${PLATFORM},Linux)
dep_arch=linux-386
else ifeq (${PLATFORM},Darwin)
dep_arch=darwin-386
endif

DEP_VERSION=v0.5.0
.PHONY: get-dep
get-dep: bin/dep

bin/dep:
mkdir -p ./bin
curl -L https://github.com/golang/dep/releases/download/$(DEP_VERSION)/dep-${dep_arch} -o ./bin/dep
chmod +x ./bin/dep

static:
./scripts/gobuild.sh

Expand Down Expand Up @@ -111,7 +127,7 @@ ubuntu-trusty:
get-deps:
go get golang.org/x/tools/cover
go get golang.org/x/tools/cmd/cover
go get github.com/fzipp/gocyclo
go get github.com/fzipp/gocyclo/cmd/gocyclo
go get golang.org/x/tools/cmd/goimports
go get github.com/golang/mock/mockgen
go get honnef.co/go/tools/cmd/staticcheck
Expand All @@ -123,6 +139,7 @@ clean:
-rm -f amazon-ecs-volume-plugin.conf
-rm -f amazon-ecs-volume-plugin.service
-rm -f amazon-ecs-volume-plugin.socket
-rm -rf ./bin
-rm -f ./sources.tgz
-rm -f ./amazon-ecs-init
-rm -f ./ecs-agent-*.tar
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ Additionally, the following environment variable(s) can be used to configure the
| Environment Variable Name | Example Value(s) | Description | Default value |
|:----------------|:----------------------------|:------------|:-----------------------|
| `ECS_SKIP_LOCALHOST_TRAFFIC_FILTER` | <true | false> | By default, the ecs-init service adds an iptable rule to drop non-local packets to localhost if they're not part of an existing forwarded connection or DNAT, and removes the rule upon stop. If `ECS_SKIP_LOCALHOST_TRAFFIC_FILTER` is set to true, this rule will not be added/removed. | false |
| `ECS_ALLOW_OFFHOST_INTROSPECTION_ACCESS` | <true | false> | By default, the ecs-init service adds an iptable rule to block access to ECS Agent's introspection port from off-host (or containers in awsvpc network mode), and removes the rule upon stop. If `ECS_ALLOW_OFFHOST_INTROSPECTION_ACCESS` is set to true, this rule will not be added/removed. | false |

The above environment variable(s) can be used in the following way
- On Amazon Linux 1, the flag `ECS_SKIP_LOCALHOST_TRAFFIC_FILTER` can be turned on by adding `env ECS_SKIP_LOCALHOST_TRAFFIC_FILTER=true` to /etc/init/ecs.conf.
- On Amazon Linux 2, the flag `ECS_SKIP_LOCALHOST_TRAFFIC_FILTER` can be turned on by adding `ECS_SKIP_LOCALHOST_TRAFFIC_FILTER=true` to /etc/ecs/ecs.config.

## Usage
The upstart script installed by the Amazon Elastic Container Service RPM can be started or stopped with the following commands respectively:
Expand Down
2 changes: 1 addition & 1 deletion ecs-init/ECSVERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.44.4
1.50.2
15 changes: 10 additions & 5 deletions ecs-init/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ecs-init/Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

[[constraint]]
name = "github.com/aws/aws-sdk-go"
version = "1.27.0"
version = "v1.36.0"

[prune]
go-tests = true
Expand Down
2 changes: 1 addition & 1 deletion ecs-init/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (
// DefaultAgentVersion is the version of the agent that will be
// fetched if required. This should look like v1.2.3 or an
// 8-character sha, as is downloadable from S3.
DefaultAgentVersion = "v1.44.4"
DefaultAgentVersion = "v1.50.2"

// AgentPartitionBucketName is the name of the paritional s3 bucket that stores the agent
AgentPartitionBucketName = "amazon-ecs-agent"
Expand Down
60 changes: 59 additions & 1 deletion ecs-init/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"bytes"
"encoding/json"
"io"
"os"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -106,6 +107,16 @@ const (
iptablesUsrLibDir = "/usr/lib"
iptablesLib64Dir = "/lib64"
iptablesUsrLib64Dir = "/usr/lib64"

hostResourcesRootDir = "/var/lib/ecs/deps"
containerResourcesRootDir = "/managed-agents"

execCapabilityName = "execute-command"
execBinRelativePath = "bin"
execConfigRelativePath = "config"
execCertsRelativePath = "certs"

execAgentLogRelativePath = "/exec"
)

var pluginDirs = []string{
Expand All @@ -114,6 +125,8 @@ var pluginDirs = []string{
pluginSpecFilesUsrDir,
}

var isPathValid = defaultIsPathValid

// Client enables business logic for running the Agent inside Docker
type Client struct {
docker dockerclient
Expand Down Expand Up @@ -256,7 +269,7 @@ func (c *Client) getContainerConfig(envVarsFromFiles map[string]string) *godocke
"ECS_AGENT_CONFIG_FILE_PATH": config.AgentJSONConfigFile(),
"ECS_UPDATE_DOWNLOAD_DIR": config.CacheDirectory(),
"ECS_UPDATES_ENABLED": "true",
"ECS_AVAILABLE_LOGGING_DRIVERS": `["json-file","syslog","awslogs","none"]`,
"ECS_AVAILABLE_LOGGING_DRIVERS": `["json-file","syslog","awslogs","fluentd","none"]`,
"ECS_ENABLE_TASK_IAM_ROLE": "true",
"ECS_ENABLE_TASK_IAM_ROLE_NETWORK_HOST": "true",
"ECS_AGENT_LABELS": "",
Expand Down Expand Up @@ -375,6 +388,7 @@ func (c *Client) getHostConfig(envVarsFromFiles map[string]string) *godocker.Hos
config.CgroupMountpoint() + ":" + DefaultCgroupMountpoint,
// bind mount instance config dir
config.InstanceConfigDirectory() + ":" + config.InstanceConfigDirectory(),
filepath.Join(config.LogDirectory(), execAgentLogRelativePath) + ":" + filepath.Join(logDir, execAgentLogRelativePath),
}

// for al, al2 add host ssl cert directory mounts
Expand All @@ -393,6 +407,10 @@ func (c *Client) getHostConfig(envVarsFromFiles map[string]string) *godocker.Hos
}

binds = append(binds, getDockerPluginDirBinds()...)

// only add bind mounts when the src file/directory exists on host; otherwise docker API create an empty directory on host
binds = append(binds, getCapabilityExecBinds()...)

return createHostConfig(binds)
}

Expand Down Expand Up @@ -427,6 +445,46 @@ func getDockerPluginDirBinds() []string {
return pluginBinds
}

func getCapabilityExecBinds() []string {
hostResourcesDir := filepath.Join(hostResourcesRootDir, execCapabilityName)
containerResourcesDir := filepath.Join(containerResourcesRootDir, execCapabilityName)

var binds []string

// bind mount the entire /host/dependency/path/execute-command/bin folder
hostBinDir := filepath.Join(hostResourcesDir, execBinRelativePath)
if isPathValid(hostBinDir, true) {
binds = append(binds,
hostBinDir+":"+filepath.Join(containerResourcesDir, execBinRelativePath)+readOnly)
}

// bind mount the entire /host/dependency/path/execute-command/config folder
// in read-write mode to allow ecs-agent to write config files to host file system
// (docker will) create the config folder if it does not exist
hostConfigDir := filepath.Join(hostResourcesDir, execConfigRelativePath)
binds = append(binds,
hostConfigDir+":"+filepath.Join(containerResourcesDir, execConfigRelativePath))

// bind mount the entire /host/dependency/path/execute-command/certs folder
hostCertsDir := filepath.Join(hostResourcesDir, execCertsRelativePath)
if isPathValid(hostCertsDir, true) {
binds = append(binds,
hostCertsDir+":"+filepath.Join(containerResourcesDir, execCertsRelativePath)+readOnly)
}

return binds
}

func defaultIsPathValid(path string, shouldBeDirectory bool) bool {
fileInfo, err := os.Stat(path)
if err != nil {
return false
}

isDirectory := fileInfo.IsDir()
return (isDirectory && shouldBeDirectory) || (!isDirectory && !shouldBeDirectory)
}

// nvidiaGPUDevicesPresent checks if nvidia GPU devices are present in the instance
func nvidiaGPUDevicesPresent() bool {
matches, err := MatchFilePatternForGPU(gpu.NvidiaGPUDeviceFilePattern)
Expand Down
Loading

0 comments on commit 9e001ec

Please sign in to comment.