feat: enforce TLS service identities

This commit is contained in:
2026-11-04 23:05:11 +03:00
parent cb51354889
commit 951e554e06
46 changed files with 681 additions and 165 deletions
+26 -7
View File
@@ -2,6 +2,8 @@ package main
import (
"bytes"
"crypto/tls"
"crypto/x509"
"encoding/json"
"flag"
"fmt"
@@ -17,10 +19,11 @@ import (
)
type apiClient struct {
baseURL string
client *http.Client
token string
userID string
baseURL string
client *http.Client
transport *http.Transport
token string
userID string
}
func main() {
@@ -32,9 +35,23 @@ func main() {
}
func run() error {
baseURL := flag.String("base-url", "http://localhost:8080", "API base URL")
baseURL := flag.String("base-url", "https://localhost:8443", "API base URL")
caFile := flag.String("ca-file", ".runtime/security/public-ca/ca.crt", "trusted CA certificate")
flag.Parse()
client := &apiClient{baseURL: *baseURL, client: &http.Client{Timeout: 10 * time.Second}}
caPEM, err := os.ReadFile(*caFile)
if err != nil {
return fmt.Errorf("read trusted CA: %w", err)
}
roots := x509.NewCertPool()
if !roots.AppendCertsFromPEM(caPEM) {
return fmt.Errorf("trusted CA does not contain a certificate")
}
transport := &http.Transport{TLSClientConfig: &tls.Config{MinVersion: tls.VersionTLS12, RootCAs: roots}}
defer transport.CloseIdleConnections()
client := &apiClient{
baseURL: *baseURL, client: &http.Client{Transport: transport, Timeout: 10 * time.Second},
transport: transport,
}
if err := client.registerAndLogin(); err != nil {
return err
}
@@ -130,7 +147,9 @@ func (c *apiClient) verifyConcurrentIdempotency() error {
instances = make(map[string]struct{})
messageID string
)
transport := &http.Transport{DisableKeepAlives: true, MaxConnsPerHost: workers}
transport := c.transport.Clone()
transport.DisableKeepAlives = true
transport.MaxConnsPerHost = workers
client := &http.Client{Transport: transport, Timeout: 10 * time.Second}
defer transport.CloseIdleConnections()