-
Notifications
You must be signed in to change notification settings - Fork 755
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
Add logging for attempted and successful TLS connections to server #1486
Merged
sergeybykov
merged 4 commits into
temporalio:master
from
sergeybykov:pr/log-tls-connections
Apr 23, 2021
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
220c1f3
Add logging for attempted and successful TLS connections to server
sergeybykov 9e43c3c
Address code review feedback
sergeybykov dd66b88
Add client's Common Name to log of successful connections
sergeybykov 660edc4
Add server name to logging of connection attempts
sergeybykov File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ import ( | |
"time" | ||
|
||
"github.com/uber-go/tally" | ||
"go.temporal.io/server/common/log/tag" | ||
|
||
"go.temporal.io/server/common/auth" | ||
"go.temporal.io/server/common/config" | ||
|
@@ -154,7 +155,7 @@ func (s *localStoreTlsProvider) GetFrontendServerConfig() (*tls.Config, error) { | |
return s.getOrCreateConfig( | ||
&s.cachedFrontendServerConfig, | ||
func() (*tls.Config, error) { | ||
return newServerTLSConfig(s.frontendCertProvider, s.frontendPerHostCertProviderMap, &s.settings.Frontend) | ||
return newServerTLSConfig(s.frontendCertProvider, s.frontendPerHostCertProviderMap, &s.settings.Frontend, s.logger) | ||
}, | ||
s.settings.Frontend.IsEnabled()) | ||
} | ||
|
@@ -163,7 +164,7 @@ func (s *localStoreTlsProvider) GetInternodeServerConfig() (*tls.Config, error) | |
return s.getOrCreateConfig( | ||
&s.cachedInternodeServerConfig, | ||
func() (*tls.Config, error) { | ||
return newServerTLSConfig(s.internodeCertProvider, nil, &s.settings.Internode) | ||
return newServerTLSConfig(s.internodeCertProvider, nil, &s.settings.Internode, s.logger) | ||
}, | ||
s.settings.Internode.IsEnabled()) | ||
} | ||
|
@@ -238,32 +239,45 @@ func newServerTLSConfig( | |
certProvider CertProvider, | ||
perHostCertProviderMap PerHostCertProviderMap, | ||
config *config.GroupTLS, | ||
logger log.Logger, | ||
) (*tls.Config, error) { | ||
|
||
clientAuthRequired := config.Server.RequireClientAuth | ||
tlsConfig, err := getServerTLSConfigFromCertProvider(certProvider, clientAuthRequired) | ||
tlsConfig, err := getServerTLSConfigFromCertProvider(certProvider, clientAuthRequired, "", logger) | ||
mastermanu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
tlsConfig.GetConfigForClient = func(c *tls.ClientHelloInfo) (*tls.Config, error) { | ||
|
||
remoteAddress := c.Conn.RemoteAddr().String() | ||
logger.Info("attempted incoming TLS connection", tag.Address(remoteAddress), tag.HostID(c.ServerName)) | ||
mastermanu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if perHostCertProviderMap != nil { | ||
perHostCertProvider, hostClientAuthRequired, err := perHostCertProviderMap.GetCertProvider(c.ServerName) | ||
if err != nil { | ||
logger.Warn("cannot find a per-host provider for attempted incoming TLS connection", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to log the error here? |
||
tag.HostID(c.ServerName), tag.Address(remoteAddress)) | ||
return nil, err | ||
} | ||
|
||
if perHostCertProvider != nil { | ||
return getServerTLSConfigFromCertProvider(perHostCertProvider, hostClientAuthRequired) | ||
return getServerTLSConfigFromCertProvider(perHostCertProvider, hostClientAuthRequired, remoteAddress, logger) | ||
} | ||
return getServerTLSConfigFromCertProvider(certProvider, clientAuthRequired) | ||
return getServerTLSConfigFromCertProvider(certProvider, clientAuthRequired, remoteAddress, logger) | ||
} | ||
return getServerTLSConfigFromCertProvider(certProvider, clientAuthRequired) | ||
return getServerTLSConfigFromCertProvider(certProvider, clientAuthRequired, remoteAddress, logger) | ||
mastermanu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return tlsConfig, nil | ||
} | ||
|
||
func getServerTLSConfigFromCertProvider(certProvider CertProvider, requireClientAuth bool) (*tls.Config, error) { | ||
func getServerTLSConfigFromCertProvider( | ||
certProvider CertProvider, | ||
requireClientAuth bool, | ||
remoteAddress string, | ||
logger log.Logger) (*tls.Config, error) { | ||
|
||
// Get serverCert from disk | ||
serverCert, err := certProvider.FetchServerCertificate() | ||
if err != nil { | ||
|
@@ -290,10 +304,12 @@ func getServerTLSConfigFromCertProvider(certProvider CertProvider, requireClient | |
|
||
clientCaPool = ca | ||
} | ||
logger.Info("returning TLS config for connection", tag.Address(remoteAddress)) | ||
return auth.NewTLSConfigWithCertsAndCAs( | ||
clientAuthType, | ||
[]tls.Certificate{*serverCert}, | ||
clientCaPool), nil | ||
clientCaPool, | ||
logger), nil | ||
} | ||
|
||
func newClientTLSConfig(clientProvider CertProvider, serverName string, isAuthRequired bool, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we think this should be Debug level log to avoid spamming if there are a lot of incoming connections? Or is Info fine?