Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add event payload cryptographer for personal data #546

Merged
merged 3 commits into from
Mar 25, 2024
Merged

Conversation

DavidBadura
Copy link
Member

@DavidBadura DavidBadura commented Mar 19, 2024

I took this blog post as inspiration and built a prototype:

https://www.eventstore.com/blog/protecting-sensitive-data-in-event-sourced-systems-with-crypto-shredding-1

This is what an event looks like when you use personal data:

<?php
use Patchlevel\EventSourcing\Attribute\DataSubjectId;
use Patchlevel\EventSourcing\Attribute\Event;
use Patchlevel\EventSourcing\Attribute\PersonalData;
use Patchlevel\EventSourcing\Serializer\Normalizer\IdNormalizer;

#[Event('profile.created')]
final class ProfileCreated
{
    public function __construct(
        #[IdNormalizer]
        #[DataSubjectId]
        public ProfileId $profileId,
        #[PersonalData(fallback: 'unknown')]
        public string $name,
    ) {
    }
}

And you can use a processor to remove personal data:

use Patchlevel\EventSourcing\Attribute\Processor;
use Patchlevel\EventSourcing\Attribute\Subscribe;
use Patchlevel\EventSourcing\Cryptography\Store\CipherKeyStore;
use Patchlevel\EventSourcing\Message\Message;

#[Processor('delete_personal_data')]
final class DeletePersonalDataProcessor
{
    public function __construct(
        private readonly CipherKeyStore $cipherKeyStore,
    ) {
    }

    #[Subscribe(UserHasRequestedDeletion::class)]
    public function handleUserHasRequestedDeletion(Message $message): void
    {
        $event = $message->event();

        $this->cipherKeyStore->remove($event->profileId->toString());
    }
}

@DavidBadura DavidBadura added the enhancement New feature or request label Mar 19, 2024
Copy link

github-actions bot commented Mar 19, 2024

Hello 👋

here is the most recent benchmark result:

SubscriptionEngineBench
=======================

+---------------------------+-----------------+-----------------+-----------------+------------+
|                           | time (kde mode)                   | memory                       |
+---------------------------+-----------------+-----------------+-----------------+------------+
| subject                   | Tag: <current>  | Tag: base       | Tag: <current>  | Tag: base  |
+---------------------------+-----------------+-----------------+-----------------+------------+
| benchHandle10000Events () | 3.253s (±0.00%) | 3.231s (±0.00%) | 37.782mb        | 37.764mb   |
+---------------------------+-----------------+-----------------+-----------------+------------+

PersonalDataBench
=================

+----------------------------------------+--------------------+-----------------+
|                                        | time (kde mode)    | memory          |
+----------------------------------------+--------------------+-----------------+
| subject                                | Tag: <current>     | Tag: <current>  |
+----------------------------------------+--------------------+-----------------+
| benchLoad10000Events ()                | 231.896ms (±0.00%) | 39.980mb        |
| benchSave1Event ()                     | 1.455ms (±0.00%)   | 39.980mb        |
| benchSave10000Events ()                | 481.688ms (±0.00%) | 39.983mb        |
| benchSave10000Aggregates ()            | 14.107s (±0.00%)   | 39.980mb        |
| benchSave10000AggregatesTransaction () | 11.807s (±0.00%)   | 40.482mb        |
+----------------------------------------+--------------------+-----------------+

SplitStreamBench
================

+-------------------------+--------------------+--------------------+-----------------+------------+
|                         | time (kde mode)                         | memory                       |
+-------------------------+--------------------+--------------------+-----------------+------------+
| subject                 | Tag: <current>     | Tag: base          | Tag: <current>  | Tag: base  |
+-------------------------+--------------------+--------------------+-----------------+------------+
| benchLoad10000Events () | 5.475ms (±0.00%)   | 5.498ms (±0.00%)   | 41.234mb        | 41.203mb   |
| benchSave10000Events () | 556.626ms (±0.00%) | 568.987ms (±0.00%) | 41.244mb        | 41.222mb   |
+-------------------------+--------------------+--------------------+-----------------+------------+

SimpleSetupBench
================

+----------------------------------------+--------------------+--------------------+-----------------+------------+
|                                        | time (kde mode)                         | memory                       |
+----------------------------------------+--------------------+--------------------+-----------------+------------+
| subject                                | Tag: <current>     | Tag: base          | Tag: <current>  | Tag: base  |
+----------------------------------------+--------------------+--------------------+-----------------+------------+
| benchLoad10000Events ()                | 154.010ms (±0.00%) | 152.617ms (±0.00%) | 37.343mb        | 37.324mb   |
| benchSave1Event ()                     | 949.500μs (±0.00%) | 969.600μs (±0.00%) | 37.343mb        | 37.324mb   |
| benchSave10000Events ()                | 440.978ms (±0.00%) | 394.101ms (±0.00%) | 37.343mb        | 37.333mb   |
| benchSave10000Aggregates ()            | 9.689s (±0.00%)    | 9.879s (±0.00%)    | 37.343mb        | 37.324mb   |
| benchSave10000AggregatesTransaction () | 7.429s (±0.00%)    | 7.455s (±0.00%)    | 37.343mb        | 37.324mb   |
+----------------------------------------+--------------------+--------------------+-----------------+------------+

SnapshotsBench
==============

+----------------------------------------+--------------------+--------------------+-----------------+------------+
|                                        | time (kde mode)                         | memory                       |
+----------------------------------------+--------------------+--------------------+-----------------+------------+
| subject                                | Tag: <current>     | Tag: base          | Tag: <current>  | Tag: base  |
+----------------------------------------+--------------------+--------------------+-----------------+------------+
| benchLoad10000EventsMissingSnapshot () | 153.172ms (±0.00%) | 154.625ms (±0.00%) | 37.361mb        | 37.343mb   |
| benchLoad10000Events ()                | 514.500μs (±0.00%) | 513.900μs (±0.00%) | 37.361mb        | 37.343mb   |
+----------------------------------------+--------------------+--------------------+-----------------+------------+

This comment gets update everytime a new commit comes in!

@DavidBadura DavidBadura force-pushed the personal-data branch 7 times, most recently from 3fbf35e to 5133209 Compare March 19, 2024 22:37
@DavidBadura DavidBadura added this to the 3.0.0 milestone Mar 19, 2024
@DavidBadura DavidBadura changed the title poc personal data add event payload cryptographer for personal data Mar 19, 2024
@DavidBadura DavidBadura force-pushed the personal-data branch 6 times, most recently from 5a239f6 to 8f46d96 Compare March 20, 2024 12:59
@DavidBadura DavidBadura marked this pull request as ready for review March 20, 2024 15:49
@DavidBadura DavidBadura merged commit e3da365 into 3.0.x Mar 25, 2024
35 of 36 checks passed
@DavidBadura DavidBadura deleted the personal-data branch March 25, 2024 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants