-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support deployment behind nginx reverse proxy
- Loading branch information
Luca Bassi
committed
Oct 17, 2024
1 parent
dd7ae26
commit 719b68d
Showing
11 changed files
with
280 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Use nginx as a reverse proxy | ||
|
||
It is possible to deploy StoRM WebDAV using nginx as a reverse proxy. | ||
|
||
The main pros of this type of deployment are: | ||
|
||
- use nginx to manage TLS termination | ||
- delegate VOMS proxy authentication to [ngx_http_voms_module](https://baltig.infn.it/cnafsd/ngx_http_voms_module) | ||
- improve performance of downloads by using nginx to handle GET requests | ||
|
||
## How to deploy StoRM WebDAV using nginx | ||
|
||
Install nginx and [ngx_http_voms_module](https://baltig.infn.it/cnafsd/ngx_http_voms_module) on your server. | ||
|
||
Change the configuration of nginx to: | ||
|
||
- enable the client certificates | ||
- set the correct headers for VOMS authentication | ||
- add an internal endpoint to which to redirect GET requests | ||
|
||
In your `application.yml` configuration set `storm.nginx-reverse-proxy` to `true`. | ||
|
||
Example nginx configuration: | ||
|
||
``` | ||
server { | ||
location /internal-get { | ||
internal; | ||
alias /; | ||
sendfile on; | ||
tcp_nopush on; | ||
keepalive_timeout 65; | ||
tcp_nodelay on; | ||
} | ||
location / { | ||
proxy_pass http://127.0.0.1:8086; | ||
proxy_set_header X-VOMS-voms_user $voms_user; | ||
proxy_set_header X-VOMS-ssl_client_ee_s_dn $ssl_client_ee_s_dn; | ||
proxy_set_header X-VOMS-voms_user_ca $voms_user_ca; | ||
proxy_set_header X-VOMS-ssl_client_ee_i_dn $ssl_client_ee_i_dn; | ||
proxy_set_header X-VOMS-voms_fqans $voms_fqans; | ||
proxy_set_header X-VOMS-voms_server $voms_server; | ||
proxy_set_header X-VOMS-voms_server_ca $voms_server_ca; | ||
proxy_set_header X-VOMS-voms_vo $voms_vo; | ||
proxy_set_header X-VOMS-voms_server_uri $voms_server_uri; | ||
proxy_set_header X-VOMS-voms_not_before $voms_not_before; | ||
proxy_set_header X-VOMS-voms_not_after $voms_not_after; | ||
proxy_set_header X-VOMS-voms_generic_attributes $voms_generic_attributes; | ||
proxy_set_header X-VOMS-voms_serial $voms_serial; | ||
} | ||
listen [::]:8443 ssl http2; | ||
listen 8443 ssl http2; | ||
ssl_certificate /etc/grid-security/hostcert.pem; | ||
ssl_certificate_key /etc/grid-security/hostkey.pem; | ||
ssl_client_certificate /etc/pki/ca-trust/extracted/pem/tls-ca-bundle-all.pem; | ||
ssl_verify_client optional; | ||
ssl_verify_depth 10; | ||
client_max_body_size 0; | ||
error_page 497 https://$host:8443$request_uri; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/org/italiangrid/storm/webdav/authz/VOMSConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright (c) Istituto Nazionale di Fisica Nucleare, 2014-2023. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.italiangrid.storm.webdav.authz; | ||
|
||
public interface VOMSConstants { | ||
|
||
String VOMS_USER_HEADER = "X-VOMS-voms_user"; | ||
String SSL_CLIENT_EE_S_DN_HEADER = "X-VOMS-ssl_client_ee_s_dn"; | ||
String VOMS_USER_CA_HEADER = "X-VOMS-voms_user_ca"; | ||
String SSL_CLIENT_EE_I_DN_HEADER = "X-VOMS-ssl_client_ee_i_dn"; | ||
String VOMS_FQANS_HEADER = "X-VOMS-voms_fqans"; | ||
String VOMS_VO_HEADER = "X-VOMS-voms_vo"; | ||
String VOMS_SERVER_URI_HEADER = "X-VOMS-voms_server_uri"; | ||
String VOMS_NOT_BEFORE_HEADER = "X-VOMS-voms_not_before"; | ||
String VOMS_NOT_AFTER_HEADER = "X-VOMS-voms_not_after"; | ||
String VOMS_GENERIC_ATTRIBUTES_HEADER = "X-VOMS-voms_generic_attributes"; | ||
String VOMS_SERIAL_HEADER = "X-VOMS-voms_serial"; | ||
|
||
String VOMS_DATE_FORMAT = "yyyyMMddHHmmss'Z'"; | ||
|
||
String VOMS_GENERIC_ATTRIBUTES_REGEX = "n=(\\S*) v=(\\S*) q=(\\S*)"; | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/org/italiangrid/storm/webdav/authz/VOMSNginxFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright (c) Istituto Nazionale di Fisica Nucleare, 2014-2023. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.italiangrid.storm.webdav.authz; | ||
|
||
import javax.security.auth.x500.X500Principal; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.springframework.security.authentication.AuthenticationManager; | ||
|
||
public class VOMSNginxFilter extends VOMSAuthenticationFilter implements VOMSConstants { | ||
|
||
public VOMSNginxFilter(AuthenticationManager mgr) { | ||
super(mgr); | ||
} | ||
|
||
@Override | ||
protected Object getPreAuthenticatedPrincipal(HttpServletRequest request) { | ||
if (request.getHeader(VOMS_USER_HEADER) != null | ||
&& request.getHeader(SSL_CLIENT_EE_S_DN_HEADER) != null) { | ||
return new X500Principal(request.getHeader(SSL_CLIENT_EE_S_DN_HEADER)).getName(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
protected Object getPreAuthenticatedCredentials(HttpServletRequest request) { | ||
return new Object(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,12 @@ public Resource getResource(String pathInContext) { | |
|
||
} | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
resourceService.doGet(request, response, pathResolver, serviceConfig); | ||
Check notice Code scanning / SonarCloud Exceptions should not be thrown from servlet methods Low
Handle the following exceptions that could be thrown by "doGet": ServletException, IOException. See more on SonarCloud
|
||
} | ||
|
||
@Override | ||
protected void doHead(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.