Skip to content

Commit 8cc6d36

Browse files
add HSTS headers to HTTPS mode
1 parent eb4c18c commit 8cc6d36

File tree

14 files changed

+272
-115
lines changed

14 files changed

+272
-115
lines changed

cmd/fa-om-exporter/main.go

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,6 @@ func main() {
8888
addr := fmt.Sprintf("%s:%d", *host, *port)
8989
log.Printf("Start Pure FlashArray exporter %s on %s", version, addr)
9090

91-
http.HandleFunc("/", index)
92-
http.HandleFunc("/metrics/volumes", func(w http.ResponseWriter, r *http.Request) {
93-
metricsHandler(w, r)
94-
})
95-
http.HandleFunc("/metrics/hosts", func(w http.ResponseWriter, r *http.Request) {
96-
metricsHandler(w, r)
97-
})
98-
http.HandleFunc("/metrics/pods", func(w http.ResponseWriter, r *http.Request) {
99-
metricsHandler(w, r)
100-
})
101-
http.HandleFunc("/metrics/directories", func(w http.ResponseWriter, r *http.Request) {
102-
metricsHandler(w, r)
103-
})
104-
http.HandleFunc("/metrics/array", func(w http.ResponseWriter, r *http.Request) {
105-
metricsHandler(w, r)
106-
})
107-
http.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {
108-
metricsHandler(w, r)
109-
})
11091
if isFile(*cert) && isFile(*key) {
11192

11293
cfg := &tls.Config{
@@ -125,9 +106,55 @@ func main() {
125106
TLSConfig: cfg,
126107
Addr: addr,
127108
}
128-
109+
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
110+
w.Header().Add("Strict-Transport-Security", "max-age=63072000; includeSubDomains")
111+
index(w, r)
112+
})
113+
http.HandleFunc("/metrics/volumes", func(w http.ResponseWriter, r *http.Request) {
114+
w.Header().Add("Strict-Transport-Security", "max-age=63072000; includeSubDomains")
115+
metricsHandler(w, r)
116+
})
117+
http.HandleFunc("/metrics/hosts", func(w http.ResponseWriter, r *http.Request) {
118+
w.Header().Add("Strict-Transport-Security", "max-age=63072000; includeSubDomains")
119+
metricsHandler(w, r)
120+
})
121+
http.HandleFunc("/metrics/pods", func(w http.ResponseWriter, r *http.Request) {
122+
w.Header().Add("Strict-Transport-Security", "max-age=63072000; includeSubDomains")
123+
metricsHandler(w, r)
124+
})
125+
http.HandleFunc("/metrics/directories", func(w http.ResponseWriter, r *http.Request) {
126+
w.Header().Add("Strict-Transport-Security", "max-age=63072000; includeSubDomains")
127+
metricsHandler(w, r)
128+
})
129+
http.HandleFunc("/metrics/array", func(w http.ResponseWriter, r *http.Request) {
130+
w.Header().Add("Strict-Transport-Security", "max-age=63072000; includeSubDomains")
131+
metricsHandler(w, r)
132+
})
133+
http.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {
134+
w.Header().Add("Strict-Transport-Security", "max-age=63072000; includeSubDomains")
135+
metricsHandler(w, r)
136+
})
129137
log.Fatal(srv.ListenAndServeTLS(*cert, *key))
130138
} else {
139+
http.HandleFunc("/", index)
140+
http.HandleFunc("/metrics/volumes", func(w http.ResponseWriter, r *http.Request) {
141+
metricsHandler(w, r)
142+
})
143+
http.HandleFunc("/metrics/hosts", func(w http.ResponseWriter, r *http.Request) {
144+
metricsHandler(w, r)
145+
})
146+
http.HandleFunc("/metrics/pods", func(w http.ResponseWriter, r *http.Request) {
147+
metricsHandler(w, r)
148+
})
149+
http.HandleFunc("/metrics/directories", func(w http.ResponseWriter, r *http.Request) {
150+
metricsHandler(w, r)
151+
})
152+
http.HandleFunc("/metrics/array", func(w http.ResponseWriter, r *http.Request) {
153+
metricsHandler(w, r)
154+
})
155+
http.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {
156+
metricsHandler(w, r)
157+
})
131158
log.Fatal(http.ListenAndServe(addr, nil))
132159
}
133160
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/akamensky/argparse v1.4.0
77
github.com/go-resty/resty/v2 v2.14.0
88
github.com/google/go-cmp v0.6.0
9-
github.com/prometheus/client_golang v1.20.0
9+
github.com/prometheus/client_golang v1.20.2
1010
github.com/prometheus/client_model v0.6.1
1111
gopkg.in/yaml.v3 v3.0.1
1212
)
@@ -17,7 +17,7 @@ require (
1717
github.com/klauspost/compress v1.17.9 // indirect
1818
github.com/kr/text v0.2.0 // indirect
1919
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
20-
github.com/prometheus/common v0.55.0 // indirect
20+
github.com/prometheus/common v0.58.0 // indirect
2121
github.com/prometheus/procfs v0.15.1 // indirect
2222
golang.org/x/net v0.28.0 // indirect
2323
golang.org/x/sys v0.24.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
1919
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
2020
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
2121
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
22-
github.com/prometheus/client_golang v1.20.0 h1:jBzTZ7B099Rg24tny+qngoynol8LtVYlA2bqx3vEloI=
23-
github.com/prometheus/client_golang v1.20.0/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
22+
github.com/prometheus/client_golang v1.20.2 h1:5ctymQzZlyOON1666svgwn3s6IKWgfbjsejTMiXIyjg=
23+
github.com/prometheus/client_golang v1.20.2/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
2424
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
2525
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
26-
github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc=
27-
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
26+
github.com/prometheus/common v0.58.0 h1:N+N8vY4/23r6iYfD3UQZUoJPnUYAo7v6LG5XZxjZTXo=
27+
github.com/prometheus/common v0.58.0/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0=
2828
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
2929
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
3030
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=

vendor/github.com/prometheus/client_golang/prometheus/process_collector.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/prometheus/client_golang/prometheus/promhttp/http.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/prometheus/common/expfmt/decode.go

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/prometheus/common/expfmt/encode.go

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/prometheus/common/expfmt/expfmt.go

Lines changed: 30 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/prometheus/common/expfmt/openmetrics_create.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/prometheus/common/expfmt/text_create.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)