Skip to content

Commit 99a477c

Browse files
authored
[beatreceivers] Add support for kerberos (#11163)
* Support loadbalance:false option
1 parent 64aff5a commit 99a477c

File tree

3 files changed

+57
-11
lines changed

3 files changed

+57
-11
lines changed

internal/pkg/otel/translate/otelconfig.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/go-viper/mapstructure/v2"
1515
koanfmaps "github.com/knadh/koanf/maps"
1616

17+
"github.com/elastic/elastic-agent-client/v7/pkg/client"
1718
"github.com/elastic/elastic-agent/internal/pkg/agent/application/monitoring/monitoringhelpers"
1819

1920
"github.com/elastic/elastic-agent-libs/logp"
@@ -25,7 +26,7 @@ import (
2526

2627
"github.com/elastic/beats/v7/libbeat/outputs/elasticsearch"
2728
"github.com/elastic/beats/v7/x-pack/libbeat/management"
28-
"github.com/elastic/elastic-agent-client/v7/pkg/client"
29+
"github.com/elastic/beats/v7/x-pack/otel/extension/beatsauthextension"
2930
"github.com/elastic/elastic-agent-libs/config"
3031
"github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
3132
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
@@ -649,15 +650,18 @@ func BeatDataPath(componentId string) string {
649650
// getBeatsAuthExtensionConfig sets http transport settings on beatsauth
650651
// currently this is only supported for elasticsearch output
651652
func getBeatsAuthExtensionConfig(outputCfg *config.C) (map[string]any, error) {
652-
defaultTransportSettings := elasticsearch.ESDefaultTransportSettings()
653+
654+
authSettings := beatsauthextension.BeatsAuthConfig{
655+
Transport: elasticsearch.ESDefaultTransportSettings(),
656+
}
653657

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

659663
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
660-
Result: &defaultTransportSettings,
664+
Result: &authSettings,
661665
TagName: "config",
662666
SquashTagOption: "inline",
663667
DecodeHook: cfgDecodeHookFunc(),
@@ -670,20 +674,27 @@ func getBeatsAuthExtensionConfig(outputCfg *config.C) (map[string]any, error) {
670674
return nil, err
671675
}
672676

673-
newConfig, err := config.NewConfigFrom(defaultTransportSettings)
677+
newConfig, err := config.NewConfigFrom(authSettings)
674678
if err != nil {
675679
return nil, err
676680
}
677681

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

691+
if authSettings.Kerberos != nil {
692+
err = newConfig.SetString("kerberos.auth_type", -1, authSettings.Kerberos.AuthType.String())
693+
if err != nil {
694+
return nil, fmt.Errorf("error setting kerberos auth type url:%w ", err)
695+
}
696+
}
697+
687698
var newMap map[string]any
688699
err = newConfig.Unpack(&newMap)
689700
if err != nil {

internal/pkg/otel/translate/otelconfig_test.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,10 +1302,10 @@ func TestGetBeatsAuthExtensionConfig(t *testing.T) {
13021302
},
13031303
},
13041304
{
1305-
name: "with ssl enabled and verification_mode full",
1305+
name: "with ssl enabled and verification_mode certificate",
13061306
outputCfg: map[string]any{
13071307
"ssl.enabled": true,
1308-
"ssl.verification_mode": "full",
1308+
"ssl.verification_mode": "certificate",
13091309
},
13101310
expected: map[string]any{
13111311
"continue_on_error": true,
@@ -1324,11 +1324,41 @@ func TestGetBeatsAuthExtensionConfig(t *testing.T) {
13241324
"key_passphrase_path": "",
13251325
"renegotiation": int64(0),
13261326
"supported_protocols": []interface{}{},
1327-
"verification_mode": uint64(0),
1327+
"verification_mode": uint64(2),
13281328
},
13291329
"timeout": "1m30s",
13301330
},
13311331
},
1332+
{
1333+
name: "with kerberos is enabled",
1334+
outputCfg: map[string]any{
1335+
"kerberos": map[string]any{
1336+
"enabled": true,
1337+
"auth_type": "password",
1338+
"config_path": "temp/krb5.conf",
1339+
"username": "beats",
1340+
"password": "testing",
1341+
"realm": "elastic",
1342+
},
1343+
},
1344+
expected: map[string]any{
1345+
"continue_on_error": true,
1346+
"idle_connection_timeout": "3s",
1347+
"timeout": "1m30s",
1348+
"kerberos": map[string]any{
1349+
"enabled": true,
1350+
"auth_type": "password",
1351+
"config_path": "temp/krb5.conf",
1352+
"username": "beats",
1353+
"password": "testing",
1354+
"realm": "elastic",
1355+
"enable_krb5_fast": false,
1356+
"service_name": "",
1357+
"keytab": "",
1358+
},
1359+
"proxy_disable": false,
1360+
},
1361+
},
13321362
}
13331363

13341364
for _, tt := range tests {

internal/pkg/otel/translate/output_elasticsearch.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/go-viper/mapstructure/v2"
1818

1919
"github.com/elastic/beats/v7/libbeat/common"
20+
"github.com/elastic/beats/v7/libbeat/common/transport/kerberos"
2021
"github.com/elastic/beats/v7/libbeat/outputs"
2122
"github.com/elastic/beats/v7/libbeat/outputs/elasticsearch"
2223
"github.com/elastic/beats/v7/libbeat/publisher/queue/memqueue"
@@ -196,8 +197,6 @@ func checkUnsupportedConfig(cfg *config.C) error {
196197
return fmt.Errorf("ladbalance:false is currently not supported: %w", errors.ErrUnsupported)
197198
} else if cfg.HasField("non_indexable_policy") {
198199
return fmt.Errorf("non_indexable_policy is currently not supported: %w", errors.ErrUnsupported)
199-
} else if cfg.HasField("kerberos") {
200-
return fmt.Errorf("kerberos is currently not supported: %w", errors.ErrUnsupported)
201200
}
202201

203202
return nil
@@ -273,6 +272,12 @@ func cfgDecodeHookFunc() mapstructure.DecodeHookFunc {
273272
return nil, fmt.Errorf("failed parsing proxy_url: %w", err)
274273
}
275274
return proxyURL, nil
275+
case t == reflect.TypeOf(kerberos.AuthType(0)):
276+
var authType kerberos.AuthType
277+
if err := authType.Unpack(data.(string)); err != nil {
278+
return nil, fmt.Errorf("failed parsing kerberos.auth_type: %w", err)
279+
}
280+
return authType, nil
276281
default:
277282
return data, nil
278283
}

0 commit comments

Comments
 (0)