Challenge 1: Requiring an IP Range AND a Valid User — Solution
Walkthrough
The config:
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /etc/apache2/.htpasswd
Require ip 172.16.0.0/12
Require valid-user
Why RequireAll is necessary here:
Simply writing "Require ip 172.16.0.0/12" and "Require valid-user" as
two separate, unwrapped Require lines at the same level would combine
them with Apache's default OR logic -- a request from the right IP
range would be let through even without valid credentials, and a
correctly authenticated user from any IP at all would also be let
through, satisfying either condition alone. The exercise specifically
asks for BOTH to be required together, which needs the explicit
wrapper around both Require lines -- only then does
Apache demand that every condition inside the block be satisfied
before granting access.
WHY THIS WORKS AS AN ANSWER
------------------------------
This exercise checks that the reader knows Apache's default
multiple-Require behavior is OR, not AND, and reaches for the
explicit wrapper specifically when genuine AND logic is
needed -- a very easy mistake to make by just listing two Require
lines and assuming they combine restrictively by default.