Bug 24537 - Add support for IP ranges in ILS-DI:AuthorizedIPs using Net::Netmask
Summary: Add support for IP ranges in ILS-DI:AuthorizedIPs using Net::Netmask
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Web services (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: David Cook
QA Contact: Kyle M Hall
URL:
Keywords:
: 20243 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-01-30 03:40 UTC by David Cook
Modified: 2020-11-30 21:48 UTC (History)
5 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
It's now possible to not only allow a single IP, but multiple IPs, IP ranges and subnets access to the ILS-DI API.
Version(s) released in:
20.05.00


Attachments
Bug 24537: Allow IP ranges in ILS-DI:AuthorizedIPs using Net::Netmask (2.66 KB, patch)
2020-01-30 04:21 UTC, David Cook
Details | Diff | Splinter Review
Bug 24537: Allow IP ranges in ILS-DI:AuthorizedIPs using Net::Netmask (2.71 KB, patch)
2020-04-01 06:14 UTC, David Nind
Details | Diff | Splinter Review
Bug 24537: Allow IP ranges in ILS-DI:AuthorizedIPs using Net::Netmask (2.78 KB, patch)
2020-04-01 10:29 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 24537: Tidy code (1.50 KB, patch)
2020-04-01 10:29 UTC, Kyle M Hall
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description David Cook 2020-01-30 03:40:24 UTC
By using Net::Netmask (introduced by Bug 23068), we can allow IP ranges in the ILS-DI:AuthorizedIPs system preference. 

This makes it much easier to integrate with other systems.
Comment 1 David Cook 2020-01-30 04:21:48 UTC
Created attachment 98105 [details] [review]
Bug 24537: Allow IP ranges in ILS-DI:AuthorizedIPs using Net::Netmask

This patch uses Net::Netmask to match IPs from ILS-DI:AuthorizedIPs
against $ENV{REMOTE_USER}. By using Net::Netmask, we can use addresses
in a variety of formats. This includes 127.0.0.1, 192.168.1.0/24,
10.0.0, and so on.

To Test:
1. Apply the patch
2. Empty the 'ILS-DI:AuthorizedIPs' system preference
3. Send a request to '/cgi-bin/koha/ilsdi.pl?service=LookupPatron&id=1&id_type=cardnumber'
3b. Note that the request is successful
4. Set the 'ILS-DI:AuthorizedIPs' system preference to a subnet including
your IP address (e.g. 192.168.1.0/24)
5. Send a request to '/cgi-bin/koha/ilsdi.pl?service=LookupPatron&id=1&id_type=cardnumber'
5b. Note that the request is successful
6. Set the 'ILS-DI:AuthorizedIPs' system preference to a subnet that doesn't include
your IP address (e.g. 1.1.1)
7. Send a request to '/cgi-bin/koha/ilsdi.pl?service=LookupPatron&id=1&id_type=cardnumber'
7b. Note that your request is refused
8. Try a variety of permutations including bad values (e.g. 192.168.1.) or multiple values
(e.g. 10.0.0.0/8,192.168.1.0/24) or multiple values including a mix of good and bad values
Comment 2 David Cook 2020-01-30 04:24:46 UTC
Note that this really shines when you're running Koha behind a reverse proxy and you use koha_trusted_proxies to set your REMOTE_USER to the IP address that contacted your reverse proxy (or the last one in a trust chain). 

(Note also that there are other places in Koha that could benefit from this. Like OpacSuppressionByIPRange, RestrictedPageLocalIPs, etc.)
Comment 3 Katrin Fischer 2020-01-30 06:56:08 UTC
*** Bug 20243 has been marked as a duplicate of this bug. ***
Comment 4 David Nind 2020-04-01 06:14:43 UTC
Created attachment 102172 [details] [review]
Bug 24537: Allow IP ranges in ILS-DI:AuthorizedIPs using Net::Netmask

This patch uses Net::Netmask to match IPs from ILS-DI:AuthorizedIPs
against $ENV{REMOTE_USER}. By using Net::Netmask, we can use addresses
in a variety of formats. This includes 127.0.0.1, 192.168.1.0/24,
10.0.0, and so on.

To Test:
1. Apply the patch
2. Empty the 'ILS-DI:AuthorizedIPs' system preference
3. Send a request to '/cgi-bin/koha/ilsdi.pl?service=LookupPatron&id=1&id_type=cardnumber'
3b. Note that the request is successful
4. Set the 'ILS-DI:AuthorizedIPs' system preference to a subnet including
your IP address (e.g. 192.168.1.0/24)
5. Send a request to '/cgi-bin/koha/ilsdi.pl?service=LookupPatron&id=1&id_type=cardnumber'
5b. Note that the request is successful
6. Set the 'ILS-DI:AuthorizedIPs' system preference to a subnet that doesn't include
your IP address (e.g. 1.1.1)
7. Send a request to '/cgi-bin/koha/ilsdi.pl?service=LookupPatron&id=1&id_type=cardnumber'
7b. Note that your request is refused
8. Try a variety of permutations including bad values (e.g. 192.168.1.) or multiple values
(e.g. 10.0.0.0/8,192.168.1.0/24) or multiple values including a mix of good and bad values

Signed-off-by: David Nind <david@davidnind.com>
Comment 5 David Cook 2020-04-01 06:53:52 UTC
Thanks, David! You're a legend :).
Comment 6 Kyle M Hall 2020-04-01 10:29:05 UTC
Created attachment 102213 [details] [review]
Bug 24537: Allow IP ranges in ILS-DI:AuthorizedIPs using Net::Netmask

This patch uses Net::Netmask to match IPs from ILS-DI:AuthorizedIPs
against $ENV{REMOTE_USER}. By using Net::Netmask, we can use addresses
in a variety of formats. This includes 127.0.0.1, 192.168.1.0/24,
10.0.0, and so on.

To Test:
1. Apply the patch
2. Empty the 'ILS-DI:AuthorizedIPs' system preference
3. Send a request to '/cgi-bin/koha/ilsdi.pl?service=LookupPatron&id=1&id_type=cardnumber'
3b. Note that the request is successful
4. Set the 'ILS-DI:AuthorizedIPs' system preference to a subnet including
your IP address (e.g. 192.168.1.0/24)
5. Send a request to '/cgi-bin/koha/ilsdi.pl?service=LookupPatron&id=1&id_type=cardnumber'
5b. Note that the request is successful
6. Set the 'ILS-DI:AuthorizedIPs' system preference to a subnet that doesn't include
your IP address (e.g. 1.1.1)
7. Send a request to '/cgi-bin/koha/ilsdi.pl?service=LookupPatron&id=1&id_type=cardnumber'
7b. Note that your request is refused
8. Try a variety of permutations including bad values (e.g. 192.168.1.) or multiple values
(e.g. 10.0.0.0/8,192.168.1.0/24) or multiple values including a mix of good and bad values

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 7 Kyle M Hall 2020-04-01 10:29:20 UTC
Created attachment 102214 [details] [review]
Bug 24537: Tidy code

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 8 Martin Renvoize 2020-04-06 11:22:44 UTC
Nice work everyone!

Pushed to master for 20.05
Comment 9 Joy Nelson 2020-04-29 17:57:43 UTC
enhancement not backported to 19.11.x