[Bug]: A WebSub policy's executionCondition is dropped on deploy, so the policy runs on every message

Đang mở
#4,296 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Start with generatePolicyList in platform-api/plugins/eventgateway/service/websub_api_deployment.go and model.Policy in platform-api/internal/model/api.go; trace how policy fields are copied into the deployment YAML and read by the gateway. Check the deployed artifact and the gateway's GET /api/management/v1/websub-apis/{id} output. Done when the condition is preserved in the artifact and the gateway runs the policy only when it holds.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Area/EventGateway Area/Platform-API Aspect/API Severity/Major Type/Bug
Please select the area the issue is related to

Event Gateway, Platform API

Please select the aspect the issue is related to

Aspect/API (API backends, definitions, contracts, interfaces, OpenAPI)

Description

A WebSub API's policy executionCondition is lost when the API is deployed, so the policy runs on every message. platform-api stores the condition and returns it on GET, but the deployment artifact doesn't carry it in a form the gateway reads:

allChannels:
    on_message_received:
        policies:
            - executioncondition: null
              name: log-message
              params: {}
              version: v1
receiver:
    policies:
        - executioncondition: request.header.x-run == 'yes'
          name: log-message
          ...

The event gateway's copy of the API (GET /api/management/v1/websub-apis/b01-ws) lists the policy with no condition at all. A message published without the x-run header, so with the condition false, still ran the policy:

level=DEBUG msg="[body] calling OnRequestBody" policy=log-message version=v1 route=SUB|/b01ws/v1/webhook-receiver|*

Where it comes from in the code:

  • generatePolicyList (platform-api/plugins/eventgateway/service/websub_api_deployment.go:721) copies only Name, Version and Params, so allChannels and per-channel policies lose the condition.
  • model.Policy (platform-api/internal/model/api.go:100) has JSON tags only. The YAML artifact therefore writes the field as executioncondition instead of executionCondition, even where the value survives (the receiver section).

Expected: a policy with an executionCondition runs only when the condition holds.
Actual: the condition is dropped and the policy always runs.

Steps to Reproduce

Setup: platform-api built with -tags experimental and an event gateway connected to it, both built from main.

Deployments to an event gateway built from main currently fail because of #4288. To reproduce this issue I cleared that gateway's stored version in platform-api's database (UPDATE gateways SET version='' WHERE handle='<event-gateway-id>'). That is a test workaround.

  1. Create the API with a conditional policy:
    POST /api/v0.9/websub-apis with {"id":"b01-ws","displayName":"b01-ws","version":"v1","projectId":"default","context":"/b01ws","allChannels":{"on_message_received":{"policies":[{"name":"log-message","version":"v1","params":{},"executionCondition":"request.header.x-run == 'yes'"}]}},"channels":{"orders":{}}}. The 201 response returns the executionCondition.
  2. Deploy it to the event gateway (POST /api/v0.9/websub-apis/b01-ws/deployments, base: current). Wait for DEPLOYED.
  3. Read the stored artifact (SELECT content FROM deployments WHERE uuid='<deploymentId>'). The policies look as shown above.
  4. GET /api/management/v1/websub-apis/b01-ws on the event gateway controller lists log-message with no condition.
  5. Subscribe a callback to topic orders (POST http://<event-gateway>:8080/b01ws/v1/hub, form hub.mode=subscribe&hub.topic=orders&hub.callback=<listener>), then publish without an x-run header: POST http://<event-gateway>:8080/b01ws/v1/webhook-receiver?topic=orders with {"msg":"msg-1"}.
  6. The event-gateway runtime logs calling OnRequestBody policy=log-message, so the policy ran although its condition is false.
Severity Level of the Issue

Severity/Major (Important functionality is broken. Should be prioritized. Doesn't need immediate attention)

Environment Details (with versions)
  • Source: main at f5c93849.
  • platform-api built from source with -tags experimental (SQLite).
  • Event gateway images 0.10.0-SNAPSHOT built from that commit; Kafka bitnamilegacy/kafka:4.0.0-debian-12-r10.
  • macOS with Rancher Desktop.
Ngôn ngữ chính
Go
Star
85
Fork
137
Merge trung bình
1 ngày 12 giờ
Pull request đã merge (30 ngày)
247

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của wso2/api-platform

Tất cả issue của wso2/api-platform

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.