feat(clients/go): mxgw-go -require-certificate-validation flag (mxaccessgw#199)
This commit is contained in:
@@ -501,7 +501,10 @@ buffer is widened to 16 MiB so a single long command line (e.g. a bulk write wit
|
|||||||
thousands of handles) does not trip bufio's default 64 KiB token-too-long limit;
|
thousands of handles) does not trip bufio's default 64 KiB token-too-long limit;
|
||||||
a line that still exceeds 16 MiB surfaces as a framed error and ends the session.
|
a line that still exceeds 16 MiB surfaces as a framed error and ends the session.
|
||||||
|
|
||||||
Use TLS options for a secured gateway:
|
Use TLS options for a secured gateway. Over TLS (no `-plaintext`) with
|
||||||
|
no `-ca-cert`, `mxgw-go` skips certificate verification by default (self-signed
|
||||||
|
gateway certs); pass `-require-certificate-validation` to verify against the
|
||||||
|
system trust roots instead:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
go run ./cmd/mxgw-go smoke -endpoint mxgateway.example.local:5001 -ca-cert C:\certs\mxgateway-ca.pem -server-name-override mxgateway.example.local -api-key-env MXGATEWAY_API_KEY -item Area001.Tag.Value -json
|
go run ./cmd/mxgw-go smoke -endpoint mxgateway.example.local:5001 -ca-cert C:\certs\mxgateway-ca.pem -server-name-override mxgateway.example.local -api-key-env MXGATEWAY_API_KEY -item Area001.Tag.Value -json
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ type commonOptions struct {
|
|||||||
Plaintext bool `json:"plaintext"`
|
Plaintext bool `json:"plaintext"`
|
||||||
CACertFile string `json:"caCertFile,omitempty"`
|
CACertFile string `json:"caCertFile,omitempty"`
|
||||||
ServerName string `json:"serverNameOverride,omitempty"`
|
ServerName string `json:"serverNameOverride,omitempty"`
|
||||||
|
|
||||||
|
RequireCertificateValidation bool `json:"requireCertificateValidation,omitempty"`
|
||||||
CallTimeout string `json:"callTimeout,omitempty"`
|
CallTimeout string `json:"callTimeout,omitempty"`
|
||||||
|
|
||||||
apiKeyValue string
|
apiKeyValue string
|
||||||
@@ -1295,6 +1297,7 @@ func bindCommonFlags(flags *flag.FlagSet) *commonOptions {
|
|||||||
flags.StringVar(&common.APIKeyEnv, "api-key-env", "MXGATEWAY_API_KEY", "environment variable containing the API key")
|
flags.StringVar(&common.APIKeyEnv, "api-key-env", "MXGATEWAY_API_KEY", "environment variable containing the API key")
|
||||||
flags.BoolVar(&common.Plaintext, "plaintext", false, "use plaintext transport")
|
flags.BoolVar(&common.Plaintext, "plaintext", false, "use plaintext transport")
|
||||||
flags.StringVar(&common.CACertFile, "ca-cert", "", "CA certificate file")
|
flags.StringVar(&common.CACertFile, "ca-cert", "", "CA certificate file")
|
||||||
|
flags.BoolVar(&common.RequireCertificateValidation, "require-certificate-validation", false, "verify the gateway TLS certificate against system roots (default skips verification when no -ca-cert is given)")
|
||||||
flags.StringVar(&common.ServerName, "server-name-override", "", "TLS server name override")
|
flags.StringVar(&common.ServerName, "server-name-override", "", "TLS server name override")
|
||||||
flags.StringVar(&common.CallTimeout, "call-timeout", "30s", "per-call timeout")
|
flags.StringVar(&common.CallTimeout, "call-timeout", "30s", "per-call timeout")
|
||||||
return common
|
return common
|
||||||
@@ -1312,6 +1315,7 @@ func dialForCommand(ctx context.Context, common *commonOptions) (*mxgateway.Clie
|
|||||||
Plaintext: options.Plaintext,
|
Plaintext: options.Plaintext,
|
||||||
CACertFile: options.CACertFile,
|
CACertFile: options.CACertFile,
|
||||||
ServerNameOverride: options.ServerName,
|
ServerNameOverride: options.ServerName,
|
||||||
|
RequireCertificateValidation: options.RequireCertificateValidation,
|
||||||
CallTimeout: options.timeout,
|
CallTimeout: options.timeout,
|
||||||
})
|
})
|
||||||
return client, options, err
|
return client, options, err
|
||||||
@@ -1528,6 +1532,7 @@ func dialGalaxyForCommand(ctx context.Context, common *commonOptions) (*mxgatewa
|
|||||||
Plaintext: options.Plaintext,
|
Plaintext: options.Plaintext,
|
||||||
CACertFile: options.CACertFile,
|
CACertFile: options.CACertFile,
|
||||||
ServerNameOverride: options.ServerName,
|
ServerNameOverride: options.ServerName,
|
||||||
|
RequireCertificateValidation: options.RequireCertificateValidation,
|
||||||
CallTimeout: options.timeout,
|
CallTimeout: options.timeout,
|
||||||
})
|
})
|
||||||
return client, options, err
|
return client, options, err
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -859,3 +860,24 @@ func TestRunStreamEventsPrintsReplayGap(t *testing.T) {
|
|||||||
t.Fatalf("stream-events -json gap cursors must be JSON numbers, got: %s", lines[0])
|
t.Fatalf("stream-events -json gap cursors must be JSON numbers, got: %s", lines[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRequireCertificateValidationFlag(t *testing.T) {
|
||||||
|
parse := func(args ...string) commonOptions {
|
||||||
|
flags := flag.NewFlagSet("t", flag.ContinueOnError)
|
||||||
|
common := bindCommonFlags(flags)
|
||||||
|
if err := flags.Parse(args); err != nil {
|
||||||
|
t.Fatalf("parse: %v", err)
|
||||||
|
}
|
||||||
|
resolved, err := common.resolved()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("resolved: %v", err)
|
||||||
|
}
|
||||||
|
return resolved
|
||||||
|
}
|
||||||
|
if parse().RequireCertificateValidation {
|
||||||
|
t.Fatal("default must stay lenient")
|
||||||
|
}
|
||||||
|
if !parse("-require-certificate-validation").RequireCertificateValidation {
|
||||||
|
t.Fatal("flag must set RequireCertificateValidation")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user