Skip to content

Commit 831be8b

Browse files
authored
CMR-10213 new jetty library (attempt 2) with improved logging code. (#2258)
* Updating Jetty to a much newer version to improve security * Removed block-excessive-queries function as it has long passed since it was needed * Attempt 2 (#2257)
1 parent 327c850 commit 831be8b

26 files changed

Lines changed: 146 additions & 104 deletions

File tree

access-control-app/project.clj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@
3232
[clj-time "0.15.1"]
3333
[com.fasterxml.jackson.core/jackson-core "2.15.4"]
3434
[commons-codec/commons-codec "1.11"]
35-
[commons-io "2.6"]
35+
[commons-io "2.18.0"]
3636
[compojure "1.6.1"]
3737
[gov.nasa.earthdata/cmr-site-templates "0.1.1-SNAPSHOT"]
3838
[org.clojure/clojure "1.11.2"]
3939
[org.clojure/tools.reader "1.3.2"]
40-
[ring/ring-codec "1.1.3"]
41-
[ring/ring-core "1.10.0"]
40+
[org.eclipse.jetty/jetty-http "11.0.24"]
41+
[org.eclipse.jetty/jetty-util "11.0.24"]
42+
[ring/ring-codec "1.2.0"]
43+
[ring/ring-core "1.13.0"]
44+
[ring/ring-jetty-adapter "1.13.0"]
4245
[ring/ring-json "0.5.1"]]
4346
project-dependencies)
4447
:plugins [[lein-modules "0.3.11"]
@@ -57,8 +60,8 @@
5760
[org.clojure/tools.nrepl "0.2.13"]
5861
[pjstadig/humane-test-output "0.9.0"]
5962
[proto-repl "0.3.1"]
60-
[ring/ring-codec "1.1.3"]
61-
[ring/ring-jetty-adapter "1.10.0"]
63+
[ring/ring-codec "1.2.0"]
64+
[ring/ring-jetty-adapter "1.13.0"]
6265
[ring-mock "0.1.5"]]
6366
:jvm-opts ^:replace ["-server"]
6467
:source-paths ["src" "dev" "test" "int-test"]

acl-lib/project.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(defproject nasa-cmr/cmr-acl-lib "0.1.0-SNAPSHOT"
22
:description "Contains utilities for retreiving and working with ACLs."
33
:url "https://github.com/nasa/Common-Metadata-Repository/tree/master/acl-lib"
4-
:dependencies [[commons-io "2.6"]
4+
:dependencies [[commons-io "2.18.0"]
55
[nasa-cmr/cmr-transmit-lib "0.1.0-SNAPSHOT"]
66
[org.clojure/clojure "1.11.2"]
77
[potemkin "0.4.5"]]
@@ -32,7 +32,9 @@
3232
:internal-repos {}
3333
:kaocha {:dependencies [[lambdaisland/kaocha "1.0.732"]
3434
[lambdaisland/kaocha-cloverage "1.0.75"]
35-
[lambdaisland/kaocha-junit-xml "0.0.76"]]}}
35+
[lambdaisland/kaocha-junit-xml "0.0.76"]
36+
;; ring is needed or this fails in sys int group3
37+
[ring/ring-jetty-adapter "1.13.0"]]}}
3638
:aliases {;; Kaocha test aliases
3739
;; refer to tests.edn for test configuration
3840
"kaocha" ["with-profile" "+kaocha" "run" "-m" "kaocha.runner"]

bootstrap-app/project.clj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[clj-http "2.3.0"]
66
[clj-time "0.15.1"]
77
[commons-codec/commons-codec "1.11"]
8-
[commons-io "2.6"]
8+
[commons-io "2.18.0"]
99
[compojure "1.6.1"]
1010
[io.github.jaybarra/drift "1.5.4.2-SNAPSHOT"]
1111
[nasa-cmr/cmr-access-control-app "0.1.0-SNAPSHOT"]
@@ -22,8 +22,11 @@
2222
[org.clojure/tools.nrepl "0.2.13"]
2323
[org.clojure/tools.reader "1.3.2"]
2424
[potemkin "0.4.5"]
25-
[ring/ring-codec "1.1.3"]
26-
[ring/ring-core "1.10.0"]
25+
[org.eclipse.jetty/jetty-http "11.0.24"]
26+
[org.eclipse.jetty/jetty-util "11.0.24"]
27+
[ring/ring-codec "1.2.0"]
28+
[ring/ring-core "1.13.0"]
29+
[ring/ring-jetty-adapter "1.13.0"]
2730
[ring/ring-json "0.5.1"]]
2831
:plugins [[io.github.jaybarra/drift "1.5.4.2-SNAPSHOT"]
2932
[lein-exec "0.3.7"]
@@ -35,7 +38,8 @@
3538
:dependency-check {:output-format [:all]
3639
:suppression-file "resources/security/suppression.xml"}}
3740
:dev {:dependencies [[org.clojure/tools.namespace "0.2.11"]
38-
[org.clojars.gjahad/debug-repl "0.3.3"]]
41+
[org.clojars.gjahad/debug-repl "0.3.3"]
42+
[ring/ring-jetty-adapter "1.13.0"]]
3943
:jvm-opts ^:replace ["-server"]
4044
:source-paths ["src" "dev" "test"]}
4145
:uberjar {:main cmr.bootstrap.runner

common-app-lib/project.clj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
[nasa-cmr/cmr-transmit-lib "0.1.0-SNAPSHOT"]
1313
[org.clojure/clojure "1.11.2"]
1414
[com.vladsch.flexmark/flexmark-all "0.64.0"]
15-
[ring/ring-core "1.10.0"]
15+
[org.eclipse.jetty/jetty-util "11.0.24"]
16+
[ring/ring-core "1.13.0"]
17+
[ring/ring-jetty-adapter "1.13.0"]
1618
[ring/ring-json "0.5.1"]
1719
[selmer "1.12.5"]]
1820
:plugins [[lein-shell "0.5.0"]]
@@ -23,6 +25,8 @@
2325
:suppression-file "resources/security/suppression.xml"}}
2426
:dev {:dependencies [[org.clojure/tools.namespace "0.2.11"]
2527
[org.clojure/tools.nrepl "0.2.13"]
28+
[ring/ring-codec "1.2.0"]
29+
[ring/ring-jetty-adapter "1.13.0"]
2630
[org.clojars.gjahad/debug-repl "0.3.3"]]
2731
:jvm-opts ^:replace ["-server"]
2832
:source-paths ["src" "dev" "test"]}

common-lib/project.clj

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@
3333
[org.clojure/tools.nrepl "0.2.13"]
3434
[org.clojure/tools.reader "1.3.2"]
3535
;; These dependencies should be updated in tandem with the ring dependencies below.
36-
;; To find the corresponding versions, see: https://clojars.org/ring/ring-core/versions/1.9.6
37-
[org.eclipse.jetty/jetty-http "9.4.53.v20231009"]
38-
[org.eclipse.jetty/jetty-io "9.4.53.v20231009"]
39-
[org.eclipse.jetty/jetty-servlets "9.4.53.v20231009"]
40-
[org.eclipse.jetty/jetty-util "9.4.53.v20231009"]
36+
;; To find the corresponding versions, see: https://clojars.org/ring/ring-core/versions/1.13.0
37+
[org.eclipse.jetty/jetty-util "11.0.24"]
38+
[org.eclipse.jetty/jetty-http "11.0.24"]
39+
[org.eclipse.jetty/jetty-io "11.0.24"]
40+
[org.eclipse.jetty/jetty-server "11.0.24"]
4141
;; load jts core lib first to make sure it is available for shapefile integration,
4242
;; otherwise ES referenced 1.15.0 version will be mistakenly picked for shapefile
4343
[org.locationtech.jts/jts-core "1.18.2"]
4444
[org.ow2.asm/asm "7.0"]
4545
[potemkin "0.4.5"]
46-
[ring/ring-core "1.10.0"]
47-
[ring/ring-jetty-adapter "1.10.0"]
46+
[ring/ring-core "1.13.0"]
47+
[ring/ring-jetty-adapter "1.13.0"]
4848
[ring/ring-json "0.5.1"]]
4949
:repositories [["jitpack.io" "https://jitpack.io"]]
5050
:plugins [[lein-exec "0.3.7"]
@@ -61,6 +61,8 @@
6161
[org.clojars.gjahad/debug-repl "0.3.3"]
6262
[criterium "0.4.4"]
6363
[proto-repl "0.3.1"]
64+
[ring/ring-core "1.13.0"]
65+
[ring/ring-jetty-adapter "1.13.0"]
6466
[clj-http "2.3.0"]]
6567
:jvm-opts ^:replace ["-server"]
6668
;; XXX Note that profiling can be kept in a profile,
@@ -74,7 +76,8 @@
7476
; "-Dcom.sun.management.jmxremote.authenticate=false"
7577
; "-Dcom.sun.management.jmxremote.port=1098"]
7678
:source-paths ["src" "dev" "test"]}
77-
:static {}
79+
:static {:dependencies [[org.eclipse.jetty/jetty-http "11.0.24"]
80+
[org.eclipse.jetty/jetty-util "11.0.24"]]}
7881
;; This profile is used for linting and static analysis. To run for this
7982
;; project, use `lein lint` from inside the project directory. To run for
8083
;; all projects at the same time, use the same command but from the top-

common-lib/src/cmr/common/api/web_server.clj

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,29 @@
99
[ring.adapter.jetty :as jetty])
1010
(:import
1111
(java.io ByteArrayInputStream InputStream)
12-
(org.eclipse.jetty.server Server NCSARequestLog Connector HttpConnectionFactory)
12+
(org.eclipse.jetty.server Server CustomRequestLog Connector HttpConnectionFactory)
1313
(org.eclipse.jetty.server.handler RequestLogHandler)
14-
(org.eclipse.jetty.server.handler.gzip GzipHandler)))
14+
(org.eclipse.jetty.server.handler.gzip GzipHandler)
15+
(org.eclipse.jetty.server Slf4jRequestLogWriter)))
1516

1617
(def MIN_THREADS
1718
"The minimum number of threads for Jetty to use to process requests. The was originally set to the
1819
ring jetty adapter default of 8."
1920
8)
2021

22+
(declare use-web-compression?)
23+
(defconfig use-web-compression?
24+
"Indicates whether the servers will use gzip compression. Disable this to
25+
make tcpmon usable"
26+
{:default true
27+
:type Boolean})
28+
29+
(declare use-access-log)
30+
(defconfig use-access-log
31+
"Indicates whether the servers will use the access log."
32+
{:default true
33+
:type Boolean})
34+
2135
(declare MAX_THREADS)
2236
(defconfig MAX_THREADS
2337
"The maximum number of threads for Jetty to use to process requests. This was originally set to
@@ -141,12 +155,12 @@
141155
application logging. As a result the access log entries will be in the same log as the
142156
application log."
143157
[existing-handler]
144-
(doto (RequestLogHandler.)
145-
(.setHandler existing-handler)
146-
(.setRequestLog
147-
(doto (NCSARequestLog.)
148-
(.setLogLatency true)
149-
(.setLogDateFormat "yyyy-MM-dd HH:mm:ss.SSS")))))
158+
(let [log-writer (Slf4jRequestLogWriter.)
159+
log-format (str CustomRequestLog/EXTENDED_NCSA_FORMAT " %{yyyy-MM-dd HH:mm:ss.SSS}t")]
160+
(doto (RequestLogHandler.)
161+
(.setHandler existing-handler)
162+
(.setRequestLog
163+
(CustomRequestLog. log-writer log-format)))))
150164

151165
(defn- create-gzip-handler
152166
"Setup gzip compression for responses. Compression will be used for any response larger than
@@ -224,9 +238,9 @@
224238
"Creates a new web server. Accepts argument of port and a routes function that should accept
225239
system argument and return compojure routes to use."
226240
([port routes-fn]
227-
(create-web-server port routes-fn true true))
228-
([port routes-fn use-compression use-access-log]
241+
(create-web-server port routes-fn use-web-compression? use-access-log))
242+
([port routes-fn use-compression use-access-log-opt]
229243
(map->WebServer {:port port
230244
:use-compression? use-compression
231-
:use-access-log? use-access-log
245+
:use-access-log? use-access-log-opt
232246
:routes-fn routes-fn})))

dev-system/project.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
:url "http://www.eclipse.org/legal/epl-v10.html"}
5151
:dependencies ~(concat '[[commons-codec/commons-codec "1.11"]
5252
[org.clojure/clojure "1.11.2"]
53-
[ring/ring-codec "1.1.1"]]
53+
[ring/ring-codec "1.2.0"]
54+
[ring/ring-jetty-adapter "1.13.0"]]
5455
project-dependencies)
5556
:plugins [[lein-environ "1.1.0"]
5657
[lein-shell "0.5.0"]]

dev-system/src/cmr/dev_system/config.clj

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,6 @@
2929
{:default 5601
3030
:type Long})
3131

32-
(defconfig use-web-compression?
33-
"Indicates whether the servers will use gzip compression. Disable this to
34-
make tcpmon usable"
35-
{:default true
36-
:type Boolean})
37-
38-
(defconfig use-access-log
39-
"Indicates whether the servers will use the access log."
40-
{:default false
41-
:type Boolean})
42-
4332
(defconfig dev-system-echo-type
4433
"Specifies whether dev system should run an in-memory mock ECHO or use an
4534
external ECHO."

dev-system/src/cmr/dev_system/system.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[cmr.access-control.system :as access-control-system]
55
[cmr.bootstrap.config :as bootstrap-config]
66
[cmr.bootstrap.system :as bootstrap-system]
7+
[cmr.common.api.web-server :as web-serv]
78
[cmr.common.jobs :as jobs]
89
[cmr.common.lifecycle :as lifecycle]
910
[cmr.common.log :refer [info warn error]]
@@ -78,8 +79,8 @@
7879
"Update the web configuration options for the passed app system."
7980
[app-system]
8081
(-> app-system
81-
(assoc-in [:web :use-compression?] (dev-config/use-web-compression?))
82-
(assoc-in [:web :use-access-log?] (dev-config/use-access-log))))
82+
(assoc-in [:web :use-compression?] (web-serv/use-web-compression?))
83+
(assoc-in [:web :use-access-log?] (web-serv/use-access-log))))
8384

8485
(defn- set-web-server-options
8586
"Modifies an app server instance to configure web server options, returning a

elastic-utils-lib/project.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[clj-http "3.11.0"]
88
[clojurewerkz/elastisch "5.0.0-beta1"]
99
[commons-codec/commons-codec "1.11"]
10-
[commons-io "2.6"]
10+
[commons-io "2.18.0"]
1111
[nasa-cmr/cmr-common-lib "0.1.1-SNAPSHOT"]
1212
[nasa-cmr/cmr-transmit-lib "0.1.0-SNAPSHOT"]
1313
[org.apache.logging.log4j/log4j-api "2.15.0"]
@@ -47,7 +47,9 @@
4747
:internal-repos {}
4848
:kaocha {:dependencies [[lambdaisland/kaocha "1.0.732"]
4949
[lambdaisland/kaocha-cloverage "1.0.75"]
50-
[lambdaisland/kaocha-junit-xml "0.0.76"]]}}
50+
[lambdaisland/kaocha-junit-xml "0.0.76"]
51+
;; ring is needed or this fails in sys int group3
52+
[ring/ring-jetty-adapter "1.13.0"]]}}
5153
:aliases {;; Kaocha test aliases
5254
;; refer to tests.edn for test configuration
5355
"kaocha" ["with-profile" "+kaocha" "run" "-m" "kaocha.runner"]

0 commit comments

Comments
 (0)