Skip to content

Add analyzer for empty protocol and addresses in Service Entry#28664

Merged
istio-testing merged 6 commits intoistio:masterfrom
zufardhiyaulhaq:master
Dec 2, 2020
Merged

Add analyzer for empty protocol and addresses in Service Entry#28664
istio-testing merged 6 commits intoistio:masterfrom
zufardhiyaulhaq:master

Conversation

@zufardhiyaulhaq
Copy link
Copy Markdown
Member

Issue related: #27990

Add warning analyzer for empty Protocol and Addresses in ServiceEntry object. Since if both empty, probably will cause a mesh wide error.

result:

istio $ ./out/linux_amd64/istioctl analyze --use-kube=false galley/pkg/config/analysis/analyzers/testdata/serviceentry-empty-protocol-addresses.yaml -n default    master
Warning [IST0133] (ServiceEntry service-entry-test-03.default galley/pkg/config/analysis/analyzers/testdata/serviceentry-empty-protocol-addresses.yaml:49) one or more Protocol empty in ServiceEntry default/service-entry-test-03 with Addresses Empty.
Warning [IST0133] (ServiceEntry service-entry-test-04.default galley/pkg/config/analysis/analyzers/testdata/serviceentry-empty-protocol-addresses.yaml:65) one or more Protocol empty in ServiceEntry default/service-entry-test-04 with Addresses Empty.

[x] Configuration Infrastructure
[ ] Docs
[ ] Installation
[x] Networking
[ ] Performance and Scalability
[ ] Policies and Telemetry
[ ] Security
[ ] Test and Release
[ ] User Experience
[ ] Developer Infrastructure

Pull Request Attributes
Please check any characteristics that apply to this pull request.
[x] Does not have any changes that may affect Istio users.

@zufardhiyaulhaq zufardhiyaulhaq requested a review from a team as a code owner November 6, 2020 19:03
@istio-policy-bot istio-policy-bot added area/networking release-notes-none Indicates a PR that does not require release notes. labels Nov 6, 2020
@google-cla google-cla bot added the cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. label Nov 6, 2020
@istio-testing istio-testing added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test labels Nov 6, 2020
@istio-testing
Copy link
Copy Markdown
Collaborator

Hi @zufardhiyaulhaq. Thanks for your PR.

I'm waiting for a istio member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@shamsher31
Copy link
Copy Markdown
Member

/ok-to-test

@istio-testing istio-testing added ok-to-test Set this label allow normal testing to take place for a PR not submitted by an Istio org member. and removed needs-ok-to-test labels Nov 9, 2020
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if Addresses is set but the Ports[*].Protocol is empty?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

if Addresses is set with Ports[*].Protocol is empty. It will not cause a cluster wide problem #27990 since we already have Addresses that match the traffic. CMIIW

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
description: "Addresses and Protocol is Empty in ServiceEntry."
description: "Addresses or Protocol is empty in ServiceEntry."

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I prefer with Addresses and Protocol is empty in ServiceEntry. since this analyzer match if Addresses and Protocol are empty.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think Addresses is optional but the user must set Protocol?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

miss documentation probably, please check @howardjohn comment #27990 (comment)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is fixed

@zufardhiyaulhaq
Copy link
Copy Markdown
Member Author

I get this lint error, should I change the struct to Analyzer rather than ServiceEntryAnalyzer?

galley/pkg/config/analysis/analyzers/serviceentry/serviceentry.go:29:6: type name will be used as serviceentry.ServiceEntryAnalyzer by other packages, and that stutters; consider calling this Analyzer (golint)

@shamsher31 shamsher31 requested a review from a team November 9, 2020 07:56
@howardjohn
Copy link
Copy Markdown
Member

This should also be for protocol: TCP now that i think about it, not just unset

@zufardhiyaulhaq
Copy link
Copy Markdown
Member Author

This should also be for protocol: TCP now that i think about it, not just unset

can you explain the behaviour when we using TCP port in serviceentry?

@howardjohn
Copy link
Copy Markdown
Member

can you explain the behaviour when we using TCP port in serviceentry?

Yeah, basically the empty protocol means we set up listeners for TCP AND HTTP. The "tcp" part is what causes this issue of binding to all traffic on the port. So just TCP also has the same problem

@zufardhiyaulhaq
Copy link
Copy Markdown
Member Author

can you explain the behaviour when we using TCP port in serviceentry?

Yeah, basically the empty protocol means we set up listeners for TCP AND HTTP. The "tcp" part is what causes this issue of binding to all traffic on the port. So just TCP also has the same problem

this only applies to ServiceEntry with empty addresses right (Protocol TCP)? since if we define the addresses, the listener only match the specific addresses. So we don't need to make analyzer for that cases.

@zufardhiyaulhaq
Copy link
Copy Markdown
Member Author

@howardjohn should we create another code like IST0134 ServiceEntryProtocolTCPAndAddressesEmpty for tcp port? wdyt?

@howardjohn
Copy link
Copy Markdown
Member

I would use a single code to apply to anything that can cause this symptom. IMO, code should be based on the user impact (capture all traffic on port),not the cause (missing protocol vs tcp)

@istio-testing istio-testing added the needs-rebase Indicates a PR needs to be rebased before being merged label Nov 15, 2020
@istio-testing istio-testing removed the needs-rebase Indicates a PR needs to be rebased before being merged label Nov 16, 2020
@zufardhiyaulhaq
Copy link
Copy Markdown
Member Author

@howardjohn adding TCP check also. I am dividing into other code since I am following the current code that based on the cause

Warning [IST0135] (ServiceEntry service-entry-test-03.default galley/pkg/config/analysis/analyzers/testdata/serviceentry-missing-addresses-protocol-tcp.yaml:49) missing Addresses with Protocol TCP, which can lead to undefined behavior.

Warning [IST0134] (ServiceEntry service-entry-test-03.default galley/pkg/config/analysis/analyzers/testdata/serviceentry-missing-addresses-protocol.yaml:49) missing Addresses and Protocol, which can lead to undefined behavior.
Warning [IST0134] (ServiceEntry service-entry-test-04.default galley/pkg/config/analysis/analyzers/testdata/serviceentry-missing-addresses-protocol.yaml:65) missing Addresses and Protocol, which can lead to undefined behavior.

@zufardhiyaulhaq zufardhiyaulhaq requested review from esnible, howardjohn and shamsher31 and removed request for a team November 16, 2020 10:55
@zufardhiyaulhaq
Copy link
Copy Markdown
Member Author

Any update related to this folks?

Copy link
Copy Markdown
Member

@howardjohn howardjohn left a comment

Choose a reason for hiding this comment

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

LGTM

- name: err
type: error

- name: "ServiceEntryMissingAddressesAndProtocol"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Not sure we need two different messages for these - they are essentially identical


if se.Addresses == nil {
for index, port := range se.Ports {
if port.Protocol == "TCP" {
Copy link
Copy Markdown
Member

@shamsher31 shamsher31 Nov 23, 2020

Choose a reason for hiding this comment

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

I think you can combine this condition with the above function. So there will be 2 checks.
one with port.Protocol == "" and other with port.Protocol == "TCP" in one function?

Copy link
Copy Markdown
Member Author

@zufardhiyaulhaq zufardhiyaulhaq Nov 23, 2020

Choose a reason for hiding this comment

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

actually yes we can do that. do you have suggestions for the message in galley/pkg/config/analysis/msg/messages.yaml? actually, I am confused about how to create the message

cc @howardjohn

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@zufardhiyaulhaq To create a new message, edit messages.yaml. Then run go generate in the messages directory after setting $REPO_ROOT. I do this:

export REPO_ROOT=~/go/src/istio.io/istio
cd ~/go/src/istio.io/istio/galley/pkg/config/analysis/msg
go generate

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@esnible pardon me, not creating a new message. I mean the message format. currently, I am using two analyzer code (IST0134 and IST0135) to separate

  • empty Addresses and empty Protocol
  • empty Addresses with Protocol TCP

@shamsher31 this is done

Copy link
Copy Markdown
Member

@shamsher31 shamsher31 left a comment

Choose a reason for hiding this comment

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

Overall LGTM. I will let @esnible provide feedback on multiple messages.

@zufardhiyaulhaq
Copy link
Copy Markdown
Member Author

can you review this PR @esnible? thanks

@esnible
Copy link
Copy Markdown
Contributor

esnible commented Nov 30, 2020

Would it make sense to have a single warning?

- name: "AddressesRequired"
    code: IST0134
    level: Warning
    description: “Virtual IP addresses are required for ports serving TCP (or unset) protocol”.
    template: "ServiceEntry addresses are required for this protocol.”

(I don’t know why empty protocol is allowed — our docs say protocol “MUST BE one of HTTP|HTTPS|GRPC|HTTP2|MONGO|TCP|TLS.”)

@zufardhiyaulhaq
Copy link
Copy Markdown
Member Author

@esnible yes but we can still apply it directly. The behaviour with missing protocol is explained by @howardjohn in this thread #27990 (comment)

I can refactor to match only protocol TCP without addresses. but I think we must agree first probably to move to another issue for empty protocol.

@esnible
Copy link
Copy Markdown
Contributor

esnible commented Nov 30, 2020

@esnible yes but we can still apply it directly. The behaviour with missing protocol is explained by @howardjohn in this thread #27990 (comment)

I can refactor to match only protocol TCP without addresses. but I think we must agree first probably to move to another issue for empty protocol.

It is fine to keep this PR, with the check for empty Protocol, because it works. Combine the messages.

@zufardhiyaulhaq
Copy link
Copy Markdown
Member Author

/retest

1 similar comment
@zufardhiyaulhaq
Copy link
Copy Markdown
Member Author

/retest

@zufardhiyaulhaq
Copy link
Copy Markdown
Member Author

@esnible yes but we can still apply it directly. The behaviour with missing protocol is explained by @howardjohn in this thread #27990 (comment)
I can refactor to match only protocol TCP without addresses. but I think we must agree first probably to move to another issue for empty protocol.

It is fine to keep this PR, with the check for empty Protocol, because it works. Combine the messages.

this is done @esnible

@thehackercat
Copy link
Copy Markdown
Contributor

should we add this rule to validationWebhook?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/networking cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. ok-to-test Set this label allow normal testing to take place for a PR not submitted by an Istio org member. release-notes-none Indicates a PR that does not require release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants