Skip to content

Commit 9b283c2

Browse files
Merge pull request #2790 from tvpartytonight/PUP-11973_backport
(PUP-11973) Only send compiler header for v3 catalog requests
2 parents ee3eee9 + 467e1e2 commit 9b283c2

File tree

6 files changed

+45
-15
lines changed

6 files changed

+45
-15
lines changed

src/clj/puppetlabs/puppetserver/ringutils.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@
7575
(handler req)
7676
{:status 403 :body "Forbidden."})))
7777

78+
(defn wrap-with-certname-as-compiler
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."
81+
[handler name]
82+
(fn [request]
83+
(ring/header (handler request) "X-Puppet-Compiler-Name" name)))
84+
7885
(defn wrap-with-puppet-version-header
7986
"Function that returns a middleware that adds an
8087
X-Puppet-Version header to the response."

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: 15 additions & 8 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
@@ -1366,7 +1371,8 @@
13661371
environment-class-cache-enabled :- schema/Bool
13671372
boltlib-path :- (schema/maybe [schema/Str])
13681373
bolt-builtin-content-dir :- (schema/maybe [schema/Str])
1369-
bolt-projects-dir :- (schema/maybe schema/Str)]
1374+
bolt-projects-dir :- (schema/maybe schema/Str)
1375+
certname :- schema/Str]
13701376
(let [ruby-request-handler (wrap-middleware handle-request
13711377
wrap-with-authorization-check
13721378
puppet-version)
@@ -1384,7 +1390,8 @@
13841390
environment-class-cache-enabled
13851391
boltlib-path
13861392
bolt-builtin-content-dir
1387-
bolt-projects-dir)))
1393+
bolt-projects-dir
1394+
certname)))
13881395

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

src/clj/puppetlabs/services/master/master_service.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@
149149
environment-class-cache-enabled
150150
boltlib-path
151151
bolt-builtin-content-dir
152-
bolt-projects-dir))
152+
bolt-projects-dir
153+
certname))
153154
routes (comidi/context path ring-app)
154155
route-metadata (comidi/route-metadata routes)
155156
comidi-handler (comidi/routes->handler routes)

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)