From 137da274cc8da08bc2bb7f830598fa3f5a403e58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Samin?= Date: Tue, 13 Apr 2021 17:50:09 +0200 Subject: [PATCH] feat(service): add ip address in router logs (#5789) --- engine/api/api.go | 6 ++--- engine/api/api_routes.go | 2 +- engine/api/config.go | 8 +++++-- engine/api/router.go | 28 +++++++++++++++++++++--- engine/api/services/cdn.go | 20 +++++++++++++---- engine/api/test/assets/assets.go | 5 +++-- engine/api/workflow_queue.go | 2 +- engine/api/workflow_queue_test.go | 8 ++++--- engine/cdn/cdn.go | 8 +++---- engine/cdn/types.go | 20 ++++++++--------- engine/config.go | 14 ++++++++++++ engine/elasticsearch/elasticsearch.go | 8 +++---- engine/elasticsearch/types.go | 9 +++----- engine/hatchery/kubernetes/kubernetes.go | 8 ++++--- engine/hatchery/local/local.go | 8 +++---- engine/hatchery/marathon/marathon.go | 8 +++---- engine/hatchery/openstack/openstack.go | 8 +++---- engine/hatchery/serve.go | 20 ++++++++++++++++- engine/hatchery/swarm/swarm.go | 5 ----- engine/hatchery/swarm/swarm_conf.go | 7 +++++- engine/hatchery/vsphere/hatchery.go | 8 +++---- engine/hooks/hooks.go | 8 +++---- engine/hooks/types.go | 7 ++---- engine/migrateservice/service.go | 16 +++++--------- engine/repositories/repositories.go | 8 +++---- engine/repositories/types.go | 19 +++++++--------- engine/service/types.go | 19 +++++++++------- engine/ui/types.go | 23 +++++++++---------- engine/ui/ui.go | 2 +- engine/vcs/types.go | 11 ++++------ engine/vcs/vcs.go | 8 +++---- engine/worker/internal/take.go | 17 ++++++++++++++ sdk/log/fields.go | 2 ++ sdk/services.go | 5 +++-- sdk/worker.go | 27 ++++++++++++----------- 35 files changed, 229 insertions(+), 153 deletions(-) diff --git a/engine/api/api.go b/engine/api/api.go index 653dda7d31..2b8baa9168 100644 --- a/engine/api/api.go +++ b/engine/api/api.go @@ -64,10 +64,7 @@ type Configuration struct { API string `toml:"api" default:"http://localhost:8081" json:"api"` UI string `toml:"ui" default:"http://localhost:8080" json:"ui"` } `toml:"url" comment:"#####################\n CDS URLs Settings \n####################" json:"url"` - HTTP struct { - Addr string `toml:"addr" default:"" commented:"true" comment:"Listen HTTP address without port, example: 127.0.0.1" json:"addr"` - Port int `toml:"port" default:"8081" json:"port"` - } `toml:"http" json:"http"` + HTTP service.HTTPRouterConfiguration `toml:"http" json:"http"` Secrets struct { Key string `toml:"key" json:"-"` } `toml:"secrets" json:"secrets"` @@ -552,6 +549,7 @@ func (a *API) Serve(ctx context.Context) error { a.Router = &Router{ Mux: mux.NewRouter(), Background: ctx, + Config: a.Config.HTTP, } a.InitRouter() if err := a.initWebsocket(event.DefaultPubSubKey); err != nil { diff --git a/engine/api/api_routes.go b/engine/api/api_routes.go index 38c90cfdc0..f4a010f79d 100644 --- a/engine/api/api_routes.go +++ b/engine/api/api_routes.go @@ -443,7 +443,7 @@ func (api *API) InitRouter() { r.Handle("/template/{groupName}/{templateSlug}/usage", Scope(sdk.AuthConsumerScopeTemplate), r.GET(api.getTemplateUsageHandler)) //Not Found handler - r.Mux.NotFoundHandler = http.HandlerFunc(NotFoundHandler) + r.Mux.NotFoundHandler = http.HandlerFunc(r.NotFoundHandler) r.computeScopeDetails() } diff --git a/engine/api/config.go b/engine/api/config.go index 5e1233bcab..f363156dba 100644 --- a/engine/api/config.go +++ b/engine/api/config.go @@ -33,7 +33,7 @@ func (api *API) ConfigVCShandler() service.Handler { func (api *API) ConfigCDNHandler() service.Handler { return func(ctx context.Context, w http.ResponseWriter, r *http.Request) error { - tcpURL, err := services.GetCDNPublicTCPAdress(ctx, api.mustDB()) + tcpURL, tcpURLEnableTLS, err := services.GetCDNPublicTCPAdress(ctx, api.mustDB()) if err != nil { return err } @@ -41,6 +41,10 @@ func (api *API) ConfigCDNHandler() service.Handler { if err != nil { return err } - return service.WriteJSON(w, sdk.CDNConfig{TCPURL: tcpURL, HTTPURL: httpURL}, http.StatusOK) + return service.WriteJSON(w, + sdk.CDNConfig{TCPURL: tcpURL, + TCPURLEnableTLS: tcpURLEnableTLS, + HTTPURL: httpURL}, + http.StatusOK) } } diff --git a/engine/api/router.go b/engine/api/router.go index f453ba1526..96edfb3d38 100644 --- a/engine/api/router.go +++ b/engine/api/router.go @@ -59,6 +59,7 @@ type Router struct { nbPanic int lastPanic *time.Time scopeDetails []sdk.AuthConsumerScopeDetail + Config service.HTTPRouterConfiguration } // HandlerConfigFunc is a type used in the router configuration fonction "Handle" @@ -224,7 +225,6 @@ func (r *Router) computeScopeDetails() { Methods: methods, }) } - details[i].Scope = scope details[i].Endpoints = endpoints } @@ -340,6 +340,13 @@ func (r *Router) handle(uri string, scope HandlerScope, handlers ...*service.Han telemetry.Path, req.URL.Path, telemetry.Method, req.Method) + // Retrieve the client ip address from the header (X-Forwarded-For by default) + clientIP := req.Header.Get(r.Config.HeaderXForwardedFor) + if clientIP == "" { + // If the header has not been found, fallback on the remote adress from the http request + clientIP = req.RemoteAddr + } + // Prepare logging fields ctx = context.WithValue(ctx, cdslog.Method, req.Method) ctx = context.WithValue(ctx, cdslog.Route, cleanURL) @@ -347,6 +354,7 @@ func (r *Router) handle(uri string, scope HandlerScope, handlers ...*service.Han ctx = context.WithValue(ctx, cdslog.Deprecated, rc.IsDeprecated) ctx = context.WithValue(ctx, cdslog.Handler, rc.Name) ctx = context.WithValue(ctx, cdslog.Action, rc.Name) + ctx = context.WithValue(ctx, cdslog.IPAddress, clientIP) var fields = mux.Vars(req) for k, v := range fields { @@ -534,8 +542,22 @@ func MaintenanceAware() service.HandlerConfigParam { } // NotFoundHandler is called by default by Mux is any matching handler has been found -func NotFoundHandler(w http.ResponseWriter, req *http.Request) { - service.WriteError(context.Background(), w, req, sdk.NewError(sdk.ErrNotFound, fmt.Errorf("%s not found", req.URL.Path))) +func (r *Router) NotFoundHandler(w http.ResponseWriter, req *http.Request) { + ctx := req.Context() + + // Retrieve the client ip address from the header (X-Forwarded-For by default) + clientIP := req.Header.Get(r.Config.HeaderXForwardedFor) + if clientIP == "" { + // If the header has not been found, fallback on the remote adress from the http request + clientIP = req.RemoteAddr + } + + // Prepare logging fields + ctx = context.WithValue(ctx, cdslog.Method, req.Method) + ctx = context.WithValue(ctx, cdslog.RequestURI, req.RequestURI) + ctx = context.WithValue(ctx, cdslog.IPAddress, clientIP) + + service.WriteError(ctx, w, req, sdk.NewError(sdk.ErrNotFound, fmt.Errorf("%s not found", req.URL.Path))) } // StatusPanic returns router status. If nbPanic > 30 -> Alert, if nbPanic > 0 -> Warn diff --git a/engine/api/services/cdn.go b/engine/api/services/cdn.go index 247e380365..0485fac737 100644 --- a/engine/api/services/cdn.go +++ b/engine/api/services/cdn.go @@ -8,17 +8,29 @@ import ( "github.com/ovh/cds/sdk" ) -func GetCDNPublicTCPAdress(ctx context.Context, db gorp.SqlExecutor) (string, error) { +func GetCDNPublicTCPAdress(ctx context.Context, db gorp.SqlExecutor) (string, bool, error) { srvs, err := LoadAllByType(ctx, db, sdk.TypeCDN) if err != nil { - return "", err + return "", false, err } + + var tcp_addr string + var tcp_tls bool + +findAddr: for _, svr := range srvs { if addr, ok := svr.Config["public_tcp"]; ok { - return addr.(string), nil + tcp_addr = addr.(string) + if tls, ok := svr.Config["public_tcp_enable_tls"]; ok { + tcp_tls = tls.(bool) + } + break findAddr } } - return "", sdk.NewErrorFrom(sdk.ErrNotFound, "unable to find any tcp configuration in CDN Uservice") + if tcp_addr != "" { + return tcp_addr, tcp_tls, nil + } + return "", false, sdk.NewErrorFrom(sdk.ErrNotFound, "unable to find any tcp configuration in CDN Uservice") } func GetCDNPublicHTTPAdress(ctx context.Context, db gorp.SqlExecutor) (string, error) { diff --git a/engine/api/test/assets/assets.go b/engine/api/test/assets/assets.go index 0a74af5cfa..10c88d5a4a 100644 --- a/engine/api/test/assets/assets.go +++ b/engine/api/test/assets/assets.go @@ -545,8 +545,9 @@ func InitCDNService(t *testing.T, db gorpmapper.SqlExecutorWithTx, scopes ...sdk PublicKey: publicKey, ConsumerID: &hConsumer.ID, Config: map[string]interface{}{ - "public_tcp": "cdn.net:4545", - "public_http": "http://cdn.net:8080", + "public_tcp": "cdn.net:4545", + "public_http": "http://cdn.net:8080", + "public_tcp_enable_tls": true, }, }, } diff --git a/engine/api/workflow_queue.go b/engine/api/workflow_queue.go index 8802272ce7..79ebe8fdf6 100644 --- a/engine/api/workflow_queue.go +++ b/engine/api/workflow_queue.go @@ -111,7 +111,7 @@ func (api *API) postTakeWorkflowJobHandler() service.Handler { // Get CDN TCP Addr // Get CDN TCP Addr - pbji.GelfServiceAddr, err = services.GetCDNPublicTCPAdress(ctx, api.mustDB()) + pbji.GelfServiceAddr, pbji.GelfServiceAddrEnableTLS, err = services.GetCDNPublicTCPAdress(ctx, api.mustDB()) if err != nil { return err } diff --git a/engine/api/workflow_queue_test.go b/engine/api/workflow_queue_test.go index 07659a1a58..484e1a6e45 100644 --- a/engine/api/workflow_queue_test.go +++ b/engine/api/workflow_queue_test.go @@ -6,9 +6,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/ovh/cds/engine/api/bootstrap" - "github.com/ovh/cds/engine/api/database/gorpmapping" - "github.com/ovh/cds/engine/featureflipping" "io/ioutil" "net/http" "net/http/httptest" @@ -18,6 +15,10 @@ import ( "testing" "time" + "github.com/ovh/cds/engine/api/bootstrap" + "github.com/ovh/cds/engine/api/database/gorpmapping" + "github.com/ovh/cds/engine/featureflipping" + "github.com/ovh/venom" "github.com/rockbears/log" @@ -484,6 +485,7 @@ func Test_postTakeWorkflowJobHandler(t *testing.T) { require.NoError(t, json.Unmarshal(rec.Body.Bytes(), pbji)) assert.Equal(t, "cdn.net:4545", pbji.GelfServiceAddr) + assert.Equal(t, true, pbji.GelfServiceAddrEnableTLS) run, err := workflow.LoadNodeJobRun(context.TODO(), api.mustDB(), api.Cache, ctx.job.ID) require.NoError(t, err) diff --git a/engine/cdn/cdn.go b/engine/cdn/cdn.go index 24ae9722e5..984228032b 100644 --- a/engine/cdn/cdn.go +++ b/engine/cdn/cdn.go @@ -37,9 +37,6 @@ const ( func New() *Service { s := new(Service) s.GoRoutines = sdk.NewGoRoutines() - s.Router = &api.Router{ - Mux: mux.NewRouter(), - } return s } @@ -50,7 +47,10 @@ func (s *Service) Init(config interface{}) (cdsclient.ServiceConfig, error) { if !ok { return cfg, sdk.WithStack(fmt.Errorf("invalid CDN service configuration")) } - + s.Router = &api.Router{ + Mux: mux.NewRouter(), + Config: sConfig.HTTP, + } cfg.Host = sConfig.API.HTTP.URL cfg.Token = sConfig.API.Token cfg.InsecureSkipVerifyTLS = sConfig.API.HTTP.Insecure diff --git a/engine/cdn/types.go b/engine/cdn/types.go index 5a3f015ee6..12bbbb26e6 100644 --- a/engine/cdn/types.go +++ b/engine/cdn/types.go @@ -64,17 +64,15 @@ type Service struct { // Configuration is the hooks configuration structure type Configuration struct { - Name string `toml:"name" default:"cds-cdn" comment:"Name of this CDS CDN Service\n Enter a name to enable this service" json:"name"` - TCP sdk.TCPServer `toml:"tcp" comment:"######################\n CDS CDN TCP Configuration \n######################" json:"tcp"` - HTTP struct { - Addr string `toml:"addr" default:"" commented:"true" comment:"Listen address without port, example: 127.0.0.1" json:"addr"` - Port int `toml:"port" default:"8089" json:"port"` - } `toml:"http" comment:"######################\n CDS CDN HTTP Configuration \n######################" json:"http"` - URL string `default:"http://localhost:8089" json:"url" comment:"Private URL for communication with API"` - PublicTCP string `toml:"publicTCP" default:"localhost:8090" comment:"Public address to access to CDN TCP server" json:"public_tcp"` - PublicHTTP string `toml:"publicHTTP" default:"http://localhost:8089" comment:"Public address to access to CDN HTTP server" json:"public_http"` - Database database.DBConfigurationWithEncryption `toml:"database" comment:"################################\n Postgresql Database settings \n###############################" json:"database"` - Cache struct { + Name string `toml:"name" default:"cds-cdn" comment:"Name of this CDS CDN Service\n Enter a name to enable this service" json:"name"` + TCP sdk.TCPServer `toml:"tcp" comment:"######################\n CDS CDN TCP Configuration \n######################" json:"tcp"` + HTTP service.HTTPRouterConfiguration `toml:"http" comment:"######################\n CDS CDN HTTP Configuration \n######################" json:"http"` + URL string `default:"http://localhost:8089" json:"url" comment:"Private URL for communication with API"` + PublicTCP string `toml:"publicTCP" default:"localhost:8090" comment:"Public address to access to CDN TCP server" json:"public_tcp"` + PublicTCPEnableTLS bool `toml:"publicTCPEnableTLS" comment:"Enable TLS on public address to access to CDN TCP server" json:"public_tcp_enable_tls"` + PublicHTTP string `toml:"publicHTTP" default:"http://localhost:8089" comment:"Public address to access to CDN HTTP server" json:"public_http"` + Database database.DBConfigurationWithEncryption `toml:"database" comment:"################################\n Postgresql Database settings \n###############################" json:"database"` + Cache struct { TTL int `toml:"ttl" default:"60" json:"ttl"` LruSize int64 `toml:"lruSize" default:"134217728" json:"lruSize" comment:"Redis LRU cache for logs items in bytes (default: 128MB)"` Redis struct { diff --git a/engine/config.go b/engine/config.go index 96bbc63157..840db4e6c2 100644 --- a/engine/config.go +++ b/engine/config.go @@ -80,32 +80,39 @@ func configBootstrap(args []string) Configuration { HealthURL: "https://ovh.github.io", Type: "doc", }) + conf.API.HTTP.Port = 8081 case sdk.TypeUI: conf.UI = &ui.Configuration{} conf.UI.Name = "cds-ui-" + namesgenerator.GetRandomNameCDS(0) defaults.SetDefaults(conf.UI) + conf.UI.HTTP.Port = 8080 case "migrate": conf.DatabaseMigrate = &migrateservice.Configuration{} defaults.SetDefaults(conf.DatabaseMigrate) conf.DatabaseMigrate.Name = "cds-migrate-" + namesgenerator.GetRandomNameCDS(0) conf.DatabaseMigrate.ServiceAPI.DB.Schema = "public" conf.DatabaseMigrate.ServiceCDN.DB.Schema = "cdn" + conf.DatabaseMigrate.HTTP.Port = 8087 case sdk.TypeHatchery + ":local": conf.Hatchery.Local = &local.HatcheryConfiguration{} defaults.SetDefaults(conf.Hatchery.Local) conf.Hatchery.Local.Name = "cds-hatchery-local-" + namesgenerator.GetRandomNameCDS(0) + conf.Hatchery.Local.HTTP.Port = 8086 case sdk.TypeHatchery + ":kubernetes": conf.Hatchery.Kubernetes = &kubernetes.HatcheryConfiguration{} defaults.SetDefaults(conf.Hatchery.Kubernetes) conf.Hatchery.Kubernetes.Name = "cds-hatchery-kubernetes-" + namesgenerator.GetRandomNameCDS(0) + conf.Hatchery.Kubernetes.HTTP.Port = 8086 case sdk.TypeHatchery + ":marathon": conf.Hatchery.Marathon = &marathon.HatcheryConfiguration{} defaults.SetDefaults(conf.Hatchery.Marathon) conf.Hatchery.Marathon.Name = "cds-hatchery-marathon-" + namesgenerator.GetRandomNameCDS(0) + conf.Hatchery.Marathon.HTTP.Port = 8086 case sdk.TypeHatchery + ":openstack": conf.Hatchery.Openstack = &openstack.HatcheryConfiguration{} defaults.SetDefaults(conf.Hatchery.Openstack) conf.Hatchery.Openstack.Name = "cds-hatchery-openstack-" + namesgenerator.GetRandomNameCDS(0) + conf.Hatchery.Openstack.HTTP.Port = 8086 case sdk.TypeHatchery + ":swarm": conf.Hatchery.Swarm = &swarm.HatcheryConfiguration{} defaults.SetDefaults(conf.Hatchery.Swarm) @@ -115,14 +122,17 @@ func configBootstrap(args []string) Configuration { }, } conf.Hatchery.Swarm.Name = "cds-hatchery-swarm-" + namesgenerator.GetRandomNameCDS(0) + conf.Hatchery.Swarm.HTTP.Port = 8086 case sdk.TypeHatchery + ":vsphere": conf.Hatchery.VSphere = &vsphere.HatcheryConfiguration{} defaults.SetDefaults(conf.Hatchery.VSphere) conf.Hatchery.VSphere.Name = "cds-hatchery-vsphere-" + namesgenerator.GetRandomNameCDS(0) + conf.Hatchery.VSphere.HTTP.Port = 8086 case sdk.TypeHooks: conf.Hooks = &hooks.Configuration{} defaults.SetDefaults(conf.Hooks) conf.Hooks.Name = "cds-hooks-" + namesgenerator.GetRandomNameCDS(0) + conf.Hooks.HTTP.Port = 8083 case sdk.TypeVCS: conf.VCS = &vcs.Configuration{} defaults.SetDefaults(conf.VCS) @@ -144,13 +154,16 @@ func configBootstrap(args []string) Configuration { "gerrit": {URL: "http://localhost:8080", Gerrit: &gerrit}, } conf.VCS.Name = "cds-vcs-" + namesgenerator.GetRandomNameCDS(0) + conf.VCS.HTTP.Port = 8084 case sdk.TypeRepositories: conf.Repositories = &repositories.Configuration{} defaults.SetDefaults(conf.Repositories) conf.Repositories.Name = "cds-repositories-" + namesgenerator.GetRandomNameCDS(0) + conf.Repositories.HTTP.Port = 8085 case sdk.TypeCDN: conf.CDN = &cdn.Configuration{} defaults.SetDefaults(conf.CDN) + conf.CDN.HTTP.Port = 8089 conf.CDN.Database.Schema = "cdn" conf.CDN.Units.HashLocatorSalt = sdk.RandomString(8) conf.CDN.Units.Buffers = map[string]storage.BufferConfiguration{ @@ -193,6 +206,7 @@ func configBootstrap(args []string) Configuration { case sdk.TypeElasticsearch: conf.ElasticSearch = &elasticsearch.Configuration{} defaults.SetDefaults(conf.ElasticSearch) + conf.ElasticSearch.HTTP.Port = 8088 default: sdk.Exit("Error service '%s' is unknown", a) } diff --git a/engine/elasticsearch/elasticsearch.go b/engine/elasticsearch/elasticsearch.go index 4d901feab3..b8f3da4d54 100644 --- a/engine/elasticsearch/elasticsearch.go +++ b/engine/elasticsearch/elasticsearch.go @@ -21,9 +21,6 @@ var esClient *elastic.Client func New() *Service { s := new(Service) s.GoRoutines = sdk.NewGoRoutines() - s.Router = &api.Router{ - Mux: mux.NewRouter(), - } return s } @@ -37,7 +34,10 @@ func (s *Service) ApplyConfiguration(config interface{}) error { if !ok { return fmt.Errorf("ApplyConfiguration> Invalid Elasticsearch configuration") } - + s.Router = &api.Router{ + Mux: mux.NewRouter(), + Config: s.Cfg.HTTP, + } s.HTTPURL = s.Cfg.URL s.ServiceName = s.Cfg.Name s.ServiceType = sdk.TypeElasticsearch diff --git a/engine/elasticsearch/types.go b/engine/elasticsearch/types.go index 73359f7905..2e93153834 100644 --- a/engine/elasticsearch/types.go +++ b/engine/elasticsearch/types.go @@ -16,12 +16,9 @@ type Service struct { // Configuration is the vcs configuration structure type Configuration struct { - Name string `toml:"name" comment:"Name of this CDS elasticsearch Service\n Enter a name to enable this service" json:"name"` - HTTP struct { - Addr string `toml:"addr" default:"" commented:"true" comment:"Listen address without port, example: 127.0.0.1" json:"addr"` - Port int `toml:"port" default:"8088" json:"port"` - } `toml:"http" comment:"######################\n CDS Elasticsearch HTTP Configuration \n######################" json:"http"` - URL string `default:"http://localhost:8088" json:"url"` + Name string `toml:"name" comment:"Name of this CDS elasticsearch Service\n Enter a name to enable this service" json:"name"` + HTTP service.HTTPRouterConfiguration `toml:"http" comment:"######################\n CDS Elasticsearch HTTP Configuration \n######################" json:"http"` + URL string `default:"http://localhost:8088" json:"url"` ElasticSearch struct { URL string `toml:"url" json:"url"` Username string `toml:"username" json:"username"` diff --git a/engine/hatchery/kubernetes/kubernetes.go b/engine/hatchery/kubernetes/kubernetes.go index aa60835866..4b26c2c6d7 100644 --- a/engine/hatchery/kubernetes/kubernetes.go +++ b/engine/hatchery/kubernetes/kubernetes.go @@ -30,9 +30,6 @@ import ( func New() *HatcheryKubernetes { s := new(HatcheryKubernetes) s.GoRoutines = sdk.NewGoRoutines() - s.Router = &api.Router{ - Mux: mux.NewRouter(), - } return s } @@ -57,6 +54,11 @@ func (h *HatcheryKubernetes) Init(config interface{}) (cdsclient.ServiceConfig, return cfg, sdk.WithStack(fmt.Errorf("invalid kubernetes hatchery configuration")) } + h.Router = &api.Router{ + Mux: mux.NewRouter(), + Config: sConfig.HTTP, + } + cfg.Host = sConfig.API.HTTP.URL cfg.Token = sConfig.API.Token cfg.InsecureSkipVerifyTLS = sConfig.API.HTTP.Insecure diff --git a/engine/hatchery/local/local.go b/engine/hatchery/local/local.go index 77e96c4685..cb23255017 100644 --- a/engine/hatchery/local/local.go +++ b/engine/hatchery/local/local.go @@ -29,9 +29,6 @@ import ( func New() *HatcheryLocal { s := new(HatcheryLocal) s.GoRoutines = sdk.NewGoRoutines() - s.Router = &api.Router{ - Mux: mux.NewRouter(), - } s.LocalWorkerRunner = new(localWorkerRunner) return s } @@ -42,7 +39,10 @@ func (h *HatcheryLocal) Init(config interface{}) (cdsclient.ServiceConfig, error if !ok { return cfg, sdk.WithStack(fmt.Errorf("invalid local hatchery configuration")) } - + h.Router = &api.Router{ + Mux: mux.NewRouter(), + Config: sConfig.HTTP, + } cfg.Host = sConfig.API.HTTP.URL cfg.Token = sConfig.API.Token cfg.InsecureSkipVerifyTLS = sConfig.API.HTTP.Insecure diff --git a/engine/hatchery/marathon/marathon.go b/engine/hatchery/marathon/marathon.go index 7686865df4..b7843c9d78 100644 --- a/engine/hatchery/marathon/marathon.go +++ b/engine/hatchery/marathon/marathon.go @@ -30,9 +30,6 @@ import ( func New() *HatcheryMarathon { s := new(HatcheryMarathon) s.GoRoutines = sdk.NewGoRoutines() - s.Router = &api.Router{ - Mux: mux.NewRouter(), - } return s } @@ -50,7 +47,10 @@ func (h *HatcheryMarathon) Init(config interface{}) (cdsclient.ServiceConfig, er if !ok { return cfg, sdk.WithStack(fmt.Errorf("invalid marathon hatchery configuration")) } - + h.Router = &api.Router{ + Mux: mux.NewRouter(), + Config: sConfig.HTTP, + } cfg.Host = sConfig.API.HTTP.URL cfg.Token = sConfig.API.Token cfg.InsecureSkipVerifyTLS = sConfig.API.HTTP.Insecure diff --git a/engine/hatchery/openstack/openstack.go b/engine/hatchery/openstack/openstack.go index 6773250a5d..4d747ed151 100644 --- a/engine/hatchery/openstack/openstack.go +++ b/engine/hatchery/openstack/openstack.go @@ -41,9 +41,6 @@ var _ hatchery.InterfaceWithModels = new(HatcheryOpenstack) func New() *HatcheryOpenstack { s := new(HatcheryOpenstack) s.GoRoutines = sdk.NewGoRoutines() - s.Router = &api.Router{ - Mux: mux.NewRouter(), - } return s } @@ -54,7 +51,10 @@ func (h *HatcheryOpenstack) Init(config interface{}) (cdsclient.ServiceConfig, e if !ok { return cfg, sdk.WithStack(fmt.Errorf("invalid openstack hatchery configuration")) } - + h.Router = &api.Router{ + Mux: mux.NewRouter(), + Config: sConfig.HTTP, + } cfg.Host = sConfig.API.HTTP.URL cfg.Token = sConfig.API.Token cfg.InsecureSkipVerifyTLS = sConfig.API.HTTP.Insecure diff --git a/engine/hatchery/serve.go b/engine/hatchery/serve.go index effa147c09..86784fe567 100644 --- a/engine/hatchery/serve.go +++ b/engine/hatchery/serve.go @@ -3,9 +3,12 @@ package hatchery import ( "context" "crypto/rsa" + "crypto/tls" "fmt" + "net" "net/http" "net/http/pprof" + "strings" "sync" "time" @@ -104,7 +107,7 @@ func (c *Common) initRouter(ctx context.Context, h hatchery.Interface) { r.Mux.HandleFunc("/debug/pprof/{action}", pprof.Index) r.Mux.HandleFunc("/debug/pprof/", pprof.Index) - r.Mux.NotFoundHandler = http.HandlerFunc(api.NotFoundHandler) + r.Mux.NotFoundHandler = http.HandlerFunc(r.NotFoundHandler) } func (c *Common) GetPrivateKey() *rsa.PrivateKey { @@ -139,6 +142,21 @@ func (c *Common) RefreshServiceLogger(ctx context.Context) error { Protocol: "tcp", } + if cdnConfig.TCPURLEnableTLS { + tcpCDNUrl := c.CDNLogsURL + // Check if the url has a scheme + // We have to remove if to retrieve the hostname + if i := strings.Index(tcpCDNUrl, "://"); i > -1 { + tcpCDNUrl = tcpCDNUrl[i+3:] + } + tcpCDNHostname, _, err := net.SplitHostPort(tcpCDNUrl) + if err != nil { + return sdk.WithStack(err) + } + + graylogCfg.TLSConfig = &tls.Config{ServerName: tcpCDNHostname} + } + if c.ServiceLogger == nil { logger, _, err := cdslog.New(ctx, graylogCfg) if err != nil { diff --git a/engine/hatchery/swarm/swarm.go b/engine/hatchery/swarm/swarm.go index 55e89278ee..89583f74b4 100644 --- a/engine/hatchery/swarm/swarm.go +++ b/engine/hatchery/swarm/swarm.go @@ -17,12 +17,10 @@ import ( "github.com/docker/docker/api/types" docker "github.com/docker/docker/client" "github.com/docker/go-connections/tlsconfig" - "github.com/gorilla/mux" "github.com/rockbears/log" "github.com/sirupsen/logrus" "golang.org/x/net/context" - "github.com/ovh/cds/engine/api" "github.com/ovh/cds/engine/service" "github.com/ovh/cds/sdk" "github.com/ovh/cds/sdk/cdn" @@ -35,9 +33,6 @@ import ( func New() *HatcherySwarm { s := new(HatcherySwarm) s.GoRoutines = sdk.NewGoRoutines() - s.Router = &api.Router{ - Mux: mux.NewRouter(), - } return s } diff --git a/engine/hatchery/swarm/swarm_conf.go b/engine/hatchery/swarm/swarm_conf.go index af82ef9a5b..aee48d6c88 100644 --- a/engine/hatchery/swarm/swarm_conf.go +++ b/engine/hatchery/swarm/swarm_conf.go @@ -7,8 +7,10 @@ import ( "github.com/dgrijalva/jwt-go" types "github.com/docker/docker/api/types" + "github.com/gorilla/mux" "github.com/rockbears/log" + "github.com/ovh/cds/engine/api" "github.com/ovh/cds/sdk" "github.com/ovh/cds/sdk/cdsclient" ) @@ -20,7 +22,10 @@ func (h *HatcherySwarm) Init(config interface{}) (cdsclient.ServiceConfig, error if !ok { return cfg, sdk.WithStack(fmt.Errorf("invalid swarm hatchery configuration")) } - + h.Router = &api.Router{ + Mux: mux.NewRouter(), + Config: sConfig.HTTP, + } cfg.Host = sConfig.API.HTTP.URL cfg.Token = sConfig.API.Token cfg.InsecureSkipVerifyTLS = sConfig.API.HTTP.Insecure diff --git a/engine/hatchery/vsphere/hatchery.go b/engine/hatchery/vsphere/hatchery.go index e9f13b4a59..49e8ecbf45 100644 --- a/engine/hatchery/vsphere/hatchery.go +++ b/engine/hatchery/vsphere/hatchery.go @@ -27,9 +27,6 @@ import ( func New() *HatcheryVSphere { s := new(HatcheryVSphere) s.GoRoutines = sdk.NewGoRoutines() - s.Router = &api.Router{ - Mux: mux.NewRouter(), - } return s } @@ -42,7 +39,10 @@ func (h *HatcheryVSphere) Init(config interface{}) (cdsclient.ServiceConfig, err if !ok { return cfg, sdk.WithStack(fmt.Errorf("invalid vsphere hatchery configuration")) } - + h.Router = &api.Router{ + Mux: mux.NewRouter(), + Config: sConfig.HTTP, + } cfg.Host = sConfig.API.HTTP.URL cfg.Token = sConfig.API.Token cfg.InsecureSkipVerifyTLS = sConfig.API.HTTP.Insecure diff --git a/engine/hooks/hooks.go b/engine/hooks/hooks.go index 35b69b4152..9d166dea0c 100644 --- a/engine/hooks/hooks.go +++ b/engine/hooks/hooks.go @@ -19,9 +19,6 @@ import ( func New() *Service { s := new(Service) s.GoRoutines = sdk.NewGoRoutines() - s.Router = &api.Router{ - Mux: mux.NewRouter(), - } return s } @@ -31,7 +28,10 @@ func (s *Service) Init(config interface{}) (cdsclient.ServiceConfig, error) { if !ok { return cfg, sdk.WithStack(fmt.Errorf("invalid hooks service configuration")) } - + s.Router = &api.Router{ + Mux: mux.NewRouter(), + Config: sConfig.HTTP, + } cfg.Host = sConfig.API.HTTP.URL cfg.Token = sConfig.API.Token cfg.InsecureSkipVerifyTLS = sConfig.API.HTTP.Insecure diff --git a/engine/hooks/types.go b/engine/hooks/types.go index c74f030854..22ab22f532 100644 --- a/engine/hooks/types.go +++ b/engine/hooks/types.go @@ -26,11 +26,8 @@ type Service struct { // Configuration is the hooks configuration structure type Configuration struct { - Name string `toml:"name" comment:"Name of this CDS Hooks Service\n Enter a name to enable this service" json:"name"` - HTTP struct { - Addr string `toml:"addr" default:"" commented:"true" comment:"Listen address without port, example: 127.0.0.1" json:"addr"` - Port int `toml:"port" default:"8083" json:"port"` - } `toml:"http" comment:"######################\n CDS Hooks HTTP Configuration \n######################" json:"http"` + Name string `toml:"name" comment:"Name of this CDS Hooks Service\n Enter a name to enable this service" json:"name"` + HTTP service.HTTPRouterConfiguration `toml:"http" comment:"######################\n CDS Hooks HTTP Configuration \n######################" json:"http"` URL string `toml:"url" default:"http://localhost:8083" json:"url"` URLPublic string `toml:"urlPublic" default:"http://localhost:8080/cdshooks" comment:"Public url for external call (webhook)" json:"urlPublic"` RetryDelay int64 `toml:"retryDelay" default:"120" comment:"Execution retry delay in seconds" json:"retryDelay"` diff --git a/engine/migrateservice/service.go b/engine/migrateservice/service.go index c831c18b05..3ffaf32483 100644 --- a/engine/migrateservice/service.go +++ b/engine/migrateservice/service.go @@ -30,14 +30,10 @@ var _ service.BeforeStart = new(dbmigservice) // Configuration is the exposed type for database API configuration type Configuration struct { - Name string `toml:"name" comment:"Name of this CDS Database Migrate service\n Enter a name to enable this service" json:"name"` - URL string `default:"http://localhost:8087" json:"url"` - Directory string `toml:"directory" comment:"SQL Migration files directory" default:"sql" json:"directory"` - HTTP struct { - Addr string `toml:"addr" default:"" commented:"true" comment:"Listen address without port, example: 127.0.0.1" json:"addr"` - Port int `toml:"port" default:"8087" json:"port"` - Insecure bool `toml:"insecure" default:"false" commented:"true" comment:"sslInsecureSkipVerify, set to true if you use a self-signed SSL on CDS API" json:"insecure"` - } `toml:"http" comment:"#####################################\n CDS DB Migrate HTTP configuration \n####################################" json:"http"` + Name string `toml:"name" comment:"Name of this CDS Database Migrate service\n Enter a name to enable this service" json:"name"` + URL string `default:"http://localhost:8087" json:"url"` + Directory string `toml:"directory" comment:"SQL Migration files directory" default:"sql" json:"directory"` + HTTP service.HTTPRouterConfiguration `toml:"http" comment:"#####################################\n CDS DB Migrate HTTP configuration \n####################################" json:"http"` API service.APIServiceConfiguration `toml:"api" comment:"####################\n CDS API Settings \n###################" json:"api"` ServiceAPI struct { Enable bool `toml:"enable" default:"true" comment:"set to false to disable migration for API database" json:"enable"` @@ -84,7 +80,6 @@ func (s *dbmigservice) ApplyConfiguration(cfg interface{}) error { } dbCfg, _ := cfg.(Configuration) - s.cfg = dbCfg s.ServiceName = s.cfg.Name s.ServiceType = sdk.TypeDBMigrate @@ -92,7 +87,8 @@ func (s *dbmigservice) ApplyConfiguration(cfg interface{}) error { s.MaxHeartbeatFailures = s.cfg.API.MaxHeartbeatFailures s.Router = &api.Router{ - Mux: mux.NewRouter(), + Mux: mux.NewRouter(), + Config: s.cfg.HTTP, } return nil } diff --git a/engine/repositories/repositories.go b/engine/repositories/repositories.go index 91b50f89e5..932abcde77 100644 --- a/engine/repositories/repositories.go +++ b/engine/repositories/repositories.go @@ -19,9 +19,6 @@ import ( func New() *Service { s := new(Service) s.GoRoutines = sdk.NewGoRoutines() - s.Router = &api.Router{ - Mux: mux.NewRouter(), - } return s } @@ -31,7 +28,10 @@ func (s *Service) Init(config interface{}) (cdsclient.ServiceConfig, error) { if !ok { return cfg, sdk.WithStack(fmt.Errorf("invalid repositories service configuration")) } - + s.Router = &api.Router{ + Mux: mux.NewRouter(), + Config: sConfig.HTTP, + } cfg.Host = sConfig.API.HTTP.URL cfg.Token = sConfig.API.Token cfg.InsecureSkipVerifyTLS = sConfig.API.HTTP.Insecure diff --git a/engine/repositories/types.go b/engine/repositories/types.go index a74596b4b3..823ef795ae 100644 --- a/engine/repositories/types.go +++ b/engine/repositories/types.go @@ -21,17 +21,14 @@ type Service struct { // Configuration is the vcs configuration structure type Configuration struct { - Name string `toml:"name" comment:"Name of this CDS Repositories Service\n Enter a name to enable this service" json:"name"` - Basedir string `toml:"basedir" comment:"Root directory where the service will store all checked-out repositories" json:"basedir"` - OperationRetention int `toml:"operationRetention" comment:"Operation retention in redis store (in days)" default:"5" json:"operationRetention"` - RepositoriesRetention int `toml:"repositoriesRetention" comment:"Re retention on the filesystem (in days)" default:"10" json:"repositoriesRetention"` - HTTP struct { - Addr string `toml:"addr" default:"" commented:"true" comment:"Listen address without port, example: 127.0.0.1" json:"addr"` - Port int `toml:"port" default:"8085" json:"port"` - } `toml:"http" comment:"######################\n CDS Repositories HTTP Configuration \n######################" json:"http"` - URL string `default:"http://localhost:8085" json:"url"` - API service.APIServiceConfiguration `toml:"api" comment:"######################\n CDS API Settings \n######################" json:"api"` - Cache struct { + Name string `toml:"name" comment:"Name of this CDS Repositories Service\n Enter a name to enable this service" json:"name"` + Basedir string `toml:"basedir" comment:"Root directory where the service will store all checked-out repositories" json:"basedir"` + OperationRetention int `toml:"operationRetention" comment:"Operation retention in redis store (in days)" default:"5" json:"operationRetention"` + RepositoriesRetention int `toml:"repositoriesRetention" comment:"Re retention on the filesystem (in days)" default:"10" json:"repositoriesRetention"` + HTTP service.HTTPRouterConfiguration `toml:"http" comment:"######################\n CDS Repositories HTTP Configuration \n######################" json:"http"` + URL string `default:"http://localhost:8085" json:"url"` + API service.APIServiceConfiguration `toml:"api" comment:"######################\n CDS API Settings \n######################" json:"api"` + Cache struct { TTL int `toml:"ttl" default:"60" json:"ttl"` Redis struct { Host string `toml:"host" default:"localhost:6379" comment:"If your want to use a redis-sentinel based cluster, follow this syntax! @sentinel1:26379,sentinel2:26379,sentinel3:26379" json:"host"` diff --git a/engine/service/types.go b/engine/service/types.go index 27d8e55d73..0f42601b33 100644 --- a/engine/service/types.go +++ b/engine/service/types.go @@ -24,16 +24,19 @@ type APIServiceConfiguration struct { MaxHeartbeatFailures int `toml:"maxHeartbeatFailures" default:"10" json:"maxHeartbeatFailures"` } +type HTTPRouterConfiguration struct { + Addr string `toml:"addr" default:"" commented:"true" comment:"Listen HTTP address without port, example: 127.0.0.1" json:"addr"` + Port int `toml:"port" default:"8081" json:"port"` + HeaderXForwardedFor string `toml:"headerXForwardedFor" default:"X-Forwarded-For" json:"header_w_forwarded_for"` +} + // HatcheryCommonConfiguration is the base configuration for all hatcheries type HatcheryCommonConfiguration struct { - Name string `toml:"name" default:"" comment:"Name of Hatchery" json:"name"` - RSAPrivateKey string `toml:"rsaPrivateKey" default:"" comment:"The RSA Private Key used by the hatchery.\nThis is mandatory." json:"-"` - HTTP struct { - Addr string `toml:"addr" default:"" commented:"true" comment:"Listen address without port, example: 127.0.0.1" json:"addr"` - Port int `toml:"port" default:"8086" json:"port"` - } `toml:"http" comment:"######################\n CDS Hatchery HTTP Configuration \n######################" json:"http"` - URL string `toml:"url" default:"http://localhost:8086" comment:"URL of this Hatchery" json:"url"` - API struct { + Name string `toml:"name" default:"" comment:"Name of Hatchery" json:"name"` + RSAPrivateKey string `toml:"rsaPrivateKey" default:"" comment:"The RSA Private Key used by the hatchery.\nThis is mandatory." json:"-"` + HTTP HTTPRouterConfiguration `toml:"http" comment:"######################\n CDS Hatchery HTTP Configuration \n######################" json:"http"` + URL string `toml:"url" default:"http://localhost:8086" comment:"URL of this Hatchery" json:"url"` + API struct { HTTP struct { URL string `toml:"url" default:"http://localhost:8081" comment:"CDS API URL" json:"url"` Insecure bool `toml:"insecure" default:"false" commented:"true" comment:"sslInsecureSkipVerify, set to true if you use a self-signed SSL on CDS API" json:"insecure"` diff --git a/engine/ui/types.go b/engine/ui/types.go index 6e681de284..9a2ca6abfd 100644 --- a/engine/ui/types.go +++ b/engine/ui/types.go @@ -19,17 +19,14 @@ type Service struct { // Configuration is the ui configuration structure type Configuration struct { - Name string `toml:"name" comment:"Name of this CDS UI Service\n Enter a name to enable this service" json:"name"` - Staticdir string `toml:"staticdir" default:"./ui_static_files" comment:"This directory must contain the dist directory." json:"staticdir"` - BaseURL string `toml:"baseURL" commented:"true" comment:"If you expose CDS UI with https://your-domain.com/ui, enter the value '/ui/'. Optional" json:"baseURL"` - DeployURL string `toml:"deployURL" commented:"true" comment:"You can start CDS UI proxy on a sub path like https://your-domain.com/ui with value '/ui' (the value should not be given when the sub path is added by a proxy in front of CDS). Optional" json:"deployURL"` - SentryURL string `toml:"sentryURL" commented:"true" comment:"Sentry URL. Optional" json:"-"` - HTTP struct { - Addr string `toml:"addr" default:"" commented:"true" comment:"Listen address without port, example: 127.0.0.1" json:"addr"` - Port int `toml:"port" default:"8080" json:"port"` - } `toml:"http" comment:"######################\n CDS UI HTTP Configuration \n######################" json:"http"` - URL string `toml:"url" comment:"Public URL of this UI service." default:"http://localhost:8080" json:"url"` - API service.APIServiceConfiguration `toml:"api" comment:"######################\n CDS API Settings \n######################" json:"api"` - HooksURL string `toml:"hooksURL" comment:"Hooks µService URL" default:"http://localhost:8083" json:"hooksURL"` - CDNURL string `toml:"cdnURL" comment:"CDN µService URL" default:"http://localhost:8089" json:"cdnURL"` + Name string `toml:"name" comment:"Name of this CDS UI Service\n Enter a name to enable this service" json:"name"` + Staticdir string `toml:"staticdir" default:"./ui_static_files" comment:"This directory must contain the dist directory." json:"staticdir"` + BaseURL string `toml:"baseURL" commented:"true" comment:"If you expose CDS UI with https://your-domain.com/ui, enter the value '/ui/'. Optional" json:"baseURL"` + DeployURL string `toml:"deployURL" commented:"true" comment:"You can start CDS UI proxy on a sub path like https://your-domain.com/ui with value '/ui' (the value should not be given when the sub path is added by a proxy in front of CDS). Optional" json:"deployURL"` + SentryURL string `toml:"sentryURL" commented:"true" comment:"Sentry URL. Optional" json:"-"` + HTTP service.HTTPRouterConfiguration `toml:"http" comment:"######################\n CDS UI HTTP Configuration \n######################" json:"http"` + URL string `toml:"url" comment:"Public URL of this UI service." default:"http://localhost:8080" json:"url"` + API service.APIServiceConfiguration `toml:"api" comment:"######################\n CDS API Settings \n######################" json:"api"` + HooksURL string `toml:"hooksURL" comment:"Hooks µService URL" default:"http://localhost:8083" json:"hooksURL"` + CDNURL string `toml:"cdnURL" comment:"CDN µService URL" default:"http://localhost:8089" json:"cdnURL"` } diff --git a/engine/ui/ui.go b/engine/ui/ui.go index 86f0352986..df0e97a574 100644 --- a/engine/ui/ui.go +++ b/engine/ui/ui.go @@ -40,7 +40,6 @@ func (s *Service) Init(config interface{}) (cdsclient.ServiceConfig, error) { if !ok { return cfg, sdk.WithStack(fmt.Errorf("invalid ui service configuration")) } - cfg.Host = sConfig.API.HTTP.URL cfg.Token = sConfig.API.Token cfg.InsecureSkipVerifyTLS = sConfig.API.HTTP.Insecure @@ -63,6 +62,7 @@ func (s *Service) ApplyConfiguration(config interface{}) error { s.ServiceType = sdk.TypeUI s.HTTPURL = s.Cfg.URL s.MaxHeartbeatFailures = s.Cfg.API.MaxHeartbeatFailures + s.Router.Config = s.Cfg.HTTP // HTMLDir must contains the ui dist directory. // ui.tar.gz contains the dist directory diff --git a/engine/vcs/types.go b/engine/vcs/types.go index be963e748d..8ff5659e3c 100644 --- a/engine/vcs/types.go +++ b/engine/vcs/types.go @@ -20,13 +20,10 @@ type Service struct { // Configuration is the vcs configuration structure type Configuration struct { - Name string `toml:"name" comment:"Name of this CDS VCS Service\n Enter a name to enable this service" json:"name"` - HTTP struct { - Addr string `toml:"addr" default:"" commented:"true" comment:"Listen address without port, example: 127.0.0.1" json:"addr"` - Port int `toml:"port" default:"8084" json:"port"` - } `toml:"http" comment:"######################\n CDS VCS HTTP Configuration \n######################" json:"http"` - URL string `default:"http://localhost:8084" json:"url"` - UI struct { + Name string `toml:"name" comment:"Name of this CDS VCS Service\n Enter a name to enable this service" json:"name"` + HTTP service.HTTPRouterConfiguration `toml:"http" comment:"######################\n CDS VCS HTTP Configuration \n######################" json:"http"` + URL string `default:"http://localhost:8084" json:"url"` + UI struct { HTTP struct { URL string `toml:"url" default:"http://localhost:8080" json:"url"` } `toml:"http" json:"http"` diff --git a/engine/vcs/vcs.go b/engine/vcs/vcs.go index 8e890971f7..eaa79e452b 100644 --- a/engine/vcs/vcs.go +++ b/engine/vcs/vcs.go @@ -24,9 +24,6 @@ import ( func New() *Service { s := new(Service) s.GoRoutines = sdk.NewGoRoutines() - s.Router = &api.Router{ - Mux: mux.NewRouter(), - } return s } @@ -36,7 +33,10 @@ func (s *Service) Init(config interface{}) (cdsclient.ServiceConfig, error) { if !ok { return cfg, sdk.WithStack(fmt.Errorf("invalid vcs configuration")) } - + s.Router = &api.Router{ + Mux: mux.NewRouter(), + Config: sConfig.HTTP, + } cfg.Host = sConfig.API.HTTP.URL cfg.Token = sConfig.API.Token cfg.InsecureSkipVerifyTLS = sConfig.API.HTTP.Insecure diff --git a/engine/worker/internal/take.go b/engine/worker/internal/take.go index 142de6253d..60ef90a3b5 100644 --- a/engine/worker/internal/take.go +++ b/engine/worker/internal/take.go @@ -2,7 +2,9 @@ package internal import ( "context" + "crypto/tls" "encoding/base64" + "net" "strings" "time" @@ -67,6 +69,21 @@ func (w *CurrentWorker) Take(ctx context.Context, job sdk.WorkflowNodeJobRun) er }, } + if info.GelfServiceAddrEnableTLS { + tcpCDNUrl := info.GelfServiceAddr + // Check if the url has a scheme + // We have to remove if to retrieve the hostname + if i := strings.Index(tcpCDNUrl, "://"); i > -1 { + tcpCDNUrl = tcpCDNUrl[i+3:] + } + tcpCDNHostname, _, err := net.SplitHostPort(tcpCDNUrl) + if err != nil { + return sdk.WithStack(err) + } + + graylogCfg.TLSConfig = &tls.Config{ServerName: tcpCDNHostname} + } + l, h, err := cdslog.New(ctx, graylogCfg) if err != nil { return sdk.WithStack(err) diff --git a/sdk/log/fields.go b/sdk/log/fields.go index e37d790d56..8c11ae8554 100644 --- a/sdk/log/fields.go +++ b/sdk/log/fields.go @@ -28,6 +28,7 @@ const ( StatusNum = log.Field("status_num") Goroutine = log.Field("goroutine") RequestID = log.Field("request_id") + IPAddress = log.Field("ip_address") Service = log.Field("service") Stacktrace = log.Field("stack_trace") Duration = log.Field("duration_milliseconds_num") @@ -46,6 +47,7 @@ func init() { AuthSessionID, AuthSessionIAT, AuthSessionTokenID, + IPAddress, Method, Route, RequestURI, diff --git a/sdk/services.go b/sdk/services.go index c16a679eb5..bbe336fe91 100644 --- a/sdk/services.go +++ b/sdk/services.go @@ -93,6 +93,7 @@ type ServiceConfiguration struct { } type CDNConfig struct { - TCPURL string `json:"tcp_url"` - HTTPURL string `json:"http_url"` + TCPURL string `json:"tcp_url"` + TCPURLEnableTLS bool `json:"tcp_url_enable_tls"` + HTTPURL string `json:"http_url"` } diff --git a/sdk/worker.go b/sdk/worker.go index 87bd9f75f0..27b641cb96 100644 --- a/sdk/worker.go +++ b/sdk/worker.go @@ -77,17 +77,18 @@ func TemplateEnvs(args WorkerArgs, envs map[string]string) (map[string]string, e // WorkflowNodeJobRunData is returned to worker in answer to postTakeWorkflowJobHandler type WorkflowNodeJobRunData struct { - NodeJobRun WorkflowNodeJobRun - Secrets []Variable - Features map[FeatureName]bool - Number int64 - SubNumber int64 - SigningKey string - GelfServiceAddr string - CDNHttpAddr string - ProjectKey string - WorkflowName string - WorkflowID int64 - RunID int64 - NodeRunName string + NodeJobRun WorkflowNodeJobRun + Secrets []Variable + Features map[FeatureName]bool + Number int64 + SubNumber int64 + SigningKey string + GelfServiceAddr string + GelfServiceAddrEnableTLS bool + CDNHttpAddr string + ProjectKey string + WorkflowName string + WorkflowID int64 + RunID int64 + NodeRunName string }