Skip to content

Commit 6d26799

Browse files
authored
Update security api and delete istio mark (#847)
1 parent 33e5642 commit 6d26799

File tree

39 files changed

+42
-643
lines changed

39 files changed

+42
-643
lines changed

dubbod/planet/pkg/bootstrap/config_controller.go

Lines changed: 7 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,28 @@ package bootstrap
1818

1919
import (
2020
"context"
21-
"crypto/tls"
22-
"crypto/x509"
2321
"encoding/json"
24-
"encoding/pem"
2522
"fmt"
2623
configaggregate "github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/config/aggregate"
27-
"github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/config/kube/gateway"
28-
"github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/features"
29-
"github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/leaderelection"
30-
"github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/leaderelection/k8sleaderelection/k8sresourcelock"
31-
"github.com/apache/dubbo-kubernetes/pkg/config/schema/gvr"
32-
"k8s.io/apimachinery/pkg/api/errors"
33-
"net/url"
34-
"strings"
35-
36-
"github.com/apache/dubbo-kubernetes/api/networking/v1alpha3"
3724
"github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/config/kube/crdclient"
3825
"github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/config/kube/file"
26+
"github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/config/kube/gateway"
3927
"github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/config/memory"
4028
dubboCredentials "github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/credentials"
4129
"github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/credentials/kube"
30+
"github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/features"
31+
"github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/leaderelection"
32+
"github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/leaderelection/k8sleaderelection/k8sresourcelock"
4233
"github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/model"
4334
"github.com/apache/dubbo-kubernetes/pkg/adsc"
4435
"github.com/apache/dubbo-kubernetes/pkg/config/schema/collections"
36+
"github.com/apache/dubbo-kubernetes/pkg/config/schema/gvr"
4537
"github.com/apache/dubbo-kubernetes/pkg/log"
4638
"google.golang.org/grpc"
47-
"google.golang.org/grpc/credentials"
4839
"google.golang.org/grpc/credentials/insecure"
40+
"k8s.io/apimachinery/pkg/api/errors"
4941
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
42+
"net/url"
5043
)
5144

5245
type ConfigSourceAddressScheme string
@@ -276,93 +269,6 @@ func (s *Server) initConfigController(args *PlanetArgs) error {
276269
return nil
277270
}
278271

279-
// verifyCert verifies given cert against TLS settings like SANs and CRL.
280-
func (s *Server) verifyCert(certs [][]byte, tlsSettings *v1alpha3.ClientTLSSettings) error {
281-
if len(certs) == 0 {
282-
return fmt.Errorf("no certificates provided")
283-
}
284-
cert, err := x509.ParseCertificate(certs[0])
285-
if err != nil {
286-
return fmt.Errorf("failed to parse certificate: %w", err)
287-
}
288-
289-
if len(tlsSettings.SubjectAltNames) > 0 {
290-
sanMatchFound := false
291-
for _, san := range cert.DNSNames {
292-
if sanMatchFound {
293-
break
294-
}
295-
for _, name := range tlsSettings.SubjectAltNames {
296-
if san == name {
297-
sanMatchFound = true
298-
break
299-
}
300-
}
301-
}
302-
if !sanMatchFound {
303-
return fmt.Errorf("no matching SAN found")
304-
}
305-
}
306-
307-
if len(tlsSettings.CaCrl) > 0 {
308-
crlData := []byte(strings.TrimSpace(tlsSettings.CaCrl))
309-
block, _ := pem.Decode(crlData)
310-
if block != nil {
311-
crlData = block.Bytes
312-
}
313-
crl, err := x509.ParseRevocationList(crlData)
314-
if err != nil {
315-
return fmt.Errorf("failed to parse CRL: %w", err)
316-
}
317-
for _, revokedCert := range crl.RevokedCertificateEntries {
318-
if cert.SerialNumber.Cmp(revokedCert.SerialNumber) == 0 {
319-
return fmt.Errorf("certificate is revoked")
320-
}
321-
}
322-
}
323-
324-
return nil
325-
}
326-
327-
// getTransportCredentials attempts to create credentials.TransportCredentials from ClientTLSSettings in mesh config
328-
// Implemented only for SIMPLE_TLS mode
329-
// TODO:
330-
//
331-
// Implement for MUTUAL_TLS/DUBBO_MUTUAL_TLS modes
332-
func (s *Server) getTransportCredentials(args *PlanetArgs, tlsSettings *v1alpha3.ClientTLSSettings) (credentials.TransportCredentials, error) {
333-
// TODO ValidateTLS
334-
335-
switch tlsSettings.GetMode() {
336-
case v1alpha3.ClientTLSSettings_SIMPLE:
337-
if len(tlsSettings.GetCredentialName()) > 0 {
338-
rootCert, err := s.getRootCertFromSecret(tlsSettings.GetCredentialName(), args.Namespace)
339-
if err != nil {
340-
return nil, err
341-
}
342-
tlsSettings.CaCertificates = string(rootCert.Cert)
343-
tlsSettings.CaCrl = string(rootCert.CRL)
344-
}
345-
if tlsSettings.GetInsecureSkipVerify().GetValue() || len(tlsSettings.GetCaCertificates()) == 0 {
346-
return credentials.NewTLS(&tls.Config{
347-
ServerName: tlsSettings.GetSni(),
348-
}), nil
349-
}
350-
certPool := x509.NewCertPool()
351-
if !certPool.AppendCertsFromPEM([]byte(tlsSettings.GetCaCertificates())) {
352-
return nil, fmt.Errorf("failed to add ca certificate from configSource.tlsSettings to pool")
353-
}
354-
return credentials.NewTLS(&tls.Config{
355-
ServerName: tlsSettings.GetSni(),
356-
RootCAs: certPool,
357-
VerifyPeerCertificate: func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error {
358-
return s.verifyCert(rawCerts, tlsSettings)
359-
},
360-
}), nil
361-
default:
362-
return insecure.NewCredentials(), nil
363-
}
364-
}
365-
366272
// getRootCertFromSecret fetches a map of keys and values from a secret with name in namespace
367273
func (s *Server) getRootCertFromSecret(name, namespace string) (*dubboCredentials.CertInfo, error) {
368274
secret, err := s.kubeClient.Kube().CoreV1().Secrets(namespace).Get(context.Background(), name, v1.GetOptions{})

dubbod/planet/pkg/bootstrap/dubbo_ca.go

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,12 @@ package bootstrap
1919
import (
2020
"bytes"
2121
"context"
22-
"encoding/json"
2322
"fmt"
2423
"github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/features"
25-
securityModel "github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/security/model"
26-
"github.com/apache/dubbo-kubernetes/dubbod/security/pkg/cmd"
24+
"github.com/apache/dubbo-kubernetes/dubbod/security/cmd"
2725
"github.com/apache/dubbo-kubernetes/dubbod/security/pkg/pki/ca"
2826
"github.com/apache/dubbo-kubernetes/dubbod/security/pkg/pki/ra"
2927
caserver "github.com/apache/dubbo-kubernetes/dubbod/security/pkg/server/ca"
30-
"github.com/apache/dubbo-kubernetes/dubbod/security/pkg/server/ca/authenticate"
31-
"github.com/apache/dubbo-kubernetes/dubbod/security/pkg/util"
3228
"github.com/apache/dubbo-kubernetes/pkg/config/constants"
3329
"github.com/apache/dubbo-kubernetes/pkg/env"
3430
"github.com/apache/dubbo-kubernetes/pkg/log"
@@ -39,7 +35,6 @@ import (
3935
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4036
"os"
4137
"path"
42-
"strings"
4338
"time"
4439
)
4540

@@ -108,24 +103,6 @@ func (s *Server) initCAServer(ca caserver.CertificateAuthority, opts *caOptions)
108103
}
109104

110105
func (s *Server) RunCA(grpc *grpc.Server) {
111-
iss := trustedIssuer.Get()
112-
aud := audience.Get()
113-
114-
token, err := os.ReadFile(securityModel.ThirdPartyJwtPath)
115-
if err == nil {
116-
tok, err := detectAuthEnv(string(token))
117-
if err != nil {
118-
log.Warnf("Starting with invalid K8S JWT token: %v", err)
119-
} else {
120-
if iss == "" {
121-
iss = tok.Iss
122-
}
123-
if len(tok.Aud) > 0 && len(aud) == 0 {
124-
aud = tok.Aud[0]
125-
}
126-
}
127-
}
128-
129106
s.caServer.Register(grpc)
130107

131108
log.Info("Dubbod CA has started")
@@ -351,27 +328,6 @@ func (s *Server) handleCACertsFileWatch() {
351328
}
352329
}
353330

354-
func detectAuthEnv(jwt string) (*authenticate.JwtPayload, error) {
355-
jwtSplit := strings.Split(jwt, ".")
356-
if len(jwtSplit) != 3 {
357-
return nil, fmt.Errorf("invalid JWT parts: %s", jwt)
358-
}
359-
payload := jwtSplit[1]
360-
361-
payloadBytes, err := util.DecodeJwtPart(payload)
362-
if err != nil {
363-
return nil, fmt.Errorf("failed to decode jwt: %v", err.Error())
364-
}
365-
366-
structuredPayload := &authenticate.JwtPayload{}
367-
err = json.Unmarshal(payloadBytes, &structuredPayload)
368-
if err != nil {
369-
return nil, fmt.Errorf("failed to unmarshal jwt: %v", err.Error())
370-
}
371-
372-
return structuredPayload, nil
373-
}
374-
375331
func handleEvent(s *Server) {
376332
log.Info("Update Dubbod cacerts")
377333

dubbod/planet/pkg/model/service.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/apache/dubbo-kubernetes/pkg/config/protocol"
3030
"github.com/apache/dubbo-kubernetes/pkg/config/visibility"
3131
"github.com/apache/dubbo-kubernetes/pkg/maps"
32-
"github.com/apache/dubbo-kubernetes/pkg/network"
3332
"github.com/apache/dubbo-kubernetes/pkg/slices"
3433
"github.com/apache/dubbo-kubernetes/pkg/util/sets"
3534
"github.com/google/go-cmp/cmp"
@@ -167,7 +166,6 @@ type DubboEndpoint struct {
167166
LegacyClusterPortKey int
168167
EndpointPort uint32
169168
WorkloadName string
170-
Network network.ID
171169
Namespace string
172170
// Specifies the hostname of the Pod, empty for vm workload.
173171
HostName string

dubbod/planet/pkg/networking/grpcgen/cds.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func (b *clusterBuilder) applyDestinationRule(defaultCluster *cluster.Cluster) (
246246
recheckTLS = (tlsMode == networking.ClientTLSSettings_DUBBO_MUTUAL || tlsModeStr == "DUBBO_MUTUAL")
247247
}
248248
if hasTLS || recheckTLS {
249-
log.Infof("applyDestinationRule: applying TLS to default cluster %s (DestinationRule has ISTIO_MUTUAL)", b.defaultClusterName)
249+
log.Infof("applyDestinationRule: applying TLS to default cluster %s (DestinationRule has DUBBO_MUTUAL)", b.defaultClusterName)
250250
b.applyTLSForCluster(defaultCluster, nil)
251251
} else {
252252
log.Debugf("applyDestinationRule: skipping TLS for default cluster %s (DestinationRule has no TrafficPolicy or TLS)", b.defaultClusterName)
@@ -270,7 +270,7 @@ func (b *clusterBuilder) applyDestinationRule(defaultCluster *cluster.Cluster) (
270270
core.HealthStatus_DEGRADED,
271271
},
272272
}
273-
log.Infof("applyDestinationRule: applying TLS to newly generated default cluster %s (DestinationRule has ISTIO_MUTUAL)", b.defaultClusterName)
273+
log.Infof("applyDestinationRule: applying TLS to newly generated default cluster %s (DestinationRule has DUBBO_MUTUAL)", b.defaultClusterName)
274274
b.applyTLSForCluster(defaultCluster, nil)
275275
return nil, defaultCluster // Return the newly generated default cluster
276276
}
@@ -327,7 +327,7 @@ func (b *clusterBuilder) applyDestinationRule(defaultCluster *cluster.Cluster) (
327327
}
328328

329329
// applyTLSForCluster attaches a gRPC-compatible TLS transport socket whenever the
330-
// DestinationRule (or subset override) specifies ISTIO_MUTUAL/DUBBO_MUTUAL mode.
330+
// DestinationRule (or subset override) specifies DUBBO_MUTUAL/DUBBO_MUTUAL mode.
331331
func (b *clusterBuilder) applyTLSForCluster(c *cluster.Cluster, subset *networking.Subset) {
332332
if c == nil || b.svc == nil {
333333
return

dubbod/planet/pkg/networking/grpcgen/grpcgen.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ func (g *GrpcConfigGenerator) Generate(proxy *model.Proxy, w *model.WatchedResou
5353
}
5454

5555
// buildCommonTLSContext creates a TLS context that matches gRPC xDS expectations.
56-
// It is adapted from Istio's buildCommonTLSContext implementation, but kept minimal:
5756
// - Uses certificate provider "default" for workload certs and root CA
5857
// - Does not configure explicit SAN matches (left to future hardening)
5958
func buildCommonTLSContext() *tlsv3.CommonTlsContext {

dubbod/planet/pkg/networking/grpcgen/lds.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,9 @@ func buildInboundListeners(node *model.Proxy, push *model.PushContext, names []s
203203
log.Debugf("buildInboundListeners: listener %s, service=%s, isGatewayPod=%v, node.Type=%v, node.IsRouter()=%v",
204204
name, si.Service.Attributes.Name, isGatewayPod, node.Type, node.IsRouter())
205205

206-
// - DestinationRule with ISTIO_MUTUAL only configures CLIENT-SIDE (outbound) mTLS
206+
// - DestinationRule with DUBBO_MUTUAL only configures CLIENT-SIDE (outbound) mTLS
207207
// - PeerAuthentication with STRICT configures SERVER-SIDE (inbound) mTLS
208208
// Both are REQUIRED for mTLS to work. Server-side mTLS should ONLY be controlled by PeerAuthentication.
209-
// Reference: https://istio.io/latest/blog/2021/proxyless-grpc/#enabling-mtls
210209
mode := push.InboundMTLSModeForProxy(node, uint32(listenPort))
211210
if mode == model.MTLSPermissive {
212211
log.Warnf("buildInboundListeners: PERMISSIVE mTLS is not supported for proxyless gRPC; defaulting to plaintext on listener %s", name)
@@ -518,7 +517,7 @@ func buildOutboundListeners(node *model.Proxy, push *model.PushContext, filter l
518517
routeName := clusterName
519518

520519
// For gRPC proxyless, outbound listeners MUST use ApiListener with RDS
521-
// This is the correct pattern used by Istio for gRPC xDS clients
520+
// This is the correct pattern used by Dubbo for gRPC xDS clients
522521
// Using FilterChain with inline RouteConfig causes the gRPC client to remain in IDLE state
523522
hcm := &hcmv3.HttpConnectionManager{
524523
CodecType: hcmv3.HttpConnectionManager_AUTO,
@@ -543,7 +542,7 @@ func buildOutboundListeners(node *model.Proxy, push *model.PushContext, filter l
543542
},
544543
}
545544

546-
// Build outbound listener with ApiListener (Istio pattern)
545+
// Build outbound listener with ApiListener
547546
// gRPC xDS clients expect ApiListener for outbound, not FilterChain
548547
ll := &listener.Listener{
549548
Name: fullListenerName,

dubbod/planet/pkg/serviceregistry/kube/controller/controller.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ type controllerInterface interface {
5858

5959
var (
6060
log = dubbolog.RegisterScope("controller", "kube controller debugging")
61-
_ controllerInterface = &Controller{}
6261
_ serviceregistry.Instance = &Controller{}
6362
)
6463

@@ -391,7 +390,7 @@ func (c *Controller) addOrUpdateService(pre, curr *v1.Service, currConv *model.S
391390
c.opts.XDSUpdater.ServiceUpdate(shard, string(currConv.Hostname), ns, event)
392391

393392
// Note: Endpoint updates are handled separately by EndpointSlice events, not here.
394-
// This matches Istio's behavior where service changes don't immediately update endpoints.
393+
// service changes don't immediately update endpoints.
395394
// EndpointSlice events will trigger EDSUpdate (with logPushType=true) which will properly
396395
// log "Full push, new service" when a new endpoint shard is created.
397396

@@ -546,16 +545,3 @@ func (c *Controller) servicesForNamespacedName(name types.NamespacedName) []*mod
546545
}
547546
return nil
548547
}
549-
550-
func (c *Controller) Network(endpointIP string, labels labels.Instance) network.ID {
551-
// 1. check the pod/workloadEntry label
552-
if nw := labels["topology.dubbo.apache.org/network"]; nw != "" {
553-
return network.ID(nw)
554-
}
555-
// 2. check the system namespace labels
556-
if nw := c.networkFromSystemNamespace(); nw != "" {
557-
return nw
558-
}
559-
560-
return ""
561-
}

0 commit comments

Comments
 (0)