Apache Dubbo

repository·3.3·Indexed 12 days ago

https://github.com/apache/dubbo

A high-performance RPC and microservices framework providing solutions for service discovery, traffic management, observability, and security across multiple programming languages. It includes integration with Spring Boot, a dedicated Maven plugin for generating code from .proto files, and a Spring Boot Actuator for health checks and runtime management.

Tokens
18.1K
Snippets
31
Records
56
Agent score
98%

What's inside Dubbo

  1. Explore Dubbo usage examples in dubbo-demo

    3.3

    The dubbo-demo directory provides basic Dubbo usage examples intended for debugging and smoke testing. It covers three primary scenarios:

    1. Basic RPC Protocol (dubbo-demo-api): Demonstrates fundamental RPC usage, including defining and implementing a simple service, starting a server on a specific port, and creating a consumer to call that service.
    2. Spring Boot Integration (dubbo-demo-springboot): Shows how to integrate Dubbo with Spring Boot, including configuring and managing Dubbo services within the Spring Boot lifecycle.
    3. Spring Boot with IDL (dubbo-demo-springboot-idl): Demonstrates how to use Dubbo with Spring Boot when services are defined using Interface Definition Language (IDL) files, such as Proto files.

    For more advanced and feature-rich examples, refer to the dubbo-samples repository.

  2. How Apache Dubbo works

    3.3

    Apache Dubbo is a Web and RPC framework designed for building enterprise-grade microservices. It facilitates communication between consumers and providers using various RPC protocols (such as Triple, TCP, or REST).

    Key architectural components include:

    • Service Discovery: Consumers dynamically discover provider instances via registries like Zookeeper or Nacos.
    • Traffic Management: Consumers manage traffic using defined strategies.
    • Built-in Capabilities: Support for dynamic configuration, metrics, tracing, security, and a visualized console.
  3. Understand Dubbo's Security Model and Default Assumptions

    3.3

    Dubbo is designed with the foundational assumption of an internal, trusted network. By default, Dubbo provides no authentication, no encryption, and permissive deserialization.

    Key environmental assumptions include:

    • Runtime: JDK 8–21 on Linux, macOS, or Windows.
    • Network: Assumes a trusted internal network. Defaults do not include TLS or authentication.
    • I/O: Uses Netty4 for network I/O (NIO/epoll).
    • Trust: The Registry and Config Center are considered trusted components. A consumer implicitly trusts a provider once it is registered.

    If you are deploying Dubbo in a non-trusted or public network environment, you must explicitly opt-in to security features like SSL and authentication.

  4. Understand the generated Dubbo service interface

    3.3

    When you run the compiler, it generates a service class (e.g., DemoServiceDubbo) containing an interface that extends org.apache.dubbo.rpc.model.DubboStub. This interface provides the RPC methods defined in your .proto file in two flavors:

    1. Synchronous: Returns the response type directly.
    2. Asynchronous: Returns a CompletableFuture of the response type.

    The generated class also handles internal Protobuf marshalling initialization via ProtobufUtils.

    // Example of generated code structure
    public final class DemoServiceDubbo {
        public static final String SERVICE_NAME = "org.apache.dubbo.demo.DemoService";
    
        public interface IDemoService extends org.apache.dubbo.rpc.model.DubboStub {
            // Synchronous call
            org.apache.dubbo.demo.HelloReply sayHello(org.apache.dubbo.demo.HelloRequest request);
    
            // Asynchronous call
            CompletableFuture<org.apache.dubbo.demo.HelloReply> sayHelloAsync(org.apache.dubbo.demo.HelloRequest request);
        }
    }
  5. Secure Hessian2 serialization with STRICT mode

    3.3

    Dubbo integrates DefaultSerializeClassChecker into the Hessian2 serializer factory to defend against arbitrary class instantiation. You can configure the protection level:

    • WARN mode: Checks classes against a blocklist.
    • STRICT mode: Checks classes against an allowlist. This is the recommended way to mitigate RCE risks associated with Hessian2 deserialization.
  6. Identify Untrusted Input Sources in Dubbo

    3.3

    When developing services, assume the following inputs are potentially malicious and must be validated:

    RPC Traffic

    • Request Body (Consumer $\rightarrow$ Provider): Serialized method arguments. An attacker can reach the provider port and send crafted data.
    • Response Body (Provider $\rightarrow$ Consumer): Serialized return values. A compromised provider can attack a consumer via deserialization.
    • Metadata/Attachments: Dubbo request attachments are attacker-controllable.
    • Service/Method Names: Attackers can attempt to call unintended interfaces or methods.

    QoS (Quality of Service)

    • QoS Commands: Any client reaching the QoS port (default 22222) can send commands via Telnet or HTTP. Command names and JSON argument strings are untrusted.

    Serialization Negotiation

    • Serialization Type: While the Provider has priority in negotiation, the type is determined by the interaction between consumer and provider. Providers should declare only the specific serializers they intend to support to minimize attack surface.
  7. Understand the Dubbo deployment model and trust assumptions

    3.3

    Apache Dubbo is designed as an in-process Java library for building RPC-based microservices. It is intended for deployment within trusted internal networks (e.g., Data Centers or VPCs) and is not designed for direct internet exposure.

    Key Trust Assumptions:

    • Internal Network: The framework assumes service-to-service communication happens within a trusted perimeter. Exposing RPC ports (e.g., 20880, 50051) or the QoS port (22222) directly to the internet without a reverse proxy or API gateway is not a supported use case.
    • Registry & Config Center: Dubbo treats Registries (like ZooKeeper or Nacos) and Config Centers as trusted components. A compromised registry or config center is considered a total cluster compromise because they can push malicious provider addresses or credentials.
    • Provider Responses: Consumers implicitly trust the return values sent by providers during RPC calls.
    • Polyglot Support: While primarily for Java, Dubbo supports polyglot communication (Go, Python, Rust, etc.) via the Triple protocol (gRPC-compatible).
  8. Understand Dubbo RPC serialization negotiation

    3.3

    During an RPC invocation, the serialization type is determined by provider-priority negotiation.

    1. The Provider declares its supported serialization formats (e.g., Hessian2, Protobuf, Java, Fastjson2) in its URL.
    2. If multiple formats are declared, the negotiation process follows the priority established by the Provider.
    3. The Consumer serializes arguments based on this negotiated format, and the Provider deserializes them upon receipt.
  9. Mitigate Deserialization Attacks in Dubbo Providers

    3.3

    Because RPC request bodies are untrusted, providers are vulnerable to deserialization attacks. To mitigate this, follow these practices:

    1. Enable Strict Serialization Check: Set serialize.check.status to STRICT. This blocks the deserialization of any class not explicitly on an allowlist.
    2. Enforce Serializable Interface: Ensure serialize.check.serializable is set to true to enforce the Serializable interface on deserialized classes.
    3. Limit Supported Serializers: The Provider controls the negotiation. Only declare the minimum necessary serialization formats (e.g., hessian2) to reduce the attack surface.
    # Recommended security configuration for providers
    serialize.check.status=STRICT
    serialize.check.serializable=true
    # Only use necessary serializers
    serialization=hessian2
  10. Integrate Dubbo Spring Boot interceptor to propagate tags via Headers or URL Parameters

    3.3

    To propagate Dubbo tags from incoming HTTP requests to Dubbo calls, use the DubboTagHeaderOrParameterInterceptor. This interceptor looks for a header named dubbo-tag. If the header is missing, it falls back to checking the URL parameter dubbo.tag.

    Register the interceptor in your Spring Boot application by implementing WebMvcConfigurer and adding it to the InterceptorRegistry.

    @Configuration
    public class WebMvcConfig implements WebMvcConfigurer {
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new DubboTagHeaderOrParameterInterceptor())
                    .addPathPatterns("/*")
                    .excludePathPatterns("/admin");
        }
    }
  11. Manage Dubbo Logging and Profiling via Actuator

    3.3

    You can dynamically modify logging and performance profiling settings without restarting the application. Note that changes made via these endpoints are not persistent and will be lost upon application restart.

    Logging

    • Switch Log Level: Use /actuator/dubbo/switchLogLevel?args={level} to change the log level. Permitted levels: ALL, TRACE, DEBUG, INFO, WARN, ERROR, OFF.
    • Switch Log Framework: Use /actuator/dubbo/switchLogger?args={loggerAdapterName} to change the output framework. Supported names: slf4j, jcl, log4j, jdk, log4j2.
    • Query Log Config: Use /actuator/dubbo/loggerInfo to view current log configuration.

    Profiling

    Dubbo includes a performance sampling function to detect time consumption in the processing link. simple profiler is enabled by default.

    • Simple Profiler: Use /actuator/dubbo/enableSimpleProfiler or /actuator/dubbo/disableSimpleProfiler to toggle the default mode.
    • Detail Profiler: Use /actuator/dubbo/enableDetailProfiler to enable a more granular mode that collects time-consuming processing for each filter and specific protocols. Note: You must have the simple profiler enabled for the detail profiler to work.
    ### Switch Log Level Example
    GET `/actuator/dubbo/switchLogLevel?args=WARN`