{"action":"created","comment":{"url":"https://api.github.com/repos/cilium/cilium/pulls/comments/178610854","pull_request_review_id":108694265,"id":178610854,"diff_hunk":"@@ -281,9 +222,42 @@ func (req *RequestMessage) ruleMatches(rule api.PortRuleKafka) bool {\n // rules. The function will return true if the policy allows the message,\n // otherwise false is returned.\n func (req *RequestMessage) MatchesRule(rules []api.PortRuleKafka) bool {\n+\treqTopicsMap := map[string]bool{}\n+\n+\t// Maintain a map of all topics in the request\n+\t// Only if all the topics in a request are\n+\t// allowed by the rules, we should allow a request.\n+\ttopics := req.GetTopics()\n+\tfor _, topic := range topics {\n+\t\treqTopicsMap[topic] = true\n+\t}\n+\n \tfor _, rule := range rules {\n-\t\tif req.ruleMatches(rule) {\n-\t\t\treturn true\n+\t\tswitch len(topics) {\n+\t\tcase 0:\n+\t\t\tif req.ruleMatches(rule, \"\") {\n+\t\t\t\treturn true\n+\t\t\t}\n+\t\tdefault:\n+\t\t\tif rule.Topic != \"\" {\n+\t\t\t\t_, ok := reqTopicsMap[rule.Topic]\n+\t\t\t\tif ok && req.ruleMatches(rule, rule.Topic) {","path":"pkg/kafka/policy.go","position":208,"original_position":208,"commit_id":"01ba4dc84b7150765dd36892dfd49b15c28414ab","original_commit_id":"01ba4dc84b7150765dd36892dfd49b15c28414ab","user":{"login":"manalibhutiyani","id":31253464,"avatar_url":"https://avatars3.githubusercontent.com/u/31253464?v=4","gravatar_id":"","url":"https://api.github.com/users/manalibhutiyani","html_url":"https://github.com/manalibhutiyani","followers_url":"https://api.github.com/users/manalibhutiyani/followers","following_url":"https://api.github.com/users/manalibhutiyani/following{/other_user}","gists_url":"https://api.github.com/users/manalibhutiyani/gists{/gist_id}","starred_url":"https://api.github.com/users/manalibhutiyani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manalibhutiyani/subscriptions","organizations_url":"https://api.github.com/users/manalibhutiyani/orgs","repos_url":"https://api.github.com/users/manalibhutiyani/repos","events_url":"https://api.github.com/users/manalibhutiyani/events{/privacy}","received_events_url":"https://api.github.com/users/manalibhutiyani/received_events","type":"User","site_admin":false},"body":"I was trying to keep the same semantics as before, but I agree, now with a hash map, and no topic iteration, this code is redundant. Let me fix that. thanks for the comment.","created_at":"2018-04-02T18:21:18Z","updated_at":"2018-04-02T18:21:18Z","html_url":"https://github.com/cilium/cilium/pull/3445#discussion_r178610854","pull_request_url":"https://api.github.com/repos/cilium/cilium/pulls/3445","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/cilium/cilium/pulls/comments/178610854"},"html":{"href":"https://github.com/cilium/cilium/pull/3445#discussion_r178610854"},"pull_request":{"href":"https://api.github.com/repos/cilium/cilium/pulls/3445"}},"in_reply_to_id":178485951},"pull_request":{"url":"https://api.github.com/repos/cilium/cilium/pulls/3445","id":178696722,"html_url":"https://github.com/cilium/cilium/pull/3445","diff_url":"https://github.com/cilium/cilium/pull/3445.diff","patch_url":"https://github.com/cilium/cilium/pull/3445.patch","issue_url":"https://api.github.com/repos/cilium/cilium/issues/3445","number":3445,"state":"open","locked":false,"title":" Kafka multi-topic request support","user":{"login":"manalibhutiyani","id":31253464,"avatar_url":"https://avatars3.githubusercontent.com/u/31253464?v=4","gravatar_id":"","url":"https://api.github.com/users/manalibhutiyani","html_url":"https://github.com/manalibhutiyani","followers_url":"https://api.github.com/users/manalibhutiyani/followers","following_url":"https://api.github.com/users/manalibhutiyani/following{/other_user}","gists_url":"https://api.github.com/users/manalibhutiyani/gists{/gist_id}","starred_url":"https://api.github.com/users/manalibhutiyani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manalibhutiyani/subscriptions","organizations_url":"https://api.github.com/users/manalibhutiyani/orgs","repos_url":"https://api.github.com/users/manalibhutiyani/repos","events_url":"https://api.github.com/users/manalibhutiyani/events{/privacy}","received_events_url":"https://api.github.com/users/manalibhutiyani/received_events","type":"User","site_admin":false},"body":" This change includes the following:\r\n1. Policy: Allow only if all topics in a request are allowed\r\n    Currently, If a request (e.g. a produce) has multiple topics,\r\n    and one topic is allowed by policy, the whole request is allowed.\r\n    This is a security hole and should be changed to only allow a request\r\n    if all the topics are allowed.\r\n\r\n2. Tests: Extend go tests to test multi-topic requests\r\n\r\nFixes:  #3397\r\nSigned-Off-by: Manali Bhutiyani <manali@covalent.io>\r\n\r\n```release-note\r\nPolicy: Kafka multi-topic request support\r\n```","created_at":"2018-03-31T19:25:05Z","updated_at":"2018-04-02T18:21:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3db1a3f4f2e0a2625225703409d2fd27e86aaf05","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":403149902,"url":"https://api.github.com/repos/cilium/cilium/labels/pending-review","name":"pending-review","color":"fbca04","default":false},{"id":809259668,"url":"https://api.github.com/repos/cilium/cilium/labels/priority/1.0-blocker","name":"priority/1.0-blocker","color":"b60205","default":false},{"id":732923415,"url":"https://api.github.com/repos/cilium/cilium/labels/release-note/minor","name":"release-note/minor","color":"c2e0c6","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/cilium/cilium/pulls/3445/commits","review_comments_url":"https://api.github.com/repos/cilium/cilium/pulls/3445/comments","review_comment_url":"https://api.github.com/repos/cilium/cilium/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cilium/cilium/issues/3445/comments","statuses_url":"https://api.github.com/repos/cilium/cilium/statuses/01ba4dc84b7150765dd36892dfd49b15c28414ab","head":{"label":"cilium:kafka-multi-topic-hash","ref":"kafka-multi-topic-hash","sha":"01ba4dc84b7150765dd36892dfd49b15c28414ab","user":{"login":"cilium","id":21054566,"avatar_url":"https://avatars0.githubusercontent.com/u/21054566?v=4","gravatar_id":"","url":"https://api.github.com/users/cilium","html_url":"https://github.com/cilium","followers_url":"https://api.github.com/users/cilium/followers","following_url":"https://api.github.com/users/cilium/following{/other_user}","gists_url":"https://api.github.com/users/cilium/gists{/gist_id}","starred_url":"https://api.github.com/users/cilium/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cilium/subscriptions","organizations_url":"https://api.github.com/users/cilium/orgs","repos_url":"https://api.github.com/users/cilium/repos","events_url":"https://api.github.com/users/cilium/events{/privacy}","received_events_url":"https://api.github.com/users/cilium/received_events","type":"Organization","site_admin":false},"repo":{"id":48109239,"name":"cilium","full_name":"cilium/cilium","owner":{"login":"cilium","id":21054566,"avatar_url":"https://avatars0.githubusercontent.com/u/21054566?v=4","gravatar_id":"","url":"https://api.github.com/users/cilium","html_url":"https://github.com/cilium","followers_url":"https://api.github.com/users/cilium/followers","following_url":"https://api.github.com/users/cilium/following{/other_user}","gists_url":"https://api.github.com/users/cilium/gists{/gist_id}","starred_url":"https://api.github.com/users/cilium/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cilium/subscriptions","organizations_url":"https://api.github.com/users/cilium/orgs","repos_url":"https://api.github.com/users/cilium/repos","events_url":"https://api.github.com/users/cilium/events{/privacy}","received_events_url":"https://api.github.com/users/cilium/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cilium/cilium","description":"HTTP, gRPC, and Kafka Aware Security and Networking for Containers with BPF and XDP","fork":false,"url":"https://api.github.com/repos/cilium/cilium","forks_url":"https://api.github.com/repos/cilium/cilium/forks","keys_url":"https://api.github.com/repos/cilium/cilium/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cilium/cilium/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cilium/cilium/teams","hooks_url":"https://api.github.com/repos/cilium/cilium/hooks","issue_events_url":"https://api.github.com/repos/cilium/cilium/issues/events{/number}","events_url":"https://api.github.com/repos/cilium/cilium/events","assignees_url":"https://api.github.com/repos/cilium/cilium/assignees{/user}","branches_url":"https://api.github.com/repos/cilium/cilium/branches{/branch}","tags_url":"https://api.github.com/repos/cilium/cilium/tags","blobs_url":"https://api.github.com/repos/cilium/cilium/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cilium/cilium/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cilium/cilium/git/refs{/sha}","trees_url":"https://api.github.com/repos/cilium/cilium/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cilium/cilium/statuses/{sha}","languages_url":"https://api.github.com/repos/cilium/cilium/languages","stargazers_url":"https://api.github.com/repos/cilium/cilium/stargazers","contributors_url":"https://api.github.com/repos/cilium/cilium/contributors","subscribers_url":"https://api.github.com/repos/cilium/cilium/subscribers","subscription_url":"https://api.github.com/repos/cilium/cilium/subscription","commits_url":"https://api.github.com/repos/cilium/cilium/commits{/sha}","git_commits_url":"https://api.github.com/repos/cilium/cilium/git/commits{/sha}","comments_url":"https://api.github.com/repos/cilium/cilium/comments{/number}","issue_comment_url":"https://api.github.com/repos/cilium/cilium/issues/comments{/number}","contents_url":"https://api.github.com/repos/cilium/cilium/contents/{+path}","compare_url":"https://api.github.com/repos/cilium/cilium/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cilium/cilium/merges","archive_url":"https://api.github.com/repos/cilium/cilium/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cilium/cilium/downloads","issues_url":"https://api.github.com/repos/cilium/cilium/issues{/number}","pulls_url":"https://api.github.com/repos/cilium/cilium/pulls{/number}","milestones_url":"https://api.github.com/repos/cilium/cilium/milestones{/number}","notifications_url":"https://api.github.com/repos/cilium/cilium/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cilium/cilium/labels{/name}","releases_url":"https://api.github.com/repos/cilium/cilium/releases{/id}","deployments_url":"https://api.github.com/repos/cilium/cilium/deployments","created_at":"2015-12-16T12:33:31Z","updated_at":"2018-04-02T16:10:16Z","pushed_at":"2018-04-02T17:27:23Z","git_url":"git://github.com/cilium/cilium.git","ssh_url":"git@github.com:cilium/cilium.git","clone_url":"https://github.com/cilium/cilium.git","svn_url":"https://github.com/cilium/cilium","homepage":"","size":43873,"stargazers_count":1713,"watchers_count":1713,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":164,"mirror_url":null,"archived":false,"open_issues_count":455,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":164,"open_issues":455,"watchers":1713,"default_branch":"master"}},"base":{"label":"cilium:master","ref":"master","sha":"a2571a29a25c2cfc042220ae360101e1afcdcd29","user":{"login":"cilium","id":21054566,"avatar_url":"https://avatars0.githubusercontent.com/u/21054566?v=4","gravatar_id":"","url":"https://api.github.com/users/cilium","html_url":"https://github.com/cilium","followers_url":"https://api.github.com/users/cilium/followers","following_url":"https://api.github.com/users/cilium/following{/other_user}","gists_url":"https://api.github.com/users/cilium/gists{/gist_id}","starred_url":"https://api.github.com/users/cilium/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cilium/subscriptions","organizations_url":"https://api.github.com/users/cilium/orgs","repos_url":"https://api.github.com/users/cilium/repos","events_url":"https://api.github.com/users/cilium/events{/privacy}","received_events_url":"https://api.github.com/users/cilium/received_events","type":"Organization","site_admin":false},"repo":{"id":48109239,"name":"cilium","full_name":"cilium/cilium","owner":{"login":"cilium","id":21054566,"avatar_url":"https://avatars0.githubusercontent.com/u/21054566?v=4","gravatar_id":"","url":"https://api.github.com/users/cilium","html_url":"https://github.com/cilium","followers_url":"https://api.github.com/users/cilium/followers","following_url":"https://api.github.com/users/cilium/following{/other_user}","gists_url":"https://api.github.com/users/cilium/gists{/gist_id}","starred_url":"https://api.github.com/users/cilium/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cilium/subscriptions","organizations_url":"https://api.github.com/users/cilium/orgs","repos_url":"https://api.github.com/users/cilium/repos","events_url":"https://api.github.com/users/cilium/events{/privacy}","received_events_url":"https://api.github.com/users/cilium/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cilium/cilium","description":"HTTP, gRPC, and Kafka Aware Security and Networking for Containers with BPF and XDP","fork":false,"url":"https://api.github.com/repos/cilium/cilium","forks_url":"https://api.github.com/repos/cilium/cilium/forks","keys_url":"https://api.github.com/repos/cilium/cilium/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cilium/cilium/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cilium/cilium/teams","hooks_url":"https://api.github.com/repos/cilium/cilium/hooks","issue_events_url":"https://api.github.com/repos/cilium/cilium/issues/events{/number}","events_url":"https://api.github.com/repos/cilium/cilium/events","assignees_url":"https://api.github.com/repos/cilium/cilium/assignees{/user}","branches_url":"https://api.github.com/repos/cilium/cilium/branches{/branch}","tags_url":"https://api.github.com/repos/cilium/cilium/tags","blobs_url":"https://api.github.com/repos/cilium/cilium/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cilium/cilium/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cilium/cilium/git/refs{/sha}","trees_url":"https://api.github.com/repos/cilium/cilium/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cilium/cilium/statuses/{sha}","languages_url":"https://api.github.com/repos/cilium/cilium/languages","stargazers_url":"https://api.github.com/repos/cilium/cilium/stargazers","contributors_url":"https://api.github.com/repos/cilium/cilium/contributors","subscribers_url":"https://api.github.com/repos/cilium/cilium/subscribers","subscription_url":"https://api.github.com/repos/cilium/cilium/subscription","commits_url":"https://api.github.com/repos/cilium/cilium/commits{/sha}","git_commits_url":"https://api.github.com/repos/cilium/cilium/git/commits{/sha}","comments_url":"https://api.github.com/repos/cilium/cilium/comments{/number}","issue_comment_url":"https://api.github.com/repos/cilium/cilium/issues/comments{/number}","contents_url":"https://api.github.com/repos/cilium/cilium/contents/{+path}","compare_url":"https://api.github.com/repos/cilium/cilium/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cilium/cilium/merges","archive_url":"https://api.github.com/repos/cilium/cilium/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cilium/cilium/downloads","issues_url":"https://api.github.com/repos/cilium/cilium/issues{/number}","pulls_url":"https://api.github.com/repos/cilium/cilium/pulls{/number}","milestones_url":"https://api.github.com/repos/cilium/cilium/milestones{/number}","notifications_url":"https://api.github.com/repos/cilium/cilium/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cilium/cilium/labels{/name}","releases_url":"https://api.github.com/repos/cilium/cilium/releases{/id}","deployments_url":"https://api.github.com/repos/cilium/cilium/deployments","created_at":"2015-12-16T12:33:31Z","updated_at":"2018-04-02T16:10:16Z","pushed_at":"2018-04-02T17:27:23Z","git_url":"git://github.com/cilium/cilium.git","ssh_url":"git@github.com:cilium/cilium.git","clone_url":"https://github.com/cilium/cilium.git","svn_url":"https://github.com/cilium/cilium","homepage":"","size":43873,"stargazers_count":1713,"watchers_count":1713,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":164,"mirror_url":null,"archived":false,"open_issues_count":455,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":164,"open_issues":455,"watchers":1713,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cilium/cilium/pulls/3445"},"html":{"href":"https://github.com/cilium/cilium/pull/3445"},"issue":{"href":"https://api.github.com/repos/cilium/cilium/issues/3445"},"comments":{"href":"https://api.github.com/repos/cilium/cilium/issues/3445/comments"},"review_comments":{"href":"https://api.github.com/repos/cilium/cilium/pulls/3445/comments"},"review_comment":{"href":"https://api.github.com/repos/cilium/cilium/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cilium/cilium/pulls/3445/commits"},"statuses":{"href":"https://api.github.com/repos/cilium/cilium/statuses/01ba4dc84b7150765dd36892dfd49b15c28414ab"}},"author_association":"OWNER"}}
{"actor":{"display_login":"manalibhutiyani"}}