spring-cloud / spring-cloud/spring-cloud-gateway

Enhance XForwardedRemoteAddrRoutePredicateFactory to Support maxTrustedIndex in YAML Configuration

Open
#3,788 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

waiting-for-triage
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

Hi, Spring Cloud Gateway team.

I wanted to share a suggestion to improve the usability of XForwardedRemoteAddrRoutePredicateFactory for users managing configurations dynamically with Spring Cloud Config.

Problem Statement
When using Spring Cloud Config for dynamic routing, I sometimes find it inconvenient that maxTrustedIndex in XForwardedRemoteAddrRoutePredicateFactory cannot be configured via YAML. Since it currently uses ShortcutType.GATHER_LIST, I need to configure it through Java code, which requires redeployment and limits operational flexibility.

Proposed Solution
I believe that changing the shortcutType() of XForwardedRemoteAddrRoutePredicateFactory from ShortcutType.GATHER_LIST to ShortcutType.DEFAULT could allow maxTrustedIndex to be configured in YAML. This would enable a configuration like the following.

spring:
  cloud:
    gateway:
      routes:
      - id: example_route
        uri: http://example.com
        predicates:
        - name: XForwardedRemoteAddr
          args:
            sources: 1.1.1.1/1
            maxTrustedIndex: 2

It would be great if the changes could be reflected in the documentation to support this.

Alternative Approaches

  • I would like to suggest the ShortcutType.DEFAULT change as a simpler approach.

Additional context

  • Environment: Spring Cloud 2024.0.0, Java 21, Spring Cloud Config in use.
  • I believe this change could be helpful for users who manage routing dynamically without needing to redeploy.
  • If this suggestion seems appropriate, I would be happy to contribute a Pull Request with tests and documentation. I would appreciate your feedback.

Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at XForwardedRemoteAddrRoutePredicateFactory and inspect how its shortcut type handles the sources and maxTrustedIndex arguments. Review the existing predicate tests and route configuration documentation, then verify that the proposed YAML form configures both values and that the documented behavior is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
api, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.