@@ -13,6 +13,7 @@ import (
1313 "github.com/netobserv/network-observability-cli/e2e"
1414 g "github.com/onsi/ginkgo/v2"
1515 o "github.com/onsi/gomega"
16+ "github.com/onsi/gomega/types"
1617 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1718 "k8s.io/client-go/kubernetes"
1819
@@ -227,4 +228,60 @@ var _ = g.Describe("NetObserv CLI e2e integration test suite", g.Ordered, func()
227228 o .Expect (err ).NotTo (o .HaveOccurred (), fmt .Sprintf ("Failed to query Prometheus for metrics: %v" , err ))
228229 o .Expect (metricValue ).To (o .BeNumerically (">=" , 0 ), fmt .Sprintf ("Prometheus should return a valid metric value, but got %v" , metricValue ))
229230 })
231+ g .Describe ("OCP-84801: Verify CLI runs under correct privileges" , g .Label ("Privileges" ), func () {
232+
233+ tests := []struct {
234+ when string
235+ it string
236+ cliArgs []string
237+ matcher types.GomegaMatcher
238+ }{
239+ {
240+ when : "Executing `oc netobserv flows`" ,
241+ it : "does not run as privileged" ,
242+ cliArgs : []string {"flows" },
243+ matcher : o .BeFalse (),
244+ },
245+ {
246+ when : "Executing `oc netobserv flows --privileged=true`" ,
247+ it : "runs as privileged" ,
248+ cliArgs : []string {"flows" , "--privileged=true" },
249+ matcher : o .BeTrue (),
250+ },
251+
252+ {
253+ when : "Executing `oc netobserv flows --drops`" ,
254+ it : "runs as privileged" ,
255+ cliArgs : []string {"flows" , "--drops" },
256+ matcher : o .BeTrue (),
257+ },
258+ }
259+
260+ for _ , t := range tests {
261+ g .When (t .when , func () {
262+ g .It (t .it , func () {
263+ g .DeferCleanup (func () {
264+ cleanup ()
265+ })
266+ // run command async until done
267+ out , err := e2e .StartCommand (ilog , ocNetObservBinPath , t .cliArgs ... )
268+ writeOutput (StartupDate + "-flowOutput" , out )
269+ o .Expect (err ).NotTo (o .HaveOccurred (), fmt .Sprintf ("Error starting command %v" , err ))
270+
271+ // Wait for CLI to be ready
272+ daemonsetReady , err := isDaemonsetReady (clientset , "netobserv-cli" , cliNS )
273+ o .Expect (err ).NotTo (o .HaveOccurred (), "agent daemonset didn't come ready" )
274+ o .Expect (daemonsetReady ).To (o .BeTrue (), "agent daemonset didn't come ready" )
275+
276+ // Verify correct privilege setting
277+ ds , err := getDaemonSet (clientset , "netobserv-cli" , cliNS )
278+ o .Expect (err ).NotTo (o .HaveOccurred (), "DeamonSet should be created in CLI namespace" )
279+ containers := ds .Spec .Template .Spec .Containers
280+ o .Expect (len (containers )).To (o .Equal (1 ), "The number of containers specified in the template is != 1" )
281+ o .Expect (containers [0 ].SecurityContext .Privileged ).To (o .HaveValue (t .matcher ), "Priviledged is not set to true" )
282+ })
283+ })
284+
285+ }
286+ })
230287})
0 commit comments