[GH-ISSUE #16112] feat: encryption at rest with url like sqlite+sqlcipher:// #33314

Closed
opened 2026-04-25 07:13:37 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @rndmcnlly on GitHub (Jul 29, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/16112

Check Existing Issues

  • I have searched the existing issues and discussions.

Problem Description

I'd like to do a low-resource deployment of OWUI while encrypting user data at rest. In the past, I configured DATABASE_URL to point at a remote encrypted database instance, but I want to get the same effect within a single Docker container (like the default setup with sqlite, but encrypted).

Desired Solution you'd like

I'd like OWUI to check the the DATABASE_URL config for URLs like sqlite+sqlcipher:// and to use the sqlcipher3 Python package set up the connection before handing it back to the existing SQLAlchemy machinery. OWUI already contains URL parsing logic to customize engine creation in other ways.

Alternatives Considered

sqlite+pysqlcipher:// (note the "py")

SQLAlchemy already has some awareness of the SQLCipher URL scheme, but the drivers have long gone unsupported and the official docs recommend using the alternative sqlcipher3 driver instead: https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#pysqlcipher

Additional Context

Here's a sketch of how to customize the creator argument of create_engine to achieve the desired behavior:

from sqlalchemy import create_engine, text
import sqlcipher3


def create_database_engine(database_url, encryption_key=None):
    """Create SQLAlchemy engine - handles both sqlite:// and sqlite+sqlcipher:// URLs."""
    
    if database_url.startswith('sqlite+sqlcipher://'):
        # Extract path and create custom connection
        db_path = database_url.replace('sqlite+sqlcipher://', '')
        if not db_path.startswith('/'):
            db_path = '/' + db_path
        
        def creator():
            conn = sqlcipher3.connect(db_path)
            if encryption_key:
                conn.execute(f"PRAGMA key = '{encryption_key}'")
            return conn
        
        return create_engine(f"sqlite://{db_path}", creator=creator)
    else:
        # Regular SQLite
        return create_engine(database_url)

Even though big enterprise users will have their own encrypted database solution, showing that OWUI can be configured to support encryption at rest might help people run the small-scale pilot projects that let you snag those bigger enterprise customers later on.

Hat tip to the creator of the Cotypist LLM-based autocomplete app for explaining to me how to use SQLCipher to easily protect sensitive user data in a system that is already using SQLite. Both OWUI and Cotypist involve people typing potentially sensitive things into LLMs while not entirely trusting the system administrators to keep the host disk fully private.

Originally created by @rndmcnlly on GitHub (Jul 29, 2025). Original GitHub issue: https://github.com/open-webui/open-webui/issues/16112 ### Check Existing Issues - [x] I have searched the existing issues and discussions. ### Problem Description I'd like to do a low-resource deployment of OWUI while encrypting user data at rest. In the past, I configured `DATABASE_URL` to point at a remote encrypted database instance, but I want to get the same effect within a single Docker container (like the default setup with sqlite, but encrypted). ### Desired Solution you'd like I'd like OWUI to check the the `DATABASE_URL` config for URLs like `sqlite+sqlcipher://` and to use the `sqlcipher3` Python package set up the connection before handing it back to the existing SQLAlchemy machinery. OWUI already contains URL parsing logic to customize engine creation in other ways. ### Alternatives Considered ### `sqlite+pysqlcipher://` (note the "py") SQLAlchemy already has some awareness of the SQLCipher URL scheme, but the drivers have long gone unsupported and the official docs recommend using the alternative `sqlcipher3` driver instead: https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#pysqlcipher ### Additional Context Here's a sketch of how to customize the `creator` argument of `create_engine` to achieve the desired behavior: ```python from sqlalchemy import create_engine, text import sqlcipher3 def create_database_engine(database_url, encryption_key=None): """Create SQLAlchemy engine - handles both sqlite:// and sqlite+sqlcipher:// URLs.""" if database_url.startswith('sqlite+sqlcipher://'): # Extract path and create custom connection db_path = database_url.replace('sqlite+sqlcipher://', '') if not db_path.startswith('/'): db_path = '/' + db_path def creator(): conn = sqlcipher3.connect(db_path) if encryption_key: conn.execute(f"PRAGMA key = '{encryption_key}'") return conn return create_engine(f"sqlite://{db_path}", creator=creator) else: # Regular SQLite return create_engine(database_url) ``` Even though big enterprise users will have their own encrypted database solution, showing that OWUI can be configured to support encryption at rest might help people run the small-scale pilot projects that let you snag those bigger enterprise customers later on. Hat tip to the creator of the [Cotypist](https://cotypist.app/) LLM-based autocomplete app for explaining to me how to use SQLCipher to easily protect sensitive user data in a system that is already using SQLite. Both OWUI and Cotypist involve people typing potentially sensitive things into LLMs while not _entirely_ trusting the system administrators to keep the host disk fully private.
Author
Owner

@tjbck commented on GitHub (Jul 29, 2025):

Agreed, PR welcome!

<!-- gh-comment-id:3131191832 --> @tjbck commented on GitHub (Jul 29, 2025): Agreed, PR welcome!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#33314