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