Skip to content

Commit

Permalink
Re-use existing Jespa-Connection-Id header value
Browse files Browse the repository at this point in the history
+ If upstream proxy or ingress has already set this header on the request, our standard proxy include should re-use the same value. Otherwise, set to `$remote_addr:$remote_port` as before.
  • Loading branch information
amcclain committed Feb 21, 2020
1 parent c9a1e2b commit e86974e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
5 changes: 3 additions & 2 deletions includes/xh-proxy.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# Required for NTLM SSO when using Jespa
proxy_set_header Jespa-Connection-Id $remote_addr:$remote_port;
# Required for NTLM SSO when using Jespa - should contain client remote_addr:remote_port to uniquely
# ID client connection across multi-step NTLM handshake. Var is set in xh.conf, see notes there.
proxy_set_header Jespa-Connection-Id $xh_jespa_connection_id;

# Additional SSL support
proxy_set_header X-Forwarded-Proto $scheme;
Expand Down
22 changes: 19 additions & 3 deletions xh.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ gzip_min_length 1000;
gzip_proxied any;
gzip_types application/json application/javascript text/css text/javascript;

# Increase client max body size to allow for larger uploads
client_max_body_size 20m;

# Increase proxy headers hash size due to our use of proxy_set_header - as per nginx msg in log.
proxy_headers_hash_max_size 1024;

# Convenience map to specify caching expiry by request type (use in expires directive as below)
map $sent_http_content_type $expires {
default off;
Expand All @@ -16,9 +22,6 @@ map $sent_http_content_type $expires {
text/html epoch;
}

# Increase client max body size to allow for larger uploads
client_max_body_size 20m;

# Set $is_desktop and $is_mobile variables for simple UA-based sniffing.
# This was snagged from https://gist.github.com/perusio/1326701 and is not guaranteed by any means
# to be perfect or exhaustive. Apps should use with care - we can tune if we have real-world cases
Expand All @@ -35,6 +38,19 @@ map $is_desktop $is_mobile {
0 1;
}

# Set new $xh_jespa_connection_id for use in xh-proxy include, where the resulting value is
# used to add/replace a Jespa-Connection-Id header. If request arrives with a Jespa-Connection-Id
# header already set, this map will re-use that same value: the incoming header is assumed to
# have been set by an upstream proxy or k8s ingress and to contain the actual client addr and port.
# Otherwise, we create the ID with the addr and port we know about here.
map $http_jespa_connection_id $xh_jespa_connection_id {
volatile;
default $http_jespa_connection_id;

"" $remote_addr:$remote_port;
}


# App-level Dockerfiles must copy in an appropriate conf with server directives such as the below.

#server {
Expand Down

0 comments on commit e86974e

Please sign in to comment.