Skip to content

Commit b349254

Browse files
Support for Http Proxy Headers (#119)
* Add logging of x-forwarded-* and x-custom-host http headers Users can choose to log the following for http headers in the request logs: * x-forwarded-for * x-forwarded-host * x-forwarded-proto * x-custom-host This requires the environment variable `LOG_SENSITIVE_CONNECTION_DATA` to be set to `true`. If there are no headers, no fields will be added to the request logs. If there are headers, but `LOG_SENSITIVE_CONNECTION_DATA` is set to `false`(default) the values will be logged as 'redacted'. * Log SSL connection headers HA-Proxy can add certain headers for terminated ssl connections [1]. These headers can be added to the request logs if environment variable LOG_SSL_HEADERS is set to be true. Otherwise no fields will be added to the request logs. [1] https://www.haproxy.com/blog/ssl-client-certificate-information-in-http-headers-and-logs/ Co-authored-by: Christian Dinse <[email protected]>
1 parent c4c6ee1 commit b349254

File tree

12 files changed

+744
-270
lines changed

12 files changed

+744
-270
lines changed

cf-java-logging-support-core/beats/request-metrics/docs/fields.asciidoc

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,3 +695,132 @@ client, followed by proxy server addresses that forwarded the client
695695
request.
696696

697697

698+
==== x_forwarded_host
699+
700+
type: string
701+
702+
example: requested-host.example.com
703+
704+
required: False
705+
706+
The originally requested host by the client in the host HTTP request header.
707+
A proxy may forward the host header using the x-forwarded-host header.
708+
709+
710+
==== x_forwarded_proto
711+
712+
type: string
713+
714+
example: https
715+
716+
required: False
717+
718+
The original protocol used by the client to connect to the proxy or load balancer
719+
before the application.
720+
721+
722+
==== x_custom_host
723+
724+
type: string
725+
726+
example: central-host.example.com
727+
728+
required: False
729+
730+
A header set by a proxy or load balancer for special use-cases.
731+
732+
733+
==== x_ssl_client
734+
735+
type: string
736+
737+
example: 0
738+
739+
required: False
740+
741+
A header set by HA-Proxy to indicate usage of a secured connection by the
742+
client (1) or not (0).
743+
744+
745+
==== x_ssl_client_verify
746+
747+
type: string
748+
749+
example: 0
750+
751+
required: False
752+
753+
A header set by HA-Proxy to indicate the status code of the TLS/SSL connection.
754+
755+
756+
==== x_ssl_client_subject_dn
757+
758+
type: string
759+
760+
example: /C=FR/ST=Ile de France/L=Jouy en Josas/O=haproxy.com/CN=client1/[email protected]
761+
762+
required: False
763+
764+
A header set by HA-Proxy to provide the full distinguished name of the
765+
client certificate.
766+
767+
768+
==== x_ssl_client_subject_cn
769+
770+
type: string
771+
772+
example: client1
773+
774+
required: False
775+
776+
A header set by HA-Proxy to provide the full common name of the
777+
client certificate.
778+
779+
780+
==== x_ssl_client_issuer_dn
781+
782+
type: string
783+
784+
example: /C=FR/ST=Ile de France/L=Jouy en Josas/O=haproxy.com/CN=haproxy.com/[email protected]
785+
786+
required: False
787+
788+
A header set by HA-Proxy to provide the full distinguished name of the
789+
issuer of the client certificate.
790+
791+
792+
==== x_ssl_client_notbefore
793+
794+
type: string
795+
796+
example: 130613144555Z
797+
798+
required: False
799+
800+
A header set by HA-Proxy to provide the start date of the client
801+
certificate as a formatted string YYMMDDhhmmss.
802+
803+
804+
==== x_ssl_client_notafter
805+
806+
type: string
807+
808+
example: 140613144555Z
809+
810+
required: False
811+
812+
A header set by HA-Proxy to provide the end date of the client
813+
certificate as a formatted string YYMMDDhhmmss.
814+
815+
816+
==== x_ssl_client_session_id
817+
818+
type: string
819+
820+
example: session-id
821+
822+
required: False
823+
824+
A header to indicate the SSL client session id.
825+
826+

cf-java-logging-support-core/beats/request-metrics/etc/fields.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,3 +501,88 @@ request-metrics:
501501
Comma-separated list of IP addresses, the left-most being the original
502502
client, followed by proxy server addresses that forwarded the client
503503
request.
504+
505+
- name: "x_forwarded_host"
506+
type: string
507+
required: false
508+
example: "requested-host.example.com"
509+
description: |
510+
The originally requested host by the client in the host HTTP request header.
511+
A proxy may forward the host header using the x-forwarded-host header.
512+
513+
- name: "x_forwarded_proto"
514+
type: string
515+
required: false
516+
example: "https"
517+
description: |
518+
The original protocol used by the client to connect to the proxy or load balancer
519+
before the application.
520+
521+
- name: "x_custom_host"
522+
type: string
523+
required: false
524+
example: "central-host.example.com"
525+
description: |
526+
A header set by a proxy or load balancer for special use-cases.
527+
528+
- name: "x_ssl_client"
529+
type: string
530+
required: false
531+
example: "0"
532+
description: |
533+
A header set by HA-Proxy to indicate usage of a secured connection by the
534+
client (1) or not (0).
535+
536+
- name: "x_ssl_client_verify"
537+
type: string
538+
required: false
539+
example: "0"
540+
description: |
541+
A header set by HA-Proxy to indicate the status code of the TLS/SSL connection.
542+
543+
- name: "x_ssl_client_subject_dn"
544+
type: string
545+
required: false
546+
example: "/C=FR/ST=Ile de France/L=Jouy en Josas/O=haproxy.com/CN=client1/[email protected]"
547+
description: |
548+
A header set by HA-Proxy to provide the full distinguished name of the
549+
client certificate.
550+
551+
- name: "x_ssl_client_subject_cn"
552+
type: string
553+
required: false
554+
example: "client1"
555+
description: |
556+
A header set by HA-Proxy to provide the full common name of the
557+
client certificate.
558+
559+
- name: "x_ssl_client_issuer_dn"
560+
type: string
561+
required: false
562+
example: "/C=FR/ST=Ile de France/L=Jouy en Josas/O=haproxy.com/CN=haproxy.com/[email protected]"
563+
description: |
564+
A header set by HA-Proxy to provide the full distinguished name of the
565+
issuer of the client certificate.
566+
567+
- name: "x_ssl_client_notbefore"
568+
type: string
569+
required: false
570+
example: "130613144555Z"
571+
description: |
572+
A header set by HA-Proxy to provide the start date of the client
573+
certificate as a formatted string YYMMDDhhmmss.
574+
575+
- name: "x_ssl_client_notafter"
576+
type: string
577+
required: false
578+
example: "140613144555Z"
579+
description: |
580+
A header set by HA-Proxy to provide the end date of the client
581+
certificate as a formatted string YYMMDDhhmmss.
582+
583+
- name: "x_ssl_client_session_id"
584+
type: string
585+
required: false
586+
example: "session-id"
587+
description: |
588+
A header to indicate the SSL client session id.

cf-java-logging-support-core/beats/request-metrics/etc/request-metrics.template.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,65 @@
273273
"ignore_malformed": true,
274274
"type": "long"
275275
},
276+
"x_custom_host": {
277+
"doc_values": true,
278+
"index": "not_analyzed",
279+
"type": "string"
280+
},
276281
"x_forwarded_for": {
277282
"doc_values": true,
278283
"index": "not_analyzed",
279284
"type": "string"
285+
},
286+
"x_forwarded_host": {
287+
"doc_values": true,
288+
"index": "not_analyzed",
289+
"type": "string"
290+
},
291+
"x_forwarded_proto": {
292+
"doc_values": true,
293+
"index": "not_analyzed",
294+
"type": "string"
295+
},
296+
"x_ssl_client": {
297+
"doc_values": true,
298+
"index": "not_analyzed",
299+
"type": "string"
300+
},
301+
"x_ssl_client_issuer_dn": {
302+
"doc_values": true,
303+
"index": "not_analyzed",
304+
"type": "string"
305+
},
306+
"x_ssl_client_notafter": {
307+
"doc_values": true,
308+
"index": "not_analyzed",
309+
"type": "string"
310+
},
311+
"x_ssl_client_notbefore": {
312+
"doc_values": true,
313+
"index": "not_analyzed",
314+
"type": "string"
315+
},
316+
"x_ssl_client_session_id": {
317+
"doc_values": true,
318+
"index": "not_analyzed",
319+
"type": "string"
320+
},
321+
"x_ssl_client_subject_cn": {
322+
"doc_values": true,
323+
"index": "not_analyzed",
324+
"type": "string"
325+
},
326+
"x_ssl_client_subject_dn": {
327+
"doc_values": true,
328+
"index": "not_analyzed",
329+
"type": "string"
330+
},
331+
"x_ssl_client_verify": {
332+
"doc_values": true,
333+
"index": "not_analyzed",
334+
"type": "string"
280335
}
281336
}
282337
}

cf-java-logging-support-core/src/main/java/com/sap/hcp/cf/logging/common/Fields.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,15 @@ public interface Fields {
6565
public String RESPONSE_CONTENT_TYPE = "response_content_type";
6666
public String REFERER = "referer";
6767
public String X_FORWARDED_FOR = "x_forwarded_for";
68+
public String X_FORWARDED_HOST = "x_forwarded_host";
69+
public String X_FORWARDED_PROTO = "x_forwarded_proto";
70+
public String X_CUSTOM_HOST = "x_custom_host";
71+
public String X_SSL_CLIENT = "x_ssl_client";
72+
public String X_SSL_CLIENT_VERIFY = "x_ssl_client_verify";
73+
public String X_SSL_CLIENT_SUBJECT_DN = "x_ssl_client_subject_dn";
74+
public String X_SSL_CLIENT_SUBJECT_CN = "x_ssl_client_subject_cn";
75+
public String X_SSL_CLIENT_ISSUER_DN = "x_ssl_client_issuer_dn";
76+
public String X_SSL_CLIENT_NOTBEFORE = "x_ssl_client_notbefore";
77+
public String X_SSL_CLIENT_NOTAFTER = "x_ssl_client_notafter";
78+
public String X_SSL_CLIENT_SESSION_ID = "x_ssl_client_session_id";
6879
}

cf-java-logging-support-core/src/main/java/com/sap/hcp/cf/logging/common/LogOptionalFieldsSettings.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class LogOptionalFieldsSettings {
1212
private final boolean logSensitiveConnectionData;
1313
private final boolean logRemoteUserField;
1414
private final boolean logRefererField;
15+
private final boolean logSslHeaders;
1516

1617
public LogOptionalFieldsSettings(String invokingClass) {
1718
this(new Environment(), invokingClass);
@@ -22,6 +23,7 @@ public LogOptionalFieldsSettings(String invokingClass) {
2223
invokingClass);
2324
logRemoteUserField = readEnvironmentVariable(Environment.LOG_REMOTE_USER, environment, invokingClass);
2425
logRefererField = readEnvironmentVariable(Environment.LOG_REFERER, environment, invokingClass);
26+
logSslHeaders = readEnvironmentVariable(Environment.LOG_SSL_HEADERS, environment, invokingClass);
2527
}
2628

2729
private static boolean readEnvironmentVariable(String environmentVariableKey, Environment environment,
@@ -63,4 +65,8 @@ public boolean isLogRemoteUserField() {
6365
public boolean isLogRefererField() {
6466
return logRefererField;
6567
}
68+
69+
public boolean isLogSslHeaders() {
70+
return logSslHeaders;
71+
}
6672
}

cf-java-logging-support-core/src/main/java/com/sap/hcp/cf/logging/common/helper/Environment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public class Environment {
55
public static final String LOG_SENSITIVE_CONNECTION_DATA = "LOG_SENSITIVE_CONNECTION_DATA";
66
public static final String LOG_REMOTE_USER = "LOG_REMOTE_USER";
77
public static final String LOG_REFERER = "LOG_REFERER";
8+
public static final String LOG_SSL_HEADERS = "LOG_SSL_HEADERS";
89

910
public String getVariable(String name) {
1011
return System.getenv(name);

cf-java-logging-support-core/src/main/java/com/sap/hcp/cf/logging/common/request/HttpHeaders.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,36 @@ public enum HttpHeaders implements HttpHeader {
1515
CONTENT_LENGTH("content-length"), //
1616
CONTENT_TYPE("content-type"), //
1717
REFERER("referer"), //
18-
X_FORWARDED_FOR("x-forwarded-for"), //
18+
X_CUSTOM_HOST("x-custom-host", Fields.X_CUSTOM_HOST), //
19+
X_FORWARDED_FOR("x-forwarded-for", Fields.X_FORWARDED_FOR), //
20+
X_FORWARDED_HOST("x-forwarded-host", Fields.X_FORWARDED_HOST), //
21+
X_FORWARDED_PROTO("x-forwarded-proto", Fields.X_FORWARDED_PROTO), //
22+
X_SSL_CLIENT("x-ssl-client", Fields.X_SSL_CLIENT), //
23+
X_SSL_CLIENT_VERIFY("x-ssl-client-verify", Fields.X_SSL_CLIENT_VERIFY), //
24+
X_SSL_CLIENT_SUBJECT_DN("x-ssl-client-subject-dn",
25+
Fields.X_SSL_CLIENT_SUBJECT_DN), //
26+
X_SSL_CLIENT_SUBJECT_CN("x-ssl-client-subject-cn",
27+
Fields.X_SSL_CLIENT_SUBJECT_CN), //
28+
X_SSL_CLIENT_ISSUER_DN("x-ssl-client-issuer-dn",
29+
Fields.X_SSL_CLIENT_ISSUER_DN), //
30+
X_SSL_CLIENT_NOTBEFORE("x-ssl-client-notbefore",
31+
Fields.X_SSL_CLIENT_NOTBEFORE), //
32+
X_SSL_CLIENT_NOTAFTER("x-ssl-client-notafter",
33+
Fields.X_SSL_CLIENT_NOTAFTER), //
34+
X_SSL_CLIENT_SESSION_ID("x-ssl-client-session-id",
35+
Fields.X_SSL_CLIENT_SESSION_ID), //
1936
X_VCAP_REQUEST_ID("x-vcap-request-id", Fields.REQUEST_ID, true), //
2037
CORRELATION_ID("X-CorrelationID", Fields.CORRELATION_ID, true,
2138
X_VCAP_REQUEST_ID), //
2239
SAP_PASSPORT("sap-passport", Fields.SAP_PASSPORT, true), //
2340
TENANT_ID("tenantid", Fields.TENANT_ID, true); //
2441

2542
private HttpHeaders(String name) {
26-
this(name, null, false);
43+
this(name, null);
44+
}
45+
46+
private HttpHeaders(String name, String field) {
47+
this(name, field, false);
2748
}
2849

2950
private HttpHeaders(String name, String field, boolean isPropagated, HttpHeaders... aliases) {

0 commit comments

Comments
 (0)