Skip to content
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

[Metricbeat][Aerospike] Add support for basic auth #41233

Merged
merged 33 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
38f012f
Update aerospike-client-go dependency to the latest version
herrBez Oct 14, 2024
2868cf0
Bump aerospike docker image version to latest v7 available
herrBez Oct 14, 2024
9349201
Add basic auth support
herrBez Oct 14, 2024
d00051b
Add basic auth configuration tests
herrBez Oct 14, 2024
b46dd41
Add property InfoPolicy to the Metricset
herrBez Oct 14, 2024
dadb6e3
Run Mage update in x-pack module
herrBez Oct 14, 2024
441c321
Add line in CHANGELOG.next.asciidoc
herrBez Oct 14, 2024
dde2b63
Update NOTICE.txt to contain updated information on aerospike-client …
herrBez Oct 15, 2024
a30363a
Run mage check to fix build
herrBez Oct 15, 2024
1703eb0
Add support Authentication Mode
herrBez Oct 15, 2024
874572a
Add authmode to tests
herrBez Oct 15, 2024
c26c1cd
Add Auth Mode to config and run mage update
herrBez Oct 15, 2024
71505f7
Update metricbeat/module/aerospike/aerospike_test.go
herrBez Oct 21, 2024
59bdfb4
Merge remote-tracking branch 'origin/main' into aerospike-basic-auth
herrBez Oct 21, 2024
24d5fac
Merge branch 'main' into aerospike-basic-auth
herrBez Oct 22, 2024
81525a1
Fix integration test by reverting AEROSPIKE_VERSION in docker-compose
herrBez Oct 23, 2024
999e09b
Merge branch 'main' into aerospike-basic-auth
herrBez Oct 25, 2024
6a0e698
Bump version to latest 7.x available
herrBez Oct 29, 2024
b0ec92e
Adjust healthcheck to use asinfo instead of tcp ping:
herrBez Oct 29, 2024
5b623a8
Merge branch 'main' into aerospike-basic-auth
herrBez Oct 29, 2024
c9f1f22
Improve healthcheck to make sure that the namespace statistics can be…
herrBez Nov 1, 2024
7b2780a
Merge branch 'aerospike-basic-auth' of github.com:herrBez/beats into …
herrBez Nov 1, 2024
0aafa19
Update metricbeat/module/aerospike/aerospike.go
herrBez Nov 2, 2024
3870e21
Make sure username/password are set together
herrBez Nov 2, 2024
66e7e85
Improve documentation to report with which version Aerospike is expec…
herrBez Nov 7, 2024
1bce421
Make release notes for the PR more accurate
herrBez Nov 7, 2024
6fc64fa
Merge branch 'main' into aerospike-basic-auth
herrBez Nov 7, 2024
1b8bf83
Fix build by compiling aerospike asciidoc
herrBez Nov 8, 2024
4f2d73b
Merge branch 'main' into aerospike-basic-auth
herrBez Nov 10, 2024
08cf5b2
Merge remote-tracking branch 'origin/main' into aerospike-basic-auth
herrBez Nov 12, 2024
fd9da31
Merge branch 'aerospike-basic-auth' of github.com:herrBez/beats into …
herrBez Nov 12, 2024
32e4412
Remove h1q dependency, which is probably a typo
herrBez Nov 12, 2024
829542d
Merge branch 'main' into aerospike-basic-auth
herrBez Nov 12, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Added Palo Alto Networks module {pull}40686[40686]
- Restore docker.network.in.* and docker.network.out.* fields in docker module {pull}40968[40968]
- Add `id` field to all the vSphere metricsets. {pull}41097[41097]
- Bump aerospike-client-go to version v7.7.1 and add support for basic auth in Aerospike module {pull}41233[41233]
- Only watch metadata for ReplicaSets in metricbeat k8s module {pull}41289[41289]
- Add support for region/zone for Vertex AI service in GCP module {pull}41551[41551]

Expand Down
12 changes: 6 additions & 6 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2806,12 +2806,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


--------------------------------------------------------------------------------
Dependency : github.com/aerospike/aerospike-client-go
Version: v1.27.1-0.20170612174108-0f3b54da6bdc
Dependency : github.com/aerospike/aerospike-client-go/v7
Version: v7.7.1
Licence type (autodetected): Apache-2.0
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/aerospike/aerospike-client-go@v1.27.1-0.20170612174108-0f3b54da6bdc/LICENSE:
Contents of probable licence file $GOMODCACHE/github.com/aerospike/aerospike-client-go/v7@v7.7.1/LICENSE:


Apache License
Expand Down Expand Up @@ -3002,7 +3002,7 @@ Contents of probable licence file $GOMODCACHE/github.com/aerospike/aerospike-cli
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2014-2016 Aerospike, Inc.
Copyright 2014-2020 Aerospike, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54182,11 +54182,11 @@ SOFTWARE.

--------------------------------------------------------------------------------
Dependency : github.com/yuin/gopher-lua
Version: v0.0.0-20170403160031-b402f3114ec7
Version: v1.1.1
Licence type (autodetected): MIT
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/yuin/gopher-lua@v0.0.0-20170403160031-b402f3114ec7/LICENSE:
Contents of probable licence file $GOMODCACHE/github.com/yuin/gopher-lua@v1.1.1/LICENSE:

The MIT License (MIT)

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ require (
github.com/PaesslerAG/jsonpath v0.1.1
github.com/Shopify/sarama v1.27.0
github.com/StackExchange/wmi v1.2.1
github.com/aerospike/aerospike-client-go v1.27.1-0.20170612174108-0f3b54da6bdc
github.com/akavel/rsrc v0.8.0 // indirect
github.com/apoydence/eachers v0.0.0-20181020210610-23942921fe77 // indirect
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
Expand Down Expand Up @@ -176,6 +175,7 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.4.0
github.com/Azure/azure-storage-blob-go v0.15.0
github.com/Azure/go-autorest/autorest/adal v0.9.24
github.com/aerospike/aerospike-client-go/v7 v7.7.1
github.com/apache/arrow/go/v14 v14.0.2
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.12
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.13
Expand Down Expand Up @@ -406,7 +406,7 @@ require (
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/yuin/gopher-lua v0.0.0-20170403160031-b402f3114ec7 // indirect
github.com/yuin/gopher-lua v1.1.1 // indirect
gopkg.in/jcmturner/rpc.v1 v1.1.0 // indirect
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWso
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/aerospike/aerospike-client-go v1.27.1-0.20170612174108-0f3b54da6bdc h1:9iW/Fbn/R/nyUOiqo6AgwBe8uirqUIoTGF3vKG8qjoc=
github.com/aerospike/aerospike-client-go v1.27.1-0.20170612174108-0f3b54da6bdc/go.mod h1:zj8LBEnWBDOVEIJt8LvaRvDG5ARAoa5dBeHaB472NRc=
github.com/aerospike/aerospike-client-go/v7 v7.7.1 h1:lcskBtPZYe6ESObhIEQEp4XO1axYZpaFD3ie4iwr6tg=
github.com/aerospike/aerospike-client-go/v7 v7.7.1/go.mod h1:STlBtOkKT8nmp7iD+sEkr/JGEOu+4e2jGlNN0Jiu2a4=
github.com/akavel/rsrc v0.8.0 h1:zjWn7ukO9Kc5Q62DOJCcxGpXC18RawVtYAGdz2aLlfw=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down Expand Up @@ -908,8 +908,8 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yuin/gopher-lua v0.0.0-20170403160031-b402f3114ec7 h1:0gYLpmzecnaDCoeWxSfEJ7J1b6B/67+NV++4HKQXx+Y=
github.com/yuin/gopher-lua v0.0.0-20170403160031-b402f3114ec7/go.mod h1:aEV29XrmTYFr3CiRxZeGHpkvbwq+prZduBqMaascyCU=
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
Expand Down
12 changes: 11 additions & 1 deletion metricbeat/docs/modules/aerospike.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The Aerospike module uses the http://www.aerospike.com/docs/reference/info[Info
[float]
=== Compatibility

The Aerospike metricsets were tested with Aerospike 3.9 and are expected to work with all versions >= 3.9.
The Aerospike metricsets were tested with Aerospike Enterprise Edition 7.2.0.1 and are expected to work with all versions >= 4.9.


[float]
Expand Down Expand Up @@ -45,6 +45,16 @@ metricbeat.modules:
# Aerospike Cluster Name
#cluster_name: myclustername

# Username of hosts. Empty by default.
#username: root

# Password of hosts. Empty by default.
#password: secret

# Authentication modes: https://aerospike.com/docs/server/guide/security/access-control
# Possible values: internal (default), external, pki
#auth_mode: internal

# Optional SSL/TLS (disabled by default)
#ssl.enabled: true

Expand Down
10 changes: 10 additions & 0 deletions metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ metricbeat.modules:
# Aerospike Cluster Name
#cluster_name: myclustername

# Username of hosts. Empty by default.
#username: root

# Password of hosts. Empty by default.
#password: secret

# Authentication modes: https://aerospike.com/docs/server/guide/security/access-control
# Possible values: internal (default), external, pki
#auth_mode: internal

# Optional SSL/TLS (disabled by default)
#ssl.enabled: true

Expand Down
5 changes: 2 additions & 3 deletions metricbeat/module/aerospike/_meta/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ARG AEROSPIKE_VERSION
FROM aerospike:${AEROSPIKE_VERSION}
FROM aerospike/aerospike-server-enterprise:${AEROSPIKE_VERSION}

RUN apt-get update && apt-get install -y netcat-openbsd
HEALTHCHECK --interval=1s --retries=90 CMD nc -z localhost 3000
HEALTHCHECK --interval=1s --retries=90 CMD asinfo -v "namespace/test" | grep "ns_cluster_size=1" -q
10 changes: 10 additions & 0 deletions metricbeat/module/aerospike/_meta/config.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
# Aerospike Cluster Name
#cluster_name: myclustername

# Username of hosts. Empty by default.
#username: root

# Password of hosts. Empty by default.
#password: secret

# Authentication modes: https://aerospike.com/docs/server/guide/security/access-control
# Possible values: internal (default), external, pki
#auth_mode: internal

# Optional SSL/TLS (disabled by default)
#ssl.enabled: true

Expand Down
10 changes: 10 additions & 0 deletions metricbeat/module/aerospike/_meta/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
# Aerospike Cluster Name
#cluster_name: myclustername

# Username of hosts. Empty by default.
#username: root

# Password of hosts. Empty by default.
#password: secret

# Authentication modes: https://aerospike.com/docs/server/guide/security/access-control
# Possible values: internal (default), external, pki
#auth_mode: internal

# Optional SSL/TLS (disabled by default)
#ssl.enabled: true

Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/aerospike/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ The Aerospike module uses the http://www.aerospike.com/docs/reference/info[Info
[float]
=== Compatibility

The Aerospike metricsets were tested with Aerospike 3.9 and are expected to work with all versions >= 3.9.
The Aerospike metricsets were tested with Aerospike Enterprise Edition 7.2.0.1 and are expected to work with all versions >= 4.9.


[float]
Expand Down
34 changes: 33 additions & 1 deletion metricbeat/module/aerospike/aerospike.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,24 @@ import (

"github.com/elastic/elastic-agent-libs/transport/tlscommon"

as "github.com/aerospike/aerospike-client-go"
as "github.com/aerospike/aerospike-client-go/v7"
)

type Config struct {
ClusterName string `config:"cluster_name"`
TLS *tlscommon.Config `config:"ssl"`
User string `config:"username"`
Password string `config:"password"`
AuthMode string `config:"auth_mode"`
}

const (
AUTH_MODE_UNSET string = ""
AUTH_MODE_INTERNAL string = "internal"
AUTH_MODE_PKI string = "pki"
AUTH_MODE_EXTERNAL string = "external"
)

// DefaultConfig return default config for the aerospike module.
func DefaultConfig() Config {
return Config{}
Expand All @@ -47,6 +57,28 @@ func ParseClientPolicy(config Config) (*as.ClientPolicy, error) {
clientPolicy.TlsConfig = tlsconfig.ToConfig()
}

if config.User != "" && config.Password != "" {
clientPolicy.User = config.User
clientPolicy.Password = config.Password
} else if config.User != "" {
return nil, fmt.Errorf("if username is set, password should be set too")
} else if config.Password != "" {
return nil, fmt.Errorf("if password is set, username should be set too")
}

switch config.AuthMode {
case AUTH_MODE_UNSET:
// Use default behavior of client
case AUTH_MODE_INTERNAL:
clientPolicy.AuthMode = as.AuthModeInternal
case AUTH_MODE_EXTERNAL:
clientPolicy.AuthMode = as.AuthModeExternal
case AUTH_MODE_PKI:
clientPolicy.AuthMode = as.AuthModePKI
default:
return nil, fmt.Errorf("unknown authentication mode '%s'", config.AuthMode)
}

if config.ClusterName != "" {
clientPolicy.ClusterName = config.ClusterName
}
Expand Down
93 changes: 92 additions & 1 deletion metricbeat/module/aerospike/aerospike_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ package aerospike

import (
"errors"
"fmt"
"testing"

"github.com/stretchr/testify/assert"

"github.com/elastic/elastic-agent-libs/transport/tlscommon"

as "github.com/aerospike/aerospike-client-go"
as "github.com/aerospike/aerospike-client-go/v7"
)

func TestParseHost(t *testing.T) {
Expand Down Expand Up @@ -105,6 +106,8 @@ func pointer[T any](d T) *T {

func TestParseClientPolicy(t *testing.T) {
sampleClusterName := "TestCluster"
sampleUser := "TestUser"
samplePassword := "MySecretPassword"

TLSPolicy := as.NewClientPolicy()
tlsconfig, _ := tlscommon.LoadTLSConfig(&tlscommon.Config{Enabled: pointer(true)})
Expand All @@ -113,6 +116,24 @@ func TestParseClientPolicy(t *testing.T) {
ClusterNamePolicy := as.NewClientPolicy()
ClusterNamePolicy.ClusterName = sampleClusterName

UserPasswordClientPolicy := as.NewClientPolicy()
UserPasswordClientPolicy.User = sampleUser
UserPasswordClientPolicy.Password = samplePassword

UserPasswordTLSPolicy := as.NewClientPolicy()
UserPasswordTLSPolicy.User = sampleUser
UserPasswordTLSPolicy.Password = samplePassword
UserPasswordTLSPolicy.TlsConfig = tlsconfig.ToConfig()

ExternalAuthModePolicy := as.NewClientPolicy()
ExternalAuthModePolicy.AuthMode = as.AuthModeExternal

PKIAuthModePolicy := as.NewClientPolicy()
PKIAuthModePolicy.AuthMode = as.AuthModePKI

InternalAuthModePolicy := as.NewClientPolicy()
InternalAuthModePolicy.AuthMode = as.AuthModeInternal

tests := []struct {
Name string
Config Config
Expand Down Expand Up @@ -143,6 +164,66 @@ func TestParseClientPolicy(t *testing.T) {
expectedClientPolicy: ClusterNamePolicy,
expectedErr: nil,
},
{
Name: "Username and password are honored",
Config: Config{
User: sampleUser,
Password: samplePassword,
},
expectedClientPolicy: UserPasswordClientPolicy,
expectedErr: nil,
},
{
Name: "Username is set and password is not set",
Config: Config{
User: sampleUser,
},
expectedClientPolicy: as.NewClientPolicy(),
expectedErr: fmt.Errorf("if username is set, password should be set too"),
},
{
Name: "Password is set and user is not set",
Config: Config{
Password: samplePassword,
},
expectedClientPolicy: as.NewClientPolicy(),
expectedErr: fmt.Errorf("if password is set, username should be set too"),
},
{
Name: "TLS and Basic Auth",
Config: Config{
TLS: &tlscommon.Config{
Enabled: pointer(true),
},
User: sampleUser,
Password: samplePassword,
},
expectedClientPolicy: UserPasswordTLSPolicy,
expectedErr: nil,
},
{
Name: "Unsupported Authentication Mode",
Config: Config{
AuthMode: "doesnotexist",
},
expectedErr: fmt.Errorf("unknown authentication mode 'doesnotexist'"),
},
{
Name: "External Authentication Mode",
Config: Config{
AuthMode: AUTH_MODE_EXTERNAL,
},
expectedClientPolicy: ExternalAuthModePolicy,
expectedErr: fmt.Errorf("unknown authentication mode 'doesnotexist'"),
},
{
Name: "Internal Authentication Mode",
Config: Config{
AuthMode: AUTH_MODE_INTERNAL,
},
expectedClientPolicy: InternalAuthModePolicy,
expectedErr: fmt.Errorf("unknown authentication mode 'doesnotexist'"),
},
}

for _, test := range tests {
Expand All @@ -158,6 +239,16 @@ func TestParseClientPolicy(t *testing.T) {
}
assert.Equalf(t, test.expectedClientPolicy.ClusterName, result.ClusterName,
"Aerospike policy cluster name is wrong. Got '%s' expected '%s'", result.ClusterName, test.expectedClientPolicy.ClusterName)

assert.Equalf(t, test.expectedClientPolicy.User, result.User,
"Aerospike policy username is wrong. Got '%s' expected '%s'", result.User, test.expectedClientPolicy.User)

assert.Equalf(t, test.expectedClientPolicy.Password, result.Password,
"Aerospike policy password is wrong. Got '%s' expected '%s'", result.Password, test.expectedClientPolicy.Password)

assert.Equalf(t, test.expectedClientPolicy.AuthMode, result.AuthMode,
"Aerospike policy authentication mode is wrong. Got '%s' expected '%s'", result.AuthMode, test.expectedClientPolicy.AuthMode)

if test.Config.TLS.IsEnabled() {
assert.NotNil(t, result.TlsConfig, "Aerospike policy: TLS is not set even though TLS is specified in the configuration")
}
Expand Down
4 changes: 2 additions & 2 deletions metricbeat/module/aerospike/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ version: '2.3'

services:
aerospike:
image: docker.elastic.co/integrations-ci/beats-aerospike:${AEROSPIKE_VERSION:-3.9.0}-1
image: docker.elastic.co/integrations-ci/beats-aerospike:${AEROSPIKE_VERSION:-7.2.0.1}-1
build:
context: ./_meta
args:
AEROSPIKE_VERSION: ${AEROSPIKE_VERSION:-3.9.0}
AEROSPIKE_VERSION: ${AEROSPIKE_VERSION:-7.2.0.1}
ports:
- 3000
Loading
Loading