Skip to content

Commit 8a0953f

Browse files
authored
feat(tutorial): add tutorial to store sse-c key into secret manager (#5677)
1 parent 21345ad commit 8a0953f

File tree

1 file changed

+125
-0
lines changed
  • tutorials/object-storage-sse-c-with-secret-manager

1 file changed

+125
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
meta:
3+
title: Using Secret Manager to store encryption key for SSE-C
4+
description: Learn how to use Secret Manager to store encryption key for Object Storage and SSE-C.
5+
tags: object-storage secret-manager encryption
6+
products:
7+
- object-storage
8+
- secret-manager
9+
- key-manager
10+
dates:
11+
validation: 2025-10-28
12+
posted: 2025-10-28
13+
validation_frequency: 12
14+
difficulty: beginner
15+
usecase:
16+
- manage-share-and-store-data
17+
ecosystem:
18+
- scaleway-only
19+
---
20+
import Requirements from '@macros/iam/requirements.mdx'
21+
22+
This tutorial explains how to use Key Manager and Secret Manager to generate and store an encryption key for [SSE-C](/object-storage/api-cli/enable-sse-c/), used to encrypt and decrypt objects in your Scaleway Object Storage bucket.
23+
24+
<Requirements />
25+
26+
- A Scaleway account logged into the [console](https://console.scaleway.com)
27+
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
28+
- [Created](/object-storage/how-to/create-a-bucket/) an Object Storage bucket
29+
- Installed and initialized the [AWS CLI](/object-storage/api-cli/object-storage-aws-cli/)
30+
31+
The goal of this tutorial is to:
32+
33+
- Generate an encryption key using Key Manager
34+
- Store it securely in Secret Manager
35+
- Use it to encrypt your Object Storage objects with SSE-C
36+
37+
## Generating the encryption key
38+
39+
1. Open a terminal and create a key in Key Manager:
40+
41+
```bash
42+
KEY_ID=$(scw keymanager key create -o template="{{.ID}}")
43+
```
44+
45+
2. Run the following command to generate a data encryption key:
46+
47+
```bash
48+
scw keymanager key generate-data-key "$KEY_ID" -o json | jq -r .plaintext | base64 -d > ssec.key
49+
```
50+
51+
3. Create a secret in Secret manager to store the data encryption key:
52+
53+
```bash
54+
SECRET_ID=$(scw secret secret create name=ssec-key path=/keys -o template="{{.ID}}")
55+
```
56+
57+
4. Store the data encryption key in Secret Manager:
58+
59+
```bash
60+
scw secret version create "$SECRET_ID" data="@ssec.key"
61+
```
62+
63+
## Preparing the encryption key and its digest
64+
65+
You must now retrieve the encryption key from Secret Manager, encode it to base64, compute its MD5 digest, and store both values in environment variables.
66+
67+
1. Access the secret version to retrieve the raw key:
68+
69+
```bash
70+
scw secret version access "$SECRET_ID" revision=latest raw=true > ssec.key
71+
```
72+
73+
2. Encode the key to base64:
74+
75+
```bash
76+
ENCRYPTION_KEY=$(cat ssec.key | base64)
77+
```
78+
79+
3. Compute the MD5 digest of the key:
80+
81+
```bash
82+
KEY_DIGEST=$(openssl dgst -md5 -binary ssec.key | base64)
83+
```
84+
85+
<Message type="important">
86+
If you delete the secret containing the encryption key, you also lose the data encrypted with it, as you will not be able to perform `GET` operations on encrypted objects without the corresponding key.
87+
</Message>
88+
89+
### Upload and download objects with SSE-C
90+
91+
1. Upload an object of your choice to your bucket and encrypt it. Make sure that you replace:
92+
93+
- `<bucket-name>` with the name of your bucket
94+
- `<object-key>` with the desired name of the object in the bucket
95+
- `<path/to/your/file>` with the path to the file you want to upload
96+
97+
```bash
98+
aws s3api put-object \
99+
--bucket <bucket-name> \
100+
--key <object-key> \
101+
--body <path/to/your/file> \
102+
--sse-customer-algorithm AES256 \
103+
--sse-customer-key $ENCRYPTION_KEY \
104+
--sse-customer-key-md5 $KEY_DIGEST
105+
```
106+
107+
2. Download the previously uploaded object and decrypt it. Make sure that you replace:
108+
109+
- `<bucket-name>` with the name of your bucket
110+
- `<object-key>` with the name of your object in the bucket
111+
- `<path/to/your/file>` with the local path where you want to save the file
112+
113+
```bash
114+
aws s3api get-object \
115+
--bucket <bucket-name> \
116+
--key <object-key> \
117+
<path/to/destination/file> \
118+
--sse-customer-algorithm AES256 \
119+
--sse-customer-key $ENCRYPTION_KEY \
120+
--sse-customer-key-md5 $KEY_DIGEST
121+
```
122+
123+
You now know how to use Key Manager and Secret Manager to generate, store, and use an encryption key to protect your Object Storage data with SSE-C.
124+
125+
Refer to the [dedicated documentation](/object-storage/api-cli/enable-sse-c/) for more information on how to use SSE-C for Scaleway Object Storage.

0 commit comments

Comments
 (0)