diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 81ab3140..0ac01374 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -57,8 +57,8 @@ jobs: strategy: matrix: include: - - PFSENSE_VERSION: pfSense-2.8.1-RELEASE - FREEBSD_ID: freebsd15 + - PFSENSE_VERSION: pfSense-2.9.0-RELEASE + FREEBSD_ID: freebsd16 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 @@ -105,8 +105,8 @@ jobs: strategy: matrix: include: - - PFSENSE_VERSION: pfSense-2.8.1-RELEASE - FREEBSD_ID: freebsd15 + - PFSENSE_VERSION: pfSense-2.9.0-RELEASE + FREEBSD_ID: freebsd16 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 @@ -136,6 +136,10 @@ jobs: FREEBSD_ID: freebsd15 - PFSENSE_VERSION: pfSense-2.9.0-RELEASE FREEBSD_ID: freebsd16 + - PFSENSE_VERSION: pfSense-2.9.1-RELEASE + FREEBSD_ID: freebsd16 + - PFSENSE_VERSION: pfSense-2.9.2-RELEASE + FREEBSD_ID: freebsd16 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 84b20eb8..d745bcd2 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -44,7 +44,7 @@ jobs: needs: ["check_black"] strategy: matrix: - PYTHON_VERSION: ["3.10", "3.11"] + PYTHON_VERSION: ["3.14"] steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Set up Python ${{ matrix.PYTHON_VERSION }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5835c31c..3177ef26 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,7 @@ concurrency: build # Sets global environment variables for releases env: SWAGGER_UI_VERSION: "5.17.10" - PYTHON_VERSION: "3.10" + PYTHON_VERSION: "3.14" DEFAULT_PFSENSE_VERSION: "2.9.0" # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages @@ -30,6 +30,10 @@ jobs: PFSENSE_VERSION: "2.8.1" - FREEBSD_VERSION: FreeBSD-16.0-CURRENT PFSENSE_VERSION: "2.9.0" + - FREEBSD_VERSION: FreeBSD-16.0-CURRENT + PFSENSE_VERSION: "2.9.1" + - FREEBSD_VERSION: FreeBSD-16.0-CURRENT + PFSENSE_VERSION: "2.9.2" - FREEBSD_VERSION: FreeBSD-16.0-CURRENT PFSENSE_VERSION: "25.11.1" - FREEBSD_VERSION: FreeBSD-16.0-CURRENT @@ -38,6 +42,10 @@ jobs: PFSENSE_VERSION: "26.03.1" - FREEBSD_VERSION: FreeBSD-16.0-CURRENT PFSENSE_VERSION: "26.07" + - FREEBSD_VERSION: FreeBSD-16.0-CURRENT + PFSENSE_VERSION: "26.07.1" + - FREEBSD_VERSION: FreeBSD-16.0-CURRENT + PFSENSE_VERSION: "26.07.2" steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 diff --git a/README.md b/README.md index 3687aa56..25440f87 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,10 @@ The pfSense REST API package is an unofficial, open-source REST and GraphQL API firewalls. It is designed to be light-weight, fast, and easy to use. This guide will help you get started with the REST API package and provide you with the information you need to configure and use the package effectively. +> [!IMPORTANT] +> This project will soon come to end. For more information on the path forward and migration to the official +> pfSense API, please refer to the [announcement](https://github.com/pfrest/pfSense-pkg-RESTAPI/discussions/962). + ## Key Features - 200+ REST endpoints available for managing your firewall and associated services @@ -36,13 +40,13 @@ commands are included below for quick reference. Install on pfSense CE: ```bash -pkg-static add https://github.com/pfrest/pfSense-pkg-RESTAPI/releases/latest/download/pfSense-2.8.1-pkg-RESTAPI.pkg +pkg-static add https://github.com/pfrest/pfSense-pkg-RESTAPI/releases/latest/download/pfSense-2.9.2-pkg-RESTAPI.pkg ``` Install on pfSense Plus: ```bash -pkg-static -C /dev/null add https://github.com/pfrest/pfSense-pkg-RESTAPI/releases/latest/download/pfSense-26.03.1-pkg-RESTAPI.pkg +pkg-static -C /dev/null add https://github.com/pfrest/pfSense-pkg-RESTAPI/releases/latest/download/pfSense-26.07.2-pkg-RESTAPI.pkg ``` > [!WARNING] diff --git a/docs/INSTALL_AND_CONFIG.md b/docs/INSTALL_AND_CONFIG.md index a7c5ebfe..3463da6d 100644 --- a/docs/INSTALL_AND_CONFIG.md +++ b/docs/INSTALL_AND_CONFIG.md @@ -16,10 +16,14 @@ run pfSense. It's recommended to follow Netgate's [minimum hardware requirements - pfSense CE 2.8.1 - pfSense CE 2.9.0 +- pfSense CE 2.9.1 +- pfSense CE 2.9.2 - pfSense Plus 25.11.1 - pfSense Plus 26.03 - pfSense Plus 26.03.1 - pfSense Plus 26.07 +- pfSense Plus 26.07.1 +- pfSense Plus 26.07.2 !!! Warning Installation of the package on unsupported versions of pfSense may result in unexpected behavior and/or system instability. diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DHCPServer.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DHCPServer.inc index da29058f..b0c6fe1b 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DHCPServer.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DHCPServer.inc @@ -128,8 +128,8 @@ class DHCPServer extends Model { many: true, maximum_length: 17, verbose_name: 'MAC Allow', - validators: [new MACAddressValidator()], - help_text: 'MAC addresses this DHCP server is allowed to provide leases for.', + validators: [new MACAddressValidator(allow_partial: true)], + help_text: 'MAC addresses this DHCP server is allowed to provide leases for. OUI prefixes (partial MACs, e.g. `EC:71:DB`) are accepted to match all devices of a vendor (GUI parity).', ); $this->mac_deny = new StringField( default: [], @@ -137,8 +137,8 @@ class DHCPServer extends Model { many: true, maximum_length: 17, verbose_name: 'MAC Deny', - validators: [new MACAddressValidator()], - help_text: 'MAC addresses this DHCP server is not allowed to provide leases for.', + validators: [new MACAddressValidator(allow_partial: true)], + help_text: 'MAC addresses this DHCP server is not allowed to provide leases for. OUI prefixes (partial MACs, e.g. `EC:71:DB`) are accepted to match all devices of a vendor (GUI parity).', ); $this->domainsearchlist = new StringField( default: [], diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DHCPServerAddressPool.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DHCPServerAddressPool.inc index 0a4674d2..65265ff1 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DHCPServerAddressPool.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DHCPServerAddressPool.inc @@ -74,18 +74,18 @@ class DHCPServerAddressPool extends Model { allow_empty: true, many: true, maximum_length: 17, - validators: [new MACAddressValidator()], + validators: [new MACAddressValidator(allow_partial: true)], verbose_name: 'MAC Allow', - help_text: 'MAC addresses this DHCP server is allowed to provide leases for.', + help_text: 'MAC addresses this DHCP server is allowed to provide leases for. OUI prefixes (partial MACs, e.g. `EC:71:DB`) are accepted to match all devices of a vendor (GUI parity).', ); $this->mac_deny = new StringField( default: [], allow_empty: true, many: true, maximum_length: 17, - validators: [new MACAddressValidator()], + validators: [new MACAddressValidator(allow_partial: true)], verbose_name: 'MAC Deny', - help_text: 'MAC addresses this DHCP server is not allowed to provide leases for.', + help_text: 'MAC addresses this DHCP server is not allowed to provide leases for. OUI prefixes (partial MACs, e.g. `EC:71:DB`) are accepted to match all devices of a vendor (GUI parity).', ); $this->domainsearchlist = new StringField( default: [], diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/NetworkInterface.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/NetworkInterface.inc index a9bc9b70..ad0f187f 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/NetworkInterface.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/NetworkInterface.inc @@ -61,6 +61,8 @@ class NetworkInterface extends Model { public ForeignModelField $gatewayv6; public BooleanField $ipv6usev4iface; public BooleanField $slaacusev4iface; + public BooleanField $dhcp6prefixonly; + public StringField $dhcp6_ia_pd_len; public StringField $prefix_6rd; public StringField $gateway_6rd; public IntegerField $prefix_6rd_v4plen; @@ -94,10 +96,7 @@ class NetworkInterface extends Model { required: true, unique: true, maximum_length: 128, - validators: [ - new FilterNameValidator(), - new UniqueFromForeignModelValidator(model: 'FirewallAlias', field: 'name'), - ], + validators: [new UniqueFromForeignModelValidator(model: 'FirewallAlias', field: 'name')], verbose_name: 'Description', help_text: 'The descriptive name for this interface.', ); @@ -367,6 +366,43 @@ class NetworkInterface extends Model { verbose_name: 'SLAAC Use IPv4 Interface', help_text: 'Enable or disable IPv6 using the IPv4 connectivity link (PPPoE).', ); + + $this->dhcp6prefixonly = new BooleanField( + default: false, + conditions: ['typev6' => 'dhcp6'], + verbose_name: 'Request Only an IPv6 Prefix', + help_text: 'Only request an IPv6 prefix, do not request an IPv6 address.', + ); + $this->dhcp6_ia_pd_len = new StringField( + required: false, + default: 'none', + allow_empty: false, + conditions: ['typev6' => 'dhcp6'], + choices: [ + 'none', + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + '10', + '11', + '12', + '13', + '14', + '15', + '16', + ], + internal_name: 'dhcp6-ia-pd-len', + maximum_length: 4, + verbose_name: 'DHCPv6 Prefix Delegation size', + help_text: 'The delegated prefix length provided by the DHCPv6 server. `none` disables delegation; numeric values are the IA-PD length (16 -> /48 ... 0 -> /64). Normally specified by the ISP.', + ); $this->prefix_6rd = new StringField( required: true, unique: true, @@ -445,6 +481,16 @@ class NetworkInterface extends Model { * @returns string The validated $descr to set. * @throws ValidationError When the `$descr` value is invalid. */ public function validate_descr(string $descr): string { + # Only apply the filter-name validation when the descr CHANGES. pfSense + # revalidates every field on PATCH, so validating an unchanged value + # would lock entire interfaces whose pre-existing descr predates these + # rules (e.g. 'LAN', which matches a reserved pf filter token) — the + # GUI allows such interfaces to be edited without renaming. + $initial = $this->initial_object; + if ($initial !== null and $initial->descr->value === $descr) { + return $descr; + } + # Ensure OpenVPN interfaces are 22 characters or less if (str_starts_with($this->if->value, 'ovpn') and strlen($descr) > 22) { throw new ValidationError( @@ -477,6 +523,11 @@ class NetworkInterface extends Model { ); } + # Filter-name rules apply to NEW/CHANGED descr values only (moved + # from the field-level validator so unchanged legacy values are + # not re-validated on unrelated PATCHes). + (new FilterNameValidator())->validate($descr, 'descr'); + return $descr; } diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsDHCPServerTestCase.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsDHCPServerTestCase.inc index 48eb6c05..b08d234a 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsDHCPServerTestCase.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsDHCPServerTestCase.inc @@ -677,4 +677,18 @@ class APIModelsDHCPServerTestCase extends TestCase { # Delete the test interface $interface->delete(); } + + /** + * Ensures OUI-partial MAC entries (vendor prefixes, a supported pfSense GUI feature) are accepted in + * mac_allow/mac_deny. Regression test: these fields are revalidated on every PATCH, so strict validation + * locked entire scopes containing legacy partial entries behind HTTP 400 MAC_ADDRESS_VALIDATOR_FAILED. + */ + public function test_accept_oui_partial_mac_entries(): void { + $this->assert_does_not_throw(function (): void { + $dhcp_server = new DHCPServer(id: 'lan', async: false); + $dhcp_server->mac_deny->value = ['EC:71:DB', '00:60:6E', 'B8:27:EB']; + $dhcp_server->mac_allow->value = ['DC:A6:32']; + $dhcp_server->update(); + }); + } } diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsNetworkInterfaceTestCase.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsNetworkInterfaceTestCase.inc index ea6bf6c7..af01b0aa 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsNetworkInterfaceTestCase.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsNetworkInterfaceTestCase.inc @@ -52,7 +52,7 @@ class APIModelsNetworkInterfaceTestCase extends TestCase { $test_model->if->value = 'ovpn1'; # Ensure the validation succeeds when value is an acceptable length - $test_model->validate_descr('length is ok'); + $test_model->validate_descr('lengthisok'); }, ); } @@ -82,7 +82,7 @@ class APIModelsNetworkInterfaceTestCase extends TestCase { $test_model->if->value = 'ipsec1'; # Ensure the validation succeeds when value is an acceptable length - $test_model->validate_descr('length is ok'); + $test_model->validate_descr('lengthisok'); }, ); } @@ -112,7 +112,7 @@ class APIModelsNetworkInterfaceTestCase extends TestCase { $test_model->if->value = 'gif1'; # Ensure the validation succeeds when value is an acceptable length - $test_model->validate_descr('length is ok'); + $test_model->validate_descr('lengthisok'); }, ); } @@ -142,7 +142,7 @@ class APIModelsNetworkInterfaceTestCase extends TestCase { $test_model->if->value = 'gre1'; # Ensure the validation succeeds when value is an acceptable length - $test_model->validate_descr('length is ok'); + $test_model->validate_descr('lengthisok'); }, ); } @@ -876,4 +876,79 @@ class APIModelsNetworkInterfaceTestCase extends TestCase { } # TODO: Needs Tests to ensure other interface types are correctly configured on the backend + + /** + * Checks that a NEW descr value violating filter-name rules is rejected + * (FilterNameValidator now runs in validate_descr for changed values). + */ + public function test_descr_new_value_rejects_reserved_name(): void { + $this->assert_throws_response( + response_id: 'FILTER_NAME_VALIDATOR_RESERVED_NAME_USED', + code: 400, + callable: function () { + $test_model = new NetworkInterface(); + $test_model->if->value = 'igc0'; + $test_model->validate_descr('LAN'); + }, + ); + } + + /** + * Checks that validate_descr accepts reserved legacy values when the + * descr is UNCHANGED from the initial object (regression: pfSense + * revalidates every field on PATCH; validating an unchanged value + * locked whole interfaces whose descr predates the rules). + */ + public function test_descr_unchanged_legacy_value_not_revalidated(): void { + $this->assert_does_not_throw( + callable: function () { + $test_model = new NetworkInterface(); + $test_model->if->value = 'igc0'; + + # Simulate a loaded object whose initial descr is a legacy + # reserved token (e.g. created before the validator existed) + $test_model->initial_object = $test_model->copy(); + $test_model->initial_object->descr->value = 'LAN'; + $test_model->descr->value = 'LAN'; + + # Unchanged descr -> no filter-name validation + $test_model->validate_descr('LAN'); + }, + ); + } + + /** + * Checks that dhcp6_ia_pd_len accepts the GUI choices ('none' and the + * 16..0 IA-PD lengths) and rejects out-of-set values. + */ + public function test_dhcp6_ia_pd_len_choices(): void { + $this->assert_does_not_throw( + callable: function () { + $test_model = new NetworkInterface(); + $test_model->typev6->value = 'dhcp6'; + $test_model->dhcp6_ia_pd_len->value = '0'; + $test_model->dhcp6_ia_pd_len->validate(); + }, + ); + + $this->assert_does_not_throw( + callable: function () { + $test_model = new NetworkInterface(); + $test_model->typev6->value = 'dhcp6'; + $test_model->dhcp6_ia_pd_len->value = 'none'; + $test_model->dhcp6_ia_pd_len->validate(); + }, + ); + + $this->assert_throws_response( + response_id: 'FIELD_INVALID_CHOICE', + code: 400, + callable: function () { + $test_model = new NetworkInterface(); + $test_model->typev6->value = 'dhcp6'; + $test_model->dhcp6_ia_pd_len->value = '999'; + $test_model->dhcp6_ia_pd_len->validate(); + }, + ); + } } diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIValidatorsMACAddressValidatorTestCase.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIValidatorsMACAddressValidatorTestCase.inc index ae40b972..a7afe374 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIValidatorsMACAddressValidatorTestCase.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIValidatorsMACAddressValidatorTestCase.inc @@ -31,4 +31,48 @@ class APIValidatorsMACAddressValidatorTestCase extends TestCase { $test_validator->validate('00:13:10:00:00:0A'); }); } + + /** + * Checks that partial MAC addresses (OUI prefixes) are still rejected when the default strict mode is used. + */ + public function test_throw_response_for_partial_mac_by_default() { + $this->assert_throws_response( + response_id: 'MAC_ADDRESS_VALIDATOR_FAILED', + code: 400, + callable: function () { + $test_validator = new MACAddressValidator(); + $test_validator->validate('EC:71:DB'); + }, + ); + } + + /** + * Checks that partial MAC addresses (OUI prefixes) are accepted when allow_partial is enabled, matching the + * pfSense GUI behavior for DHCP mac_allow/mac_deny vendor prefix matching. + */ + public function test_allow_partial_accepts_oui_prefixes() { + $this->assert_does_not_throw(function () { + $test_validator = new MACAddressValidator(allow_partial: true); + $test_validator->validate('EC:71:DB'); + $test_validator->validate('00:60'); + $test_validator->validate('B8:27:EB:AA'); + $test_validator->validate('00:13:10:00:00:00'); + }); + } + + /** + * Checks that garbage values are still rejected when allow_partial is enabled. + */ + public function test_allow_partial_still_rejects_garbage() { + $this->assert_throws_response( + response_id: 'MAC_ADDRESS_VALIDATOR_FAILED', + code: 400, + callable: function () { + $test_validator = new MACAddressValidator(allow_partial: true); + $test_validator->validate('EC:71:ZZ'); + $test_validator->validate('not a MAC!'); + $test_validator->validate('00:13:10:00:00:00:00'); + }, + ); + } } diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Validators/MACAddressValidator.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Validators/MACAddressValidator.inc index 35a2a3d6..3b00eb2b 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Validators/MACAddressValidator.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Validators/MACAddressValidator.inc @@ -12,13 +12,18 @@ use RESTAPI\Responses\ValidationError; */ class MACAddressValidator extends RESTAPI\Core\Validator { public array $allow_keywords; + public bool $allow_partial; /** * Constructs the MACAddressValidator with requested parameters. * @param array $allow_keywords An array of specified non-MAC address keywords that should be considered valid. + * @param bool $allow_partial Whether partial MAC addresses (OUI prefixes such as `EC:71:DB`) are considered + * valid. This mirrors the pfSense GUI, which accepts partial MACs in DHCP `mac_allow`/`mac_deny` fields to + * match all devices of a vendor. Defaults to false to preserve strict full-MAC validation. */ - public function __construct(array $allow_keywords = []) { + public function __construct(array $allow_keywords = [], bool $allow_partial = false) { $this->allow_keywords = $allow_keywords; + $this->allow_partial = $allow_partial; } /** @@ -29,7 +34,7 @@ class MACAddressValidator extends RESTAPI\Core\Validator { */ public function validate(mixed $value, string $field_name = ''): void { # Throw a ValidationError if this value is not a MAC address or an allowed keyword - if (!is_macaddr($value) and !in_array($value, $this->allow_keywords)) { + if (!is_macaddr($value, $this->allow_partial) and !in_array($value, $this->allow_keywords)) { throw new ValidationError( message: "Field `$field_name` must be a valid MAC address, received `$value`.", response_id: 'MAC_ADDRESS_VALIDATOR_FAILED',