Skip to content

Commit 581f9be

Browse files
JonasVerhofsteyurishkuro
authored andcommitted
Change Zipkin CORS origins and headers to comma separated list (#1556)
Signed-off-by: Jonas Verhofsté <25819942+JonasVerhofste@users.noreply.github.com>
1 parent 75b670f commit 581f9be

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

cmd/collector/app/builder/builder_flags.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ func AddFlags(flags *flag.FlagSet) {
7878
flags.String(collectorGRPCCert, "", "Path to TLS certificate for the gRPC collector TLS service")
7979
flags.String(collectorGRPCKey, "", "Path to TLS key for the gRPC collector TLS cert")
8080
flags.String(collectorGRPCClientCA, "", "Path to a TLS CA to verify certificates presented by clients (if unset, all clients are permitted)")
81-
flags.String(collectorZipkinAllowedOrigins, "*", "Allowed origins for the Zipkin collector service, default accepts all")
82-
flags.String(collectorZipkinAllowedHeaders, "content-type", "Allowed headers for the Zipkin collector service, default content-type")
81+
flags.String(collectorZipkinAllowedOrigins, "*", "Comma separated list of allowed origins for the Zipkin collector service, default accepts all")
82+
flags.String(collectorZipkinAllowedHeaders, "content-type", "Comma separated list of allowed headers for the Zipkin collector service, default content-type")
8383
}
8484

8585
// InitFromViper initializes CollectorOptions with properties from viper

cmd/collector/main.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"net/http"
2323
"os"
2424
"strconv"
25+
"strings"
2526

2627
"github.com/gorilla/mux"
2728
"github.com/rs/cors"
@@ -227,10 +228,13 @@ func startZipkinHTTPAPI(
227228
r := mux.NewRouter()
228229
zHandler.RegisterRoutes(r)
229230

231+
origins := strings.Split(strings.Replace(allowedOrigins, " ", "", -1), ",")
232+
headers := strings.Split(strings.Replace(allowedHeaders, " ", "", -1), ",")
233+
230234
c := cors.New(cors.Options{
231-
AllowedOrigins: []string{allowedOrigins},
235+
AllowedOrigins: origins,
232236
AllowedMethods: []string{"POST"}, // Allowing only POST, because that's the only handled one
233-
AllowedHeaders: []string{allowedHeaders},
237+
AllowedHeaders: headers,
234238
})
235239

236240
httpPortStr := ":" + strconv.Itoa(zipkinPort)

0 commit comments

Comments
 (0)