Skip to content

Commit ac47124

Browse files
committed
Allow setting ActiveRecord encryption secrets
Add environment variable to set entry in secrets.yml related to active record encryption - active_record_encryption_primary_key (can be multiple) - active_record_encryption_deterministic_key (can be multiple) - active_record_encryption_key_derivation_salt Reference for '32 characters length' recommendation: https://gitlab.com/gitlab-org/gitlab/-/blob/v18.0.0-ee/config/initializers/2_secret_token.rb#L78-80 TODO: fix command line usage in documentation
1 parent 0d39d55 commit ac47124

File tree

8 files changed

+55
-1
lines changed

8 files changed

+55
-1
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ Generate random strings that are at least `64` characters long for each of `GITL
159159

160160
> **Tip**: You can generate a random string using `pwgen -Bsv1 64` and assign it as the value of `GITLAB_SECRETS_DB_KEY_BASE`.
161161
162+
Also generate random strings that are typically `32` characters long for each of `GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY`, `GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY` and `GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT`. These values are used for `ActiveRecord::Encryption` encrypted columns.
163+
162164
Start GitLab using:
163165

164166
```bash
@@ -188,6 +190,8 @@ docker run --name gitlab-redis -d \
188190

189191
Step 3. Launch the gitlab container
190192

193+
TODO: fix and verify command line option to set newly created keys (especially primary_key and deterministic_key : they must be an array)
194+
191195
```bash
192196
docker run --name gitlab -d \
193197
--link gitlab-postgresql:postgresql --link gitlab-redis:redisio \
@@ -197,6 +201,9 @@ docker run --name gitlab -d \
197201
--env 'GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alpha-numeric-string' \
198202
--env 'GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alpha-numeric-string' \
199203
--env 'GITLAB_SECRETS_ENCRYPTED_SETTINGS_KEY_BASE=long-and-random-alpha-numeric-string' \
204+
--env 'GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=long-and-random-alpha-numeric-string' \
205+
--env 'GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=long-and-random-alpha-numeric-string' \
206+
--env 'GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=long-and-random-alpha-numeric-string' \
200207
--volume /srv/docker/gitlab/gitlab:/home/git/data \
201208
sameersbn/gitlab:18.0.2
202209
```
@@ -923,6 +930,26 @@ Encryption key for session secrets. Ensure that your key is at least 64 characte
923930

924931
Encryption key for encrypted settings related stuff with GitLab. Ensure that your key is at least 64 characters long and that you don't lose it. **If you lose or change this secret, encrypted settings will not work and might cause errors in merge requests and so on** You can generate one using `pwgen -Bsv1 64`. No defaults.
925932

933+
##### `GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY`
934+
935+
The base key to non-deterministically-encrypt data for `ActiveRecord::Encryption` encrypted columns. It can be used to set value for `active_record_encryption_primary_key` in config/secrets.yml.
936+
Ensure that your key is alphanumeric string. Preferred to be 32 characters long.
937+
If you need to set multiple keys, set this parameter like `["thisisfirstprimarykey","thisissecondprimarykey"]` for example. In docker-compose.yml, you have to quote whole value.
938+
No defaults.
939+
940+
##### `GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY`
941+
942+
The base key to deterministically-encrypt data for `ActiveRecord::Encryption` encrypted columns. It can be used to set value for `active_record_encryption_deterministic_key` in config/secrets.yml.
943+
Ensure that your key is alphanumeric string. Preferred to be 32 characters long.
944+
If you need to set multiple keys, set this parameter like `["thisisfirstprimarykey","thisissecondprimarykey"]` for example. In docker-compose.yml, you have to quote whole value.
945+
No defaults.
946+
947+
##### `GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT`
948+
949+
The derivation salt to encrypt data for ActiveRecord::Encryption encrypted columns. It can be used to set value for `active_record_encryption_key_derivation_salt` in config/secrets.yml.
950+
Ensure that your key is alphanumeric string. Preferred to be 32 characters long.
951+
No defaults.
952+
926953
##### `GITLAB_TIMEZONE`
927954

928955
Configure the timezone for the gitlab application. This configuration does not effect cron jobs. Defaults to `UTC`. See the list of [acceptable values](http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html). For settings the container timezone which will affect cron, see variable `TZ`
@@ -2771,6 +2798,7 @@ Replace `x.x.x` with the version you are upgrading from. For example, if you are
27712798
> **Note**: Since GitLab `8.0.0` you need to provide the `GITLAB_SECRETS_DB_KEY_BASE` parameter while starting the image.
27722799
> **Note**: Since GitLab `8.11.0` you need to provide the `GITLAB_SECRETS_SECRET_KEY_BASE` and `GITLAB_SECRETS_OTP_KEY_BASE` parameters while starting the image. These should initially both have the same value as the contents of the `/home/git/data/.secret` file. See [Available Configuration Parameters](#available-configuration-parameters) for more information on these parameters.
27732800
> **Note**: Since Gitlab 13.7 you need to provide the `GITLAB_SECRETS_ENCRYPTED_SETTINGS_KEY_BASE` parameter while starting the image. If not provided, the key will be generated by gitlab. So you can start the image without setting this parameter. But you will lose the key when you shutting down the container without taking a backup of `secrets.yml`.
2801+
> **Note**: Since Gitlab 17.8 you need to provide `GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY`,`GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY` and `GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT`. If not provided, these keys will be generated by gitlab. So you can start the image without setting this parameter. But you will lose the key when you shutting down the container without taking a backup of `secrets.yml` and result to unusable stage of some features such as dependency proxy.
27742802

27752803
```bash
27762804
docker run --name gitlab -d [OPTIONS] sameersbn/gitlab:18.0.2

assets/runtime/config/gitlabhq/secrets.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ production:
77
secret_key_base: {{GITLAB_SECRETS_SECRET_KEY_BASE}}
88
otp_key_base: {{GITLAB_SECRETS_OTP_KEY_BASE}}
99
encrypted_settings_key_base: {{GITLAB_SECRETS_ENCRYPTED_SETTINGS_KEY_BASE}}
10+
active_record_encryption_primary_key: {{GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY}}
11+
active_record_encryption_deterministic_key: {{GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY}}
12+
active_record_encryption_key_derivation_salt: {{GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT}}
1013

1114
development:
1215
db_key_base: development

assets/runtime/env-defaults

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,15 @@ GITLAB_UPLOADS_OBJECT_STORE_CONNECTION_GOOGLE_JSON_KEY_LOCATION=${GITLAB_UPLOADS
251251
GITLAB_MATTERMOST_ENABLED=${GITLAB_MATTERMOST_ENABLED:-false}
252252
GITLAB_MATTERMOST_URL=${GITLAB_MATTERMOST_URL:-https://mattermost.example.com}
253253

254+
# secrets
254255
GITLAB_SECRETS_DB_KEY_BASE=${GITLAB_SECRETS_DB_KEY_BASE:-}
255256
GITLAB_SECRETS_SECRET_KEY_BASE=${GITLAB_SECRETS_SECRET_KEY_BASE:-}
256257
GITLAB_SECRETS_OTP_KEY_BASE=${GITLAB_SECRETS_OTP_KEY_BASE:-}
257258
GITLAB_SECRETS_ENCRYPTED_SETTINGS_KEY_BASE=${GITLAB_SECRETS_ENCRYPTED_SETTINGS_KEY_BASE:-}
259+
GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=${GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY:-}
260+
GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=${GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY:-}
261+
GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=${GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT:-}
262+
258263
GITLAB_NOTIFY_ON_BROKEN_BUILDS=${GITLAB_NOTIFY_ON_BROKEN_BUILDS:-true}
259264
GITLAB_NOTIFY_PUSHER=${GITLAB_NOTIFY_PUSHER:-false}
260265

assets/runtime/functions

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,10 @@ gitlab_configure_secrets() {
888888
GITLAB_SECRETS_DB_KEY_BASE \
889889
GITLAB_SECRETS_SECRET_KEY_BASE \
890890
GITLAB_SECRETS_OTP_KEY_BASE \
891-
GITLAB_SECRETS_ENCRYPTED_SETTINGS_KEY_BASE
891+
GITLAB_SECRETS_ENCRYPTED_SETTINGS_KEY_BASE \
892+
GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY \
893+
GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY \
894+
GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT
892895

893896
local shell_secret="${GITLAB_INSTALL_DIR}/.gitlab_shell_secret"
894897
if [[ ! -f "${shell_secret}" ]]; then

contrib/docker-swarm/docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ services:
6060
- GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alphanumeric-string
6161
- GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alphanumeric-string
6262
- GITLAB_SECRETS_ENCRYPTED_SETTINGS_KEY_BASE=long-and-random-alphanumeric-string
63+
- GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=["long-and-random-alphanumeric-string"]
64+
- GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=["long-and-random-alphanumeric-string"]
65+
- GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=long-and-random-alphanumeric-string
6366

6467
- GITLAB_ROOT_PASSWORD=
6568
- GITLAB_ROOT_EMAIL=

docker-compose.swarm.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ services:
123123
- GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alphanumeric-string
124124
- GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alphanumeric-string
125125
- GITLAB_SECRETS_ENCRYPTED_SETTINGS_KEY_BASE=long-and-random-alphanumeric-string
126+
- GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=["long-and-random-alphanumeric-string"]
127+
- GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=["long-and-random-alphanumeric-string"]
128+
- GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=long-and-random-alphanumeric-string
126129

127130
- GITLAB_ROOT_PASSWORD=
128131
- GITLAB_ROOT_EMAIL=

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ services:
6262
- GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alphanumeric-string
6363
- GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alphanumeric-string
6464
- GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alphanumeric-string
65+
- GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=["long-and-random-alphanumeric-string"]
66+
- GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=["long-and-random-alphanumeric-string"]
67+
- GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=long-and-random-alphanumeric-string
6568

6669
- GITLAB_ROOT_PASSWORD=
6770
- GITLAB_ROOT_EMAIL=

kubernetes/gitlab-rc.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ spec:
2929
value: long-and-random-alpha-numeric-string
3030
- name: GITLAB_SECRETS_ENCRYPTED_SETTINGS_KEY_BASE
3131
value: long-and-random-alpha-numeric-string
32+
- name: GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY
33+
value: '[long-and-random-alpha-numeric-string]'
34+
- name: GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY
35+
value: '[long-and-random-alpha-numeric-string]'
36+
- name: GITLAB_SECRETS_ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT
37+
value: long-and-random-alpha-numeric-string
3238

3339
- name: GITLAB_ROOT_PASSWORD
3440
value:

0 commit comments

Comments
 (0)