Skip to content

Commit

Permalink
Add HTTP URL filter
Browse files Browse the repository at this point in the history
We added support for filtering on HTTP URLs in
cilium/cilium#28275. This PR adds this feature
in the CLI by adding a new flag `--http-url`

Fixes: cilium#925

Signed-off-by: Fabian Fischer <fabian.fischer@isovalent.com>
  • Loading branch information
glrf committed Oct 2, 2023
1 parent 436be2c commit 2eda984
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/observe/flows.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ func newFlowsCmdHelper(usage cmdUsage, vp *viper.Viper, ofilter *flowFilter) *co
filterFlags.Var(filterVar(
"http-path", ofilter,
`Show only flows which match this HTTP path regular expressions (e.g. "/page/\\d+")`))
filterFlags.Var(filterVar(
"http-url", ofilter,
`Show only flows which match this HTTP URL regular expressions (e.g. "http://.*cilium\.io/page/\\d+")`))

filterFlags.Var(filterVar(
"trace-id", ofilter,
Expand Down
5 changes: 5 additions & 0 deletions cmd/observe/flows_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func newFlowFilter() *flowFilter {
{"http-status"},
{"http-method"},
{"http-path"},
{"http-url"},
{"protocol"},
{"port", "to-port"},
{"port", "from-port"},
Expand Down Expand Up @@ -435,6 +436,10 @@ func (of *flowFilter) set(f *filterTracker, name, val string, track bool) error
f.apply(func(f *flowpb.FlowFilter) {
f.HttpPath = append(f.HttpPath, val)
})
case "http-url":
f.apply(func(f *flowpb.FlowFilter) {
f.HttpUrl = append(f.HttpUrl, val)
})

case "type":
if wipe {
Expand Down
17 changes: 17 additions & 0 deletions cmd/observe/flows_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,3 +575,20 @@ func TestTrafficDirection(t *testing.T) {
})
}
}

func TestHTTPURL(t *testing.T) {
f := newFlowFilter()
cmd := newFlowsCmdWithFilter(viper.New(), f)

require.NoError(t, cmd.Flags().Parse([]string{"--http-url", `http://.*cilium\.io/foo`, "--http-url", `http://www\.cilium\.io/bar`}))
if diff := cmp.Diff(
[]*flowpb.FlowFilter{
{HttpUrl: []string{`http://.*cilium\.io/foo`, `http://www\.cilium\.io/bar`}},
},
f.whitelist.flowFilters(),
cmpopts.IgnoreUnexported(flowpb.FlowFilter{}),
); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
assert.Nil(t, f.blacklist)
}
1 change: 1 addition & 0 deletions cmd/observe_help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Filters Flags:
--http-method filter Show only flows which match this HTTP method (e.g. "get", "post")
--http-path filter Show only flows which match this HTTP path regular expressions (e.g. "/page/\\d+")
--http-status filter Show only flows which match this HTTP status code prefix (e.g. "404", "5+")
--http-url filter Show only flows which match this HTTP URL regular expressions (e.g. "http://.*cilium\.io/page/\\d+")
--identity filter Show all flows related to an endpoint with the given security identity
--ip filter Show all flows related to the given IP address. Each of the IPs can be specified as an exact match (e.g. '1.1.1.1') or as a CIDR range (e.g.'1.1.1.0/24').
--ip-version filter Show only IPv4, IPv6 flows or non IP flows (e.g. ARP packets) (ie: "none", "v4", "v6")
Expand Down

0 comments on commit 2eda984

Please sign in to comment.