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

EC2 Auto Discover with SSM: add invocation url to audit log #41689

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/srv/server/ssm_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,14 @@ func (si *SSMInstaller) getCommandStepStatusEvent(ctx context.Context, step *str
}
}

// Format for invocation url:
// https://<region>.console.aws.amazon.com/systems-manager/run-command/<command-id>/<instance-id>
// Example:
// https://eu-west-2.console.aws.amazon.com/systems-manager/run-command/3cb11aaa-11aa-1111-aaaa-2188108225de/i-0775091aa11111111
invocationURL := fmt.Sprintf("https://%s.console.aws.amazon.com/systems-manager/run-command/%s/%s",
req.Region, aws.StringValue(commandID), aws.StringValue(instanceID),
)

return &apievents.SSMRun{
Metadata: apievents.Metadata{
Type: libevents.SSMRunEvent,
Expand All @@ -355,5 +363,6 @@ func (si *SSMInstaller) getCommandStepStatusEvent(ctx context.Context, step *str
Status: status,
StandardOutput: aws.StringValue(stepResult.StandardOutputContent),
StandardError: aws.StringValue(stepResult.StandardErrorContent),
InvocationURL: invocationURL,
}, nil
}
41 changes: 23 additions & 18 deletions lib/srv/server/ssm_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,13 @@ func TestSSMInstaller(t *testing.T) {
Type: libevent.SSMRunEvent,
Code: libevent.SSMRunSuccessCode,
},
CommandID: "command-id-1",
InstanceID: "instance-id-1",
AccountID: "account-id",
Region: "eu-central-1",
ExitCode: 0,
Status: ssm.CommandStatusSuccess,
CommandID: "command-id-1",
InstanceID: "instance-id-1",
AccountID: "account-id",
Region: "eu-central-1",
ExitCode: 0,
Status: ssm.CommandStatusSuccess,
InvocationURL: "https://eu-central-1.console.aws.amazon.com/systems-manager/run-command/command-id-1/instance-id-1",
},
},
},
Expand Down Expand Up @@ -175,12 +176,13 @@ func TestSSMInstaller(t *testing.T) {
Type: libevent.SSMRunEvent,
Code: libevent.SSMRunSuccessCode,
},
CommandID: "command-id-1",
InstanceID: "instance-id-1",
AccountID: "account-id",
Region: "eu-central-1",
ExitCode: 0,
Status: ssm.CommandStatusSuccess,
CommandID: "command-id-1",
InstanceID: "instance-id-1",
AccountID: "account-id",
Region: "eu-central-1",
ExitCode: 0,
Status: ssm.CommandStatusSuccess,
InvocationURL: "https://eu-central-1.console.aws.amazon.com/systems-manager/run-command/command-id-1/instance-id-1",
},
},
},
Expand Down Expand Up @@ -225,6 +227,7 @@ func TestSSMInstaller(t *testing.T) {
Status: ssm.CommandStatusFailed,
StandardOutput: "",
StandardError: "timeout error",
InvocationURL: "https://eu-central-1.console.aws.amazon.com/systems-manager/run-command/command-id-1/instance-id-1",
},
},
},
Expand Down Expand Up @@ -275,6 +278,7 @@ func TestSSMInstaller(t *testing.T) {
Status: ssm.CommandStatusFailed,
StandardOutput: "",
StandardError: "timeout error",
InvocationURL: "https://eu-central-1.console.aws.amazon.com/systems-manager/run-command/command-id-1/instance-id-1",
},
},
},
Expand Down Expand Up @@ -335,12 +339,13 @@ func TestSSMInstaller(t *testing.T) {
Type: libevent.SSMRunEvent,
Code: libevent.SSMRunSuccessCode,
},
CommandID: "command-id-1",
InstanceID: "instance-id-1",
AccountID: "account-id",
Region: "eu-central-1",
ExitCode: 0,
Status: ssm.CommandStatusSuccess,
CommandID: "command-id-1",
InstanceID: "instance-id-1",
AccountID: "account-id",
Region: "eu-central-1",
ExitCode: 0,
Status: ssm.CommandStatusSuccess,
InvocationURL: "https://eu-central-1.console.aws.amazon.com/systems-manager/run-command/command-id-1/instance-id-1",
},
&events.SSMRun{
Metadata: events.Metadata{
Expand Down
Loading