Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log driver secret to LogConfig and agent capability #1818

Merged
merged 1 commit into from
Feb 18, 2019

Conversation

tommyhahn
Copy link
Contributor

Summary

Add the secret value of Splunk logging driver into the Container's hostconfig section and add the agent capability for secret that supports Splunk

Implementation details

Testing

  • Builds on Linux (make release)
  • Builds on Windows (go build -out amazon-ecs-agent.exe ./agent)
  • Unit tests on Linux (make test) pass
  • Unit tests on Windows (go test -timeout=30s ./agent/...) pass
  • Integration tests on Linux (make run-integ-tests) pass
  • Integration tests on Windows (.\scripts\run-integ-tests.ps1) pass
  • Functional tests on Linux (make run-functional-tests) pass
  • Functional tests on Windows (.\scripts\run-functional-tests.ps1) pass

New tests cover the changes:

Description for the changelog

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@@ -900,6 +903,27 @@ func (task *Task) ApplyExecutionRoleLogsAuth(hostConfig *dockercontainer.HostCon
return nil
}

//ApplyLogDriverSecret will add the generated splunk secret into the associated HostConfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing specific to Splunk here.

container.MergeEnvironmentVariables(envVars)
}

//Check if the "splunk-token" has already been initialized and stored in the LogCofig map
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not include logic specific to Splunk or keys like "splunk-token". If we need logic like this, it should be handled in the ECS backend so we do not need to keep updating the agent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree - this was discussed during design phase, to not cater implementation to one specific log driver.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured out a way. Will discuss and update this pr shortly.

@@ -39,6 +39,8 @@ const (
capabilityPrivateRegistryAuthASM = "private-registry-authentication.secretsmanager"
capabilitySecretEnvSSM = "secrets.ssm.environment-variables"
capabilitySecretEnvASM = "secrets.asm.environment-variables"
capabilitySecretLogDriverSSM = "secrets.ssm.logging-drivers"
capabilitySecretLogDriverASM = "secrets.asm.logging-drivers"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: run go fmt to align this with other variables

@@ -261,6 +266,7 @@ type Secret struct {
ContainerPath string `json:"containerPath"`
Type string `json:"type"`
Provider string `json:"provider"`
Target string `json:"target"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit run go fmt

Copy link
Contributor

@suneyz suneyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, are you planning to follow up with functional tests as separate PR?

@tommyhahn tommyhahn force-pushed the branch_logging_driver branch 5 times, most recently from 0f10ed1 to 0d21068 Compare February 4, 2019 22:30
@tommyhahn tommyhahn force-pushed the branch_logging_driver branch 2 times, most recently from a73b9ea to 5717f08 Compare February 5, 2019 20:47

// MergeLogDrivers appends additional pairs to
// the the container's Logging Drivers structure
func (c *Container) HasSecretAsEvnAndLogDriver() bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it should beHasSecretAsEnvOrLogDriver. either way, just calling it HasSecrets or HasSecretsAvailable might be better. also the comment needs to be changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change it to HasSecretAsEnvOrLogDriver at this time. It is specifically for checking env and log driver secrets.

@@ -807,7 +813,17 @@ func (c *Container) MergeEnvironmentVariables(envVars map[string]string) {
}
}

func (c *Container) HasSecretAsEnv() bool {
//Append the logging driver using secret into the container's LogConfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space after //

// PopulateSecretsAsEnv appends the container's env var map with secrets
func (task *Task) PopulateSecretsAsEnv(container *apicontainer.Container) *apierrors.DockerClientConfigError {
// PopulateSecretsAsEnvAndLogDriver appends the container's env var map with secrets
func (task *Task) PopulateSecretsAsEnvAndLogDriver(hostConfig *dockercontainer.HostConfig, container *apicontainer.Container) *apierrors.DockerClientConfigError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just call it PopulateSecrets so we that don't have to change the name again when new secret type is added?

@@ -63,6 +65,9 @@ const (

// SecretTypeEnv is to show secret type being ENVIRONMENT_VARIABLE
SecretTypeEnv = "ENVIRONMENT_VARIABLE"

// TargetLogDriver is to show secret target being "LOG_DRIVER", the default will be "CONTAINER"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is the default being set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CP will set the target of those env secrets as a default "container" but don't think it will be used somewhere here since they've already had a type field "ENVIRONMENT_VARIABLE"...

@samuelkarp
Copy link
Contributor

Since this code is no longer specific to Splunk, can we remove Splunk from the commit message and the PR title?

@samuelkarp samuelkarp dismissed their stale review February 5, 2019 23:31

Splunk concern addressed

@tommyhahn tommyhahn changed the title Add Splunk secret to LogConfig and agent capability Add log driver secret to LogConfig and agent capability Feb 6, 2019
@tommyhahn tommyhahn force-pushed the branch_logging_driver branch 6 times, most recently from 4f13abe to 357723a Compare February 7, 2019 01:17
@tommyhahn tommyhahn removed the bot/test label Feb 8, 2019
hostConfig.LogConfig.Config[logDriverSecretName] = logDriverSecretValue
}

func (c *Container) HasSecretAsEvnOrLogDriver() bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env

@@ -807,7 +813,15 @@ func (c *Container) MergeEnvironmentVariables(envVars map[string]string) {
}
}

func (c *Container) HasSecretAsEnv() bool {
// Append the logging driver using secret into the container's LogConfig
func (c *Container) ApplyLogDriverSecret(hostConfig *dockercontainer.HostConfig, logDriverSecretName string, logDriverSecretValue string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think this should be a method of container.. the container is not used. i think this can just be a helper function put below its caller

continue
}
if secret.Target == apicontainer.SecretTargetLogDriver {
logDriverTokenName = secret.Name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think currently you assume there's only one log driver secret, but i don't see why you need to have that assumption.. i think you can call ApplyLogDriverSecret here whenever you find a log driver secret?

@@ -138,6 +145,9 @@ func (agent *ecsAgent) capabilities() ([]*ecs.Attribute, error) {
// ecs agent version 1.23.0 supports ecs secrets integrating with aws secrets manager
capabilities = appendNameOnlyAttribute(capabilities, attributePrefix+capabilitySecretEnvASM)

// ecs agent version 1.25.0 supports ecs secrets for logging drivers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably 1.26.0?

@tommyhahn tommyhahn force-pushed the branch_logging_driver branch 4 times, most recently from d0c39fc to 5f10985 Compare February 12, 2019 07:48
@@ -269,6 +272,7 @@ type Secret struct {
ContainerPath string `json:"containerPath"`
Type string `json:"type"`
Provider string `json:"provider"`
Target string `json:"target"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry that i forgot.. i think you need to bump state file version for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@tommyhahn tommyhahn force-pushed the branch_logging_driver branch from ce89c7f to f709e9f Compare February 15, 2019 00:24
@tommyhahn tommyhahn force-pushed the branch_logging_driver branch from f709e9f to 4e818ef Compare February 15, 2019 21:44
@tommyhahn
Copy link
Contributor Author

#1856
Flaky unit test TestStateManager issue

@tommyhahn tommyhahn merged commit e325804 into aws:dev Feb 18, 2019
@tommyhahn tommyhahn deleted the branch_logging_driver branch February 18, 2019 21:33
@tommyhahn tommyhahn restored the branch_logging_driver branch February 18, 2019 22:04
@tommyhahn tommyhahn deleted the branch_logging_driver branch February 21, 2019 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants