mirror of
https://github.com/stancl/tenancy-docs.git
synced 2025-12-12 02:04:03 +00:00
Add documentation page for encrypted tenant attributes (#174)
* wip docs page related to `archtechx/tenancy/issues/760` * Update encrypt-attributes.blade.md * Update the docs page * Minor update * Update the page * Update first attribute encryption paragraph * Improve wording Co-authored-by: Samuel Štancl <samuel@archte.ch> * Update hyperlink * Change 'tenants migration' to 'tenants table' * Move Tenant attribute encryption in the navigation * Remove virtual column hyperlink Co-authored-by: lukinovec <lukinovec@gmail.com> Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
parent
d09e4864ae
commit
e9aef34d94
3 changed files with 17549 additions and 23 deletions
|
|
@ -209,6 +209,7 @@ return [
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'Console commands' => 'console-commands',
|
'Console commands' => 'console-commands',
|
||||||
|
'Tenant attribute encryption' => 'tenant-attribute-encryption',
|
||||||
'Cached lookup' => 'cached-lookup',
|
'Cached lookup' => 'cached-lookup',
|
||||||
'Real-time facades' => 'realtime-facades',
|
'Real-time facades' => 'realtime-facades',
|
||||||
'Tenant maintenance mode' => 'tenant-maintenance-mode',
|
'Tenant maintenance mode' => 'tenant-maintenance-mode',
|
||||||
|
|
|
||||||
17506
package-lock.json
generated
17506
package-lock.json
generated
File diff suppressed because it is too large
Load diff
65
source/docs/v3/tenant-attribute-encryption.blade.md
Normal file
65
source/docs/v3/tenant-attribute-encryption.blade.md
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
---
|
||||||
|
title: Tenant attribute encryption
|
||||||
|
extends: _layouts.documentation
|
||||||
|
section: content
|
||||||
|
---
|
||||||
|
|
||||||
|
# Tenant attribute encryption {#encrypt}
|
||||||
|
|
||||||
|
To encrypt attributes on the Tenant model, store them in [custom columns]({{ $page->link('tenants/#custom-columns') }}) and cast the attributes to `'encrypted'`, or your custom encryption cast.
|
||||||
|
|
||||||
|
For example, we'll encrypt the tenant's database credentials – `tenancy_db_username` and `tenancy_db_password`. We need to create custom columns for these attributes, because by default, they are stored in the virtual `data` column.
|
||||||
|
|
||||||
|
- Add custom columns to the tenants table (we recommend making the string size at least 512 characters, so the string is capable of containing the encrypted data):
|
||||||
|
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateTenantsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('tenants', function (Blueprint $table) {
|
||||||
|
$table->string('id')->primary();
|
||||||
|
|
||||||
|
// Your custom columns
|
||||||
|
$table->string('tenancy_db_username', 512);
|
||||||
|
$table->string('tenancy_db_password', 512);
|
||||||
|
|
||||||
|
$table->timestamps();
|
||||||
|
$table->json('data')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- Define the custom columns on the Tenant model:
|
||||||
|
|
||||||
|
```php
|
||||||
|
public static function getCustomColumns(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id',
|
||||||
|
'tenancy_db_username',
|
||||||
|
'tenancy_db_password',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- Then define casts for the attributes on the model (using [Laravel's encrypted casts](https://laravel.com/docs/9.x/eloquent-mutators#encrypted-casting), or your custom casts):
|
||||||
|
|
||||||
|
```php
|
||||||
|
protected $casts = [
|
||||||
|
'tenancy_db_username' => 'encrypted',
|
||||||
|
'tenancy_db_password' => 'encrypted',
|
||||||
|
];
|
||||||
|
```
|
||||||
Loading…
Add table
Add a link
Reference in a new issue