Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions internal/pkg/otel/translate/otelconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/elastic/beats/v7/x-pack/filebeat/fbreceiver"
"github.com/elastic/beats/v7/x-pack/libbeat/management"
"github.com/elastic/beats/v7/x-pack/metricbeat/mbreceiver"
"github.com/elastic/beats/v7/x-pack/otel/extension/beatsauthextension"
"github.com/elastic/elastic-agent-client/v7/pkg/client"
"github.com/elastic/elastic-agent-libs/config"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
Expand Down Expand Up @@ -618,15 +619,18 @@ func BeatDataPath(componentId string) string {
// getBeatsAuthExtensionConfig sets http transport settings on beatsauth
// currently this is only supported for elasticsearch output
func getBeatsAuthExtensionConfig(outputCfg *config.C) (map[string]any, error) {
defaultTransportSettings := elasticsearch.ESDefaultTransportSettings()

defaultAuthSettings := beatsauthextension.BeatsAuthConfig{
Transport: elasticsearch.ESDefaultTransportSettings(),
}

var resultMap map[string]any
if err := outputCfg.Unpack(&resultMap); err != nil {
return nil, err
}

decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &defaultTransportSettings,
Result: &defaultAuthSettings,
TagName: "config",
SquashTagOption: "inline",
DecodeHook: cfgDecodeHookFunc(),
Expand All @@ -639,20 +643,27 @@ func getBeatsAuthExtensionConfig(outputCfg *config.C) (map[string]any, error) {
return nil, err
}

newConfig, err := config.NewConfigFrom(defaultTransportSettings)
newConfig, err := config.NewConfigFrom(defaultAuthSettings)
if err != nil {
return nil, err
}

// proxy_url on newConfig is of type url.URL. Beatsauth extension expects it to be of string type instead
// this logic here converts url.URL to string type similar to what a user would set on filebeat config
if defaultTransportSettings.Proxy.URL != nil {
err = newConfig.SetString("proxy_url", -1, defaultTransportSettings.Proxy.URL.String())
if defaultAuthSettings.Transport.Proxy.URL != nil {
err = newConfig.SetString("proxy_url", -1, defaultAuthSettings.Transport.Proxy.URL.String())
if err != nil {
return nil, fmt.Errorf("error settingg proxy url:%w ", err)
}
}

if defaultAuthSettings.Kerberos != nil {
err = newConfig.SetString("kerberos.auth_type", -1, defaultAuthSettings.Kerberos.AuthType.String())
if err != nil {
return nil, fmt.Errorf("error settingg kerberos auth type url:%w ", err)
}
}

var newMap map[string]any
err = newConfig.Unpack(&newMap)
if err != nil {
Expand Down
36 changes: 32 additions & 4 deletions internal/pkg/otel/translate/otelconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ func TestGetOtelConfig(t *testing.T) {
"supported_protocols": []interface{}{},
"verification_mode": uint64(0),
},
"timeout": "1m30s",
}
for _, v := range extra {
// accepts one level deep parameters to replace
Expand Down Expand Up @@ -1312,10 +1311,10 @@ func TestGetBeatsAuthExtensionConfig(t *testing.T) {
},
},
{
name: "with ssl enabled and verification_mode full",
name: "with ssl enabled and verification_mode certificate",
outputCfg: map[string]any{
"ssl.enabled": true,
"ssl.verification_mode": "full",
"ssl.verification_mode": "certificate",
},
expected: map[string]any{
"continue_on_error": true,
Expand All @@ -1334,11 +1333,40 @@ func TestGetBeatsAuthExtensionConfig(t *testing.T) {
"key_passphrase_path": "",
"renegotiation": int64(0),
"supported_protocols": []interface{}{},
"verification_mode": uint64(0),
"verification_mode": uint64(2),
},
"timeout": "1m30s",
},
},
{
name: "with kerberos is enabled",
outputCfg: map[string]any{
"kerberos": map[string]any{
"auth_type": "password",
"config_path": "temp/krb5.conf",
"username": "beats",
"password": "testing",
"realm": "elastic",
},
},
expected: map[string]any{
"continue_on_error": true,
"idle_connection_timeout": "3s",
"timeout": "1m30s",
"kerberos": map[string]any{
"enabled": nil,
"auth_type": "password",
"config_path": "temp/krb5.conf",
"username": "beats",
"password": "testing",
"realm": "elastic",
"enable_krb5_fast": false,
"service_name": "",
"keytab": "",
},
"proxy_disable": false,
},
},
}

for _, tt := range tests {
Expand Down
7 changes: 7 additions & 0 deletions internal/pkg/otel/translate/output_elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/go-viper/mapstructure/v2"

"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/common/transport/kerberos"
"github.com/elastic/beats/v7/libbeat/outputs"
"github.com/elastic/beats/v7/libbeat/outputs/elasticsearch"
"github.com/elastic/beats/v7/libbeat/publisher/queue/memqueue"
Expand Down Expand Up @@ -269,6 +270,12 @@ func cfgDecodeHookFunc() mapstructure.DecodeHookFunc {
return nil, fmt.Errorf("failed parsing proxy_url: %w", err)
}
return proxyURL, nil
case t == reflect.TypeOf(kerberos.AuthType(0)):
authType := kerberos.AuthType(0)
if err := authType.Unpack(data.(string)); err != nil {
return nil, fmt.Errorf("failed parsing kerberos.auth_type: %w", err)
}
return authType, nil
default:
return data, nil
}
Expand Down