Skip to content

Commit

Permalink
fix: prevent running concurrent lambda attacks with the same ssm param
Browse files Browse the repository at this point in the history
  • Loading branch information
ReuDa committed Aug 23, 2024
1 parent a6877e4 commit 7a1ed10
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## v2.3.2 (next release)

- Update docs and parameters for Lamba Attacks to use https:/steadybit/failure-lambda
- Prevent concurrent executions of Lambda Attacks with the same Failure-SSM-Parameter

## v2.3.1

Expand Down
14 changes: 9 additions & 5 deletions extlambda/attack.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ type FailureInjectionConfig struct {
}

type LambdaActionState struct {
Account string `json:"account"`
Param string `json:"param"`
Config *FailureInjectionConfig `json:"config"`
Account string `json:"account"`
Param string `json:"param"`
Config *FailureInjectionConfig `json:"config"`
ExperimentKey *string `json:"experimentKey"`
ExecutionId *int `json:"executionId"`
}

func (a *lambdaAction) Describe() action_kit_api.ActionDescription {
Expand All @@ -73,6 +75,8 @@ func (a *lambdaAction) Prepare(_ context.Context, state *LambdaActionState, requ

state.Account = extutil.MustHaveValue(request.Target.Attributes, "aws.account")[0]
state.Param = failureInjectionParam[0]
state.ExperimentKey = request.ExecutionContext.ExperimentKey
state.ExecutionId = request.ExecutionContext.ExecutionId
state.Config = config
return nil, nil
}
Expand All @@ -93,8 +97,8 @@ func (a *lambdaAction) Start(ctx context.Context, state *LambdaActionState) (*ac
Value: extutil.Ptr(string(value)),
Type: types.ParameterTypeString,
DataType: extutil.Ptr("text"),
Description: extutil.Ptr("lambda failure injection config - set by steadybit"),
Overwrite: extutil.Ptr(true),
Description: extutil.Ptr(fmt.Sprintf("lambda failure injection config - set by steadybit experiment %s / execution %d", *state.ExperimentKey, *state.ExecutionId)),
Overwrite: extutil.Ptr(false),
})
if err != nil {
return nil, extension_kit.ToError("Failed to put ssm parameter", err)
Expand Down
10 changes: 8 additions & 2 deletions extlambda/attack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func TestLambdaAction_Prepare(t *testing.T) {
Target: &action_kit_api.Target{
Attributes: tt.attributes,
},
ExecutionContext: &action_kit_api.ExecutionContext{
ExperimentKey: extutil.Ptr("TEST-1"),
ExecutionId: extutil.Ptr(42),
},
})

//When
Expand All @@ -83,8 +87,8 @@ func TestLambdaAction_Start(t *testing.T) {
Value: extutil.Ptr("{\"failureMode\":\"test\",\"rate\":0.5,\"isEnabled\":true}"),
Type: types.ParameterTypeString,
DataType: extutil.Ptr("text"),
Description: extutil.Ptr("lambda failure injection config - set by steadybit"),
Overwrite: extutil.Ptr(true),
Description: extutil.Ptr("lambda failure injection config - set by steadybit experiment TEST-1 / execution 42"),
Overwrite: extutil.Ptr(false),
}, mock.Anything).Return(&ssm.PutParameterOutput{}, nil)
api.On("AddTagsToResource", mock.Anything, &ssm.AddTagsToResourceInput{
ResourceId: extutil.Ptr("PARAM"),
Expand All @@ -100,6 +104,8 @@ func TestLambdaAction_Start(t *testing.T) {
state := action.NewEmptyState()
state.Account = "123456789012"
state.Param = "PARAM"
state.ExperimentKey = extutil.Ptr("TEST-1")
state.ExecutionId = extutil.Ptr(42)
state.Config = &FailureInjectionConfig{
IsEnabled: true,
FailureMode: "test",
Expand Down

0 comments on commit 7a1ed10

Please sign in to comment.