Skip to content

Commit 548a8ad

Browse files
committed
Merge pull request aws#198 from adnxn/mount-cert-path
2 parents 9a4435c + f0e6f28 commit 548a8ad

File tree

7 files changed

+48
-8
lines changed

7 files changed

+48
-8
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: go
22
sudo: false
33
go:
4-
- 1.7
4+
- 1.9
55
before_install: ./scripts/hack/symlink-gopath-travisci
66
install:
77
- go get golang.org/x/tools/cover

ecs-init/config/common.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,11 @@ func DockerUnixSocket() (string, bool) {
147147
func CgroupMountpoint() string {
148148
return cgroupMountpoint
149149
}
150+
151+
// HostCertsDirPath() returns the CA store path on the host
152+
func HostCertsDirPath() string {
153+
if _, err := os.Stat(hostCertsDirPath); err != nil {
154+
return ""
155+
}
156+
return hostCertsDirPath
157+
}

ecs-init/config/config_al2.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@
1515

1616
package config
1717

18-
const cgroupMountpoint = "/sys/fs/cgroup"
18+
const (
19+
cgroupMountpoint = "/sys/fs/cgroup"
20+
hostCertsDirPath = "/etc/pki/tls/certs"
21+
)

ecs-init/config/config_suse_ubuntu.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@
1515

1616
package config
1717

18-
const cgroupMountpoint = "/sys/fs/cgroup"
18+
const (
19+
cgroupMountpoint = "/sys/fs/cgroup"
20+
hostCertsDirPath = ""
21+
)

ecs-init/config/config_unspecified.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@
1515

1616
package config
1717

18-
const cgroupMountpoint = "/cgroup"
18+
const (
19+
cgroupMountpoint = "/cgroup"
20+
hostCertsDirPath = "/etc/pki/tls/certs"
21+
)

ecs-init/docker/docker.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ func (c *Client) getContainerConfig() *godocker.Config {
220220
"ECS_ENABLE_TASK_IAM_ROLE_NETWORK_HOST": "true",
221221
}
222222

223+
// for al, al2 add host ssl cert directory envvar if available
224+
if certDir := config.HostCertsDirPath(); certDir != "" {
225+
envVariables["SSL_CERT_DIR"] = certDir
226+
}
227+
223228
// merge in platform-specific environment variables
224229
for envKey, envValue := range getPlatformSpecificEnvVariables() {
225230
envVariables[envKey] = envValue
@@ -276,6 +281,13 @@ func (c *Client) getHostConfig() *godocker.HostConfig {
276281
config.CacheDirectory() + ":" + config.CacheDirectory(),
277282
config.CgroupMountpoint() + ":" + DefaultCgroupMountpoint,
278283
}
284+
285+
// for al, al2 add host ssl cert directory mounts
286+
if certDir := config.HostCertsDirPath(); certDir != "" {
287+
certsPath := certDir + ":" + certDir + readOnly
288+
binds = append(binds, certsPath)
289+
}
290+
279291
binds = append(binds, getDockerPluginDirBinds()...)
280292
return createHostConfig(binds)
281293
}

ecs-init/docker/docker_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ import (
2222
"github.com/golang/mock/gomock"
2323
)
2424

25+
// expectedAgentBinds is the total number of agent host config binds.
26+
// Note: Change this value every time when a new bind mount is added to
27+
// agent for the tests to pass
2528
const (
26-
// expectedAgentBinds is the total number of agent host config binds.
27-
// Note: Change this value every time when a new bind mount is added to agent for
28-
// the tests to pass
29-
expectedAgentBinds = 13
29+
expectedAgentBindsUnspecifiedPlatform = 14
30+
expectedAgentBindsSuseUbuntuPlatform = 13
3031
)
3132

33+
var expectedAgentBinds = expectedAgentBindsUnspecifiedPlatform
34+
3235
func TestIsAgentImageLoadedListFailure(t *testing.T) {
3336
mockCtrl := gomock.NewController(t)
3437
defer mockCtrl.Finish()
@@ -244,6 +247,14 @@ func validateCommonCreateContainerOptions(opts godocker.CreateContainerOptions,
244247

245248
hostCfg := opts.HostConfig
246249

250+
// for hosts that do not have cert directories explicity mounted, ignore
251+
// host cert directory configuration.
252+
// TODO (adnxn): ideally, these should be behind build flags.
253+
// https://github.com/aws/amazon-ecs-init/issues/131
254+
if certDir := config.HostCertsDirPath(); certDir == "" {
255+
expectedAgentBinds = expectedAgentBindsSuseUbuntuPlatform
256+
}
257+
247258
if len(hostCfg.Binds) != expectedAgentBinds {
248259
t.Errorf("Expected exactly %d elements to be in Binds, but was %d", expectedAgentBinds, len(hostCfg.Binds))
249260
}

0 commit comments

Comments
 (0)