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 Module] Add support for TLS #38126

Merged
merged 23 commits into from
Apr 13, 2024

Conversation

herrBez
Copy link
Contributor

@herrBez herrBez commented Feb 23, 2024

Proposed commit message

[Aerospike] Add TLS support

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Author's Checklist

How to test this PR locally

Aerospike has a documentation https://aerospike.com/docs/server/guide/security/tls documentation that explains how to configure aerospike with TLS.

Nevertheless, in my tests I used NGINX with the following configuration to perform SSL termination:

user  nginx;
worker_processes  auto;

events {
}

stream {
    server {
       listen 4333 ssl;
       proxy_pass stream_aerospike;
       ssl_certificate     /etc/nginx/certs/remote_fake.crt;
       ssl_certificate_key /etc/nginx/certs/remote_fake.key;
       ssl_client_certificate /etc/nginx/certs/ca.crt;

     }

     upstream stream_aerospike {
         # hash $remote_addr consistent;
         server aerospike:3000;
     }
}

And the following docker-compose.yml:

version: '2.3'

services:
  aerospike:
    image: docker.elastic.co/integrations-ci/beats-aerospike:${AEROSPIKE_VERSION:-3.9.0}-1
    build:
      context: ./_meta
      args:
        AEROSPIKE_VERSION: ${AEROSPIKE_VERSION:-3.9.0}
    ports:
      - 3000
  reverseproxy:
    image: nginx:latest
    volumes:
      - ./nginx/certs:/etc/nginx/certs
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf  
    ports:
      - 4333:4333

Related issues

Use cases

Monitor TLS and Username/Password protected Aerospike Databases

Screenshots

Logs

@herrBez herrBez requested a review from a team as a code owner February 23, 2024 16:33
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Feb 23, 2024
Copy link
Contributor

mergify bot commented Feb 23, 2024

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @herrBez? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v8./d.0 is the label to automatically backport to the 8./d branch. /d is the digit

"testing"

"github.com/elastic/elastic-agent-libs/transport/tlscommon"
Copy link
Contributor Author

@herrBez herrBez Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what does the error mean, any guidance is much appreciated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The imports starting with github.com/elastic/ need to appear before other 3rd party imports, run goimports -w -local github.com/elastic metricbeat/module/aerospike

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Let's see if it's fixed now :)

@elasticmachine
Copy link
Collaborator

elasticmachine commented Feb 23, 2024

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Duration: 55 min 51 sec

❕ Flaky test report

No test was executed to be analysed.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@pierrehilbert pierrehilbert added the Team:Elastic-Agent Label for the Agent team label Feb 26, 2024
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent (Team:Elastic-Agent)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Feb 26, 2024
@fearful-symmetry
Copy link
Contributor

@herrBez so, I don't have much experience with Aerospike---is the idea there that basic auth would be used with the access controls in enterprise, or with a reverse proxy like nginx? If it's the latter (or both) it might be good to comment that and provide an example.

@herrBez
Copy link
Contributor Author

herrBez commented Mar 13, 2024

Hi,
Yes there are two flavors of Aerospike Community Edition (CE) and Enterprise Edition (EE). The first lacks TLS and Basic Auth support, while the latter support both features. With Aerospike CE we can use a Reverse Proxy like NGINX to add these missing features. I will try to provide these examples As soon as I can in the form of Docker-Compose file.

Comment on lines 194 to 196
assert.Equal(t, test.expectedClientPolicy.User, result.User, test.Name)
assert.Equal(t, test.expectedClientPolicy.Password, result.Password, test.Name)
assert.Equal(t, test.expectedClientPolicy.ClusterName, result.ClusterName, test.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you mind switching to Equalf and providing a description of what didn't match?

Right now if this fails in CI we will get an error like "A" does not equal "B". It is a lot easier to debug if we get something like Aerospike policy username is wrong. got: "A" expected: "B"

Copy link
Contributor Author

@herrBez herrBez Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
Thank you for the feedback. I don't mind at all ^^. So something like:

assert.Equalf(t, test.expectedClientPolicy.User, result.User, "Aerospike policy [Test '%s'] username is wrong: expected '%s' got '%s'", test.Name, test.expectedClientPolicy.User, result.User)

Or something like:

assert.Equalf(t, test.expectedClientPolicy.User, result.User, "Aerospike policy [Test '%s'] username is wrong", test.Name)

??

Should I also modify the existing tests to use Equalf?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need the test name, when it errors out go test will give us that. I prefer the ones that have expected and got (or something like that).

One thing I think that helps is to fail the test and just double check that the error message gives you enough context that you have some idea of where the problem is. For example telling me that the Username is what didn't match, the value we got, and the expected value goes a long way to helping understand where the problem might be.

I think you can just focus on the tests you are adding. That helps limit the scope of the PR.

@lalit-satapathy
Copy link
Contributor

@lalit-satapathy could we have someone for a review here?

CC: @gpop63 @shmsr

metricbeat/module/aerospike/aerospike_test.go Outdated Show resolved Hide resolved
metricbeat/module/aerospike/aerospike_test.go Outdated Show resolved Hide resolved
herrBez and others added 5 commits April 8, 2024 08:32
- [reference-config] add empty line after hosts list
- [test] remove empty line after function header
- [test] use generic pointer instead of custom one
x-pack/metricbeat/metricbeat.reference.yml Outdated Show resolved Hide resolved
@herrBez herrBez requested a review from shmsr April 9, 2024 07:11
@shmsr
Copy link
Member

shmsr commented Apr 9, 2024

Are we adding the tests that @gpop63 suggested? If yes, then I'll wait for the changes and then approve. If no, then I'll approve this PR right away; the changes look good.

cc: @gpop63 @herrBez

@herrBez herrBez requested a review from gpop63 April 11, 2024 12:12
Copy link
Contributor

@gpop63 gpop63 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, make sure to fix the docs and x-pack/metricbeat CI. make update should probably fix them.

@herrBez herrBez merged commit 5b67a54 into elastic:main Apr 13, 2024
58 checks passed
@herrBez
Copy link
Contributor Author

herrBez commented Apr 13, 2024

Thank you all for the help and the patience! After the merge I noticed we did not add an entry in the release notes. Should we add one?

@shmsr
Copy link
Member

shmsr commented Apr 13, 2024

Thank you all for the help and the patience! After the merge I noticed we did not add an entry in the release notes. Should we add one?

Yes, we should! Thanks.

@herrBez
Copy link
Contributor Author

herrBez commented Apr 15, 2024

Hi, how should we proceed? By opening a new PR? I tried committing in my branch but this PR did not get the update.

(BTW the release notes seems to contain duplicated sections e.g line 243 and 245 . Is it expcted?)

@shmsr
Copy link
Member

shmsr commented Apr 15, 2024

Hi, how should we proceed? By opening a new PR? I tried committing in my branch but this PR did not get the update.

(BTW the release notes seems to contain duplicated sections e.g line 243 and 245 . Is it expcted?)

No. Duplicates are not expected. Also, yes you can create a new PR to include the changelog entry. Please do it ASAP and tomorrow we have code freeze for 8.14 release.

@herrBez
Copy link
Contributor Author

herrBez commented Apr 15, 2024

Done in #38923 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Obs-InfraObs Label for the Observability Infrastructure Monitoring team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants