-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from koooosh/patch-ssm-agent
amazon-ssm-agent: Add dynamically-linked agent binaries
- Loading branch information
Showing
5 changed files
with
255 additions
and
7 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
packages/amazon-ssm-agent/0001-agent-Add-config-to-make-shell-optional.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
From c835d2ddc855439173a8a59828c335d169c03d15 Mon Sep 17 00:00:00 2001 | ||
From: Kush Upadhyay <[email protected]> | ||
Date: Tue, 2 Jul 2024 20:54:29 +0000 | ||
Subject: [PATCH] agent: Add config to make shell optional | ||
|
||
Signed-off-by: Kush Upadhyay <[email protected]> | ||
--- | ||
agent/appconfig/appconfig.go | 1 + | ||
agent/appconfig/contracts.go | 2 ++ | ||
agent/plugins/runscript/runscript.go | 36 +++++++++++++++++++--------- | ||
3 files changed, 28 insertions(+), 11 deletions(-) | ||
|
||
diff --git a/agent/appconfig/appconfig.go b/agent/appconfig/appconfig.go | ||
index b6abcf1..e214cd5 100644 | ||
--- a/agent/appconfig/appconfig.go | ||
+++ b/agent/appconfig/appconfig.go | ||
@@ -118,6 +118,7 @@ func DefaultConfig() SsmagentConfig { | ||
SessionLogsRetentionDurationHours: DefaultSessionLogsRetentionDurationHours, | ||
PluginLocalOutputCleanup: DefaultPluginOutputRetention, | ||
OrchestrationDirectoryCleanup: DefaultOrchestrationDirCleanup, | ||
+ UseShell: false, | ||
} | ||
var agent = AgentInfo{ | ||
Name: "amazon-ssm-agent", | ||
diff --git a/agent/appconfig/contracts.go b/agent/appconfig/contracts.go | ||
index 1337398..0a66441 100644 | ||
--- a/agent/appconfig/contracts.go | ||
+++ b/agent/appconfig/contracts.go | ||
@@ -50,6 +50,8 @@ type SsmCfg struct { | ||
PluginLocalOutputCleanup string | ||
// Configure only when it is safe to delete orchestration folder after document execution. This config overrides PluginLocalOutputCleanup when set. | ||
OrchestrationDirectoryCleanup string | ||
+ // Flag for shell dependency | ||
+ UseShell bool | ||
} | ||
|
||
// AgentInfo represents metadata for amazon-ssm-agent | ||
diff --git a/agent/plugins/runscript/runscript.go b/agent/plugins/runscript/runscript.go | ||
index 48be5e7..d8cbcf1 100644 | ||
--- a/agent/plugins/runscript/runscript.go | ||
+++ b/agent/plugins/runscript/runscript.go | ||
@@ -174,23 +174,37 @@ func (p *Plugin) runCommands(pluginID string, pluginInput RunScriptPluginInput, | ||
return | ||
} | ||
|
||
- // Create script file path | ||
- scriptPath := filepath.Join(orchestrationDir, p.ScriptName) | ||
- log.Debugf("Writing commands %v to file %v", pluginInput, scriptPath) | ||
+ appConfig := p.Context.AppConfig() | ||
|
||
- // Create script file | ||
- if err = pluginutil.CreateScriptFile(log, scriptPath, pluginInput.RunCommand, p.ByteOrderMark); err != nil { | ||
- output.MarkAsFailed(fmt.Errorf("failed to create script file. %v", err)) | ||
- return | ||
+ var commandName string | ||
+ var commandArguments []string | ||
+ | ||
+ if appConfig.Ssm.UseShell { | ||
+ | ||
+ // Create script file path | ||
+ scriptPath := filepath.Join(orchestrationDir, p.ScriptName) | ||
+ log.Debugf("Writing commands %v to file %v", pluginInput, scriptPath) | ||
+ | ||
+ // Create script file | ||
+ if err = pluginutil.CreateScriptFile(log, scriptPath, pluginInput.RunCommand, p.ByteOrderMark); err != nil { | ||
+ output.MarkAsFailed(fmt.Errorf("failed to create script file. %v", err)) | ||
+ return | ||
+ } | ||
+ | ||
+ // Construct Command Name and Arguments | ||
+ commandName = p.ShellCommand | ||
+ commandArguments = append(p.ShellArguments, scriptPath) | ||
+ } else { | ||
+ | ||
+ // Take only the first element of RunCommand since we prefer single-line commands | ||
+ commandInput := strings.Split(pluginInput.RunCommand[0], " ") | ||
+ commandName = commandInput[0] | ||
+ commandArguments = append(commandInput[1:]) | ||
} | ||
|
||
// Set execution time | ||
executionTimeout := pluginutil.ValidateExecutionTimeout(log, pluginInput.TimeoutSeconds) | ||
|
||
- // Construct Command Name and Arguments | ||
- commandName := p.ShellCommand | ||
- commandArguments := append(p.ShellArguments, scriptPath) | ||
- | ||
// Execute Command | ||
exitCode, err := p.CommandExecuter.NewExecute(p.Context, workingDir, output.GetStdoutWriter(), output.GetStderrWriter(), cancelFlag, executionTimeout, commandName, commandArguments, pluginInput.Environment) | ||
|
||
-- | ||
2.40.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"Profile":{ | ||
"ShareCreds" : true, | ||
"ShareProfile" : "", | ||
"ForceUpdateCreds" : false, | ||
"KeyAutoRotateDays": 0 | ||
}, | ||
"Mds": { | ||
"CommandWorkersLimit" : 5, | ||
"StopTimeoutMillis" : 20000, | ||
"Endpoint": "", | ||
"CommandRetryLimit": 15 | ||
}, | ||
"Ssm": { | ||
"Endpoint": "", | ||
"HealthFrequencyMinutes": 5, | ||
"CustomInventoryDefaultLocation" : "", | ||
"AssociationLogsRetentionDurationHours" : 24, | ||
"RunCommandLogsRetentionDurationHours" : 336, | ||
"SessionLogsRetentionDurationHours" : 336, | ||
"PluginLocalOutputCleanup": "", | ||
"OrchestrationDirectoryCleanup": "", | ||
"UseShell": false | ||
}, | ||
"Mgs": { | ||
"Region": "", | ||
"Endpoint": "", | ||
"StopTimeoutMillis" : 20000, | ||
"SessionWorkersLimit" : 1000, | ||
"DeniedPortForwardingRemoteIPs" : [ | ||
"169.254.169.254", | ||
"fd00:ec2::254", | ||
"169.254.169.253", | ||
"fd00:ec2::253", | ||
"169.254.169.123", | ||
"169.254.169.250" | ||
] | ||
}, | ||
"Agent": { | ||
"Region": "", | ||
"OrchestrationRootDir": "", | ||
"SelfUpdate": false, | ||
"TelemetryMetricsToCloudWatch": false, | ||
"TelemetryMetricsToSSM": true, | ||
"AuditExpirationDay" : 7, | ||
"LongRunningWorkerMonitorIntervalSeconds": 60 | ||
}, | ||
"Os": { | ||
"Lang": "en-US", | ||
"Name": "", | ||
"Version": "1" | ||
}, | ||
"S3": { | ||
"Endpoint": "", | ||
"Region": "", | ||
"LogBucket":"", | ||
"LogKey":"" | ||
}, | ||
"Kms": { | ||
"Endpoint": "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[Unit] | ||
Description=Amazon SSM agent | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=/usr/bin/amazon-ssm-agent | ||
KillMode=process | ||
|
||
# Restart the agent regardless of whether it crashes (and returns a non-zero result code) or if | ||
# is terminated normally (e.g. via 'kill -HUP'). Delay restart so that the agent is less likely | ||
# to restart during a reboot initiated by a script. If the agent exits with status 194 (reboot | ||
# requested), don't restart at all. | ||
Restart=always | ||
RestartPreventExitStatus=194 | ||
RestartSec=5 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters