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

Added tcp+tls support for syslog server #2

Open
wants to merge 1 commit into
base: syslog-main
Choose a base branch
from

Conversation

anantha96
Copy link
Collaborator

@anantha96 anantha96 commented Sep 27, 2024

Describe Your Changes

Added support to send logs to the syslog server over tcp+tls.

Checklist

The following checks are mandatory:

if err != nil {
fmt.Errorf("Failed reading the tls certificates %w", err)
}
syslogW = &syslogWriter{framer: defaultFramer, formatter: defaultFormatter, tlsConfig: syslogtlsConfig}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Construction of syslogWriter can be done via method chaining so that line 106 and 110 can be common. wdyt?
syslogW = syslogWriter.New().WithFramer(framer).WithFormatter(formatter).WithTlsConfig(tlsconfig)

}

func readTlsConfig(certFile, keyFile, CAFile, serverName string, insecureSkipVerify bool) (*tls.Config, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this function can be a method of sysCfg. All function args will be part of object and no need to pass them explicitly.

var certs []tls.Certificate
if certFile != "" {
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a TODO comment for auto-reload of client certs

InsecureSkipVerify: insecureSkipVerify,
RootCAs: rootCAs,
ServerName: serverName,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this serverName be made an optional field?

@@ -29,9 +31,28 @@ func (w *syslogWriter) basicDialer() (serverConn, error) {
return sc, err
}

func (w *syslogWriter) tlsDialer() (serverConn, error) {
c, err := tls.Dial("tcp", fmt.Sprintf("%s:%d", w.sysCfg.SyslogConfig.RemoteHost, w.sysCfg.SyslogConfig.Port), w.tlsConfig)
Copy link
Collaborator

Choose a reason for hiding this comment

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

basicDialer uses net.Dial(w.sysCfg.SyslogConfig.Protocol. And w.sysCfg.SyslogConfig.Protocol can be any protocol with TLS as well. Better if we merge basicDialer and tlsDialer into one with respective handling

// connect updates the syslogWriter with a new serverConn
func (w *syslogWriter) connect() (serverConn, error) {
conn, err := w.basicDialer()
var (
conn serverConn
Copy link
Collaborator

Choose a reason for hiding this comment

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

var conn serverConn
var err  error

conn serverConn
err error
)
if w.sysCfg.SyslogConfig.Protocol == "tcp+tls" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

switch with the default case is better here. If going forward if cases like "TCP", "UDP", "TCP+TLS" are to be supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants