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] MSSQL module cannot parse username if domain is included within the host string #13364

Open
geekpete opened this issue Aug 28, 2019 · 13 comments
Assignees
Labels
bug Metricbeat Metricbeat Team:Integrations Label for the Integrations team

Comments

@geekpete
Copy link
Member

Please include configurations and logs if available.

For confirmed bugs, please report:

  • Version: Metricbeat 7.3.0
  • Operating System: Windows
  • Discuss Forum URL:
  • Steps to Reproduce:

Using a domain within the username in credentials doesn't seem to parse regardless of escaping.

Typical configuration example might look like:

------------
# Module: mssql
# Docs: https://www.elastic.co/guide/en/beats/metricbeat/7.3/metricbeat-module-mssql.html

- module: mssql
  metricsets:
    - "transaction_log"
    - "performance"
  hosts: ["sqlserver://sa@localhost"]
  period: 10s

But when attempting to use an Active Domain user rather than the SA service account, there doesn't seem to be a way to specify the domain within the hosts connection string and have it work.

Examples of what doesn't work:

hosts: ["sqlserver://domain\user:password@server01"]
hosts: ["sqlserver://domain\\user:password@server01"]
hosts: ["sqlserver://domain/user:password@server01"]
hosts: ["sqlserver://domain\/user:password@server01"]
hosts: ["domain\user:password@server01"]
hosts: ["domain\\user:password@server01"]
hosts: ["domain/user:password@server01"]
hosts: ["domain\/user:password@server01"]

Example errors

When trying with domain:

2019-08-28T12:54:59.661+1200    ERROR   instance/beat.go:802    Exiting: 1 error: 2 errors: host parsing failed for mssql-transaction_log: error parsing URL: parse sqlserver://mydomain\user:password@server01: net/url: invalid userinfo; host parsing failed for mssql-performance: error parsing URL: parse sqlserver://mydomain\user:password@server01: net/url: invalid userinfo

Exiting: 1 error: 2 errors: host parsing failed for mssql-transaction_log: error parsing URL: parse sqlserver://mydomain\user:password@server01: net/url: invalid userinfo; host parsing failed for mssql-performance: error parsing URL: parse sqlserver://mydomain\user:password@server01: net/url: invalid userinfo

If leaving the domain out, the error is that the native user with that name cannot log in as the user with access is the domain user with that name not a native user:

2019-08-28T12:56:25.383+1200    ERROR   instance/beat.go:802    Exiting: 1 error: 2 errors: could not create connection to db: error doing ping to db: Login error: mssql: Login failed for user 'user'.; could not create connection to db: error doing ping to db: Login error: mssql: Login failed for user 'user'. 

Exiting: 1 error: 2 errors: could not create connection to db: error doing ping to db: Login error: mssql: Login failed for user 'user'.; could not create connection to db: error doing ping to db: Login error: mssql: Login failed for user 'user'.

Interestingly the domain credentials can be made to work if set separately via:

metricbeat.modules:
- module: mssql
  metricsets:
    - "transaction_log"
    - "performance"
  hosts: ["sqlserver://localhost"]
  username: domain\username
  password: verysecurepassword
  period: 10s

Related:

@sayden sayden self-assigned this Jan 31, 2020
@sayden sayden added the Metricbeat Metricbeat label Jan 31, 2020
@masci masci added Team:Integrations Label for the Integrations team and removed module labels Mar 4, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations (Team:Integrations)

@masci masci unassigned sayden Mar 4, 2021
@botelastic
Copy link

botelastic bot commented Mar 4, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@botelastic botelastic bot added the Stalled label Mar 4, 2022
@ManojS-shetty ManojS-shetty self-assigned this Apr 19, 2022
@botelastic botelastic bot removed the Stalled label Apr 19, 2022
@ManojS-shetty
Copy link
Contributor

@geekpete

Please try out the below:

hosts: ["sqlserver://domain//user:password@server01"]

and ignore the username and password in config.yml

@ManojS-shetty
Copy link
Contributor

@geekpete Any update on the above suggestion?

@ManojS-shetty
Copy link
Contributor

@geekpete Any Update here?

@geekpete
Copy link
Member Author

Sorry, I'm still working to follow up on this one.

@ManojS-shetty
Copy link
Contributor

@geekpete Any update on the suggested method?

@ManojS-shetty
Copy link
Contributor

@geekpete Any inputs so that we can proceed with the further about this?

@geekpete
Copy link
Member Author

So in the original testing for this issue it looks like we'd tried everything except the way you're suggesting:

hosts: ["sqlserver://domain\user:password@server01"]
hosts: ["sqlserver://domain\\user:password@server01"]
hosts: ["sqlserver://domain/user:password@server01"]
hosts: ["sqlserver://domain\/user:password@server01"]

but not with two forward slashes after the domain

hosts: ["sqlserver://domain//user:password@server01"]

I'll see if I can get this tested and report back.

@ManojS-shetty
Copy link
Contributor

So in the original testing for this issue it looks like we'd tried everything except the way you're suggesting:

hosts: ["sqlserver://domain\user:password@server01"]
hosts: ["sqlserver://domain\\user:password@server01"]
hosts: ["sqlserver://domain/user:password@server01"]
hosts: ["sqlserver://domain\/user:password@server01"]

but not with two forward slashes after the domain

hosts: ["sqlserver://domain//user:password@server01"]

I'll see if I can get this tested and report back.

Thank you @geekpete

@efd6
Copy link
Contributor

efd6 commented Oct 4, 2022

The issue here is that the \ character is not a valid character for userinfo. This can be worked around by percent encoding the backslash (See https://play.golang.com/p/ldyqlqiG8f7). url.PathEscape should be used on the username prior to constructing the connection URL. This looks like it can be done like this:

diff --git a/metricbeat/mb/parse/url.go b/metricbeat/mb/parse/url.go
index c0b23f421d..5c2ff19e86 100644
--- a/metricbeat/mb/parse/url.go
+++ b/metricbeat/mb/parse/url.go
@@ -71,6 +71,8 @@ func (b URLHostParserBuilder) Build() mb.HostParser {
                } else {
                        user = b.DefaultUsername
                }
+               user = url.PathEscape(user)
+
                t, ok = conf["password"]
                if ok {
                        pass, ok = t.(string)

@geekpete
Copy link
Member Author

geekpete commented May 3, 2023

Until the codebase is adjusted to automatically escape/encode the slash, it's also likely you can configure the string without the slash by manually passing the encoded value %5C directly instead of "\" in the domain user name.

ie for domain user: domain%5Cusername
eg: sqlserver://domain%5Cusername:pass@ip

@geekpete
Copy link
Member Author

Related issue to sanitize input in Kibana elastic/integrations#5213

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Metricbeat Metricbeat Team:Integrations Label for the Integrations team
Projects
None yet
Development

No branches or pull requests

6 participants