Skip to content

Commit cc141d7

Browse files
author
Ben Blackmore
committed
docs: attack list how-to
1 parent cabd60d commit cc141d7

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

docs/how-to/write-an-attack-extension.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,38 @@ Actions only need to define prepare and start endpoints. The status and stop end
5454
### Prepare
5555
In addition to what the action API docs mention, attacks will typically want to prepare the attack execution even further by generating IDs, creating entities in target systems and more. That was pretty abstract. Let us look into examples!
5656

57-
https://github.com/steadybit/extension-aws/blob/c3b268b28291024a8e4bed67fe765533367118d5/extec2/instance_attack_state.go#L94-L107
57+
```go
58+
// Source: https://github.com/steadybit/extension-aws/blob/c3b268b28291024a8e4bed67fe765533367118d5/extec2/instance_attack_state.go#L94-L107
59+
instanceId := request.Target.Attributes["aws-ec2.instance.id"]
60+
if instanceId == nil || len(instanceId) == 0 {
61+
return nil, extutil.Ptr(extension_kit.ToError("Target is missing the 'aws-ec2.instance.id' tag.", nil))
62+
}
63+
64+
action := request.Config["action"]
65+
if action == nil {
66+
return nil, extutil.Ptr(extension_kit.ToError("Missing attack action parameter.", nil))
67+
}
68+
69+
return extutil.Ptr(InstanceStateChangeState{
70+
InstanceId: instanceId[0],
71+
Action: action.(string),
72+
}), nil
73+
```
5874

5975
The most fundamental preparation activity is the extraction of attack parameters and target attributes into the action state. This extraction is necessary because start, status and stop only receive the action state. It also helps to keep the other endpoints' implementations more straightforward. Within the excerpt above from the AWS EC2 instance state change attack, we extract the `aws-ec2.instance.id` target attribute and the `action` parameter for later use.
6076

61-
https://github.com/steadybit/extension-kong/blob/2c2dfbbd98b69c12e033356ae10c95fc38c573e4/services/request_termination_attack.go#L172-L181
62-
63-
Some attacks go even further, as the excerpt above shows. The Kong request termination attack already inserts a piece of configuration into the attacked system. However, note that the configuration is marked as disabled. The attack will only switch the configuration from disabled to enabled within the start endpoint. Such patterns can be applied where possible for comprehensive preparation incorporating, among others, a validation that system modification is possible, i.e., that the attack extension is allowed to modify the system state.
77+
```go
78+
// Source: https://github.com/steadybit/extension-kong/blob/2c2dfbbd98b69c12e033356ae10c95fc38c573e4/services/request_termination_attack.go#L172-L181
79+
plugin, err := instance.CreatePlugin(&kong.Plugin{
80+
Name: utils.String("request-termination"),
81+
Enabled: utils.Bool(false),
82+
Tags: utils.Strings([]string{
83+
"created-by=steadybit",
84+
}),
85+
Service: service,
86+
Consumer: consumer,
87+
Config: config,
88+
})
89+
```
90+
91+
Some attacks go even further, as the excerpt above shows. The Kong request termination attack already inserts a piece of configuration into the attacked system. However, note that the configuration is marked as *disabled*. The attack will only switch the configuration from disabled to enabled within the start endpoint. Such patterns can be applied where possible for comprehensive preparation incorporating, among others, a validation that system modification is possible, i.e., that the attack extension is allowed to modify the system state.

0 commit comments

Comments
 (0)