pseudomuto / protoc-gen-doc

Documentation generator plugin for Google Protocol Buffers
MIT License
2.61k stars 462 forks source link

Make Google proto includes work for non-root user #424

Open timon-k opened 4 years ago

timon-k commented 4 years ago

Consider a simple example file which uses the well-known formats from google:

syntax = "proto3";

import "google/protobuf/timestamp.proto";

message Foo {
  google.protobuf.Timestamp time = 1;
}

Generating docs with a non-root user fails with pseudomuto/protoc-gen-doc:1.3.2:

> docker run -u 1000: --rm -it -v "$(pwd)/doc:/out" -v "$(pwd):/protos" pseudomuto/protoc-gen-doc foo.proto
google/protobuf/timestamp.proto: Read access is denied for file: /usr/local/include/google/protobuf/timestamp.proto

This is because, the includes for the google proto files are deployed to /usr/local/include in the docker image (pseudomuto/protoc-gen-doc:1.3.2). Unfortunately, the includes are only readable for root or staff-group users:

> docker run --rm -it --entrypoint /bin/sh pseudomuto/protoc-gen-doc
# ls -l /usr/local/include/google/protobuf
total 104
-rw-r----- 1 root staff  5820 Jul 30  2018 any.proto

This leads to the fact that the existing image cannot build docs in setups where the container does not run as root and where includes of the google types are present. Granting all other users read permission on the includes fixes the problem:

FROM pseudomuto/protoc-gen-doc:latest

RUN chmod -R a+r /usr/local/include

With such a modified image the above example works fine.