Skip to content

Commit 91214fc

Browse files
committed
Merge branch 'main' of https://github.com/openshift/configuration-anomaly-detection into deprecate-x-secret-token
2 parents cce0843 + aa454c9 commit 91214fc

File tree

14 files changed

+129
-59
lines changed

14 files changed

+129
-59
lines changed

.github/dependabot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
version: 2
22
updates:
3+
- package-ecosystem: "gomod"
4+
directories:
5+
- "/"
6+
- "interceptor/"
7+
allow:
8+
- dependency-type: all
9+
schedule:
10+
interval: "daily"
311
- package-ecosystem: "docker"
412
directory: "/build"
513
labels:

OWNERS

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
reviewers:
22
- Makdaam
33
- Nikokolas3270
4-
- Tessg22
5-
- ninabauer
64
- rafael-azevedo
75
- RaphaelBut
86
- bng0y
97
- typeid
108
- tnierman
11-
- sam-nguyen7
129
- zmird-r
10+
- joshbranham
1311
approvers:
1412
- Makdaam
1513
- Nikokolas3270
16-
- Tessg22
17-
- ninabauer
1814
- rafael-azevedo
1915
- RaphaelBut
2016
- bng0y
2117
- typeid
22-
- sam-nguyen7
18+
- tnierman
2319
- zmird-r
20+
- joshbranham
21+
- srep-team-leads
2422
maintainers:
2523
- rafael-azevedo

README.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ To add a new alert investigation:
6969

7070
- run `make bootstrap-investigation` to generate boilerplate code in `pkg/investigations` (This creates the corresponding folder & .go file, and also appends the investigation to the `availableInvestigations` interface in `registry.go`.).
7171
- investigation.Resources contain initialized clients for the clusters aws environment, ocm and more. See [Integrations](#integrations)
72+
- Add test objects or scripts used to recreate the alert symptoms to the `pkg/investigations/$INVESTIGATION_NAME/testing/` directory for future use. Be sure to clearly document the testing procedure under the `Testing` section of the investigation-specific README.md file
7273

7374
### Integrations
7475

7576
> **Note:** When writing an investiation, you can use them right away.
7677
They are initialized for you and passed to the investigation via investigation.Resources.
7778

78-
7979
* [AWS](https://github.com/aws/aws-sdk-go) -- Logging into the cluster, retreiving instance info and AWS CloudTrail events.
8080
- See `pkg/aws`
8181
* [PagerDuty](https://github.com/PagerDuty/go-pagerduty) -- Retrieving alert info, esclating or silencing incidents, and adding notes.
@@ -89,24 +89,28 @@ They are initialized for you and passed to the investigation via investigation.R
8989

9090
## Testing locally
9191

92-
### Pre-requirements
93-
- an existing cluster
94-
- an existing PagerDuty incident for the cluster and alert type that is being tested
95-
96-
To quickly create an incident for a cluster_id, you can run `./test/generate_incident.sh <alertname> <clusterid>`.
97-
Example usage:`./test/generate_incident.sh ClusterHasGoneMissing 2b94brrrrrrrrrrrrrrrrrrhkaj`.
98-
99-
### Running cadctl for an incident ID
100-
1) Export the required ENV variables, see [required ENV variables](#required-env-variables).
101-
2) Create a payload file containing the incident ID
102-
```bash
103-
export INCIDENT_ID=
104-
echo '{"__pd_metadata":{"incident":{"id":"'${INCIDENT_ID}'"}}}' > ./payload
105-
```
106-
3) Run `cadctl` using the payload file
107-
```bash
108-
./bin/cadctl investigate --payload-path payload
109-
```
92+
Requires an existing cluster.
93+
94+
1. Create a test incident and payload file for your cluster
95+
96+
```bash
97+
./test/generate_incident.sh <alertname> <clusterid>
98+
```
99+
100+
2. Export the required env variables from vault
101+
102+
> **Note:** For information on the envs see [required env variables](#required-env-variables).
103+
104+
```
105+
source test/set_stage_env.sh
106+
```
107+
108+
3. `make build`
109+
4. Run `cadctl` with the payload file created by `test/generate_incident.sh`
110+
111+
```bash
112+
./bin/cadctl investigate --payload-path payload
113+
```
110114

111115
### Logging levels
112116

cadctl/cmd/investigate/investigate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func run(cmd *cobra.Command, _ []string) error {
140140

141141
investigationResources := &investigation.Resources{Name: alertInvestigation.Name(), Cluster: cluster, ClusterDeployment: clusterDeployment, AwsClient: customerAwsClient, OcmClient: ocmClient, PdClient: pdClient}
142142

143-
logging.Infof("Starting investigation for %s", alertInvestigation.Name)
143+
logging.Infof("Starting investigation for %s", alertInvestigation.Name())
144144
result, err := alertInvestigation.Run(investigationResources)
145145
updateMetrics(alertInvestigation.Name(), &result)
146146
return err

deploy/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ See [../pkg/pagerduty/](../pkg/pagerduty/) for more details.
2727
##### OCM
2828
[task-cad-checks-secrets-ocm-client.yaml](./task-cad-checks-secrets-ocm-client.yaml) This will hold the ocm creds.
2929

30-
CAD_OCM_CLIENT_* env vars are in internal kv store.
30+
CAD_OCM_CLIENT_* env vars are in internal kv store.
3131

3232
See [../pkg/ocm/](../pkg/ocm/) for more details.
3333

@@ -49,11 +49,11 @@ Install CAD by running the following commands:
4949
```
5050

5151
2. Configure secrets
52-
52+
5353
See section at the bottom of `Tasks Secrets` to configure.
5454

5555
3. Deploy container image
56-
56+
5757
The repo builds the binary to a container using [../Dockerfile](a container file). build it using:
5858

5959
```console
@@ -92,7 +92,7 @@ Install CAD by running the following commands:
9292
Pipeline runs can be started via the following post command:
9393

9494
```console
95-
oc exec -it deploy/el-cad-event-listener -- curl -X POST -H 'X-Secret-Token: samplesecret' --connect-timeout 1 -v --data '{"event": {"data": {"id":"12312"}}}' http://el-cad-event-listener.configuration-anomaly-detection.svc.cluster.local:8080
95+
oc exec -it deploy/el-cad-event-listener -- curl -X POST -H 'X-PagerDuty-Signature: v1=samplesecret' --connect-timeout 1 -v --data '{"event": {"data": {"id":"12312"}}}' http://el-cad-event-listener.configuration-anomaly-detection.svc.cluster.local:8080
9696
```
9797

9898
For more details, see the [Tekton Documentation](https://github.com/tektoncd/triggers/tree/main/examples#invoking-the-triggers-locally).
@@ -110,7 +110,7 @@ The `tkn` tool is pulled from https://github.com/tektoncd/cli.
110110
The result of the last runs can be seen with:
111111

112112
```console
113-
tkn pipelinerun list -n configuration-anomaly-detection
113+
tkn pipelinerun list -n configuration-anomaly-detection
114114
```
115115

116116
See the [Tekton documentation](https://docs.openshift.com/container-platform/4.4/cli_reference/tkn_cli/op-tkn-reference.html) for further commands.

deploy/task-cad-checks-secrets-pd.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ stringData:
1010
CAD_PD_TOKEN: CHANGEME # refers to the generated private access token for token-based authentication
1111
CAD_PD_USERNAME: CHANGEME # refers to the username in case username/pw credentials should be used
1212
CAD_SILENT_POLICY: CHANGEME # refers to the silent policy CAD should use if the incident shall be silent
13-
PD_SIGNATURE: CHANGEME # refers to our custom Secret Token for authenticating against our pipeline
13+
PD_SIGNATURE: CHANGEME # refers to the PagerDuty webhook signature (HMAC+SHA256)

hack/bootstrap-investigation.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,30 @@ ls "${INVESTIGATION_DIR}"
4242
touch "${INVESTIGATION_DIR}/${INVESTIGATION_NAME}.go"
4343
touch "${INVESTIGATION_DIR}/metadata.yaml"
4444
touch "${INVESTIGATION_DIR}/README.md"
45+
mkdir "${INVESTIGATION_DIR}/testing/"
4546

4647
# Create README.md file
4748
cat <<EOF > "${INVESTIGATION_DIR}/README.md"
4849
# ${INVESTIGATION_NAME} Investigation
4950
5051
${INVESTIGATION_DESCRIPTION}
5152
53+
## Testing
54+
55+
Refer to the [testing README](./testing/README.md) for instructions on testing this investigation
56+
57+
EOF
58+
59+
# Create testing/README.md file
60+
cat <<EOF > "${INVESTIGATION_DIR}/testing/README.md"
61+
# Testing ${INVESTIGATION_NAME} Investigation
62+
63+
TODO:
64+
- Add a test script or test objects to this `testing/` directory for future maintainers to use
65+
- Edit this README file and add detailed instructions on how to use the script/objects to recreate the conditions for the investigation. Be sure to include any assumptions or prerequisites about the environment (disable hive syncsetting, etc)
5266
EOF
5367

68+
5469
# Create metadata.yaml file
5570
cat <<EOF > "${INVESTIGATION_DIR}/metadata.yaml"
5671
name: ${INVESTIGATION_NAME}

interceptor/pkg/interceptor/pdinterceptor.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ func (pdi *PagerDutyInterceptor) executeInterceptor(r *http.Request) ([]byte, er
110110

111111
var ireq triggersv1.InterceptorRequest
112112

113-
// logging request
114-
logging.Debug("Unwrapped Request header: %v", extractedRequest.Header)
115113
logging.Debug("Unwrapped Request body: ", originalReq.Body)
116114

117115
token, _ := os.LookupEnv("PD_SIGNATURE")
@@ -159,7 +157,7 @@ func (pdi *PagerDutyInterceptor) Process(ctx context.Context, r *triggersv1.Inte
159157
}
160158
}
161159

162-
logging.Infof("Incident %s is mapped to investigation '%s', returning InterceptorResponse `Continue: true`.", pdClient.GetIncidentID(), investigation.Name)
160+
logging.Infof("Incident %s is mapped to investigation '%s', returning InterceptorResponse `Continue: true`.", pdClient.GetIncidentID(), investigation.Name())
163161
return &triggersv1.InterceptorResponse{
164162
Continue: true,
165163
}

interceptor/test/e2e.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@ function test_interceptor {
2020

2121
local incident_id=$1
2222
local expected_response=$2
23+
local override_signature=$3
2324

2425
# Run the interceptor and print logs to temporary log file
26+
export PD_SIGNATURE="test"
2527
CAD_PD_TOKEN=$(echo $pd_test_token) CAD_SILENT_POLICY=$(echo $pd_test_silence_policy) ./../bin/interceptor > $temp_log_file 2>&1 &
26-
PD_SIGNATURE="test"
2728
PAYLOAD_BODY="{\\\"__pd_metadata\\\":{\\\"incident\\\":{\\\"id\\\":\\\"$incident_id\\\"}}}"
2829
PAYLOAD_BODY_FORMATTED='{"__pd_metadata":{"incident":{"id":"'$incident_id'"}}}'
30+
31+
# Allow for test 3; override the signature after correct one has already been added to env
32+
if [[ "$override_signature" != "" ]]; then
33+
export PD_SIGNATURE=$override_signature
34+
fi
35+
2936
SIGN=$(echo -n "$PAYLOAD_BODY_FORMATTED" | sha256hmac -K $PD_SIGNATURE | tr -d "[:space:]-")
3037

3138
# Store the PID of the interceptor process
@@ -85,4 +92,4 @@ test_interceptor "Q3722KGCG12ZWD" "$EXPECTED_RESPONSE_STOP"
8592
# Test for an alert with invalid signature
8693
echo "Test 3: expected failure due to invalid signature"
8794
PD_SIGNATURE="invalid-signature"
88-
test_interceptor "Q12WO44XJLR3H3" "$EXPECTED_RESPONSE_SIGNATURE_ERROR"
95+
test_interceptor "Q12WO44XJLR3H3" "$EXPECTED_RESPONSE_SIGNATURE_ERROR" "invalid-signature"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: insightsoperatordown
2+
rbac:
3+
roles: []
4+
clusterRoleRules:
5+
- verbs:
6+
- "get"
7+
- "list"
8+
apiGroups:
9+
- "config.openshift.io"
10+
resources:
11+
- clusteroperators
12+
customerDataAccess: false

0 commit comments

Comments
 (0)