Skip to content

Commit 92f2f2f

Browse files
committed
add configurable default profile
1 parent f4ca59d commit 92f2f2f

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ additional details on each available environment variable.
184184
| `ECS_EXCLUDE_UNTRACKED_IMAGE` | `alpine:latest` | Comma seperated list of `imageName:tag` of images that should not be deleted by the ECS agent if `ECS_ENABLE_UNTRACKED_IMAGE_CLEANUP` is enabled. | | |
185185
| `ECS_DISABLE_DOCKER_HEALTH_CHECK` | `false` | Whether to disable the Docker Container health check for the ECS Agent. | `false` | `false` |
186186
| `ECS_NVIDIA_RUNTIME` | nvidia | The Nvidia Runtime to be used to pass Nvidia GPU devices to containers. | nvidia | Not Applicable |
187+
| `ECS_EXTERNAL_CREDENTIAL_PROFILE` | default | An alternate external credential role/profile name. | default | default |
187188
| `ECS_ENABLE_SPOT_INSTANCE_DRAINING` | `true` | Whether to enable Spot Instance draining for the container instance. If true, if the container instance receives a [spot interruption notice](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-interruptions.html), agent will set the instance's status to [DRAINING](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-instance-draining.html), which gracefully shuts down and replaces all tasks running on the instance that are part of a service. It is recommended that this be set to `true` when using spot instances. | `false` | `false` |
188189
| `ECS_LOG_ROLLOVER_TYPE` | `size` | `hourly` | Determines whether the container agent logfile will be rotated based on size or hourly. By default, the agent logfile is rotated each hour. | `hourly` | `hourly` |
189190
| `ECS_LOG_OUTPUT_FORMAT` | `logfmt` | `json` | Determines the log output format. When the json format is used, each line in the log would be a structured JSON map. | `logfmt` | `logfmt` |

agent/credentials/providers/rotating_shared_credentials_provider.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ package providers
1515

1616
import (
1717
"fmt"
18+
"os"
1819
"time"
1920

2021
"github.com/aws/aws-sdk-go/aws/credentials"
2122
"github.com/cihub/seelog"
2223
)
2324

2425
const (
26+
EXTERNAL_CREDENTIAL_PROFILE_ENV_VAR = "ECS_EXTERNAL_CREDENTIAL_PROFILE"
27+
DEFAULT_CREDENTIAL_PROFILE = "default"
2528
// defaultRotationInterval is how frequently to expire and re-retrieve the credentials from file.
2629
defaultRotationInterval = time.Minute
2730
// RotatingSharedCredentialsProviderName is the name of this provider
@@ -41,11 +44,16 @@ type RotatingSharedCredentialsProvider struct {
4144
// NewRotatingSharedCredentials returns a rotating shared credentials provider
4245
// with default values set.
4346
func NewRotatingSharedCredentialsProvider() *RotatingSharedCredentialsProvider {
47+
var credentialProfile = DEFAULT_CREDENTIAL_PROFILE
48+
if externalCredentialProfile := os.Getenv("ECS_EXTERNAL_CREDENTIAL_PROFILE"); externalCredentialProfile != "" {
49+
credentialProfile = externalCredentialProfile
50+
}
51+
4452
return &RotatingSharedCredentialsProvider{
4553
RotationInterval: defaultRotationInterval,
4654
sharedCredentialsProvider: &credentials.SharedCredentialsProvider{
4755
Filename: defaultRotatingCredentialsFilename,
48-
Profile: "default",
56+
Profile: credentialProfile,
4957
},
5058
}
5159
}

agent/credentials/providers/rotating_shared_credentials_provider_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ func TestNewRotatingSharedCredentialsProvider(t *testing.T) {
3333
require.Equal(t, defaultRotatingCredentialsFilename, p.sharedCredentialsProvider.Filename)
3434
}
3535

36+
func TestNewRotatingSharedCredentialsProviderExternal(t *testing.T) {
37+
os.Setenv("ECS_EXTERNAL_CREDENTIAL_PROFILE", "external")
38+
defer os.Unsetenv("ECS_EXTERNAL_CREDENTIAL_PROFILE")
39+
p := NewRotatingSharedCredentialsProvider()
40+
require.Equal(t, time.Minute, p.RotationInterval)
41+
require.Equal(t, "external", p.sharedCredentialsProvider.Profile)
42+
require.Equal(t, defaultRotatingCredentialsFilename, p.sharedCredentialsProvider.Filename)
43+
}
44+
3645
func TestRotatingSharedCredentialsProvider_RetrieveFail_BadPath(t *testing.T) {
3746
p := NewRotatingSharedCredentialsProvider()
3847
p.sharedCredentialsProvider.Filename = "/foo/bar/baz/bad/path"

0 commit comments

Comments
 (0)