Skip to content

Commit

Permalink
Updated RHACS connector to support self signed certificate authentica…
Browse files Browse the repository at this point in the history
…tion (#1174)
  • Loading branch information
lakshmi51974368 authored and delliott90 committed Nov 29, 2022
1 parent 0898bb8 commit 664d46e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 33 deletions.
29 changes: 17 additions & 12 deletions stix_shifter_modules/rhacs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [Limitations](#limitations)
- [References](#references)


### RHACS API Endpoints

|Connector Method|RHACS API Endpoint| Method
Expand All @@ -17,6 +18,10 @@
|Alert by id Endpoint|https://<{fqdn}>v1/alerts/alertid|GET
|Ping Endpoint|https://<{fqdn}>v1/ping|GET

### Note
- RHACS(StackRox) supports both ca and self-signed certificates. Below given transmit and execute examples are based on self-signed. In case of trusted ca issued server certificate, it is not required to pass sni and self-signed parameter as they are optional.


### Format for calling stix-shifter from the command line
```
python main.py `<translate or transmit>` `<translator_module>` `<query or result>` `<STIX identity object>` `<data>`
Expand All @@ -40,10 +45,10 @@ translate rhacs query '{}' "[x-rhacs-cluster:name = 'xxxx'] START t'2022-07-07T1
#### STIX Transmit ping

```shell
transmit
rhacs
"{\"host\":\"xxxxx"}"
"{\"auth\":{\"token\": "xxxxxx"}}"
transmit
rhacs
"{\"host\":\"xxxxxx\", \"sni\":\"central.stackrox\",\"selfSignedCert\":\"-----BEGIN CERTIFICATE-----xxxxx-----END CERTIFICATE-----\"}"
"{\"auth\":{\"token\": \"xxxxx\"}}"
ping
```

Expand All @@ -58,8 +63,8 @@ ping
```shell
transmit
rhacs
"{\"host\":\"xxxxx"}"
"{\"auth\":{\"token\": "xxxxxx"}}"
"{\"host\":\"xxxxxx\", \"sni\":\"central.stackrox\",\"selfSignedCert\":\"-----BEGIN CERTIFICATE-----xxxxx-----END CERTIFICATE-----\"}"
"{\"auth\":{\"token\": \"xxxxx\"}}"
results
"Cluster:"xxxx"+Violation Time:>=07/07/2022"
0
Expand Down Expand Up @@ -277,17 +282,17 @@ query
```shell
transmit
rhacs
"{\"host\":\"xxxxx"}"
"{\"auth\":{\"token\": "xxxxxx"}}"
"{\"host\":\"xxxxxx\", \"sni\":\"central.stackrox\",\"selfSignedCert\":\"-----BEGIN CERTIFICATE-----xxxxx-----END CERTIFICATE-----\"}"
"{\"auth\":{\"token\": \"xxxxx\"}}"
results
"Cluster:"xxxx"+Violation Time:>=07/07/2022"
0
1

transmit
rhacs
"{\"host\":\"xxxxx"}"
"{\"auth\":{\"token\": "xxxxxx"}}"
"{\"host\":\"xxxxxx\", \"sni\":\"central.stackrox\",\"selfSignedCert\":\"-----BEGIN CERTIFICATE-----xxxxx-----END CERTIFICATE-----\"}"
"{\"auth\":{\"token\": \"xxxxx\"}}"
results
"Lifecycle Stage:"xxxx"+Violation Time:>=07/07/2022"
0
Expand Down Expand Up @@ -547,8 +552,8 @@ execute
rhacs
rhacs
"{\"type\":\"identity\",\"id\":\"identity--f431f809-377b-45e0-aa1c-6a4751cae5ff\",\"name\":\"rhacs\",\"identity_class \":\"events\"}"
"{\"host\":\"xxxxx"}"
"{\"auth\":{\"token\": "xxxxxx"}}"
"{\"host\":\"xxxxxx\", \"sni\":\"central.stackrox\",\"selfSignedCert\":\"-----BEGIN CERTIFICATE-----xxxxx-----END CERTIFICATE-----\"}"
"{\"auth\":{\"token\": \"xxxxx\"}}"
"[x-rhacs-cluster:name = 'xxxx'] START t'2022-07-07T08:43:10.003Z' STOP t'2022-07-08T05:35:10.003Z'"
```

Expand Down
8 changes: 8 additions & 0 deletions stix_shifter_modules/rhacs/configuration/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
"help": {
"type": "link",
"default": "data-sources.html"
},
"sni": {
"type": "text",
"optional": true
},
"selfSignedCert": {
"type": "password",
"optional": true
}
},
"configuration": {
Expand Down
48 changes: 28 additions & 20 deletions stix_shifter_modules/rhacs/configuration/lang_en.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
{
"connection": {
"host": {
"label": "Management IP address or Hostname",
"description": "Specify the IP address or hostname of the data source so that IBM Cloud Pak for Security can communicate with it"
},
"port": {
"label": "Host Port",
"description": "Set the port number that is associated with the Host name or IP"
},
"help": {
"label": "Need additional help?",
"description": "More details on the data source setting can be found in the specified link"
}
"connection": {
"host": {
"label": "Management IP address or Hostname",
"description": "Specify the IP address or hostname of the data source"
},
"configuration": {
"auth": {
"token": {
"label": "API Token",
"description": "Token with readonly access to the alert API"
}
}
"port": {
"label": "Host Port",
"description": "Set the port number that is associated with the Host name or IP"
},
"help": {
"label": "Need additional help?",
"description": "More details on the data source setting can be found in the specified link"
},
"sni": {
"label": "Server Name Indicator",
"description": "The Server Name Indicator (SNI) enables a separate hostname to be provided for SSL authentication"
},
"selfSignedCert": {
"label": "RHACS Connection Certificate",
"description": "Use self-signed SSL certificate or CA content(root and intermediate) of data source"
}
},
"configuration": {
"auth": {
"token": {
"label": "API Token",
"description": "Token with readonly access to the alert API"
}
}
}
}
5 changes: 4 additions & 1 deletion stix_shifter_modules/rhacs/stix_transmission/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ def __init__(self, connection, configuration):
if 'token' in self.auth:
headers['Authorization'] = "Bearer " + self.auth.get('token')
url_modifier_function = None
# Added self-signed certificate parameter for verification
self.client = RestApiClient(connection.get('host'),
connection.get('port', None),
headers,
url_modifier_function=url_modifier_function
url_modifier_function=url_modifier_function,
sni=connection.get('sni', None),
cert_verify=connection.get('selfSignedCert', True)
)
self.timeout = connection['options'].get('timeout')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def connection():
"""format for connection"""
return {
"host": "testhost",
"sni":"testsni",
"selfSignedCert":"-----BEGIN CERTIFICATE-----XXXX123-----END CERTIFICATE-----",
"port": 443,
"options": {"result_limit": 10}
}
Expand Down

0 comments on commit 664d46e

Please sign in to comment.