Skip to content
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

hubble: Update uint size in flow proto #11161

Merged
merged 1 commit into from Apr 27, 2020

Conversation

matej-g
Copy link
Contributor

@matej-g matej-g commented Apr 26, 2020

Size of some fields in flow.proto is unnecessarily
large (uint64), whereas for such fields
(e.g. endpoint ID or identity) a smaller type
is more appropriate.

This PR is a clean-up to update the scalar
value types of these fields. Includes some
changes to related Hubble packages (parsers
and filters) and minor test adjustments.

Fixes: cilium/hubble#158 (this is an issue originally filed in Hubble repository, before the code was moved over to Cilium)

Signed-off-by: Matej Gera matejgera@gmail.com

hubble: Update uint size in flow proto

Sizes of some fields in flow.proto is unnecessary
large (uint64), whereas for such fields
(e.g. endpoint ID or identity) a smaller type
is more appropriate.

This PR is a clean-up to update the scalar
value types of these fields. Includes some
changes to related Hubble packages (parsers
and filters) and minor test adjustments.

Fixes: cilium/hubble#158

Signed-off-by: Matej Gera <matejgera@gmail.com>
@matej-g matej-g requested a review from a team as a code owner April 26, 2020 19:41
@matej-g matej-g requested a review from a team April 26, 2020 19:41
@maintainer-s-little-helper
Copy link

Please set the appropriate release note label.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 44.784% when pulling 9c02d8f on matej-g:update-uint-sizes-flow-proto into 86045f7 on cilium:master.

@gandro
Copy link
Member

gandro commented Apr 27, 2020

test-me-please

Edit: Hit https://github.com/cilium/cilium/projects/97#card-33577672 on GKE.

@gandro
Copy link
Member

gandro commented Apr 27, 2020

Context for this PR for other reviewers: Back when Hubble was running in its own process, we used to obtain metadata via the Swagger-based Cilium API, which uses int64 for any integer types. This size was then used across the code base and the protobuf definitions, even though the actual endpoint ids are 16 bit, and the security identities are 32 bit in the datapath.

Changing the integer sizes of the protobuf definitions does not break backwards-compatibility: https://developers.google.com/protocol-buffers/docs/proto3#updating

Protobuf only supports 32 and 64 bit integers, therefore 16 bit values are still represented as 32 bit integers.

@@ -280,8 +280,8 @@ func decodeEndpoint(endpoint accesslog.EndpointInfo, namespace, podName string)
labels := endpoint.Labels
sort.Strings(labels)
return &pb.Endpoint{
ID: endpoint.ID,
Identity: endpoint.Identity,
ID: uint32(endpoint.ID),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anyone know why pkg.proxy.accesslog.EndpointInfo.[ID,Identity] are uint64 ? These type casts don't look safe to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #11161 (comment) for the rationale - the values will never exceed 32 bit (or 16 bit in this case).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But these two instances are from Cilium's proxy package hence not something that falls into your description, no?

Copy link
Member

@gandro gandro Apr 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but they suffered a similar fate: EndpointInfo was intended for JSON serialization (see #964), therefore I assume the type definitions were generated from some JSON-to-Go-struct tool, which picked int64 for the type.

I've checked all initialization of EndpointInfo.ID and they all take the value taken from GetID here (also added by the above PR) which casts a 16 bit integer to 64 bit

return uint64(e.ID)

So I don't see any safety issue here.

@rolinh rolinh added sig/hubble Impacts hubble server or relay kind/enhancement This would improve or streamline existing functionality. release-note/minor This PR changes functionality that users may find relevant to operating Cilium. labels Apr 27, 2020
Copy link
Member

@gandro gandro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks a lot for taking care of this.

We should also review the uses of uint64 for the endpoint id and identiy in other parts of the code, i.e. the getters in https://github.com/cilium/cilium/blob/86045f79ad6c3aeb104a0092d48c3691130b1699/pkg/hubble/parser/getters/getters.go also unnecessarily take uint64 parameters. But let's do that in a follow-up PR.

@gandro
Copy link
Member

gandro commented Apr 27, 2020

test-gke

Copy link
Member

@aanm aanm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gandro GKE is not required to pass in PRs at this moment.

@aanm aanm merged commit 18e5c63 into cilium:master Apr 27, 2020
1.8.0 automation moved this from In progress to Merged Apr 27, 2020
@matej-g
Copy link
Contributor Author

matej-g commented Apr 27, 2020

We should also review the uses of uint64 for the endpoint id and identiy in other parts of the code, i.e. the getters in https://github.com/cilium/cilium/blob/86045f79ad6c3aeb104a0092d48c3691130b1699/pkg/hubble/parser/getters/getters.go also unnecessarily take uint64 parameters. But let's do that in a follow-up PR.

Good call about the getters, wasn't sure whether I should include it or not as it also requires change in daemon. I will open an issue for that + PR.

rolinh added a commit to cilium/hubble that referenced this pull request Apr 28, 2020
This reduces the number of dependencies and pulls in the uint64 ->
uint32 change in flow protobuf definition (see [0]).

[0]: cilium/cilium#11161

Signed-off-by: Robin Hahling <robin.hahling@gw-computing.net>
gandro pushed a commit to cilium/hubble that referenced this pull request Apr 28, 2020
This reduces the number of dependencies and pulls in the uint64 ->
uint32 change in flow protobuf definition (see [0]).

[0]: cilium/cilium#11161

Signed-off-by: Robin Hahling <robin.hahling@gw-computing.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement This would improve or streamline existing functionality. release-note/minor This PR changes functionality that users may find relevant to operating Cilium. sig/hubble Impacts hubble server or relay
Projects
No open projects
1.8.0
  
Merged
Development

Successfully merging this pull request may close these issues.

Revisit integer sizes in protobuf definitions
5 participants