-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix tls not working correctly for es-https, imporve tls config m…
…anagement, fix verify peers, make cert/key required for carver receiver
- Loading branch information
Showing
11 changed files
with
182 additions
and
123 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2012-2023 Jason Woods and contributors | ||
* | ||
* This file is a modification of code from Logstash Forwarder. | ||
* Copyright 2012-2013 Jordan Sissel and contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package transports | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/driskell/log-courier/lc-lib/config" | ||
) | ||
|
||
type ClientTlsConfiguration struct { | ||
SSLCA string `config:"ssl ca"` | ||
|
||
*TlsConfiguration `config:",embed"` | ||
} | ||
|
||
func (f *ClientTlsConfiguration) TlsValidate(enableTls bool, p *config.Parser, configPath string) (err error) { | ||
if enableTls { | ||
if len(f.SSLCA) == 0 { | ||
return fmt.Errorf("%sssl ca is required for secure transports", configPath) | ||
} | ||
if f.CaList, err = AddCertificates(f.CaList, f.SSLCA); err != nil { | ||
return fmt.Errorf("failure loading %sssl ca: %s", configPath, err) | ||
} | ||
} else { | ||
if len(f.SSLCA) > 0 { | ||
return fmt.Errorf("%[1]sssl ca is not supported for non-secure transports", configPath) | ||
} | ||
} | ||
|
||
return f.TlsConfiguration.TlsValidate(enableTls, p, configPath) | ||
} | ||
|
||
func (f *ClientTlsConfiguration) Defaults() { | ||
} | ||
|
||
func (f *ClientTlsConfiguration) HasChanged(newConfig *ClientTlsConfiguration) bool { | ||
if newConfig.SSLCA != f.SSLCA { | ||
return true | ||
} | ||
return f.TlsConfiguration.HasChanged(newConfig.TlsConfiguration) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2012-2023 Jason Woods and contributors | ||
* | ||
* This file is a modification of code from Logstash Forwarder. | ||
* Copyright 2012-2013 Jordan Sissel and contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package transports | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
|
||
"github.com/driskell/log-courier/lc-lib/config" | ||
) | ||
|
||
const ( | ||
defaultSSLVerifyPeers = true | ||
) | ||
|
||
type ServerTlsConfiguration struct { | ||
SSLClientCA []string `config:"ssl client ca"` | ||
SSLVerifyPeers bool `config:"verify peers"` | ||
|
||
*TlsConfiguration `config:",embed"` | ||
} | ||
|
||
func (f *ServerTlsConfiguration) TlsValidate(enableTls bool, p *config.Parser, configPath string) (err error) { | ||
if enableTls { | ||
if len(f.SSLCertificate) == 0 || len(f.SSLKey) == 0 { | ||
return fmt.Errorf("%sssl certificate and ssl key must be specified for secure receivers", configPath) | ||
} | ||
|
||
for idx, clientCA := range f.SSLClientCA { | ||
if f.CaList, err = AddCertificates(f.CaList, clientCA); err != nil { | ||
return fmt.Errorf("failure loading %sssl client ca[%d]: %s", configPath, idx, err) | ||
} | ||
} | ||
} else { | ||
if len(f.SSLClientCA) > 0 { | ||
return fmt.Errorf("%sssl client ca is not supported for non-secure receivers", configPath) | ||
} | ||
} | ||
|
||
return f.TlsConfiguration.TlsValidate(enableTls, p, configPath) | ||
} | ||
|
||
func (f *ServerTlsConfiguration) Defaults() { | ||
f.SSLVerifyPeers = defaultSSLVerifyPeers | ||
} | ||
|
||
func (f *ServerTlsConfiguration) HasChanged(newConfig *ServerTlsConfiguration) bool { | ||
if !reflect.DeepEqual(newConfig.SSLClientCA, f.SSLClientCA) { | ||
return true | ||
} | ||
return f.TlsConfiguration.HasChanged(newConfig.TlsConfiguration) | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2012-2023 Jason Woods and contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package tcp | ||
|
||
import ( | ||
"regexp" | ||
|
||
"github.com/driskell/log-courier/lc-lib/config" | ||
) | ||
|
||
// Factory holds common TCP factory settings | ||
type Factory struct { | ||
config *config.Config | ||
hostportRegexp *regexp.Regexp | ||
} | ||
|
||
func newFactory(config *config.Config) *Factory { | ||
return &Factory{ | ||
config: config, | ||
hostportRegexp: regexp.MustCompile(`^\[?([^]]+)\]?:([0-9]+)$`), | ||
} | ||
} |
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
Oops, something went wrong.