Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
64c23778
Commit
64c23778
authored
Nov 21, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add migratable models for runners tokens migration
parent
3578eb45
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
120 additions
and
6 deletions
+120
-6
lib/gitlab/background_migration/encrypt_columns.rb
lib/gitlab/background_migration/encrypt_columns.rb
+6
-4
lib/gitlab/background_migration/models/encrypt_columns/namespace.rb
.../background_migration/models/encrypt_columns/namespace.rb
+28
-0
lib/gitlab/background_migration/models/encrypt_columns/project.rb
...ab/background_migration/models/encrypt_columns/project.rb
+28
-0
lib/gitlab/background_migration/models/encrypt_columns/runner.rb
...lab/background_migration/models/encrypt_columns/runner.rb
+28
-0
lib/gitlab/background_migration/models/encrypt_columns/settings.rb
...b/background_migration/models/encrypt_columns/settings.rb
+28
-0
lib/gitlab/background_migration/models/encrypt_columns/web_hook.rb
...b/background_migration/models/encrypt_columns/web_hook.rb
+2
-2
No files found.
lib/gitlab/background_migration/encrypt_columns.rb
View file @
64c23778
...
@@ -5,15 +5,17 @@ module Gitlab
...
@@ -5,15 +5,17 @@ module Gitlab
# EncryptColumn migrates data from an unencrypted column - `foo`, say - to
# EncryptColumn migrates data from an unencrypted column - `foo`, say - to
# an encrypted column - `encrypted_foo`, say.
# an encrypted column - `encrypted_foo`, say.
#
#
# To avoid depending on a particular version of the model in app/, add a
# model to `lib/gitlab/background_migration/models/encrypt_columns` and use
# it in the migration that enqueues the jobs, so code can be shared.
#
# For this background migration to work, the table that is migrated _has_ to
# For this background migration to work, the table that is migrated _has_ to
# have an `id` column as the primary key. Additionally, the encrypted column
# have an `id` column as the primary key. Additionally, the encrypted column
# should be managed by attr_encrypted, and map to an attribute with the same
# should be managed by attr_encrypted, and map to an attribute with the same
# name as the unencrypted column (i.e., the unencrypted column should be
# name as the unencrypted column (i.e., the unencrypted column should be
# shadowed).
# shadowed), unless you want to define specific methods / accessors in the
# temporary model in `/models/encrypt_columns/your_model.rb`.
#
#
# To avoid depending on a particular version of the model in app/, add a
# model to `lib/gitlab/background_migration/models/encrypt_columns` and use
# it in the migration that enqueues the jobs, so code can be shared.
class
EncryptColumns
class
EncryptColumns
def
perform
(
model
,
attributes
,
from
,
to
)
def
perform
(
model
,
attributes
,
from
,
to
)
model
=
model
.
constantize
if
model
.
is_a?
(
String
)
model
=
model
.
constantize
if
model
.
is_a?
(
String
)
...
...
lib/gitlab/background_migration/models/encrypt_columns/namespace.rb
0 → 100644
View file @
64c23778
# frozen_string_literal: true
module
Gitlab
module
BackgroundMigration
module
Models
module
EncryptColumns
# This model is shared between synchronous and background migrations to
# encrypt the `runners_token` column in `namespaces` table.
#
class
Namespace
<
ActiveRecord
::
Base
include
::
EachBatch
self
.
table_name
=
'namespaces'
self
.
inheritance_column
=
:_type_disabled
def
runners_token
=
(
value
)
self
.
runners_token_encrypted
=
::
Gitlab
::
CryptoHelper
.
aes256_gcm_encrypt
(
value
)
end
def
self
.
encrypted_attributes
{
runners_token:
{
attribute: :runners_token_encrypted
}
}
end
end
end
end
end
end
lib/gitlab/background_migration/models/encrypt_columns/project.rb
0 → 100644
View file @
64c23778
# frozen_string_literal: true
module
Gitlab
module
BackgroundMigration
module
Models
module
EncryptColumns
# This model is shared between synchronous and background migrations to
# encrypt the `runners_token` column in `projects` table.
#
class
Project
<
ActiveRecord
::
Base
include
::
EachBatch
self
.
table_name
=
'projects'
self
.
inheritance_column
=
:_type_disabled
def
runners_token
=
(
value
)
self
.
runners_token_encrypted
=
::
Gitlab
::
CryptoHelper
.
aes256_gcm_encrypt
(
value
)
end
def
self
.
encrypted_attributes
{
runners_token:
{
attribute: :runners_token_encrypted
}
}
end
end
end
end
end
end
lib/gitlab/background_migration/models/encrypt_columns/runner.rb
0 → 100644
View file @
64c23778
# frozen_string_literal: true
module
Gitlab
module
BackgroundMigration
module
Models
module
EncryptColumns
# This model is shared between synchronous and background migrations to
# encrypt the `token` column in `ci_runners` table.
#
class
Runner
<
ActiveRecord
::
Base
include
::
EachBatch
self
.
table_name
=
'ci_runners'
self
.
inheritance_column
=
:_type_disabled
def
runners_token
=
(
value
)
self
.
token_encrypted
=
::
Gitlab
::
CryptoHelper
.
aes256_gcm_encrypt
(
value
)
end
def
self
.
encrypted_attributes
{
token:
{
attribute: :token_encrypted
}
}
end
end
end
end
end
end
lib/gitlab/background_migration/models/encrypt_columns/settings.rb
0 → 100644
View file @
64c23778
# frozen_string_literal: true
module
Gitlab
module
BackgroundMigration
module
Models
module
EncryptColumns
# This model is shared between synchronous and background migrations to
# encrypt the `runners_token` column in `application_settings` table.
#
class
Settings
<
ActiveRecord
::
Base
include
::
EachBatch
self
.
table_name
=
'application_settings'
self
.
inheritance_column
=
:_type_disabled
def
runners_token
=
(
value
)
self
.
runners_token_encrypted
=
::
Gitlab
::
CryptoHelper
.
aes256_gcm_encrypt
(
value
)
end
def
self
.
encrypted_attributes
{
runners_token:
{
attribute: :runners_token_encrypted
}
}
end
end
end
end
end
end
lib/gitlab/background_migration/models/encrypt_columns/web_hook.rb
View file @
64c23778
...
@@ -15,12 +15,12 @@ module Gitlab
...
@@ -15,12 +15,12 @@ module Gitlab
attr_encrypted
:token
,
attr_encrypted
:token
,
mode: :per_attribute_iv
,
mode: :per_attribute_iv
,
algorithm:
'aes-256-gcm'
,
algorithm:
'aes-256-gcm'
,
key:
Settings
.
attr_encrypted_db_key_base_truncated
key:
::
Settings
.
attr_encrypted_db_key_base_truncated
attr_encrypted
:url
,
attr_encrypted
:url
,
mode: :per_attribute_iv
,
mode: :per_attribute_iv
,
algorithm:
'aes-256-gcm'
,
algorithm:
'aes-256-gcm'
,
key:
Settings
.
attr_encrypted_db_key_base_truncated
key:
::
Settings
.
attr_encrypted_db_key_base_truncated
end
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment