@@ -2,6 +2,7 @@ package fluent
2
2
3
3
import (
4
4
"context"
5
+ "crypto/tls"
5
6
"encoding/json"
6
7
"errors"
7
8
"fmt"
@@ -36,6 +37,9 @@ const (
36
37
// Default sub-second precision value to false since it is only compatible
37
38
// with fluentd versions v0.14 and above.
38
39
defaultSubSecondPrecision = false
40
+
41
+ // Default value whether to skip checking insecure certs on TLS connections.
42
+ defaultTlsInsecureSkipVerify = false
39
43
)
40
44
41
45
// randomGenerator is used by getUniqueId to generate ack hashes. Its value is replaced
@@ -69,6 +73,9 @@ type Config struct {
69
73
// respond with an acknowledgement. This option improves the reliability
70
74
// of the message transmission.
71
75
RequestAck bool `json:"request_ack"`
76
+
77
+ // Flag to skip verifying insecure certs on TLS connections
78
+ TlsInsecureSkipVerify bool `json: "tls_insecure_skip_verify"`
72
79
}
73
80
74
81
type ErrUnknownNetwork struct {
@@ -147,6 +154,9 @@ func newWithDialer(config Config, d dialer) (f *Fluent, err error) {
147
154
if config .MaxRetryWait == 0 {
148
155
config .MaxRetryWait = defaultMaxRetryWait
149
156
}
157
+ if ! config .TlsInsecureSkipVerify {
158
+ config .TlsInsecureSkipVerify = defaultTlsInsecureSkipVerify
159
+ }
150
160
if config .AsyncConnect {
151
161
fmt .Fprintf (os .Stderr , "fluent#New: AsyncConnect is now deprecated, please use Async instead" )
152
162
config .Async = config .Async || config .AsyncConnect
@@ -418,6 +428,13 @@ func (f *Fluent) connect(ctx context.Context) (err error) {
418
428
f .conn , err = f .dialer .DialContext (ctx ,
419
429
f .Config .FluentNetwork ,
420
430
f .Config .FluentHost + ":" + strconv .Itoa (f .Config .FluentPort ))
431
+ case "tls" :
432
+ tlsConfig := & tls.Config {InsecureSkipVerify : f .Config .TlsInsecureSkipVerify }
433
+ f .conn , err = tls .DialWithDialer (
434
+ & net.Dialer {Timeout : f .Config .Timeout },
435
+ "tcp" ,
436
+ f .Config .FluentHost + ":" + strconv .Itoa (f .Config .FluentPort ), tlsConfig ,
437
+ )
421
438
case "unix" :
422
439
f .conn , err = f .dialer .DialContext (ctx ,
423
440
f .Config .FluentNetwork ,
@@ -554,7 +571,7 @@ func (f *Fluent) write(ctx context.Context, msg *msgToSend) (bool, error) {
554
571
defer f .muconn .RUnlock ()
555
572
556
573
if f .conn == nil {
557
- return fmt .Errorf ("connection has been closed before writing to it. " )
574
+ return fmt .Errorf ("connection has been closed before writing to it" )
558
575
}
559
576
560
577
t := f .Config .WriteTimeout
0 commit comments