Skip to content

Commit 947f9c9

Browse files
committed
HIA-761: Add method of sharing credentials
1 parent ccdb909 commit 947f9c9

File tree

1 file changed

+49
-13
lines changed

1 file changed

+49
-13
lines changed

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

+49-13
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,55 @@ openssl x509 -in ./scripts/client_certificates/[environment]-[consumer]-client.p
8080

8181
## Send the credentials to the consumer
8282

83-
1. Retrieve the API key for the new consumer using Kubectl.
84-
83+
Retrieve the client api key
8584
```bash
8685
kubectl -n hmpps-integration-api-<environment> get secrets consumer-api-keys -o json | jq -r '.data.<client>' | base64 -d
8786
# E.g. kubectl -n hmpps-integration-api-dev get secrets consumer-api-keys -o json | jq -r '.data.dev' | base64 -d
8887
```
8988

90-
2. Using [One-Time Secret](https://password.link/en) and email, send the new consumer their:
91-
1. private key
92-
2. client certificate
93-
3. API key
94-
89+
Ask the client to generate a key pair and to provide the **public key only** via email
90+
```bash
91+
# Generate private key
92+
openssl genrsa -out hmpps-integration-api-cred-exchange-private-key.pem 3072
93+
94+
# Generate public key
95+
openssl rsa -in hmpps-integration-api-cred-exchange-private-key.pem -pubout -out hmpps-integration-api-cred-exchange-public-key.pem
96+
97+
```
98+
99+
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
100+
```bash
101+
# Create a symmetric key
102+
head /dev/urandom | sha256sum > symmetric.key
103+
104+
# Encrypt with client's public key
105+
openssl pkeyutl -encrypt -pubin -inkey hmpps-integration-api-cred-exchange-public-key.pem -in symmetric.key -out symmetric.key.enc
106+
```
107+
108+
We can now encrypt the client's access credentials for an environment using the symmetric key
109+
```bash
110+
# Create a tarball of the access credentials
111+
tar cvfz hmpps-integration-api-preprod.tar.gz preprod/preprod-client.key preprod/preprod-client.pem preprod/preprod-api-key
112+
113+
# Encrypt using symmetric key
114+
openssl enc -aes-256-cbc -pbkdf2 -iter 310000 -md sha256 -salt -in hmpps-integration-api-preprod.tar.gz -out hmpps-integration-api-preprod.tar.gz.enc -pass file:./symmetric.key
115+
```
116+
117+
…and encrypt the symmetric key using the client's supplied public key
118+
```bash
119+
# Encrypt with client's public key
120+
openssl pkeyutl -encrypt -pubin -inkey hmpps-integration-api-cred-exchange-public-key.pem -in symmetric.key -out symmetric.key.enc
121+
```
122+
123+
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
124+
```Bash
125+
# Decrypt symmetric key file with private key
126+
openssl pkeyutl -decrypt -inkey hmpps-integration-api-cred-exchange-private-key.pem -in symmetric.key.enc -out symmetric.key
127+
128+
# Decrypt access credentials using symmetric key
129+
openssl enc -d -aes-256-cbc -pbkdf2 -iter 310000 -md sha256 -salt -in hmpps-integration-api-preprod.tar.gz.enc -out hmpps-integration-api-preprod.tar.gz -pass file:./symmetric.key
130+
```
131+
95132
## Create new consumer subscriber queue for events
96133

97134
### Create basic infrastructure
@@ -106,7 +143,7 @@ Within the [Cloud Platform Environments GitHub repository](https://github.com/mi
106143
7. Retrieve the client queue name and ARN with the following command:
107144
```bash
108145
kubectl -n hmpps-integration-api-[environment] get secrets [your queue secret name] -o json
109-
# E.g. kubectl -n hmpps-integration-api-dev get secrets event-mapps-queue -o json
146+
# E.g. kubectl -n hmpps-integration-api-dev get secrets event-mapps-queue -o json
110147
```
111148
8. Send the client queue name and ARN to the consumer
112149

@@ -125,8 +162,7 @@ aws sqs get-queue-attributes --attribute-names ApproximateNumberOfMessages --que
125162
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
126163
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.
127164
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.
128-
4. Save the change
129-
5. Create new [Cloud Platform Environments GitHub repository](https://github.com/ministryofjustice/cloud-platform-environments/tree/main) branch
130-
6. Update terraform to load the secret value from AWS and update filter_policy value. Follow [Example](https://github.com/ministryofjustice/cloud-platform-environments/pull/22111/files). Note: The name of aws_secretsmanager_secret module has to be same as the secret name created from step 4/5 above.
131-
7. Follow steps 3-8 in [Create an API key](#create-an-api-key) to merge branch to main.
132-
165+
4. Save the change
166+
5. Create new [Cloud Platform Environments GitHub repository](https://github.com/ministryofjustice/cloud-platform-environments/tree/main) branch
167+
6. Update terraform to load the secret value from AWS and update filter_policy value. Follow [Example](https://github.com/ministryofjustice/cloud-platform-environments/pull/22111/files). Note: The name of aws_secretsmanager_secret module has to be same as the secret name created from step 4/5 above.
168+
7. Follow steps 3-8 in [Create an API key](#create-an-api-key) to merge branch to main.

0 commit comments

Comments
 (0)