-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
301 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package main | ||
|
||
type config struct { | ||
RekorServerURL string `yaml:"rekorServerURL"` | ||
RekorServerURL string `yaml:"rekorServerURL"` | ||
Policies []policy `yaml:"policies"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
rekorServerURL: https://rekor.sigstore.dev | ||
policies: | ||
- name: x509-used | ||
description: |- | ||
Alerts if any x509 type key is used | ||
body: | | ||
package auth | ||
default allow = false | ||
allow { | ||
format := input.spec.signature.format | ||
format != "x509" | ||
} | ||
- name: allow-all | ||
description: |- | ||
Alerts on all entries | ||
body: | | ||
package auth | ||
default allow = true | ||
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/nsmith5/rekor-sidekick/rekor" | ||
"github.com/open-policy-agent/opa/rego" | ||
) | ||
|
||
type policy struct { | ||
Name string | ||
Description string | ||
Body string | ||
} | ||
|
||
func (p policy) allowed(e rekor.LogEntry) (bool, error) { | ||
r := rego.New( | ||
rego.Query("data.auth.allow"), | ||
rego.Module(p.Name, p.Body), | ||
rego.Input(e), | ||
) | ||
rs, err := r.Eval(context.Background()) | ||
if err != nil { | ||
return false, err | ||
} | ||
return rs.Allowed(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/nsmith5/rekor-sidekick/rekor" | ||
) | ||
|
||
func TestPolicy(t *testing.T) { | ||
tests := map[policy]struct { | ||
Allow []rekor.LogEntry | ||
Deny []rekor.LogEntry | ||
}{ | ||
policy{ | ||
Name: `allow-all`, | ||
Description: ``, | ||
Body: "package auth\ndefault allow = true", | ||
}: { | ||
Allow: []rekor.LogEntry{ | ||
rekor.LogEntry{ | ||
"spec": map[string]interface{}{ | ||
"foo": "bar", | ||
}, | ||
}, | ||
rekor.LogEntry{}, | ||
}, | ||
Deny: []rekor.LogEntry{}, | ||
}, | ||
policy{ | ||
Name: `only x509 signature`, | ||
Description: ``, | ||
Body: `package auth | ||
default auth = false | ||
allow { | ||
format := input.spec.signature.format | ||
format == "x509" | ||
}`, | ||
}: { | ||
Allow: []rekor.LogEntry{ | ||
rekor.LogEntry{ | ||
"spec": map[string]interface{}{ | ||
"signature": map[string]interface{}{ | ||
"format": "x509", | ||
}, | ||
}, | ||
}, | ||
}, | ||
Deny: []rekor.LogEntry{ | ||
rekor.LogEntry{ | ||
"spec": map[string]interface{}{ | ||
"signature": map[string]interface{}{ | ||
"format": "minisign", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for p, data := range tests { | ||
t.Run(p.Name, func(t *testing.T) { | ||
for _, entry := range data.Allow { | ||
violation, err := p.allowed(entry) | ||
if err != nil { | ||
t.Errorf("policy %s failed to check allowed entry with error %s", p.Name, err) | ||
continue | ||
} | ||
if !violation { | ||
t.Errorf("policy %s denied entry which was expected to be allowed", p.Name) | ||
} | ||
|
||
} | ||
|
||
for _, entry := range data.Deny { | ||
violation, err := p.allowed(entry) | ||
if err != nil { | ||
t.Errorf("policy %s failed to check allowed entry with error %s", p.Name, err) | ||
continue | ||
} | ||
if violation { | ||
t.Errorf("policy %s allowed entry which was expected to be denied", p.Name) | ||
} | ||
|
||
} | ||
|
||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters