Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Jérémy Munsch
fa8810881c
Encrypt sensitive Data 2022-12-22 10:36:32 +01:00
7 changed files with 353 additions and 5 deletions

View file

@ -6,6 +6,18 @@ use Illuminate\Database\Eloquent\Model;
class LDCNetwork extends Model
{
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'cidr' => 'encrypted',
'first_ip' => 'encrypted',
'last_ip' => 'encrypted',
];
/**
* The table associated with the model.
*

View file

@ -18,8 +18,35 @@ class Project extends Model
* @var array
*/
protected $casts = [
'dev_login' => 'array',
'prod_login' => 'array',
'dev_login' => 'encrypted:array',
'prod_login' => 'encrypted:array',
'prod_document_root' => 'encrypted',
'dev_document_root' => 'encrypted',
'prod_unix_user' => 'encrypted',
'prod_unix_pwd' => 'encrypted',
'dev_unix_user' => 'encrypted',
'dev_unix_pwd' => 'encrypted',
'prod_db_user' => 'encrypted',
'prod_db_pwd' => 'encrypted',
'dev_db_user' => 'encrypted',
'dev_db_pwd' => 'encrypted',
'prod_db_schema' => 'encrypted',
'dev_db_schema' => 'encrypted',
'prod_comment' => 'encrypted',
'dev_comment' => 'encrypted',
'prod_eai' => 'encrypted',
'dev_eai' => 'encrypted',
'prod_whitelist_fw' => 'encrypted',
'dev_whitelist_fw' => 'encrypted',
'dev_htaccess_user' => 'encrypted',
'dev_htaccess_pwd' => 'encrypted',
'prod_ga_id' => 'encrypted',
'prod_laravel_app_key' => 'encrypted',
'dev_laravel_app_key' => 'encrypted',
'prod_smtp_config' => 'encrypted',
'prod_smtp_key' => 'encrypted',
'prod_haproxy_id' => 'encrypted',
'dev_haproxy_id' => 'encrypted',
'https' => 'boolean'
];

View file

@ -14,7 +14,8 @@ class ProjectStatusChecker extends Model
protected $casts = [
'code' => 'array',
'sitemap' => 'boolean',
'robots' => 'boolean'
'robots' => 'boolean',
'code' => 'encrypted'
];
/**

View file

@ -11,6 +11,21 @@ class Server extends Model
{
use CastsEnums;
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'virtual_ip' => 'encrypted',
'ssh' => 'encrypted',
'infraweb_ip' => 'encrypted',
'title' => 'encrypted',
'name' => 'encrypted',
'function' => 'encrypted',
'comment' => 'encrypted',
];
/**
* Map attribute names to enum classes.
*

View file

@ -6,6 +6,17 @@ use Illuminate\Database\Eloquent\Model;
class ServiceAccount extends Model
{
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'account' => 'encrypted',
'password' => 'encrypted',
'url' => 'encrypted',
];
/**
* The attributes that are mass assignable.
*

View file

@ -0,0 +1,282 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
class EncryptSensitiveData extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// * Transform varchar 255 to text
Schema::table('projects', function (Blueprint $table) {
$table->text('prod_document_root')->change();
$table->text('dev_document_root')->change();
$table->text('prod_unix_user')->change();
$table->text('prod_unix_pwd')->change();
$table->text('dev_unix_user')->change();
$table->text('dev_unix_pwd')->change();
$table->text('prod_db_user')->change();
$table->text('prod_db_pwd')->change();
$table->text('dev_db_user')->change();
$table->text('dev_db_pwd')->change();
$table->text('prod_db_schema')->change();
$table->text('dev_db_schema')->change();
$table->text('prod_comment')->change();
$table->text('dev_comment')->change();
$table->text('prod_eai')->change();
$table->text('dev_eai')->change();
$table->text('prod_whitelist_fw')->change();
$table->text('dev_whitelist_fw')->change();
$table->text('dev_htaccess_user')->change();
$table->text('dev_htaccess_pwd')->change();
$table->text('prod_ga_id')->change();
$table->text('prod_laravel_app_key')->change();
$table->text('dev_laravel_app_key')->change();
$table->text('prod_smtp_config')->change();
$table->text('prod_smtp_key')->change();
$table->text('prod_haproxy_id')->change();
$table->text('dev_haproxy_id')->change();
});
Schema::table('servers', function (Blueprint $table) {
$table->text('virtual_ip')->change();
$table->text('ssh')->change();
$table->text('infraweb_ip')->change();
$table->text('title')->change();
$table->text('name')->change();
$table->text('function')->change();
$table->text('comment')->nullable()->change();
});
Schema::table('ldc_networks', function (Blueprint $table) {
$table->text('cidr')->change();
$table->text('first_ip')->change();
$table->text('last_ip')->change();
$table->timestamp('updated_at')->nullable()->default(null)->change();
});
Schema::table('service_accounts', function (Blueprint $table) {
$table->text('account')->change();
$table->text('password')->change();
$table->text('url')->change();
});
Schema::table('users', function (Blueprint $table) {
$table->text('totp_secret')->change();
});
// * encrypt columns
DB::table('projects')->get()->map(function (object $row) {
DB::table('projects')->where('id', $row->id)
->update([
'dev_login' => Crypt::encryptString($row->dev_login),
'prod_login' => Crypt::encryptString($row->prod_login),
'prod_document_root' => Crypt::encryptString($row->prod_document_root),
'dev_document_root' => Crypt::encryptString($row->dev_document_root),
'prod_unix_user' => Crypt::encryptString($row->prod_unix_user),
'prod_unix_pwd' => Crypt::encryptString($row->prod_unix_pwd),
'dev_unix_user' => Crypt::encryptString($row->dev_unix_user),
'dev_unix_pwd' => Crypt::encryptString($row->dev_unix_pwd),
'prod_db_user' => Crypt::encryptString($row->prod_db_user),
'prod_db_pwd' => Crypt::encryptString($row->prod_db_pwd),
'dev_db_user' => Crypt::encryptString($row->dev_db_user),
'dev_db_pwd' => Crypt::encryptString($row->dev_db_pwd),
'prod_db_schema' => Crypt::encryptString($row->prod_db_schema),
'dev_db_schema' => Crypt::encryptString($row->dev_db_schema),
'prod_comment' => Crypt::encryptString($row->prod_comment),
'dev_comment' => Crypt::encryptString($row->dev_comment),
'prod_eai' => Crypt::encryptString($row->prod_eai),
'dev_eai' => Crypt::encryptString($row->dev_eai),
'prod_whitelist_fw' => Crypt::encryptString($row->prod_whitelist_fw),
'dev_whitelist_fw' => Crypt::encryptString($row->dev_whitelist_fw),
'dev_htaccess_user' => Crypt::encryptString($row->dev_htaccess_user),
'dev_htaccess_pwd' => Crypt::encryptString($row->dev_htaccess_pwd),
'prod_ga_id' => Crypt::encryptString($row->prod_ga_id),
'prod_laravel_app_key' => Crypt::encryptString($row->prod_laravel_app_key),
'dev_laravel_app_key' => Crypt::encryptString($row->dev_laravel_app_key),
'prod_smtp_config' => Crypt::encryptString($row->prod_smtp_config),
'prod_smtp_key' => Crypt::encryptString($row->prod_smtp_key),
'prod_haproxy_id' => Crypt::encryptString($row->prod_haproxy_id),
'dev_haproxy_id' => Crypt::encryptString($row->dev_haproxy_id),
]);
});
DB::table('servers')->get()->map(function (object $row) {
DB::table('servers')->where('id', $row->id)
->update([
'virtual_ip' => Crypt::encryptString($row->virtual_ip),
'ssh' => Crypt::encryptString($row->ssh),
'infraweb_ip' => Crypt::encryptString($row->infraweb_ip),
'title' => Crypt::encryptString($row->title),
'name' => Crypt::encryptString($row->name),
'function' => Crypt::encryptString($row->function),
'comment' => Crypt::encryptString($row->comment),
]);
});
DB::table('ldc_networks')->get()->map(function (object $row) {
DB::table('ldc_networks')->where('id', $row->id)
->update([
'cidr' => Crypt::encryptString($row->cidr),
'first_ip' => Crypt::encryptString($row->first_ip),
'last_ip' => Crypt::encryptString($row->last_ip),
]);
});
DB::table('project_status_checkers')->get()->map(function (object $row) {
DB::table('project_status_checkers')->where('id', $row->id)
->update([
'code' => Crypt::encryptString($row->code)
]);
});
DB::table('service_accounts')->get()->map(function (object $row) {
DB::table('service_accounts')->where('id', $row->id)
->update([
'account' => Crypt::encryptString($row->account),
'password' => Crypt::encryptString($row->password),
'url' => Crypt::encryptString($row->url)
]);
});
DB::table('users')->get()->map(function (object $row) {
DB::table('users')->where('id', $row->id)
->update([
'totp_secret' => Crypt::encryptString($row->totp_secret),
]);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// * decrypt columns
DB::table('projects')->get()->map(function (object $row) {
DB::table('projects')->where('id', $row->id)
->update([
'dev_login' => Crypt::decryptString($row->dev_login),
'prod_login' => Crypt::decryptString($row->prod_login),
'prod_document_root' => Crypt::decryptString($row->prod_document_root),
'dev_document_root' => Crypt::decryptString($row->dev_document_root),
'prod_unix_user' => Crypt::decryptString($row->prod_unix_user),
'prod_unix_pwd' => Crypt::decryptString($row->prod_unix_pwd),
'dev_unix_user' => Crypt::decryptString($row->dev_unix_user),
'dev_unix_pwd' => Crypt::decryptString($row->dev_unix_pwd),
'prod_db_user' => Crypt::decryptString($row->prod_db_user),
'prod_db_pwd' => Crypt::decryptString($row->prod_db_pwd),
'dev_db_user' => Crypt::decryptString($row->dev_db_user),
'dev_db_pwd' => Crypt::decryptString($row->dev_db_pwd),
'prod_db_schema' => Crypt::decryptString($row->prod_db_schema),
'dev_db_schema' => Crypt::decryptString($row->dev_db_schema),
'prod_comment' => Crypt::decryptString($row->prod_comment),
'dev_comment' => Crypt::decryptString($row->dev_comment),
'prod_eai' => Crypt::decryptString($row->prod_eai),
'dev_eai' => Crypt::decryptString($row->dev_eai),
'prod_whitelist_fw' => Crypt::decryptString($row->prod_whitelist_fw),
'dev_whitelist_fw' => Crypt::decryptString($row->dev_whitelist_fw),
'dev_htaccess_user' => Crypt::decryptString($row->dev_htaccess_user),
'dev_htaccess_pwd' => Crypt::decryptString($row->dev_htaccess_pwd),
'prod_ga_id' => Crypt::decryptString($row->prod_ga_id),
'prod_laravel_app_key' => Crypt::decryptString($row->prod_laravel_app_key),
'dev_laravel_app_key' => Crypt::decryptString($row->dev_laravel_app_key),
'prod_smtp_config' => Crypt::decryptString($row->prod_smtp_config),
'prod_smtp_key' => Crypt::decryptString($row->prod_smtp_key),
'prod_haproxy_id' => Crypt::decryptString($row->prod_haproxy_id),
'dev_haproxy_id' => Crypt::decryptString($row->dev_haproxy_id),
]);
});
DB::table('servers')->get()->map(function (object $row) {
DB::table('servers')->where('id', $row->id)
->update([
'virtual_ip' => Crypt::decryptString($row->virtual_ip),
'ssh' => Crypt::decryptString($row->ssh),
'infraweb_ip' => Crypt::decryptString($row->infraweb_ip),
'title' => Crypt::decryptString($row->title),
'name' => Crypt::decryptString($row->name),
'function' => Crypt::decryptString($row->function),
'comment' => Crypt::decryptString($row->comment),
]);
});
DB::table('ldc_networks')->get()->map(function (object $row) {
DB::table('ldc_networks')->where('id', $row->id)
->update([
'cidr' => Crypt::decryptString($row->cidr),
'first_ip' => Crypt::decryptString($row->first_ip),
'last_ip' => Crypt::decryptString($row->last_ip),
]);
});
DB::table('project_status_checkers')->get()->map(function (object $row) {
DB::table('project_status_checkers')->where('id', $row->id)
->update([
'code' => Crypt::decryptString($row->code)
]);
});
DB::table('service_accounts')->get()->map(function (object $row) {
DB::table('service_accounts')->where('id', $row->id)
->update([
'account' => Crypt::decryptString($row->account),
'password' => Crypt::decryptString($row->password),
'url' => Crypt::decryptString($row->url)
]);
});
DB::table('users')->get()->map(function (object $row) {
DB::table('users')->where('id', $row->id)
->update([
'totp_secret' => Crypt::decryptString($row->totp_secret),
]);
});
Schema::table('users', function (Blueprint $table) {
$table->string('totp_secret', 100)->change();
});
Schema::table('ldc_networks', function (Blueprint $table) {
$table->string('cidr', 50)->change();
$table->string('first_ip', 50)->change();
$table->string('last_ip', 50)->change();
});
Schema::table('projects', function (Blueprint $table) {
$table->string('prod_document_root')->change();
$table->string('dev_document_root')->change();
$table->string('prod_unix_user')->change();
$table->string('prod_unix_pwd')->change();
$table->string('dev_unix_user')->change();
$table->string('dev_unix_pwd')->change();
$table->string('prod_db_user')->change();
$table->string('prod_db_pwd')->change();
$table->string('dev_db_user')->change();
$table->string('dev_db_pwd')->change();
$table->string('prod_db_schema')->change();
$table->string('dev_db_schema')->change();
$table->string('prod_comment')->change();
$table->string('dev_comment')->change();
$table->string('prod_eai')->change();
$table->string('dev_eai')->change();
$table->string('prod_whitelist_fw')->change();
$table->string('dev_whitelist_fw')->change();
$table->string('dev_htaccess_user')->change();
$table->string('dev_htaccess_pwd')->change();
$table->string('prod_ga_id', 50)->change();
$table->string('prod_laravel_app_key')->change();
$table->string('dev_laravel_app_key')->change();
$table->string('prod_smtp_config')->change();
$table->string('prod_smtp_key')->change();
$table->string('prod_haproxy_id')->change();
$table->string('dev_haproxy_id')->change();
});
Schema::table('servers', function (Blueprint $table) {
$table->string('virtual_ip', 20)->change();
$table->string('ssh', 50)->change();
$table->string('infraweb_ip', 20)->change();
$table->string('title', 50)->change();
$table->string('name', 50)->change();
$table->string('function', 50)->change();
$table->string('comment')->nullable()->change();
});
Schema::table('service_accounts', function (Blueprint $table) {
$table->string('account')->change();
$table->string('password')->change();
$table->string('url')->change();
});
}
}

View file

@ -66,7 +66,7 @@
$data = [
'name' => 'dev_login',
'url' => $project->dev_bo_url ?? '',
'type' => $project->type ?? '',
'type' => $project->type->value ?? '',
'dataList' => json_decode(old('dev_login', json_encode(optional($project ?? null)->dev_login ?? [])))
];
@endphp
@ -78,7 +78,7 @@
$data = [
'name' => 'prod_login',
'url' => $project->prod_bo_url ?? '',
'type' => $project->type ?? '',
'type' => $project->type->value ?? '',
'dataList' => json_decode(old('prod_login', json_encode(optional($project ?? null)->prod_login ?? [])))
];
@endphp