Skip to content

Commit 0870f8c

Browse files
committed
fix(tlsbridge): validate internal_cidrs at config load; doc rename (review #522)
- TLSBridgeConfig.Validate now rejects malformed internal_cidrs entries so an operator CIDR typo fails loudly at load instead of being silently dropped by Decision (which would stop excluding an intended in-cluster range under scope=external). Adds TestTLSBridgeConfig_Validate covering scope/ca_source/ file-paths/CIDR cases. - Update the TLSBridgeConfig doc comment: 'MITM termination' -> 'TLS termination (formerly MITM)' for grep-consistency with the rename. Signed-off-by: Hai Huang <huang195@gmail.com>
1 parent 448cbec commit 0870f8c

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

authbridge/authlib/config/config.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package config
55
import (
66
"encoding/json"
77
"fmt"
8+
"net"
89
"os"
910
"strings"
1011

@@ -42,8 +43,9 @@ type Config struct {
4243
TLSBridge *TLSBridgeConfig `yaml:"tls_bridge,omitempty" json:"tls_bridge,omitempty"`
4344
}
4445

45-
// TLSBridgeConfig configures the outbound TLS bridge (MITM termination of
46-
// agent egress so the outbound plugin pipeline sees decrypted HTTPS).
46+
// TLSBridgeConfig configures the outbound TLS bridge (TLS termination of
47+
// agent egress — formerly "MITM" — so the outbound plugin pipeline sees
48+
// decrypted HTTPS).
4749
type TLSBridgeConfig struct {
4850
Enabled bool `yaml:"enabled" json:"enabled"`
4951
Scope string `yaml:"scope" json:"scope"` // external | all
@@ -66,6 +68,11 @@ func (b *TLSBridgeConfig) Validate() error {
6668
if b.CASource == "file" && (b.CACertPath == "" || b.CAKeyPath == "") {
6769
return fmt.Errorf("tls_bridge.ca_source=file requires ca_cert_path and ca_key_path")
6870
}
71+
for _, c := range b.InternalCIDRs {
72+
if _, _, err := net.ParseCIDR(c); err != nil {
73+
return fmt.Errorf("tls_bridge.internal_cidrs: %q is not a valid CIDR: %w", c, err)
74+
}
75+
}
6976
return nil
7077
}
7178

authbridge/authlib/config/config_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,31 @@ func TestConfig_TLSBridgeBlockDecodes(t *testing.T) {
750750
}
751751
}
752752

753+
func TestTLSBridgeConfig_Validate(t *testing.T) {
754+
cases := []struct {
755+
name string
756+
cfg TLSBridgeConfig
757+
wantErr bool
758+
}{
759+
{"valid empty", TLSBridgeConfig{}, false},
760+
{"valid full", TLSBridgeConfig{Scope: "all", CASource: "ephemeral", InternalCIDRs: []string{"10.0.0.0/8", "172.30.0.0/16"}}, false},
761+
{"bad scope", TLSBridgeConfig{Scope: "internal"}, true},
762+
{"bad ca_source", TLSBridgeConfig{CASource: "vault"}, true},
763+
{"file ca without paths", TLSBridgeConfig{CASource: "file"}, true},
764+
{"file ca with paths", TLSBridgeConfig{CASource: "file", CACertPath: "/c", CAKeyPath: "/k"}, false},
765+
{"bad cidr typo", TLSBridgeConfig{InternalCIDRs: []string{"10.0.0.0/8", "10.0.0.0./8"}}, true},
766+
{"bad cidr missing mask", TLSBridgeConfig{InternalCIDRs: []string{"10.0.0.0"}}, true},
767+
}
768+
for _, tc := range cases {
769+
t.Run(tc.name, func(t *testing.T) {
770+
err := tc.cfg.Validate()
771+
if (err != nil) != tc.wantErr {
772+
t.Errorf("Validate() error = %v, wantErr %v", err, tc.wantErr)
773+
}
774+
})
775+
}
776+
}
777+
753778
// Absent mtls block leaves cfg.MTLS nil — today's behavior, no TLS.
754779
func TestLoad_MTLS_AbsentBlock(t *testing.T) {
755780
dir := t.TempDir()

0 commit comments

Comments
 (0)