Skip to content

grpc-gateway fails to load proto file with message "proto3 disallow 'optional' label" #14421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
yixinguo-ssc opened this issue Apr 16, 2025 · 3 comments · Fixed by yixinguo-ssc/kong#1 · May be fixed by #14426
Open
1 task done

grpc-gateway fails to load proto file with message "proto3 disallow 'optional' label" #14421

yixinguo-ssc opened this issue Apr 16, 2025 · 3 comments · Fixed by yixinguo-ssc/kong#1 · May be fixed by #14426

Comments

@yixinguo-ssc
Copy link

yixinguo-ssc commented Apr 16, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Kong version (3.9.0)

3.9.0

Current Behavior

I have grpc-gateway plugin enabled for a grpc backend service with http mappings defined in the proto file.
The error proto3 disallow 'optional' label is shown in kong logs when making an Http request to a rpc method with optional labeled field in the request.

kong-1               | 2025/04/11 17:49:53 [error] 1411#0: *6441 [kong] init.lua:406 [grpc-gateway] /usr/local/share/lua/5.1/protoc.lua:651: /protos/proto/feature-a/v1/feature-a-health.proto:23:12: proto3 disallow 'optional' label, client: 192.168.65.1

I experimented and found that adding this line to function _M.new() in kong/tools/grpc.lua fixes the error

  protoc_instance.proto3_optional = true

Expected Behavior

grpc-gateway should successfully load the proto file and route the http request to the rpc method

Steps To Reproduce

kong.yaml

  - name: feature-a-user
    protocol: grpc
    host: grpc-example
    port: 50051
    routes:
      - name: feature-a-user
        protocols:
          - http
        paths:
          - /v1/feature-a/user/
        strip_path: true
        plugins:
          - name: grpc-gateway
            config:
              proto: feature-a/v1/feature-a-user.proto

feature-a-user.proto

syntax = "proto3";

package feature.user.v1;

import "google/api/annotations.proto";

service User {
  rpc UpdateUser (UpdateUserRequest) returns (UpdateUserResponse) {
    option (google.api.http) = {
      patch: "/v1/feature-a/user/{id}"
      body: "*"
    };
  }
}

message UpdateUserRequest {
  string id = 1;
  optional string name = 2;
  optional string email = 3;
}

Http request

curl -X PATCH 0.0.0.0:8000/v1/feature-a/user/1 -d '{"name": "test"}'

Anything else?

I tried to push a branch to this repo with the change to grpc.lua, however I am getting permission denied. I can make the PR if I'm granted permissions to push branches and create PRs

@joelact
Copy link
Contributor

joelact commented Apr 17, 2025

Hey @yixinguo-ssc!

You should fork the project, clone it, and submit your changes to a branch. You should not see any more problems when pushing your changes.

Then you can open a PR from your fork to the main project, and you should be good to go.

Check the contributing guidelines before submitting your PR: https://github.com/Kong/kong/blob/master/CONTRIBUTING.md

Hope this helps,
Joel

@yixinguo-ssc
Copy link
Author

@joelact thanks, I opened a PR #14426
Could you or somebody take a look?

@yixinguo-ssc yixinguo-ssc reopened this Apr 30, 2025
@chronolaw
Copy link
Contributor

Thanks for your contribution, we will check it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants