diff --git a/pkg/models/tenant/tenant.go b/pkg/models/tenant/tenant.go index 959523714..9303e1717 100644 --- a/pkg/models/tenant/tenant.go +++ b/pkg/models/tenant/tenant.go @@ -303,20 +303,7 @@ func (t *tenantOperator) listIntersectedNamespaces(user user.Info, iNamespaces []*corev1.Namespace ) - // When user can list all namespaces, the namespaces which do not belong to any workspace should be considered - listNs := authorizer.AttributesRecord{ - User: user, - Verb: "list", - APIGroup: "", - APIVersion: "v1", - Resource: "namespaces", - ResourceRequest: true, - } - decision, _, err := t.authorizer.Authorize(listNs) - if err != nil { - return nil, err - } - includeNsWithoutWs := len(workspaceSet) == 0 && len(workspaceSubstrs) == 0 && decision == authorizer.DecisionAllow + includeNsWithoutWs := len(workspaceSet) == 0 && len(workspaceSubstrs) == 0 roleBindings, err := t.am.ListRoleBindings(user.GetName(), "") if err != nil { diff --git a/pkg/simple/client/events/elasticsearch/elasticsearch.go b/pkg/simple/client/events/elasticsearch/elasticsearch.go index f0ccad1e4..600e36094 100644 --- a/pkg/simple/client/events/elasticsearch/elasticsearch.go +++ b/pkg/simple/client/events/elasticsearch/elasticsearch.go @@ -226,6 +226,7 @@ func parseToQueryPart(f *events.Filter) interface{} { Filter []map[string]interface{} `json:"filter,omitempty"` Should []map[string]interface{} `json:"should,omitempty"` MinimumShouldMatch *int `json:"minimum_should_match,omitempty"` + MustNot []map[string]interface{} `json:"must_not,omitempty"` } var mini = 1 b := BoolBody{} @@ -236,19 +237,29 @@ func parseToQueryPart(f *events.Filter) interface{} { if len(f.InvolvedObjectNamespaceMap) > 0 { bi := BoolBody{MinimumShouldMatch: &mini} for k, v := range f.InvolvedObjectNamespaceMap { - bi.Should = append(bi.Should, map[string]interface{}{ - "bool": &BoolBody{ - Filter: []map[string]interface{}{{ - "match_phrase": map[string]string{"involvedObject.namespace.keyword": k}, - }, { - "range": map[string]interface{}{ - "lastTimestamp": map[string]interface{}{ - "gte": v, + if k == "" { + bi.Should = append(bi.Should, map[string]interface{}{ + "bool": &BoolBody{ + MustNot: []map[string]interface{}{{ + "exists": map[string]string{"field": "involvedObject.namespace"}, + }}, + }, + }) + } else { + bi.Should = append(bi.Should, map[string]interface{}{ + "bool": &BoolBody{ + Filter: []map[string]interface{}{{ + "match_phrase": map[string]string{"involvedObject.namespace.keyword": k}, + }, { + "range": map[string]interface{}{ + "lastTimestamp": map[string]interface{}{ + "gte": v, + }, }, - }, - }}, - }, - }) + }}, + }, + }) + } } if len(bi.Should) > 0 { b.Filter = append(b.Filter, map[string]interface{}{"bool": &bi})