SeaQL / SeaQL/sea-orm

Model Encryption

Open
#2,792 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
9.9k
Forks
734
Avg merge
6h 36m
Merged PRs (30d)
8

Description

Motivation

I'm wondering if there are any plans or rough ideas of a design for SeaORM to support AEAD for certain fields of a model, similar to Active Record Encryption? It would be great if this could be handled transparently by SeaORM, and 2.0's entity-first approach seems to align quite well.

Proposed Solutions

I imagine the UX could be something like the combination of a macro indicating that a column is encrypted, and accompanying trait implementations for encryption of ActiveModel's and decryption of Models:

#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "example")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    #[sea_orm(encrypted)] // encrypted column
    pub secret: String, 
}

/// Some trait that handles fetching keys and applying encryption on save
impl ActiveModelEncryption for ActiveModel {}

/// Some trait that handles fetching keys and decrypting columns at query time
impl ModelDecryption for Model {}
Alternatives

Perhaps a custom ActiveModel and FromQueryResult struct implementation could accomplish this? However, it would be awesome to be first-class in SeaORM and seems to align with the project's goals.

Additional Information

It would also be interesting to consider how to support the deterministic vs. non-deterministic configurations to allow for querying encrypted data, or migrating from cleartext to encrypted data.
https://guides.rubyonrails.org/active_record_encryption.html#support-for-unencrypted-data

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with SeaORM's custom ActiveModel and FromQueryResult documentation referenced in the issue, then review how model fields and ActiveModels are currently defined. Clarify the scope for AEAD encryption, key handling, deterministic versus non-deterministic behavior, querying, and cleartext migration; done would be an agreed design or implementation plan.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.