mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-14 14:43:46 +00:00
Omit the RULES
tab if the policy rules feature is inactive (#303)
* Omit the `RULES` tab if the policy rules feature is inactive (WIP) * Propagate the boolean value `isRulesEnabled` from file read error to UI * Remove the debug log
This commit is contained in:
parent
db1f7d34cf
commit
cdf1c39a52
@ -113,7 +113,7 @@ func startReadingChannel(outputItems <-chan *tapApi.OutputChannelItem, extension
|
|||||||
json.Unmarshal([]byte(mizuEntry.Entry), &pair)
|
json.Unmarshal([]byte(mizuEntry.Entry), &pair)
|
||||||
harEntry, err := utils.NewEntry(&pair)
|
harEntry, err := utils.NewEntry(&pair)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
rules, _ := models.RunValidationRulesState(*harEntry, mizuEntry.Service)
|
rules, _, _ := models.RunValidationRulesState(*harEntry, mizuEntry.Service)
|
||||||
baseEntry.Rules = rules
|
baseEntry.Rules = rules
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,11 +143,13 @@ func GetEntry(c *gin.Context) {
|
|||||||
protocol, representation, bodySize, _ := extension.Dissector.Represent(&entryData)
|
protocol, representation, bodySize, _ := extension.Dissector.Represent(&entryData)
|
||||||
|
|
||||||
var rules []map[string]interface{}
|
var rules []map[string]interface{}
|
||||||
|
var isRulesEnabled bool
|
||||||
if entryData.ProtocolName == "http" {
|
if entryData.ProtocolName == "http" {
|
||||||
var pair tapApi.RequestResponsePair
|
var pair tapApi.RequestResponsePair
|
||||||
json.Unmarshal([]byte(entryData.Entry), &pair)
|
json.Unmarshal([]byte(entryData.Entry), &pair)
|
||||||
harEntry, _ := utils.NewEntry(&pair)
|
harEntry, _ := utils.NewEntry(&pair)
|
||||||
_, rulesMatched := models.RunValidationRulesState(*harEntry, entryData.Service)
|
_, rulesMatched, _isRulesEnabled := models.RunValidationRulesState(*harEntry, entryData.Service)
|
||||||
|
isRulesEnabled = _isRulesEnabled
|
||||||
inrec, _ := json.Marshal(rulesMatched)
|
inrec, _ := json.Marshal(rulesMatched)
|
||||||
json.Unmarshal(inrec, &rules)
|
json.Unmarshal(inrec, &rules)
|
||||||
}
|
}
|
||||||
@ -158,6 +160,7 @@ func GetEntry(c *gin.Context) {
|
|||||||
BodySize: bodySize,
|
BodySize: bodySize,
|
||||||
Data: entryData,
|
Data: entryData,
|
||||||
Rules: rules,
|
Rules: rules,
|
||||||
|
IsRulesEnabled: isRulesEnabled,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,8 +97,8 @@ type ExtendedCreator struct {
|
|||||||
Source *string `json:"_source"`
|
Source *string `json:"_source"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunValidationRulesState(harEntry har.Entry, service string) (tapApi.ApplicableRules, []rules.RulesMatched) {
|
func RunValidationRulesState(harEntry har.Entry, service string) (tapApi.ApplicableRules, []rules.RulesMatched, bool) {
|
||||||
resultPolicyToSend := rules.MatchRequestPolicy(harEntry, service)
|
resultPolicyToSend, isEnabled := rules.MatchRequestPolicy(harEntry, service)
|
||||||
statusPolicyToSend, latency, numberOfRules := rules.PassedValidationRules(resultPolicyToSend)
|
statusPolicyToSend, latency, numberOfRules := rules.PassedValidationRules(resultPolicyToSend)
|
||||||
return tapApi.ApplicableRules{Status: statusPolicyToSend, Latency: latency, NumberOfRules: numberOfRules}, resultPolicyToSend
|
return tapApi.ApplicableRules{Status: statusPolicyToSend, Latency: latency, NumberOfRules: numberOfRules}, resultPolicyToSend, isEnabled
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,12 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/romana/rlog"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/romana/rlog"
|
||||||
|
|
||||||
"github.com/google/martian/har"
|
"github.com/google/martian/har"
|
||||||
"github.com/up9inc/mizu/shared"
|
"github.com/up9inc/mizu/shared"
|
||||||
jsonpath "github.com/yalp/jsonpath"
|
jsonpath "github.com/yalp/jsonpath"
|
||||||
@ -43,9 +44,11 @@ func ValidateService(serviceFromRule string, service string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func MatchRequestPolicy(harEntry har.Entry, service string) []RulesMatched {
|
func MatchRequestPolicy(harEntry har.Entry, service string) (resultPolicyToSend []RulesMatched, isEnabled bool) {
|
||||||
enforcePolicy, _ := shared.DecodeEnforcePolicy(fmt.Sprintf("%s/%s", shared.RulePolicyPath, shared.RulePolicyFileName))
|
enforcePolicy, err := shared.DecodeEnforcePolicy(fmt.Sprintf("%s/%s", shared.RulePolicyPath, shared.RulePolicyFileName))
|
||||||
var resultPolicyToSend []RulesMatched
|
if err == nil {
|
||||||
|
isEnabled = true
|
||||||
|
}
|
||||||
for _, rule := range enforcePolicy.Rules {
|
for _, rule := range enforcePolicy.Rules {
|
||||||
if !ValidatePath(rule.Path, harEntry.Request.URL) || !ValidateService(rule.Service, service) {
|
if !ValidatePath(rule.Path, harEntry.Request.URL) || !ValidateService(rule.Service, service) {
|
||||||
continue
|
continue
|
||||||
@ -93,7 +96,7 @@ func MatchRequestPolicy(harEntry har.Entry, service string) []RulesMatched {
|
|||||||
resultPolicyToSend = appendRulesMatched(resultPolicyToSend, true, rule)
|
resultPolicyToSend = appendRulesMatched(resultPolicyToSend, true, rule)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return resultPolicyToSend
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func PassedValidationRules(rulesMatched []RulesMatched) (bool, int64, int) {
|
func PassedValidationRules(rulesMatched []RulesMatched) (bool, int64, int) {
|
||||||
|
@ -138,6 +138,7 @@ type MizuEntryWrapper struct {
|
|||||||
BodySize int64 `json:"bodySize"`
|
BodySize int64 `json:"bodySize"`
|
||||||
Data MizuEntry `json:"data"`
|
Data MizuEntry `json:"data"`
|
||||||
Rules []map[string]interface{} `json:"rulesMatched,omitempty"`
|
Rules []map[string]interface{} `json:"rulesMatched,omitempty"`
|
||||||
|
IsRulesEnabled bool `json:"isRulesEnabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BaseEntryDetails struct {
|
type BaseEntryDetails struct {
|
||||||
|
@ -71,7 +71,7 @@ export const EntryDetailed: React.FC<EntryDetailedProps> = ({entryData}) => {
|
|||||||
/>
|
/>
|
||||||
{entryData.data && <EntrySummary data={entryData.data}/>}
|
{entryData.data && <EntrySummary data={entryData.data}/>}
|
||||||
<>
|
<>
|
||||||
{entryData.data && <EntryViewer representation={entryData.representation} rulesMatched={entryData.rulesMatched} elapsedTime={entryData.data.elapsedTime} color={entryData.protocol.backgroundColor}/>}
|
{entryData.data && <EntryViewer representation={entryData.representation} isRulesEnabled={entryData.isRulesEnabled} rulesMatched={entryData.rulesMatched} elapsedTime={entryData.data.elapsedTime} color={entryData.protocol.backgroundColor}/>}
|
||||||
</>
|
</>
|
||||||
</>
|
</>
|
||||||
};
|
};
|
||||||
|
@ -153,10 +153,8 @@ export const EntryTableSection: React.FC<EntrySectionProps> = ({title, color, ar
|
|||||||
|
|
||||||
|
|
||||||
interface EntryPolicySectionProps {
|
interface EntryPolicySectionProps {
|
||||||
service: string,
|
|
||||||
title: string,
|
title: string,
|
||||||
color: string,
|
color: string,
|
||||||
response: any,
|
|
||||||
latency?: number,
|
latency?: number,
|
||||||
arrayToIterate: any[],
|
arrayToIterate: any[],
|
||||||
}
|
}
|
||||||
@ -200,7 +198,7 @@ export const EntryPolicySectionContainer: React.FC<EntryPolicySectionContainerPr
|
|||||||
</CollapsibleContainer>
|
</CollapsibleContainer>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const EntryTablePolicySection: React.FC<EntryPolicySectionProps> = ({service, title, color, response, latency, arrayToIterate}) => {
|
export const EntryTablePolicySection: React.FC<EntryPolicySectionProps> = ({title, color, latency, arrayToIterate}) => {
|
||||||
return <React.Fragment>
|
return <React.Fragment>
|
||||||
{
|
{
|
||||||
arrayToIterate && arrayToIterate.length > 0 ?
|
arrayToIterate && arrayToIterate.length > 0 ?
|
||||||
|
@ -33,8 +33,8 @@ const SectionsRepresentation: React.FC<any> = ({data, color}) => {
|
|||||||
return <>{sections}</>;
|
return <>{sections}</>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AutoRepresentation: React.FC<any> = ({representation, rulesMatched, elapsedTime, color}) => {
|
const AutoRepresentation: React.FC<any> = ({representation, isRulesEnabled, rulesMatched, elapsedTime, color}) => {
|
||||||
const TABS = [
|
var TABS = [
|
||||||
{
|
{
|
||||||
tab: 'request'
|
tab: 'request'
|
||||||
},
|
},
|
||||||
@ -58,6 +58,10 @@ const AutoRepresentation: React.FC<any> = ({representation, rulesMatched, elapse
|
|||||||
TABS[1]['hidden'] = true;
|
TABS[1]['hidden'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isRulesEnabled) {
|
||||||
|
TABS.pop()
|
||||||
|
}
|
||||||
|
|
||||||
return <div className={styles.Entry}>
|
return <div className={styles.Entry}>
|
||||||
{<div className={styles.body}>
|
{<div className={styles.body}>
|
||||||
<div className={styles.bodyHeader}>
|
<div className={styles.bodyHeader}>
|
||||||
@ -70,8 +74,8 @@ const AutoRepresentation: React.FC<any> = ({representation, rulesMatched, elapse
|
|||||||
{response && currentTab === TABS[1].tab && <React.Fragment>
|
{response && currentTab === TABS[1].tab && <React.Fragment>
|
||||||
<SectionsRepresentation data={response} color={color}/>
|
<SectionsRepresentation data={response} color={color}/>
|
||||||
</React.Fragment>}
|
</React.Fragment>}
|
||||||
{currentTab === TABS[2].tab && <React.Fragment>
|
{TABS.length > 2 && currentTab === TABS[2].tab && <React.Fragment>
|
||||||
<EntryTablePolicySection service={representation.service} title={'Rule'} color={color} latency={elapsedTime} response={response} arrayToIterate={rulesMatched ? rulesMatched : []}/>
|
<EntryTablePolicySection title={'Rule'} color={color} latency={elapsedTime} arrayToIterate={rulesMatched ? rulesMatched : []}/>
|
||||||
</React.Fragment>}
|
</React.Fragment>}
|
||||||
</div>}
|
</div>}
|
||||||
</div>;
|
</div>;
|
||||||
@ -79,13 +83,14 @@ const AutoRepresentation: React.FC<any> = ({representation, rulesMatched, elapse
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
representation: any;
|
representation: any;
|
||||||
|
isRulesEnabled: boolean;
|
||||||
rulesMatched: any;
|
rulesMatched: any;
|
||||||
color: string;
|
color: string;
|
||||||
elapsedTime: number;
|
elapsedTime: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const EntryViewer: React.FC<Props> = ({representation, rulesMatched, elapsedTime, color}) => {
|
const EntryViewer: React.FC<Props> = ({representation, isRulesEnabled, rulesMatched, elapsedTime, color}) => {
|
||||||
return <AutoRepresentation representation={representation} rulesMatched={rulesMatched} elapsedTime={elapsedTime} color={color}/>
|
return <AutoRepresentation representation={representation} isRulesEnabled={isRulesEnabled} rulesMatched={rulesMatched} elapsedTime={elapsedTime} color={color}/>
|
||||||
};
|
};
|
||||||
|
|
||||||
export default EntryViewer;
|
export default EntryViewer;
|
||||||
|
Loading…
Reference in New Issue
Block a user