|
| 1 | +==================== |
| 2 | +Base Field Encrypted |
| 3 | +==================== |
| 4 | + |
| 5 | +.. |
| 6 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 7 | + !! This file is generated by oca-gen-addon-readme !! |
| 8 | + !! changes will be overwritten. !! |
| 9 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 10 | + !! source digest: sha256:06e7f89cc87e56516e52403b660a0a674b99f951dc070feeb58654e05f89946c |
| 11 | + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 12 | +
|
| 13 | +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png |
| 14 | + :target: https://odoo-community.org/page/development-status |
| 15 | + :alt: Beta |
| 16 | +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png |
| 17 | + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html |
| 18 | + :alt: License: AGPL-3 |
| 19 | +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github |
| 20 | + :target: https://github.com/OCA/server-auth/tree/16.0/base_field_encrypted |
| 21 | + :alt: OCA/server-auth |
| 22 | +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png |
| 23 | + :target: https://translation.odoo-community.org/projects/server-auth-16-0/server-auth-16-0-base_field_encrypted |
| 24 | + :alt: Translate me on Weblate |
| 25 | +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png |
| 26 | + :target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=16.0 |
| 27 | + :alt: Try me on Runboat |
| 28 | + |
| 29 | +|badge1| |badge2| |badge3| |badge4| |badge5| |
| 30 | + |
| 31 | +This module provides a generic mixin to symmetrically encrypt data in the database |
| 32 | +while maintaining a standard Python workflow for developers. |
| 33 | + |
| 34 | +Odoo natively handles `password="True"` on views by sending plaintext data |
| 35 | +to the client, where the browser masks it. This module intercepts reads and writes |
| 36 | +to implement actual "data at rest" encryption using the `cryptography` library. |
| 37 | + |
| 38 | +**Table of contents** |
| 39 | + |
| 40 | +.. contents:: |
| 41 | + :local: |
| 42 | + |
| 43 | +Configuration |
| 44 | +============= |
| 45 | + |
| 46 | +To use this module, you need to configure a master encryption key in your |
| 47 | +``odoo.conf`` file: |
| 48 | + |
| 49 | +1. Generate a URL-safe base64-encoded 32-byte key. You have two options: |
| 50 | + |
| 51 | + **Option A (Recommended - UI Wizard):** |
| 52 | + - Log in as an Administrator (with "Settings" access). |
| 53 | + - Go to Settings > Technical > Security > Generate Encryption Key (Fernet). |
| 54 | + - Copy the generated key. |
| 55 | + |
| 56 | + **Option B (Terminal):** |
| 57 | + .. code-block:: python |
| 58 | +
|
| 59 | + from cryptography.fernet import Fernet |
| 60 | + print(Fernet.generate_key().decode()) |
| 61 | +
|
| 62 | +2. Add the copied key to your configuration file under the ``[options]`` section: |
| 63 | + |
| 64 | + .. code-block:: ini |
| 65 | +
|
| 66 | + [options] |
| 67 | + encryption_key = <YOUR_GENERATED_KEY> |
| 68 | +
|
| 69 | +3. Restart your Odoo server. |
| 70 | + |
| 71 | +If no key is configured, or the key is invalid, the module will log a warning |
| 72 | +and fallback to storing data in plaintext to prevent data loss. |
| 73 | + |
| 74 | +**WARNING:** The encryption key is NOT stored in the database. If you lose |
| 75 | +the key, all previously encrypted fields will become permanently unreadable. |
| 76 | +Keep your ``odoo.conf`` safe. |
| 77 | + |
| 78 | +Usage |
| 79 | +===== |
| 80 | + |
| 81 | +To use the encryption capabilities in your own custom models: |
| 82 | + |
| 83 | +1. Inherit the mixin in your model: |
| 84 | + |
| 85 | + .. code-block:: python |
| 86 | +
|
| 87 | + class MyIntegration(models.Model): |
| 88 | + _name = 'my.integration' |
| 89 | + _inherit = ['encryption.mixin'] |
| 90 | +
|
| 91 | + api_secret = fields.Char(string="API Secret", encrypted=True) |
| 92 | +
|
| 93 | +2. In your XML view, use the native `password="True"` attribute so the frontend masks it: |
| 94 | + |
| 95 | + .. code-block:: xml |
| 96 | +
|
| 97 | + <field name="api_secret" password="True" /> |
| 98 | +
|
| 99 | +Internal Python code can access `record.api_secret` normally and will receive the |
| 100 | +decrypted plaintext value. The web client will only receive `********`. |
| 101 | + |
| 102 | +Bug Tracker |
| 103 | +=========== |
| 104 | + |
| 105 | +Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-auth/issues>`_. |
| 106 | +In case of trouble, please check there if your issue has already been reported. |
| 107 | +If you spotted it first, help us to smash it by providing a detailed and welcomed |
| 108 | +`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20base_field_encrypted%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
| 109 | + |
| 110 | +Do not contact contributors directly about support or help with technical issues. |
| 111 | + |
| 112 | +Credits |
| 113 | +======= |
| 114 | + |
| 115 | +Contributors |
| 116 | +~~~~~~~~~~~~ |
| 117 | + |
| 118 | +* Antonio Ruban <antoniodavid8@gmail.com> |
| 119 | + |
| 120 | +Maintainers |
| 121 | +~~~~~~~~~~~ |
| 122 | + |
| 123 | +This module is maintained by the OCA. |
| 124 | + |
| 125 | +.. image:: https://odoo-community.org/logo.png |
| 126 | + :alt: Odoo Community Association |
| 127 | + :target: https://odoo-community.org |
| 128 | + |
| 129 | +OCA, or the Odoo Community Association, is a nonprofit organization whose |
| 130 | +mission is to support the collaborative development of Odoo features and |
| 131 | +promote its widespread use. |
| 132 | + |
| 133 | +.. |maintainer-antoniodavid| image:: https://github.com/antoniodavid.png?size=40px |
| 134 | + :target: https://github.com/antoniodavid |
| 135 | + :alt: antoniodavid |
| 136 | + |
| 137 | +Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: |
| 138 | + |
| 139 | +|maintainer-antoniodavid| |
| 140 | + |
| 141 | +This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/16.0/base_field_encrypted>`_ project on GitHub. |
| 142 | + |
| 143 | +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
0 commit comments