diff --git a/auth_totp_bypass_ip_range/README.rst b/auth_totp_bypass_ip_range/README.rst new file mode 100644 index 000000000..c40becdeb --- /dev/null +++ b/auth_totp_bypass_ip_range/README.rst @@ -0,0 +1,119 @@ +=================== +IP based MFA bypass +=================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:293829077d34925720abfd9ded62f8faa4f395c144d03ecd0e5c7d8091d5bf55 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github + :target: https://github.com/OCA/server-auth/tree/16.0/auth_totp_bypass_ip_range + :alt: OCA/server-auth +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-auth-16-0/server-auth-16-0-auth_totp_bypass_ip_range + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to define some IP networks as not needing multi +factor authentication. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure this module, you need to: + +1. Enable debug mode +2. Go to Settings / Technical / System parameters +3. Create or edit parameter ``auth_totp_bypass_ip_range.networks`` + +The parameter can contain a whitespace separated list of networks in +`CIDR +notation `__. +A specific IP address would be ie 42.42.42.42/32 + +Usage +===== + +To use this module, you need to: + +1. Enable 2FA for some user +2. Connect from an IP that was configured to bypass 2FA +3. Observe that no 2FA challenge is raised + +Known issues / Roadmap +====================== + +- support IPv6 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Hunki Enterprises BV + +Contributors +------------ + +- Holger Brunn + (https://hunki-enterprises.com) + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-hbrunn| image:: https://github.com/hbrunn.png?size=40px + :target: https://github.com/hbrunn + :alt: hbrunn + +Current `maintainer `__: + +|maintainer-hbrunn| + +This module is part of the `OCA/server-auth `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/auth_totp_bypass_ip_range/__init__.py b/auth_totp_bypass_ip_range/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/auth_totp_bypass_ip_range/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/auth_totp_bypass_ip_range/__manifest__.py b/auth_totp_bypass_ip_range/__manifest__.py new file mode 100644 index 000000000..5b1d26e6b --- /dev/null +++ b/auth_totp_bypass_ip_range/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2025 Hunki Enterprises BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + +{ + "name": "IP based MFA bypass", + "summary": "Define IP ranges consideres safe without MFA", + "version": "16.0.1.0.0", + "development_status": "Alpha", + "category": "Extra Tools", + "website": "https://github.com/OCA/server-auth", + "author": "Hunki Enterprises BV, Odoo Community Association (OCA)", + "maintainers": ["hbrunn"], + "license": "AGPL-3", + "depends": ["auth_totp"], + "data": [], + "demo": [], +} diff --git a/auth_totp_bypass_ip_range/models/__init__.py b/auth_totp_bypass_ip_range/models/__init__.py new file mode 100644 index 000000000..883516533 --- /dev/null +++ b/auth_totp_bypass_ip_range/models/__init__.py @@ -0,0 +1 @@ +from . import res_users diff --git a/auth_totp_bypass_ip_range/models/res_users.py b/auth_totp_bypass_ip_range/models/res_users.py new file mode 100644 index 000000000..cf7ff5588 --- /dev/null +++ b/auth_totp_bypass_ip_range/models/res_users.py @@ -0,0 +1,43 @@ +# Copyright 2025 Hunki Enterprises BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + +from ipaddress import IPv4Address, IPv4Network + +from odoo import models +from odoo.http import request + + +class ResUsers(models.Model): + _inherit = "res.users" + + def _auth_totp_bypass_ip_range(self): + """ + Determine if the current request comes from an IP that bypasses MFA + """ + networks = ( + self.env["ir.config_parameter"] + .sudo() + .get_param("auth_totp_bypass_ip_range.networks", "") + .split() + ) + ip = IPv4Address(request.httprequest.environ["REMOTE_ADDR"]) + for network in networks: + if ip in IPv4Network(network, strict=False): + return True + return False + + def _mfa_type(self): + """ + Don't do MFA if the request comes from an IP that is configures to bypass it + """ + if self._auth_totp_bypass_ip_range(): + return None + return super()._mfa_type() + + def _mfa_url(self): + """ + Don't do MFA if the request comes from an IP that is configures to bypass it + """ + if self._auth_totp_bypass_ip_range(): + return None + return super()._mfa_url() diff --git a/auth_totp_bypass_ip_range/readme/CONFIGURE.md b/auth_totp_bypass_ip_range/readme/CONFIGURE.md new file mode 100644 index 000000000..caefef774 --- /dev/null +++ b/auth_totp_bypass_ip_range/readme/CONFIGURE.md @@ -0,0 +1,7 @@ +To configure this module, you need to: + +1. Enable debug mode +2. Go to Settings / Technical / System parameters +3. Create or edit parameter ``auth_totp_bypass_ip_range.networks`` + +The parameter can contain a whitespace separated list of networks in [CIDR notation](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation). A specific IP address would be ie 42.42.42.42/32 diff --git a/auth_totp_bypass_ip_range/readme/CONTRIBUTORS.md b/auth_totp_bypass_ip_range/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..cf8bf7205 --- /dev/null +++ b/auth_totp_bypass_ip_range/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Holger Brunn \ (https://hunki-enterprises.com) diff --git a/auth_totp_bypass_ip_range/readme/DESCRIPTION.md b/auth_totp_bypass_ip_range/readme/DESCRIPTION.md new file mode 100644 index 000000000..ae27f25cc --- /dev/null +++ b/auth_totp_bypass_ip_range/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module allows to define some IP networks as not needing multi factor authentication. diff --git a/auth_totp_bypass_ip_range/readme/ROADMAP.md b/auth_totp_bypass_ip_range/readme/ROADMAP.md new file mode 100644 index 000000000..db203ccd7 --- /dev/null +++ b/auth_totp_bypass_ip_range/readme/ROADMAP.md @@ -0,0 +1 @@ +- support IPv6 diff --git a/auth_totp_bypass_ip_range/readme/USAGE.md b/auth_totp_bypass_ip_range/readme/USAGE.md new file mode 100644 index 000000000..1f5318dd3 --- /dev/null +++ b/auth_totp_bypass_ip_range/readme/USAGE.md @@ -0,0 +1,5 @@ +To use this module, you need to: + +1. Enable 2FA for some user +2. Connect from an IP that was configured to bypass 2FA +3. Observe that no 2FA challenge is raised diff --git a/auth_totp_bypass_ip_range/static/description/icon.png b/auth_totp_bypass_ip_range/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/auth_totp_bypass_ip_range/static/description/icon.png differ diff --git a/auth_totp_bypass_ip_range/static/description/index.html b/auth_totp_bypass_ip_range/static/description/index.html new file mode 100644 index 000000000..f32803d87 --- /dev/null +++ b/auth_totp_bypass_ip_range/static/description/index.html @@ -0,0 +1,461 @@ + + + + + +IP based MFA bypass + + + +
+

IP based MFA bypass

+ + +

Alpha License: AGPL-3 OCA/server-auth Translate me on Weblate Try me on Runboat

+

This module allows to define some IP networks as not needing multi +factor authentication.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Configuration

+

To configure this module, you need to:

+
    +
  1. Enable debug mode
  2. +
  3. Go to Settings / Technical / System parameters
  4. +
  5. Create or edit parameter auth_totp_bypass_ip_range.networks
  6. +
+

The parameter can contain a whitespace separated list of networks in +CIDR +notation. +A specific IP address would be ie 42.42.42.42/32

+
+
+

Usage

+

To use this module, you need to:

+
    +
  1. Enable 2FA for some user
  2. +
  3. Connect from an IP that was configured to bypass 2FA
  4. +
  5. Observe that no 2FA challenge is raised
  6. +
+
+
+

Known issues / Roadmap

+
    +
  • support IPv6
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Hunki Enterprises BV
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

hbrunn

+

This module is part of the OCA/server-auth project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/auth_totp_bypass_ip_range/tests/__init__.py b/auth_totp_bypass_ip_range/tests/__init__.py new file mode 100644 index 000000000..847016c76 --- /dev/null +++ b/auth_totp_bypass_ip_range/tests/__init__.py @@ -0,0 +1 @@ +from . import test_auth_totp_bypass_ip_range diff --git a/auth_totp_bypass_ip_range/tests/test_auth_totp_bypass_ip_range.py b/auth_totp_bypass_ip_range/tests/test_auth_totp_bypass_ip_range.py new file mode 100644 index 000000000..39e6d037d --- /dev/null +++ b/auth_totp_bypass_ip_range/tests/test_auth_totp_bypass_ip_range.py @@ -0,0 +1,32 @@ +# Copyright 2025 Hunki Enterprises BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + +from unittest.mock import MagicMock, patch + +from odoo.tests.common import TransactionCase + + +class SomethingCase(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.user = cls.env.ref("base.user_demo") + cls.user.totp_secret = "4242" + + def test_bypass(self): + """Test that demo user can bypass MFA""" + user = self.user.with_user(self.user) + with patch( + "odoo.addons.auth_totp_bypass_ip_range.models.res_users.request", + new=MagicMock, + ) as patched_request: + patched_request.httprequest = MagicMock() + patched_request.httprequest.environ = {"REMOTE_ADDR": "42.42.42.42"} + self.assertTrue(user._mfa_type()) + self.assertTrue(user._mfa_url()) + self.env["ir.config_parameter"].set_param( + "auth_totp_bypass_ip_range.networks", + "1.1.1.0/16\n 42.42.42.42 42.42.1.0/24", + ) + self.assertIsNone(user._mfa_type()) + self.assertIsNone(user._mfa_url()) diff --git a/auth_totp_bypass_ip_range/views/model_name_view.xml b/auth_totp_bypass_ip_range/views/model_name_view.xml new file mode 100644 index 000000000..8c5d2cb08 --- /dev/null +++ b/auth_totp_bypass_ip_range/views/model_name_view.xml @@ -0,0 +1,23 @@ + + + + + My view description + model.name + +
+ +
+
+
+ + + My view description + model.name + + + + + +
diff --git a/auth_totp_bypass_ip_range/views/report_name.xml b/auth_totp_bypass_ip_range/views/report_name.xml new file mode 100644 index 000000000..5fee5df4f --- /dev/null +++ b/auth_totp_bypass_ip_range/views/report_name.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + diff --git a/setup/auth_totp_bypass_ip_range/odoo/addons/auth_totp_bypass_ip_range b/setup/auth_totp_bypass_ip_range/odoo/addons/auth_totp_bypass_ip_range new file mode 120000 index 000000000..f8fda2af0 --- /dev/null +++ b/setup/auth_totp_bypass_ip_range/odoo/addons/auth_totp_bypass_ip_range @@ -0,0 +1 @@ +../../../../auth_totp_bypass_ip_range \ No newline at end of file diff --git a/setup/auth_totp_bypass_ip_range/setup.py b/setup/auth_totp_bypass_ip_range/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/auth_totp_bypass_ip_range/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)