Skip to content

Commit 467e1e2

Browse files
(PUP-11973) Only send compiler header for v3 catalog requests
1 parent 4a843ae commit 467e1e2

File tree

5 files changed

+40
-22
lines changed

5 files changed

+40
-22
lines changed

src/clj/puppetlabs/puppetserver/ringutils.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
{:status 403 :body "Forbidden."})))
7777

7878
(defn wrap-with-certname-as-compiler
79-
"Function that returns middleware that add X-Puppet-Compiler-Name to the response"
79+
"Function that returns middleware that add X-Puppet-Compiler-Name to the response,
80+
only for the posts to the v3 catalog endpoint. Otherwise, do nothing."
8081
[handler name]
8182
(fn [request]
8283
(ring/header (handler request) "X-Puppet-Compiler-Name" name)))

src/clj/puppetlabs/services/legacy_routes/legacy_routes_service.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
false
4646
nil
4747
nil
48-
nil))
48+
nil
49+
(get-in config [:puppetserver :certname])))
4950
master-route-handler (comidi/routes->handler master-routes)
5051
master-mount (master-core/get-master-mount
5152
master-ns

src/clj/puppetlabs/services/master/master_core.clj

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,8 @@
10511051
"v3 route tree for the ruby side of the master service."
10521052
[request-handler :- IFn
10531053
bolt-builtin-content-dir :- (schema/maybe [schema/Str])
1054-
bolt-projects-dir :- (schema/maybe schema/Str)]
1054+
bolt-projects-dir :- (schema/maybe schema/Str)
1055+
certname :- schema/Str]
10551056
(comidi/routes
10561057
(comidi/GET ["/node/" [#".*" :rest]] request
10571058
(request-handler request))
@@ -1072,7 +1073,8 @@
10721073
(comidi/GET ["/catalog/" [#".*" :rest]] request
10731074
(request-handler (assoc request :include-code-id? true)))
10741075
(comidi/POST ["/catalog/" [#".*" :rest]] request
1075-
(request-handler (assoc request :include-code-id? true)))
1076+
(let [request-handler (ringutils/wrap-with-certname-as-compiler request-handler certname)]
1077+
(request-handler (assoc request :include-code-id? true))))
10761078
(comidi/PUT ["/facts/" [#".*" :rest]] request
10771079
(request-handler request))
10781080
(comidi/PUT ["/report/" [#".*" :rest]] request
@@ -1178,9 +1180,10 @@
11781180
wrap-with-jruby-queue-limit :- IFn
11791181
boltlib-path :- (schema/maybe [schema/Str])
11801182
bolt-builtin-content-dir :- (schema/maybe [schema/Str])
1181-
bolt-projects-dir :- (schema/maybe schema/Str)]
1183+
bolt-projects-dir :- (schema/maybe schema/Str)
1184+
certname :- schema/Str]
11821185
(comidi/context "/v3"
1183-
(v3-ruby-routes ruby-request-handler bolt-builtin-content-dir bolt-projects-dir)
1186+
(v3-ruby-routes ruby-request-handler bolt-builtin-content-dir bolt-projects-dir certname)
11841187
(comidi/wrap-routes
11851188
(v3-clojure-routes jruby-service
11861189
get-code-content-fn
@@ -1292,7 +1295,8 @@
12921295
environment-class-cache-enabled :- schema/Bool
12931296
boltlib-path :- (schema/maybe [schema/Str])
12941297
bolt-builtin-content-dir :- (schema/maybe [schema/Str])
1295-
bolt-projects-dir :- (schema/maybe schema/Str)]
1298+
bolt-projects-dir :- (schema/maybe schema/Str)
1299+
certname :- schema/Str]
12961300
(comidi/routes
12971301
(v3-routes ruby-request-handler
12981302
clojure-request-wrapper
@@ -1303,7 +1307,8 @@
13031307
wrap-with-jruby-queue-limit
13041308
boltlib-path
13051309
bolt-builtin-content-dir
1306-
bolt-projects-dir)
1310+
bolt-projects-dir
1311+
certname)
13071312
(v4-routes clojure-request-wrapper
13081313
jruby-service
13091314
wrap-with-jruby-queue-limit
@@ -1313,16 +1318,14 @@
13131318
wrap-middleware :- IFn
13141319
[handler :- IFn
13151320
authorization-fn :- IFn
1316-
puppet-version :- schema/Str
1317-
certname :- schema/Str]
1321+
puppet-version :- schema/Str]
13181322
(-> handler
13191323
authorization-fn
13201324
(middleware/wrap-uncaught-errors :plain)
13211325
middleware/wrap-request-logging
13221326
i18n/locale-negotiator
13231327
middleware/wrap-response-logging
1324-
(ringutils/wrap-with-puppet-version-header puppet-version)
1325-
(ringutils/wrap-with-certname-as-compiler certname)))
1328+
(ringutils/wrap-with-puppet-version-header puppet-version)))
13261329

13271330
(schema/defn ^:always-validate get-master-route-config
13281331
"Get the webserver route configuration for the master service"
@@ -1372,14 +1375,12 @@
13721375
certname :- schema/Str]
13731376
(let [ruby-request-handler (wrap-middleware handle-request
13741377
wrap-with-authorization-check
1375-
puppet-version
1376-
certname)
1378+
puppet-version)
13771379
clojure-request-wrapper (fn [handler]
13781380
(wrap-middleware
13791381
(ring/wrap-params handler)
13801382
wrap-with-authorization-check
1381-
puppet-version
1382-
certname))]
1383+
puppet-version))]
13831384
(root-routes ruby-request-handler
13841385
clojure-request-wrapper
13851386
jruby-service
@@ -1389,7 +1390,8 @@
13891390
environment-class-cache-enabled
13901391
boltlib-path
13911392
bolt-builtin-content-dir
1392-
bolt-projects-dir)))
1393+
bolt-projects-dir
1394+
certname)))
13931395

13941396
(def MasterStatusV1
13951397
{(schema/optional-key :experimental) {:http-metrics [http-metrics/RouteSummary]

test/integration/puppetlabs/services/master/master_service_test.clj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,17 @@
694694
(finally
695695
(jruby-testutils/return-instance jruby-service jruby-instance :http-report-processor-metrics-test)))))))
696696

697+
(deftest ^:integration compiler-name-as-header
698+
(testing "POSTs to the v3 catalog endpoint return the certname as a header"
699+
(bootstrap-testutils/with-puppetserver-running
700+
app
701+
{:jruby-puppet {:gem-path gem-path
702+
:max-active-instances 1
703+
:server-code-dir test-resources-code-dir
704+
:server-conf-dir master-service-test-runtime-dir}}
705+
(let [resp (http-post "/puppet/v3/catalog/foo?environment=production" "")]
706+
(is (= "localhost" (get-in resp [:headers "x-puppet-compiler-name"])))))))
707+
697708
(deftest encoded-spaces-test
698709
(testing "Encoded spaces should be routed correctly"
699710
(bootstrap-testutils/with-puppetserver-running

test/unit/puppetlabs/services/master/master_core_test.clj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
true
5252
nil
5353
["./dev-resources/puppetlabs/services/master/master_core_test/builtin_bolt_content"]
54-
"./dev-resources/puppetlabs/services/master/master_core_test/bolt_projects")
54+
"./dev-resources/puppetlabs/services/master/master_core_test/bolt_projects"
55+
"test-certname")
5556
(comidi/routes->handler)
5657
(wrap-middleware identity puppet-version)))
5758

@@ -65,10 +66,12 @@
6566
request (partial app-request app)]
6667
(is (= 200 (:status (request "/v3/environments"))))
6768
(is (= 200 (:status (request "/v3/catalog/bar?environment=environment1234"))))
68-
(is (= 200 (:status (app (-> {:request-method :post
69-
:uri "/v3/catalog/bar"
70-
:content-type "application/x-www-form-urlencoded"}
71-
(ring-mock/body "environment=environment1234"))))))
69+
(let [response (app (-> {:request-method :post
70+
:uri "/v3/catalog/bar"
71+
:content-type "application/x-www-form-urlencoded"}
72+
(ring-mock/body "environment=environment1234")))]
73+
(is (= "test-certname" (get-in response [:headers "X-Puppet-Compiler-Name"]))
74+
(is (= 200 (:status response)))))
7275
(is (nil? (request "/foo")))
7376
(is (nil? (request "/foo/bar")))
7477
(doseq [[method paths]

0 commit comments

Comments
 (0)