internal/website/docs/SECURITY_MIGRATION.md
This document provides guidance for migrating to secure TLS certificate verification in go-micro v5.
Default Behavior: TLS certificate verification is disabled by default (InsecureSkipVerify: true)
Reason: Backward compatibility with existing deployments to avoid breaking production systems during routine upgrades.
Security Risk: The default behavior is vulnerable to man-in-the-middle (MITM) attacks.
Set the environment variable to enable certificate verification:
export MICRO_TLS_SECURE=true
This enables proper TLS certificate verification while maintaining compatibility with v5.
In your code, explicitly use the secure configuration:
import (
"go-micro.dev/v5/broker"
mls "go-micro.dev/v5/util/tls"
)
// Create broker with secure TLS config
b := broker.NewHttpBroker(
broker.TLSConfig(mls.SecureConfig()),
)
For fine-grained control, provide your own TLS configuration:
import (
"crypto/tls"
"crypto/x509"
"go-micro.dev/v5/broker"
"io/ioutil"
)
// Load CA certificates
caCert, err := ioutil.ReadFile("/path/to/ca-cert.pem")
if err != nil {
log.Fatal(err)
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
// Create custom TLS config
tlsConfig := &tls.Config{
RootCAs: caCertPool,
MinVersion: tls.VersionTLS12,
}
// Create broker with custom config
b := broker.NewHttpBroker(
broker.TLSConfig(tlsConfig),
)
The current implementation maintains backward compatibility, allowing safe rolling upgrades:
Test in Staging:
# In staging environment
export MICRO_TLS_SECURE=true
Deploy with Feature Flag: Use environment-based configuration for gradual rollout
Monitor for Issues: Watch for TLS handshake failures or certificate validation errors
Full Production Rollout: Once validated, enable across all services
Certificate Trust: When enabling secure mode, ensure:
Service Mesh Alternative: Consider using a service mesh (Istio, Linkerd, etc.) for:
In go-micro v6, the default will change to secure by default:
InsecureSkipVerify: false (certificate verification enabled)package main
import (
"fmt"
mls "go-micro.dev/v5/util/tls"
"os"
)
func main() {
os.Setenv("MICRO_TLS_SECURE", "true")
config := mls.Config()
fmt.Printf("InsecureSkipVerify: %v (should be false)\n", config.InsecureSkipVerify)
}
Create a test service and verify it:
Cause: The server certificate is not signed by a trusted CA
Solution:
InsecureConfig() explicitlyCause: Server certificate has expired
Solution:
Cause: Mixed certificate authorities or missing certificates
Solution:
For issues or questions about TLS security migration, please: