Skip to content

Commit 5eca581

Browse files
authored
feat: use envoy extensions to preserve case for http1 header (#754)
* refactor: optimize ssh log * feat: use envoy extensions preserve_casev3 to preserve http1 header case * feat: use envoy extensions preserve_casev3 to preserve http1 header case
1 parent 6b8fb2b commit 5eca581

File tree

6 files changed

+529
-5
lines changed

6 files changed

+529
-5
lines changed

pkg/controlplane/cache.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
dstv3inspector "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/listener/original_dst/v3"
2222
httpconnectionmanager "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
2323
tcpproxy "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/tcp_proxy/v3"
24+
preservecasev3 "github.com/envoyproxy/go-control-plane/envoy/extensions/http/header_formatters/preserve_case/v3"
2425
httpv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/v3"
2526
matcher "github.com/envoyproxy/go-control-plane/envoy/type/matcher/v3"
2627
"github.com/envoyproxy/go-control-plane/pkg/cache/types"
@@ -78,6 +79,14 @@ func ConvertContainerPort(ports ...corev1.ContainerPort) []ContainerPort {
7879
return result
7980
}
8081

82+
// createPreserveCaseConfig creates a TypedExtensionConfig for preserving header case
83+
func createPreserveCaseConfig(anyFunc func(m proto.Message) *anypb.Any) *corev3.TypedExtensionConfig {
84+
return &corev3.TypedExtensionConfig{
85+
Name: "preserve_case",
86+
TypedConfig: anyFunc(&preservecasev3.PreserveCaseFormatterConfig{}),
87+
}
88+
}
89+
8190
type Rule struct {
8291
Headers map[string]string
8392
LocalTunIPv4 string
@@ -213,7 +222,15 @@ func ToCluster(clusterName string) *cluster.Cluster {
213222
IdleTimeout: durationpb.New(time.Second * 10),
214223
},
215224
UpstreamProtocolOptions: &httpv3.HttpProtocolOptions_UseDownstreamProtocolConfig{
216-
UseDownstreamProtocolConfig: &httpv3.HttpProtocolOptions_UseDownstreamHttpConfig{},
225+
UseDownstreamProtocolConfig: &httpv3.HttpProtocolOptions_UseDownstreamHttpConfig{
226+
HttpProtocolOptions: &corev3.Http1ProtocolOptions{
227+
HeaderKeyFormat: &corev3.Http1ProtocolOptions_HeaderKeyFormat{
228+
HeaderFormat: &corev3.Http1ProtocolOptions_HeaderKeyFormat_StatefulFormatter{
229+
StatefulFormatter: createPreserveCaseConfig(anyFunc),
230+
},
231+
},
232+
},
233+
},
217234
},
218235
}),
219236
},
@@ -236,7 +253,15 @@ func OriginCluster() *cluster.Cluster {
236253
TypedExtensionProtocolOptions: map[string]*anypb.Any{
237254
"envoy.extensions.upstreams.http.v3.HttpProtocolOptions": anyFunc(&httpv3.HttpProtocolOptions{
238255
UpstreamProtocolOptions: &httpv3.HttpProtocolOptions_UseDownstreamProtocolConfig{
239-
UseDownstreamProtocolConfig: &httpv3.HttpProtocolOptions_UseDownstreamHttpConfig{},
256+
UseDownstreamProtocolConfig: &httpv3.HttpProtocolOptions_UseDownstreamHttpConfig{
257+
HttpProtocolOptions: &corev3.Http1ProtocolOptions{
258+
HeaderKeyFormat: &corev3.Http1ProtocolOptions_HeaderKeyFormat{
259+
HeaderFormat: &corev3.Http1ProtocolOptions_HeaderKeyFormat_StatefulFormatter{
260+
StatefulFormatter: createPreserveCaseConfig(anyFunc),
261+
},
262+
},
263+
},
264+
},
240265
},
241266
}),
242267
},
@@ -399,6 +424,14 @@ func ToListener(listenerName string, routeName string, port int32, p corev1.Prot
399424
}),
400425
},
401426
}},
427+
// Configure HTTP protocol options to preserve header case
428+
HttpProtocolOptions: &corev3.Http1ProtocolOptions{
429+
HeaderKeyFormat: &corev3.Http1ProtocolOptions_HeaderKeyFormat{
430+
HeaderFormat: &corev3.Http1ProtocolOptions_HeaderKeyFormat_StatefulFormatter{
431+
StatefulFormatter: createPreserveCaseConfig(anyFunc),
432+
},
433+
},
434+
},
402435
}
403436

404437
tcpConfig := &tcpproxy.TcpProxy{

pkg/ssh/ssh.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ func PortMapUntil(ctx context.Context, conf *SshConfig, remote, local netip.Addr
104104
plog.G(ctx).Debugf("Failed to accept ssh conn: %v", err1)
105105
continue
106106
}
107-
plog.G(ctx).Debugf("Accepted ssh conn from %s", localConn.RemoteAddr().String())
108107
go func() {
109108
defer localConn.Close()
110109

@@ -117,10 +116,10 @@ func PortMapUntil(ctx context.Context, conf *SshConfig, remote, local netip.Addr
117116
cancelFunc1()
118117
return
119118
}
120-
plog.G(ctx).Debugf("Failed to dial into remote %s: %v", remote.String(), err)
119+
plog.G(ctx).Debugf("Failed to dial remote from %s<=>%s -> %s: %v", localConn.LocalAddr().String(), localConn.RemoteAddr().String(), remote.String(), err)
121120
return
122121
}
123-
plog.G(ctx).Debugf("Opened ssh port-forward to %s", remote.String())
122+
plog.G(ctx).Debugf("Opened ssh port-forward to %s<=>%s -> %s", localConn.LocalAddr().String(), localConn.RemoteAddr().String(), remote.String())
124123

125124
defer remoteConn.Close()
126125
copyStream(ctx, localConn, remoteConn)

vendor/github.com/envoyproxy/go-control-plane/envoy/extensions/http/header_formatters/preserve_case/v3/preserve_case.pb.go

Lines changed: 255 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)