Skip to content

Need to be able to skip TLS verification #1

Description

@xgattuso

Hello,

I wanted to suggest a PR but apparently I'm unable to. So suggesting here the changes.

Thanks for this lib by the way!

It fixes two things: one is the port type. To prevent, during autodetection, to end up with the following error:

dial tcp: lookup tcp/⋹: Servname not supported for ai_socktype

The right type is required.

It fixes this bug: optix2000/nsd_exporter#5

The other change is about to give the ability to set skipTLSverify. nsd_exporter will be patched accordingly.

# ./nsd_exporter
2024/12/17 13:16:46 tls: failed to verify certificate: x509: certificate relies on legacy Common Name field, use SANs instead
# ./nsd_exporter -skipTLSverify
2024/12/17 13:16:49 Started.

Being aware that the latter is a breaking change it might maybe deserve a v2.0.0. Let me know how do you want to proceed (split PR, won't be implemented...).

Here is my diff.

$ git diff origin/HEAD..skipTLSverify 
diff --git a/nsdctl.go b/nsdctl.go
index 2ae122e..9e805a4 100644
--- a/nsdctl.go
+++ b/nsdctl.go
@@ -116,7 +116,7 @@ type NSDClient struct {
 }
 
 // NewClientFromConfig tries to autodetect and create a new NSDClient from an config file
-func NewClientFromConfig(configPath string) (*NSDClient, error) {
+func NewClientFromConfig(configPath string, skipTLSverify bool) (*NSDClient, error) {
        filename := path.Base(configPath)
 
        var detectedType string
@@ -189,10 +189,10 @@ func NewClientFromConfig(configPath string) (*NSDClient, error) {
        }
 
        if port != 0 {
-               hostString = "127.0.0.1:" + string(port)
+               hostString = "127.0.0.1:" + strconv.FormatUint(uint64(port), 10)
        }
 
-       return NewClient(detectedType, hostString, caFile, keyFile, certFile, false)
+       return NewClient(detectedType, hostString, caFile, keyFile, certFile, skipTLSverify)
 }
 
 // NewClient creates a complete new NSDClient and returns any errors encountered

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions