Gentoo Archives: gentoo-user

From: thelma@×××××××××××.com
To: gentoo-user@l.g.o
Subject: [gentoo-user] apache 2.4 - deny access to directory
Date: Mon, 30 Nov 2020 18:09:56
Message-Id: d56c7223-666d-cd58-581a-72efc303bc0b@sys-concept.com
In Reply to: Re: [gentoo-user] apache 2.4 - deny access to directory by Michael
1 On 11/30/2020 05:34 AM, Michael wrote:
2 > On Sunday, 29 November 2020 18:22:09 GMT thelma@×××××××××××.com wrote:
3 >> Thelma
4 >>
5 >> On 11/29/2020 03:22 AM, Michael wrote:
6 >>> On Sunday, 29 November 2020 07:30:16 GMT thelma@×××××××××××.com wrote:
7 >>>> I'm trying to deny access to all except specific IP address in a
8 >>>> directory, just testing it.
9 >>>>
10 >>>> In modules.d/00_default_settings.conf
11 >>>>
12 >>>> <Directory "/var/www/localhost/htdocs">
13 >>>>
14 >>>> Options MultiViews
15 >>>> AllowOverride All
16 >>>> Require all granted
17 >>>>
18 >>>> </Directory>
19 >>>>
20 >>>> in admin/.htaccess
21 >>>>
22 >>>> <RequireAll>
23 >>>>
24 >>>> Require all denied
25 >>>> Require ip 10.0.0.100
26 >>>>
27 >>>> </RequireAll>
28 >>>>
29 >>>> My IP is 10.0.0.112 and I can still access the server /admin directory
30 >>>>
31 >>>> What am I missing?
32 >>>
33 >>> In apache 2.4 the access control syntax has changed. The RequireAll
34 >>> directive means *all* authorisation directives within it must succeed.
35 >>>
36 >>> https://httpd.apache.org/docs/2.4/mod/mod_authz_core.html#requireall
37 >>>
38 >>> What happens if you just remove the first line, "Require all denied"?
39 >>
40 >> As you suggested I have:
41 >> in admin/.htaccess
42 >>
43 >> <RequireAll>
44 >> Require ip 10.0.0.100
45 >> </RequireAll>
46 >>
47 >> My IP is: 10.0.0.112 and it still allow me to access it. I know apache
48 >> 2.4 is reading the file as the the below direcive works.
49 >
50 > I've tested different RequireAll directives in a .htaccess file and with
51 > otherwise default apache settings I can confirm:
52 >
53 > This is correct:
54 > =========================
55 > <RequireAll>
56 > Require ip 10.0.0.100
57 > </RequireAll>
58 > =========================
59 > will only allow visitors from 10.0.0.100 to access the directory content.
60 >
61 > This is also correct:
62 > =========================
63 > <RequireAll>
64 > Require all granted
65 > Require ip 10.0.0.100
66 > </RequireAll>
67 > =========================
68 > will only allow visitors from 10.0.0.100 to access the directory content.
69 >
70 > Finally, this won't work:
71 > =========================
72 > <RequireAll>
73 > Require all denied
74 > Require ip 10.0.0.100
75 > </RequireAll>
76 > =========================
77 > because it returns 403 for all clients irrespective of IP address, since both
78 > subdirectives must be correct for the RequireAll to be true.
79 >
80 > I notice you have 'Options MultiViews' in your modules.d/
81 > 00_default_settings.conf, which will parse paths to find and serve any file
82 > requested by the client even if the URL is not complete. It might be this
83 > conflicts with your .htaccess within admin/ subdirectory, but I'm not sure.
84 > Something in apache logs may shed light in this.
85 >
86 >
87 >> AuthName "restricted stuff"
88 >> AuthType Basic
89 >> AuthUserFile "/etc/apache2/users"
90 >> require user webmaster
91 >>
92 >> I've tried adding
93 >> RewriteEngine on
94 >>
95 >> With it, I can not login at all (access denied) regardless of IP.
96 >
97 > With apache 2.4 a new <If> directive was added to perform conditional checks
98 > and replace/augment many of the mod_rewrite functionalities. I don't know how
99 > you have structured your RewriteCond and RewriteRule, but obviously they don't
100 > work as intended if they totally block access.
101 >
102 > You could check conflicting rules between your apache config and any .htaccess
103 > directives, or any loose and contradictory .htaccess files in higher
104 > subdirectories.
105
106 Here is complete file: modules.d/00_default_settings.conf
107 I've removed 'Options MultiViews' but it disn't help.
108
109 Timeout 300
110 KeepAlive On
111 MaxKeepAliveRequests 100
112 KeepAliveTimeout 15
113 UseCanonicalName Off
114 AccessFileName .htaccess
115 ServerTokens Prod
116 TraceEnable off
117 ServerSignature Off
118 HostnameLookups Off
119 EnableMMAP On
120 EnableSendfile Off
121 FileETag MTime Size
122 ContentDigest Off
123 ErrorLog /var/log/apache2/error_log
124 LogLevel warn
125
126 <Directory />
127 Options FollowSymLinks
128 AllowOverride None
129 Require all denied
130 </Directory>
131
132 <Directory "/var/www/localhost/htdocs">
133 AllowOverride All
134 Require all granted
135 </Directory>
136
137 <IfModule dir_module>
138 DirectoryIndex index.html index.html.var
139 </IfModule>
140
141 <FilesMatch "^\.ht">
142 Require all denied
143 </FilesMatch>
144
145 The server root .htaccess is empty
146 In server root/admin/.htaccess
147
148 <RequireAll>
149 Require ip 10.0.0.100
150 </RequireAll>
151
152 AuthName "restricted stuff"
153 AuthType Basic
154 AuthUserFile "/etc/apache2/users"
155 require user webmaster
156
157 My IP is 10.0.0.109 so I should be denied access to admin/index.php but
158 I'm able to view it/access it.
159 It seems to me it is reading .htaccess file as "AuthType Basic" work, it
160 is asking me for a password. but "Require ip" doesn't work. Because my
161 IP is 10.0.0.109 apache should deny me access with "access denied.
162
163 It is strange as the directive: "DirectoryIndex index.html
164 index.html.var" does not include "index.php" and I'm able to access this
165 file "admin/index.php"
166 so the index.php must be define somewhere else. Most likely via httpd.conf:
167
168 httpd.conf:75:LoadModule autoindex_module modules/mod_autoindex.so (but
169 this is a binary file, can not read it).

Replies

Subject Author
Re: [gentoo-user] apache 2.4 - deny access to directory Michael <confabulate@××××××××.com>