Use dedicated signing key for CI_JOB_JWT (take 3)
1 unresolved thread
In !28063 (merged) we implemented new CI variable (CI_JOB_JWT
) that is JWT signed with the instance's OpenID Connect signing key. While this is fine, during security review it was recommended we switch to using dedidcated signing key for these tokens - !28063 (comment 325521818).
This is the third attempt to replace openid_connect_signing_key
with the new ci_jwt_signing_key
when generating CI_JOB_JWT
.
The first MR (!34249 (merged)) had to be reverted due to gitlab-com/gl-infra/production#2284 (closed).
With the second attempt (!38762 (closed)) we took as lightly different approach - instead of trying to generate and save the key on the fly when missing (and fail if there is no write access) we just skip generating CI_JOB_JWT
if there is no key available. During review @shinya.maeda suggested we store the new key in application_settings
table instead of a file - #222690 (comment 395216567). This idea was approved in general by @dcouture in teh context of application security - #222690 (comment 398368920).
After giving some thought to this proposal I also think it will be better:
The use of the new key is behind a ci_jwt_signing_key
feature flag and disabled by default - !38762 (diffs).
The new key value is populated with migration for existing instances and database fixtures for new installations.
The MR also implements /-/jwks
endpoint instead of delegating to the doorkeeper-openid_connect
gem. Response will still include openid_connect_signing_key for seamless rollout.
Related to #214607 (closed).
$ bundle exec rails db:migrate:up VERSION=20201008011523
== 20201008011523 AddCiJwtSigningKeyToApplicationSettings: migrating ==========
-- add_column(:application_settings, :encrypted_ci_jwt_signing_key, :text)
-> 0.0065s
-- add_column(:application_settings, :encrypted_ci_jwt_signing_key_iv, :text)
-> 0.0008s
== 20201008011523 AddCiJwtSigningKeyToApplicationSettings: migrated (0.0075s) =
$ bundle exec rails db:migrate:up VERSION=20201008011937
== 20201008011937 AddTextLimitToApplicationSettingsEncryptedCiJwtSigningKeyIv: migrating
-- transaction_open?()
-> 0.0000s
-- current_schema()
-> 0.0003s
-- execute("ALTER TABLE application_settings\nADD CONSTRAINT check_85a39b68ff\nCHECK ( char_length(encrypted_ci_jwt_signing_key_iv) <= 255 )\nNOT VALID;\n")
-> 0.0086s
-- current_schema()
-> 0.0002s
-- execute("SET statement_timeout TO 0")
-> 0.0003s
-- execute("ALTER TABLE application_settings VALIDATE CONSTRAINT check_85a39b68ff;")
-> 0.0009s
-- execute("RESET ALL")
-> 0.0003s
== 20201008011937 AddTextLimitToApplicationSettingsEncryptedCiJwtSigningKeyIv: migrated (0.0231s)
$ bundle exec rails db:migrate:up VERSION=20201008013434
== 20201008013434 GenerateCiJwtSigningKey: migrating ==========================
== 20201008013434 GenerateCiJwtSigningKey: migrated (0.2750s) =================
$ bundle exec rails db:migrate:down VERSION=20201008013434
== 20201008013434 GenerateCiJwtSigningKey: reverting ==========================
== 20201008013434 GenerateCiJwtSigningKey: reverted (0.1526s) =================
$ bundle exec rails db:migrate:down VERSION=20201008011937
== 20201008011937 AddTextLimitToApplicationSettingsEncryptedCiJwtSigningKeyIv: reverting
-- execute("ALTER TABLE application_settings\nDROP CONSTRAINT IF EXISTS check_85a39b68ff\n")
-> 0.0013s
== 20201008011937 AddTextLimitToApplicationSettingsEncryptedCiJwtSigningKeyIv: reverted (0.0046s)
$ bundle exec rails db:migrate:down VERSION=20201008011523
== 20201008011523 AddCiJwtSigningKeyToApplicationSettings: reverting ==========
-- remove_column(:application_settings, :encrypted_ci_jwt_signing_key_iv, :text)
-> 0.0015s
-- remove_column(:application_settings, :encrypted_ci_jwt_signing_key, :text)
-> 0.0004s
== 20201008011523 AddCiJwtSigningKeyToApplicationSettings: reverted (0.0049s) =
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
@gitlab-com/gl-security/appsec
Related to #214607 (closed)