Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Enabling CORS settings on OTLP Reciever HTTP endpoint #4549

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
faac2ef
configuring allowed headers and alloewed origins in OTLP reciever HTT…
severussnape321 Jun 23, 2023
6baee5c
Merge branch 'main' of https://github.com/pmuls99/jaeger into enableC…
severussnape321 Jul 11, 2023
e27c5fe
Merge branch 'main' of https://github.com/pmuls99/jaeger into enableC…
severussnape321 Jul 13, 2023
df13374
Merge branch 'jaegertracing:main' into enableCORSSettings
pmuls99 Jul 13, 2023
6c38a23
Merge branch 'main' of https://github.com/pmuls99/jaeger into enableC…
severussnape321 Jul 14, 2023
a3f4b32
added a new pkg,corscfg to enable cors on OTLP and Zipkin
severussnape321 Jul 15, 2023
e87329d
Merge branch 'enableCORSSettings' of https://github.com/pmuls99/jaege…
severussnape321 Jul 15, 2023
771142d
fixed a minor mistake
severussnape321 Jul 15, 2023
4e14f48
Merge branch 'main' into enableCORSSettings
pmuls99 Jul 15, 2023
cc8c6c2
Merge branch 'main' of https://github.com/pmuls99/jaeger into enableC…
severussnape321 Jul 15, 2023
6ef3983
Merge branch 'enableCORSSettings' of https://github.com/pmuls99/jaege…
severussnape321 Jul 15, 2023
9e90575
made several minor changes
severussnape321 Jul 15, 2023
73d3621
changed the name of corscfg file to options.go
severussnape321 Jul 15, 2023
148f357
Merge branch 'main' of https://github.com/pmuls99/jaeger into enableC…
severussnape321 Jul 16, 2023
52bfc4b
fixed naming convention
severussnape321 Jul 16, 2023
ce035f4
[hotrod]: Upgrade `redis` service to native OTEL instrumentation
afzal442 Jun 20, 2023
f7e4614
[test] Avoid logging to testing.T from server goroutine (#4546)
yurishkuro Jun 22, 2023
ae8e44e
configuring allowed headers and alloewed origins in OTLP reciever HTT…
severussnape321 Jun 23, 2023
6139771
Bump anchore/sbom-action from 0.14.1 to 0.14.3 (#4552)
dependabot[bot] Jun 28, 2023
2991952
Add readme
yurishkuro Jun 28, 2023
3fc7182
Rebuild jaeger-ui if the tree does not match any tag exactly (#4553)
bobrik Jun 29, 2023
1185b1b
Support normalized metric names (#4555)
albertteoh Jun 29, 2023
0b1dbf8
Fix OTEL logging in HotRod example (#4556)
albertteoh Jul 2, 2023
7fdf0e7
[hotROD] Replace gRPC instrumentation with OTEL (#4558)
afzal442 Jul 2, 2023
e7b3c3a
[hotROD] Add OTEL instrumentation to customer svc (#4559)
afzal442 Jul 2, 2023
dbf602b
Configure groups for dependabot
yurishkuro Jul 4, 2023
fbf4c55
Reduce dependabot pattern to 50 chars
yurishkuro Jul 4, 2023
4b41175
Bump the otel-collector group with 2 updates (#4563)
dependabot[bot] Jul 4, 2023
58624c1
Bump the hashicorp group with 1 update (#4562)
dependabot[bot] Jul 4, 2023
c18134d
Bump step-security/harden-runner from 2.4.0 to 2.4.1 (#4551)
dependabot[bot] Jul 4, 2023
93f278c
Bump golang.org/x/sys from 0.9.0 to 0.10.0 (#4564)
dependabot[bot] Jul 4, 2023
550f688
Bump the otel-collector group with 1 update (#4568)
dependabot[bot] Jul 6, 2023
97ee792
Bump golang.org/x/net from 0.11.0 to 0.12.0 (#4569)
dependabot[bot] Jul 6, 2023
c1bd659
[tracegen] Enable OTEL debug logging (#4571)
yurishkuro Jul 6, 2023
5ec2657
Prepare release v1.47.0 (#4570)
jkowall Jul 6, 2023
43522da
[hotrod] Handle both OT and OTEL baggage (#4572)
yurishkuro Jul 6, 2023
4e82597
Bump grpcio from 1.50.0 to 1.53.0 in /docker-compose/monitor (#4567)
dependabot[bot] Jul 7, 2023
1e6c97c
[hotrod] Bump jquery to 3.7.0 (#4577)
yurishkuro Jul 11, 2023
98b1423
[tracegen] Enable BlockOnQueueFull in OTel SDK to avoid dropped spans…
haanhvu Jul 11, 2023
1d3ed07
Raise awareness of current Russia-Ukraine situation, targeting Russia…
yurishkuro Jul 13, 2023
44a4b6a
Fix link
yurishkuro Jul 13, 2023
58e2bdb
added a new pkg,corscfg to enable cors on OTLP and Zipkin
severussnape321 Jul 15, 2023
c4350e3
fixed a minor mistake
severussnape321 Jul 15, 2023
c54ce55
[kafka-consumer] Use wait group to ensure goroutine is finished befor…
kennyaz Jul 14, 2023
a29eb29
made several minor changes
severussnape321 Jul 15, 2023
90307e3
changed the name of corscfg file to options.go
severussnape321 Jul 15, 2023
bbacd0c
[hotrod] Upgrade HotROD to use OpenTelemetry instrumentation (#4548)
afzal442 Jul 15, 2023
be840c4
[hotrod] Validate user input to avoid security warnings from code sca…
yurishkuro Jul 16, 2023
aa0169e
fixed naming convention
severussnape321 Jul 16, 2023
8832a94
Merge branch 'enableCORSSettings' of https://github.com/pmuls99/jaege…
severussnape321 Jul 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/collector/app/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ func (c *Collector) Start(options *flags.CollectorOptions) error {
Handler: c.spanHandlers.ZipkinSpansHandler,
TLSConfig: options.Zipkin.TLS,
HealthCheck: c.hCheck,
AllowedHeaders: options.Zipkin.AllowedHeaders,
AllowedOrigins: options.Zipkin.AllowedOrigins,
CORSConfig: options.Zipkin.CORS,
Logger: c.logger,
MetricsFactory: c.metricsFactory,
KeepAlive: options.Zipkin.KeepAlive,
Expand Down
32 changes: 18 additions & 14 deletions cmd/collector/app/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/flags"
"github.com/jaegertracing/jaeger/pkg/config/corscfg"
"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
"github.com/jaegertracing/jaeger/pkg/tenancy"
"github.com/jaegertracing/jaeger/ports"
Expand All @@ -38,19 +39,16 @@ const (

flagSuffixHostPort = "host-port"

flagSuffixHTTPReadTimeout = "read-timeout"
flagSuffixHTTPReadHeaderTimeout = "read-header-timeout"
flagSuffixHTTPIdleTimeout = "idle-timeout"

flagSuffixHTTPReadTimeout = "read-timeout"
flagSuffixHTTPReadHeaderTimeout = "read-header-timeout"
flagSuffixHTTPIdleTimeout = "idle-timeout"
flagSuffixGRPCMaxReceiveMessageLength = "max-message-size"
flagSuffixGRPCMaxConnectionAge = "max-connection-age"
flagSuffixGRPCMaxConnectionAgeGrace = "max-connection-age-grace"

flagCollectorOTLPEnabled = "collector.otlp.enabled"

flagZipkinHTTPHostPort = "collector.zipkin.host-port"
flagZipkinAllowedHeaders = "collector.zipkin.allowed-headers"
flagZipkinAllowedOrigins = "collector.zipkin.allowed-origins"
flagZipkinKeepAliveEnabled = "collector.zipkin.keep-alive"

// DefaultNumWorkers is the default number of workers consuming from the processor queue
Expand Down Expand Up @@ -98,6 +96,12 @@ var otlpServerFlagsCfg = struct {
var tlsZipkinFlagsConfig = tlscfg.ServerFlagsConfig{
Prefix: "collector.zipkin",
}
var corsZipkinFlags = corscfg.Flags{
Prefix: "collector.zipkin",
}
var corsOTLPFlags = corscfg.Flags{
Prefix: "collector.otlp.http",
}

// CollectorOptions holds configuration for collector
type CollectorOptions struct {
Expand All @@ -121,12 +125,10 @@ type CollectorOptions struct {
Zipkin struct {
// HTTPHostPort is the host:port address that the Zipkin collector service listens in on for http requests
HTTPHostPort string
// ZipkinAllowedOrigins is a list of origins a cross-domain request to the Zipkin collector service can be executed from
AllowedOrigins string
// ZipkinAllowedHeaders is a list of headers that the Zipkin collector service allowes the client to use with cross-domain requests
AllowedHeaders string
// TLS configures secure transport for Zipkin endpoint to collect spans
TLS tlscfg.Options
// CORS allows CORS requests , sets the values for Allowed Headers and Allowed Origins.
CORS corscfg.Options
// KeepAlive configures allow Keep-Alive for Zipkin HTTP server
KeepAlive bool
}
Expand All @@ -153,6 +155,8 @@ type HTTPOptions struct {
ReadHeaderTimeout time.Duration
// IdleTimeout sets the respective parameter of http.Server
IdleTimeout time.Duration
// CORS allows CORS requests , sets the values for Allowed Headers and Allowed Origins.
CORS corscfg.Options
}

// GRPCOptions defines options for a gRPC server
Expand Down Expand Up @@ -186,13 +190,13 @@ func AddFlags(flags *flag.FlagSet) {

flags.Bool(flagCollectorOTLPEnabled, true, "Enables OpenTelemetry OTLP receiver on dedicated HTTP and gRPC ports")
addHTTPFlags(flags, otlpServerFlagsCfg.HTTP, "")
corsOTLPFlags.AddFlags(flags)
addGRPCFlags(flags, otlpServerFlagsCfg.GRPC, "")

flags.String(flagZipkinAllowedHeaders, "content-type", "Comma separated list of allowed headers for the Zipkin collector service, default content-type")
flags.String(flagZipkinAllowedOrigins, "*", "Comma separated list of allowed origins for the Zipkin collector service, default accepts all")
flags.String(flagZipkinHTTPHostPort, "", "The host:port (e.g. 127.0.0.1:9411 or :9411) of the collector's Zipkin server (disabled by default)")
flags.Bool(flagZipkinKeepAliveEnabled, true, "KeepAlive configures allow Keep-Alive for Zipkin HTTP server (enabled by default)")
tlsZipkinFlagsConfig.AddFlags(flags)
corsZipkinFlags.AddFlags(flags)

tenancy.AddFlags(flags)
}
Expand Down Expand Up @@ -273,19 +277,19 @@ func (cOpts *CollectorOptions) InitFromViper(v *viper.Viper, logger *zap.Logger)
if err := cOpts.OTLP.HTTP.initFromViper(v, logger, otlpServerFlagsCfg.HTTP); err != nil {
return cOpts, fmt.Errorf("failed to parse OTLP/HTTP server options: %w", err)
}
cOpts.OTLP.HTTP.CORS = corsOTLPFlags.InitFromViper(v)
if err := cOpts.OTLP.GRPC.initFromViper(v, logger, otlpServerFlagsCfg.GRPC); err != nil {
return cOpts, fmt.Errorf("failed to parse OTLP/gRPC server options: %w", err)
}

cOpts.Zipkin.AllowedHeaders = v.GetString(flagZipkinAllowedHeaders)
cOpts.Zipkin.AllowedOrigins = v.GetString(flagZipkinAllowedOrigins)
cOpts.Zipkin.KeepAlive = v.GetBool(flagZipkinKeepAliveEnabled)
cOpts.Zipkin.HTTPHostPort = ports.FormatHostPort(v.GetString(flagZipkinHTTPHostPort))
if tlsZipkin, err := tlsZipkinFlagsConfig.InitFromViper(v); err == nil {
cOpts.Zipkin.TLS = tlsZipkin
} else {
return cOpts, fmt.Errorf("failed to parse Zipkin TLS options: %w", err)
}
cOpts.Zipkin.CORS = corsZipkinFlags.InitFromViper(v)

return cOpts, nil
}
2 changes: 2 additions & 0 deletions cmd/collector/app/handler/otlp_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ func applyHTTPSettings(cfg *confighttp.HTTPServerSettings, opts *flags.HTTPOptio
if opts.TLS.Enabled {
cfg.TLSSetting = applyTLSSettings(&opts.TLS)
}
cfg.CORS.AllowedHeaders = opts.CORS.AllowedHeaders
cfg.CORS.AllowedOrigins = opts.CORS.AllowedOrigins
}

func applyTLSSettings(opts *tlscfg.Options) *configtls.TLSServerSetting {
Expand Down
12 changes: 4 additions & 8 deletions cmd/collector/app/server/zipkin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package server
import (
"net"
"net/http"
"strings"
"time"

"github.com/gorilla/mux"
Expand All @@ -27,6 +26,7 @@ import (

"github.com/jaegertracing/jaeger/cmd/collector/app/handler"
"github.com/jaegertracing/jaeger/cmd/collector/app/zipkin"
"github.com/jaegertracing/jaeger/pkg/config/corscfg"
"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
"github.com/jaegertracing/jaeger/pkg/healthcheck"
"github.com/jaegertracing/jaeger/pkg/httpmetrics"
Expand All @@ -39,8 +39,7 @@ type ZipkinServerParams struct {
TLSConfig tlscfg.Options
HostPort string
Handler handler.ZipkinSpansHandler
AllowedOrigins string
AllowedHeaders string
CORSConfig corscfg.Options
HealthCheck *healthcheck.HealthCheck
Logger *zap.Logger
MetricsFactory metrics.Factory
Expand Down Expand Up @@ -86,13 +85,10 @@ func serveZipkin(server *http.Server, listener net.Listener, params *ZipkinServe
zHandler := zipkin.NewAPIHandler(params.Handler)
zHandler.RegisterRoutes(r)

origins := strings.Split(strings.ReplaceAll(params.AllowedOrigins, " ", ""), ",")
headers := strings.Split(strings.ReplaceAll(params.AllowedHeaders, " ", ""), ",")

cors := cors.New(cors.Options{
AllowedOrigins: origins,
AllowedOrigins: params.CORSConfig.AllowedOrigins,
AllowedMethods: []string{"POST"}, // Allowing only POST, because that's the only handled one
AllowedHeaders: headers,
AllowedHeaders: params.CORSConfig.AllowedHeaders,
})

recoveryHandler := recoveryhandler.NewRecoveryHandler(params.Logger, true)
Expand Down
43 changes: 43 additions & 0 deletions pkg/config/corscfg/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2023 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package corscfg

import (
"flag"

"github.com/spf13/viper"
)

const (
corsPrefix = ".cors"
corsAllowedHeaders = corsPrefix + ".allowed-headers"
corsAllowedOrigins = corsPrefix + ".allowed-origins"
)

type Flags struct {
Prefix string
}

func (c Flags) AddFlags(flags *flag.FlagSet) {
flags.String(c.Prefix+corsAllowedHeaders, "content-type", "Allowed headers for the HTTP port , default content-type")
flags.String(c.Prefix+corsAllowedOrigins, "*", "Allowed origins for the HTTP port , default accepts all")
}

func (c Flags) InitFromViper(v *viper.Viper) Options {
var p Options
p.AllowedHeaders = v.GetStringSlice(c.Prefix + corsAllowedHeaders)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that previously we were stripping whitespace

strings.Split(strings.ReplaceAll(params.AllowedOrigins, " ", ""), ",")

Is it going to be done automatically by viper.GetStringSlice? If not it's not a backwards compatible change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add tests to this package? it's small and has no external deps, no reason not to write tests, and in particular validate ^^^

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just checking with you if I was going in the right direction , since I am new to the community. I will write the tests and validate soon, sorry for the delay!

p.AllowedOrigins = v.GetStringSlice(c.Prefix + corsAllowedOrigins)
return p
}
20 changes: 20 additions & 0 deletions pkg/config/corscfg/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2023 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package corscfg

type Options struct {
AllowedOrigins []string `mapstructure:"allowed_origins"`
AllowedHeaders []string `mapstructure:"allowed_headers"`
}
Loading