Skip to content

Commit 5b579a8

Browse files
Commit changes made by code formatters
1 parent 913df1a commit 5b579a8

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

docs/guides/setting-up-a-new-consumer.md

+15-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ per environment.
1313
- [Access to Cloud Platform’s Kubernetes cluster](https://user-guide.cloud-platform.service.justice.gov.uk/documentation/getting-started/kubectl-config.html#installing-kubectl)
1414

1515
As a pre-requisite to create a client certificate by running the script below, please ensure that:
16+
1617
- You are logged in so that you can access AWS resources via the CLI.
1718
- Verify that you have all your AWS credentials ready by opening the config file in the ".aws" directory.
1819

@@ -23,6 +24,7 @@ Run the [generate-client-certificate.sh](/scripts/client_certificates/generate.s
2324
```bash
2425
make generate-client-certificate
2526
```
27+
2628
This will output three files in the ./scripts/client_certificates directory:
2729

2830
- a private key e.g. `dev-nhs-client.key`
@@ -81,12 +83,14 @@ openssl x509 -in ./scripts/client_certificates/[environment]-[consumer]-client.p
8183
## Send the credentials to the consumer
8284

8385
Retrieve the client api key
86+
8487
```bash
8588
kubectl -n hmpps-integration-api-<environment> get secrets consumer-api-keys -o json | jq -r '.data.<client>' | base64 -d
8689
# E.g. kubectl -n hmpps-integration-api-dev get secrets consumer-api-keys -o json | jq -r '.data.dev' | base64 -d
8790
```
8891

8992
Ask the client to generate a key pair and to provide the **public key only** via email
93+
9094
```bash
9195
# Generate private key
9296
openssl genrsa -out hmpps-integration-api-cred-exchange-private-key.pem 3072
@@ -97,6 +101,7 @@ openssl rsa -in hmpps-integration-api-cred-exchange-private-key.pem -pubout -out
97101
```
98102

99103
As size of data we can encrypt with the client's public key is limited we now create a symmetric encryption key and encrypt using the client's public key
104+
100105
```bash
101106
# Create a symmetric key
102107
head /dev/urandom | sha256sum > symmetric.key
@@ -106,6 +111,7 @@ openssl pkeyutl -encrypt -pubin -inkey hmpps-integration-api-cred-exchange-publi
106111
```
107112

108113
We can now encrypt the client's access credentials for an environment using the symmetric key
114+
109115
```bash
110116
# Create a tarball of the access credentials
111117
tar cvfz hmpps-integration-api-preprod.tar.gz preprod/preprod-client.key preprod/preprod-client.pem preprod/preprod-api-key
@@ -115,12 +121,14 @@ openssl enc -aes-256-cbc -pbkdf2 -iter 310000 -md sha256 -salt -in hmpps-integra
115121
```
116122

117123
…and encrypt the symmetric key using the client's supplied public key
124+
118125
```bash
119126
# Encrypt with client's public key
120127
openssl pkeyutl -encrypt -pubin -inkey hmpps-integration-api-cred-exchange-public-key.pem -in symmetric.key -out symmetric.key.enc
121128
```
122129

123130
We can now send the **encrypted** symmetric key (`symmetric.key.enc`) and **encrypted** access credentials (`hmpps-integration-api-preprod.tar.gz.enc`) to the client via email. The client may now decrypt the symmetric key using their private key and subsequently the access credentials using the symmetric key
131+
124132
```Bash
125133
# Decrypt symmetric key file with private key
126134
openssl pkeyutl -decrypt -inkey hmpps-integration-api-cred-exchange-private-key.pem -in symmetric.key.enc -out symmetric.key
@@ -132,6 +140,7 @@ openssl enc -d -aes-256-cbc -pbkdf2 -iter 310000 -md sha256 -salt -in hmpps-inte
132140
## Create new consumer subscriber queue for events
133141

134142
### Create basic infrastructure
143+
135144
Within the [Cloud Platform Environments GitHub repository](https://github.com/ministryofjustice/cloud-platform-environments/tree/main) and the namespace of the environment:
136145

137146
1. Create a branch.
@@ -141,13 +150,14 @@ Within the [Cloud Platform Environments GitHub repository](https://github.com/mi
141150
5. Add a client queue mapping. Example: [locals.tf](https://github.com/ministryofjustice/cloud-platform-environments/blob/6e6ad3d6c8bd070b3ba65ce8568fa79c2cfe4e30/namespaces/live.cloud-platform.service.justice.gov.uk/hmpps-integration-api-dev/resources/locals.tf#L13)
142151
6. Follow steps 3-8 in [Create an API key](#create-an-api-key) to merge branch to main.
143152
7. Retrieve the client queue name and ARN with the following command:
144-
```bash
145-
kubectl -n hmpps-integration-api-[environment] get secrets [your queue secret name] -o json
146-
# E.g. kubectl -n hmpps-integration-api-dev get secrets event-mapps-queue -o json
147-
```
153+
```bash
154+
kubectl -n hmpps-integration-api-[environment] get secrets [your queue secret name] -o json
155+
# E.g. kubectl -n hmpps-integration-api-dev get secrets event-mapps-queue -o json
156+
```
148157
8. Send the client queue name and ARN to the consumer
149158

150159
The consumer can use the `POST /token` endpoint in API Gateway to retrieve temporary credentials, then use the SQS APIs or SDKs to receive and delete messages. For example:
160+
151161
```shell
152162
temporary_credentials=$(curl --cert client.pem --key client.key -H "x-api-key: $api_key" -XPOST https://dev.integration-api.hmpps.service.justice.gov.uk/token)
153163
export AWS_ACCESS_KEY_ID=$(jq -r '.AccessKeyId' <<< "$creds")
@@ -159,6 +169,7 @@ aws sqs get-queue-attributes --attribute-names ApproximateNumberOfMessages --que
159169
```
160170

161171
### Using AWS secret for filter Policy
172+
162173
1. Login to the [AWS Console](https://user-guide.cloud-platform.service.justice.gov.uk/documentation/getting-started/accessing-the-cloud-console.html), navigate to Secrets Manager and navigate to the secret created in the previous step by search using the secret description. e.g. MAPPS event filter list Pre-prod
163174
2. Click on the secret and then click on Retrieve secret value. If this is your first time accessing the new secret, you will see an error Failed to get the secret value.
164175
3. Click on Set secret Value, and set the Plaintext value as: {"eventType":["default"]}. Setting filter to default will block subscriber receiving any messages. Event notifier will update the subscriber and AWS secret with actual filter list later.

0 commit comments

Comments
 (0)