Skip to content

ryan-shaw/django-secrets-fields

Repository files navigation

DJANGO-SECRETS-FIELDS

❯ Encrypted fields in Django

license last-commit code-cov


🔗 Table of Contents


📍 Overview

Django encrypted fields with support for multiple backends, currently supports symmetric encryption using Fernet and AWS Secrets Manager. Two fields types are currently supported, SecretTextField and SecretJSONField.


👾 Features

  • Symmetric Encryption: Encrypt fields using Fernet encryption.
  • AWS Secrets Manager: Use AWS Secrets Manager as a backend for storing secrets.
  • Multiple Backends: Use multiple backends for different fields.

🚀 Getting Started

☑️ Prerequisites

Before getting started with django-secrets-fields, ensure your runtime environment meets the following requirements:

  • Programming Language: Python 3.10+

⚙️ Installation

Install django-secrets-fields:

pip install django-secrets-fields

To use backend that requires AWS install using:

pip install django-secrets-fields[aws]

🤖 Usage

settings.py

DJANGO_SECRETS_FIELDS = {
    "default": {
        "backend": "secrets_fields.backends.encrypted.EncryptedBackend",
        "encryption_key": b"<fernet key>",
    },
    "aws": {
        "backend": "secrets_fields.backends.secretsmanager.SecretsManagerBackend",
        "prefix": "/path/",
    },
}

# If you need to migrate from plaintext fields, set this value to True and run `manage.py migrate_encrypted` - this could take a long time depending on the number of models and instances.
DJANGO_SECRETS_FIELDS_MIGRATE = True

A Fernet key can be generated using the following command:

python manage.py generate_fernet_key

models.py

from django.db import models
from secrets_fields.fields import SecretJSONField, SecretTextField


class MyModel(models.Model):
	secret_text = SecretTextField(backend="aws")
	secret_json = SecretJSONField()

📌 Project Roadmap

  • Symmetric backend: Add symmetric encryption backend.
  • Asymmetric backedn: Add asymmetric encryption backend.
  • AWS Parameter Store: Add AWS Parameter Store backend.

🔰 Contributing

Contributing Guidelines
  1. Fork the Repository: Start by forking the project repository to your github account.
  2. Clone Locally: Clone the forked repository to your local machine using a git client.
    git clone https://github.com/ryan-shaw/django-secrets-fields
  3. Create a New Branch: Always work on a new branch, giving it a descriptive name.
    git checkout -b new-feature-x
  4. Make Your Changes: Develop and test your changes locally.
  5. Commit Your Changes: Commit with a clear message describing your updates.
    git commit -m 'Implemented new feature x.'
  6. Push to github: Push the changes to your forked repository.
    git push origin new-feature-x
  7. Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.
  8. Review: Once your PR is reviewed and approved, it will be merged into the main branch. Congratulations on your contribution!
Contributor Graph


🎗 License

This project is protected under the MIT License. For more details, refer to the LICENSE file.


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages