Skip to content

Commit

Permalink
add basic-auth-enable settings on prom logger (#251)
Browse files Browse the repository at this point in the history
* add basic-auth-enable settings on prom logger
* update README.md
  • Loading branch information
dmachard authored Mar 28, 2023
1 parent 567befa commit d2ab6b3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

*NOTE: The code before version 1.x is considered beta quality and is subject to breaking changes.*

`DNS-collector` acts as a passive high speed **aggregator, analyzer, transporter and logging** for your DNS messages, written in **Golang**. The DNS traffic can be collected and aggregated from simultaneously [sources](doc/collectors.md) like DNStap streams, network interface or log files and relays it to multiple other [listeners](doc/loggers.md) with some [transformations](doc/transformers.md) on it ([traffic filtering](doc/transformers.md#dns-filtering), [user privacy](doc/transformers.md#user-privacy), ...) and DNS protocol conversions (to [plain text](doc/configuration.md#custom-text-format), [json](doc/dnsjson.md), and more... ).
`DNS-collector` acts as a passive high speed **ingestor, aggregator and analyzer** for your DNS traffic, written in **Golang**. The DNS traffic can be collected and aggregated from simultaneously [sources](doc/collectors.md) like DNStap streams, network interface or log files and relays it to multiple other [listeners](doc/loggers.md) with some [transformations](doc/transformers.md) on it ([traffic filtering](doc/transformers.md#dns-filtering), [user privacy](doc/transformers.md#user-privacy), ...) and DNS protocol conversions (to [plain text](doc/configuration.md#custom-text-format), [json](doc/dnsjson.md), and more... ).

Additionally, DNS-collector also support
- [Extension Mechanisms for DNS (EDNS)](doc/dnsparser.md) decoding
Expand Down
4 changes: 3 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ multiplexer:
- name: console
stdout:
mode: text

routes:
- from: [ tap ]
to: [ console ]
Expand Down Expand Up @@ -202,6 +202,8 @@ multiplexer:
# listen-ip: 0.0.0.0
# # listening port
# listen-port: 8080
# # enable basic authentication
# basic-auth-enable: true
# # default login
# basic-auth-login: admin
# # default password
Expand Down
26 changes: 14 additions & 12 deletions dnsutils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,19 @@ type Config struct {
TextFormat string `yaml:"text-format"`
} `yaml:"stdout"`
Prometheus struct {
Enable bool `yaml:"enable"`
ListenIP string `yaml:"listen-ip"`
ListenPort int `yaml:"listen-port"`
TlsSupport bool `yaml:"tls-support"`
TlsMutual bool `yaml:"tls-mutual"`
TlsMinVersion string `yaml:"tls-min-version"`
CertFile string `yaml:"cert-file"`
KeyFile string `yaml:"key-file"`
PromPrefix string `yaml:"prometheus-prefix"`
TopN int `yaml:"top-n"`
BasicAuthLogin string `yaml:"basic-auth-login"`
BasicAuthPwd string `yaml:"basic-auth-pwd"`
Enable bool `yaml:"enable"`
ListenIP string `yaml:"listen-ip"`
ListenPort int `yaml:"listen-port"`
TlsSupport bool `yaml:"tls-support"`
TlsMutual bool `yaml:"tls-mutual"`
TlsMinVersion string `yaml:"tls-min-version"`
CertFile string `yaml:"cert-file"`
KeyFile string `yaml:"key-file"`
PromPrefix string `yaml:"prometheus-prefix"`
TopN int `yaml:"top-n"`
BasicAuthLogin string `yaml:"basic-auth-login"`
BasicAuthPwd string `yaml:"basic-auth-pwd"`
BasicAuthEnabled bool `yaml:"basic-auth-enable"`
} `yaml:"prometheus"`
RestAPI struct {
Enable bool `yaml:"enable"`
Expand Down Expand Up @@ -470,6 +471,7 @@ func (c *Config) SetDefault() {
c.Loggers.Prometheus.TopN = 10
c.Loggers.Prometheus.BasicAuthLogin = "admin"
c.Loggers.Prometheus.BasicAuthPwd = "changeme"
c.Loggers.Prometheus.BasicAuthEnabled = true

c.Loggers.RestAPI.Enable = false
c.Loggers.RestAPI.ListenIP = LOCALHOST_IP
Expand Down
2 changes: 2 additions & 0 deletions doc/loggers.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ See the [swagger](https://generator.swagger.io/?url=https://raw.githubuserconten
Options:
- `listen-ip`: (string) listening IP
- `listen-port`: (integer) listening port
- `basic-auth-enable`: (boolean) enable or disable basic authentication
- `basic-auth-login`: (string) default login for basic auth
- `basic-auth-pwd`: (string) default password for basic auth
- `tls-support`: (boolean) tls support
Expand All @@ -107,6 +108,7 @@ Default values:
restapi:
listen-ip: 0.0.0.0
listen-port: 8080
basic-auth-enable: true
basic-auth-login: admin
basic-auth-pwd: changeme
tls-support: true
Expand Down
15 changes: 12 additions & 3 deletions loggers/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,20 @@ func NewPrometheus(config *dnsutils.Config, logger *logger.Logger, version strin

handler := authMiddleware(mux)

o.httpServer = &http.Server{
Handler: handler,
ErrorLog: o.logger.ErrorLogger(),
o.httpServer = &http.Server{}
if o.config.Loggers.Prometheus.BasicAuthEnabled {
o.httpServer.Handler = handler
} else {
o.httpServer.Handler = mux
}

o.httpServer.ErrorLog = o.logger.ErrorLogger()

// o.httpServer = &http.Server{
// Handler: handler,
// ErrorLog: o.logger.ErrorLogger(),
// }

return o
}

Expand Down

0 comments on commit d2ab6b3

Please sign in to comment.