mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 12:25:53 +02:00
Add support for certificate authentication for agents and bouncers (#1428)
This commit is contained in:
parent
bdda8691ff
commit
1c0fe09576
55 changed files with 1985 additions and 218 deletions
|
@ -1,10 +1,13 @@
|
|||
package csconfig
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/yamlpatch"
|
||||
|
@ -19,9 +22,12 @@ type APICfg struct {
|
|||
}
|
||||
|
||||
type ApiCredentialsCfg struct {
|
||||
URL string `yaml:"url,omitempty" json:"url,omitempty"`
|
||||
Login string `yaml:"login,omitempty" json:"login,omitempty"`
|
||||
Password string `yaml:"password,omitempty" json:"-"`
|
||||
URL string `yaml:"url,omitempty" json:"url,omitempty"`
|
||||
Login string `yaml:"login,omitempty" json:"login,omitempty"`
|
||||
Password string `yaml:"password,omitempty" json:"-"`
|
||||
CACertPath string `yaml:"ca_cert_path,omitempty"`
|
||||
KeyPath string `yaml:"key_path,omitempty"`
|
||||
CertPath string `yaml:"cert_path,omitempty"`
|
||||
}
|
||||
|
||||
/*global api config (for lapi->oapi)*/
|
||||
|
@ -73,11 +79,34 @@ func (l *LocalApiClientCfg) Load() error {
|
|||
l.Credentials.URL = l.Credentials.URL + "/"
|
||||
}
|
||||
}
|
||||
|
||||
if l.Credentials.Login != "" && (l.Credentials.CACertPath != "" || l.Credentials.CertPath != "" || l.Credentials.KeyPath != "") {
|
||||
return fmt.Errorf("user/password authentication and TLS authentication are mutually exclusive")
|
||||
}
|
||||
|
||||
if l.InsecureSkipVerify == nil {
|
||||
apiclient.InsecureSkipVerify = false
|
||||
} else {
|
||||
apiclient.InsecureSkipVerify = *l.InsecureSkipVerify
|
||||
}
|
||||
|
||||
if l.Credentials.CACertPath != "" && l.Credentials.CertPath != "" && l.Credentials.KeyPath != "" {
|
||||
cert, err := tls.LoadX509KeyPair(l.Credentials.CertPath, l.Credentials.KeyPath)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to load api client certificate")
|
||||
}
|
||||
|
||||
caCert, err := ioutil.ReadFile(l.Credentials.CACertPath)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to load cacert")
|
||||
}
|
||||
|
||||
caCertPool := x509.NewCertPool()
|
||||
caCertPool.AppendCertsFromPEM(caCert)
|
||||
|
||||
apiclient.Cert = &cert
|
||||
apiclient.CaCertPool = caCertPool
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -128,8 +157,15 @@ type LocalApiServerCfg struct {
|
|||
}
|
||||
|
||||
type TLSCfg struct {
|
||||
CertFilePath string `yaml:"cert_file"`
|
||||
KeyFilePath string `yaml:"key_file"`
|
||||
CertFilePath string `yaml:"cert_file"`
|
||||
KeyFilePath string `yaml:"key_file"`
|
||||
ClientVerification string `yaml:"client_verification,omitempty"`
|
||||
ServerName string `yaml:"server_name"`
|
||||
CACertPath string `yaml:"ca_cert_path"`
|
||||
AllowedAgentsOU []string `yaml:"agents_allowed_ou"`
|
||||
AllowedBouncersOU []string `yaml:"bouncers_allowed_ou"`
|
||||
CRLPath string `yaml:"crl_path"`
|
||||
CacheExpiration *time.Duration `yaml:"cache_expiration,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Config) LoadAPIServer() error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue