Skip to content

Commit 912fdfb

Browse files
committed
Changed Default output: OPA is the default output.
1 parent e3e1dd5 commit 912fdfb

File tree

6 files changed

+18
-9
lines changed

6 files changed

+18
-9
lines changed

advisor/advisor.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package advisor
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/open-policy-agent/opa/ast"
76
"os"
87

8+
"github.com/open-policy-agent/opa/ast"
9+
910
"github.com/sysdiglabs/kube-policy-advisor/advisor/types"
1011

1112
"github.com/sysdiglabs/kube-policy-advisor/advisor/processor"

advisor/processor/generate.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package processor
22

33
import (
44
"fmt"
5-
"github.com/open-policy-agent/opa/ast"
65
"sort"
76
"strings"
87

8+
"github.com/open-policy-agent/opa/ast"
9+
910
"github.com/sysdiglabs/kube-policy-advisor/advisor/report"
1011
"github.com/sysdiglabs/kube-policy-advisor/advisor/types"
1112
"github.com/sysdiglabs/kube-policy-advisor/generator"

generator/generator.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
"github.com/open-policy-agent/opa/ast"
87
"io/ioutil"
98
"log"
109
"os"
1110
"path/filepath"
1211
"strconv"
1312

13+
"github.com/open-policy-agent/opa/ast"
14+
1415
"k8s.io/client-go/kubernetes/scheme"
1516

1617
"github.com/ghodss/yaml"
@@ -902,7 +903,7 @@ func (pg *Generator) GenerateOPAWithName(
902903

903904
mod.Rules = append(mod.Rules, valueSecContextRule)
904905

905-
rule.Body.Append(ast.MustParseExpr("message := sprintf(\"Workflow or pod compliant with the policy.\", [workload.metadata.name])"))
906+
rule.Body.Append(ast.MustParseExpr("message := sprintf(\"Workflow or pod not compliant with the security policy.\", [workload.metadata.name])"))
906907
mod.Package = pack
907908
mod.Rules = append(mod.Rules, &rule)
908909

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/open-policy-agent/opa v0.32.1
1414
github.com/sirupsen/logrus v1.8.1
1515
github.com/spf13/cobra v1.2.1
16+
golang.org/x/tools v0.1.6 // indirect
1617
gopkg.in/inf.v0 v0.9.0 // indirect
1718
k8s.io/api v0.0.0-20190816222004-e3a6b8045b0b
1819
k8s.io/apimachinery v0.0.0-20190816221834-a9f1d8a9c101

go.sum

+5
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
546546
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
547547
github.com/yuin/goldmark v1.3.5 h1:dPmz1Snjq0kmkz159iL7S6WzdahUTHnHB5M56WFVifs=
548548
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
549+
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
549550
go.etcd.io/etcd/api/v3 v3.5.0 h1:GsV3S+OfZEOCNXdtNkBSR7kgLobAa/SO6tCxRa0GAYw=
550551
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
551552
go.etcd.io/etcd/client/pkg/v3 v3.5.0 h1:2aQv6F436YnN7I4VbI8PPYrBhu+SmrTaADcf8Mi/6PU=
@@ -661,6 +662,7 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
661662
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
662663
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
663664
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
665+
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
664666
golang.org/x/net v0.0.0-20210825183410-e898025ed96a h1:bRuuGXV8wwSdGTB+CtJf+FjgO1APK1CoO39T4BN/XBw=
665667
golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
666668
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -743,6 +745,7 @@ golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7w
743745
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
744746
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
745747
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
748+
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
746749
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf h1:2ucpDCmfkl8Bd/FsLtiD653Wf96cW37s+iGx93zsu4k=
747750
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
748751
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
@@ -817,6 +820,8 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f
817820
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
818821
golang.org/x/tools v0.1.2 h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA=
819822
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
823+
golang.org/x/tools v0.1.6 h1:SIasE1FVIQOWz2GEAHFOmoW7xchJcqlucjSULTL0Ag4=
824+
golang.org/x/tools v0.1.6/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
820825
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
821826
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
822827
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

kube-policy-advisor.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func convert(podObjFilename string, pspFilename string, OPAformat string, OPAdef
8888

8989
err = ioutil.WriteFile(pspFilename, []byte(pspString), 0644)
9090

91-
log.Infof("Wrote generated psp to %s", pspFilename)
91+
log.Infof("Wrote generated policy to %s", pspFilename)
9292

9393
return nil
9494
}
@@ -168,8 +168,8 @@ func main() {
168168

169169
var inspectCmd = &cobra.Command{
170170
Use: "inspect",
171-
Short: "Inspect a live K8s Environment to generate a PodSecurityPolicy",
172-
Long: "Fetch all objects in the provided namespace to generate a Pod Security Policy",
171+
Short: "Inspect a live K8s Environment to generate an OPA Policy (default) or a Pod Security Policy",
172+
Long: "Fetch all objects in the provided namespace to generate an OPA Policy (default) or a Pod Security Policy",
173173
Run: func(cmd *cobra.Command, args []string) {
174174

175175
err := inspect(kubeconfig, namespace, excludeNamespaces, withReport, withGrant, OPAformat, OPAdefaultRule)
@@ -182,8 +182,8 @@ func main() {
182182

183183
var convertCmd = &cobra.Command{
184184
Use: "convert",
185-
Short: "Generate a PodSecurityPolicy from a single K8s Yaml file",
186-
Long: "Generate a PodSecurityPolicy from a single K8s Yaml file containing a pod Spec e.g. DaemonSet, Deployment, ReplicaSet, StatefulSet, ReplicationController, CronJob, Job, or Pod",
185+
Short: "Generate an OPA Policy (default) or a Pod Security Policy from a single K8s Yaml file",
186+
Long: "Generate an OPA Policy (default) or a Pod Security Policy from a single K8s Yaml file containing a pod Spec e.g. DaemonSet, Deployment, ReplicaSet, StatefulSet, ReplicationController, CronJob, Job, or Pod",
187187
PreRun: func(cmd *cobra.Command, args []string) {
188188
if podObjFilename == "" {
189189
log.Fatalf("--podFile must be provided")

0 commit comments

Comments
 (0)