-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1417 policy validations #1548
1417 policy validations #1548
Conversation
Signed-off-by: Kavitha Krishnan <[email protected]>
Signed-off-by: Kavitha Krishnan <[email protected]> Signed-off-by: Adam Shamblin <[email protected]> Signed-off-by: Kavitha Krishnan <[email protected]>
Signed-off-by: Adam Shamblin <[email protected]> Signed-off-by: Kavitha Krishnan <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #1548 +/- ##
==========================================
+ Coverage 26.49% 27.12% +0.63%
==========================================
Files 126 136 +10
Lines 7214 7686 +472
==========================================
+ Hits 1911 2085 +174
- Misses 5093 5374 +281
- Partials 210 227 +17
Continue to review full report at Codecov.
|
I'm just curious why the test run needed to be approved since it says first time contributor, but we got the other PR merged yesterday, so I don't understand why it blocked you again? 🤔 |
It didn't need approval to run when I was the author. Looks like Adam has to contribute a PR under his name to get the permission. The merged PR was under my name. |
apiVersion: admissionregistration.k8s.io/v1 | ||
kind: MutatingWebhookConfiguration | ||
metadata: | ||
creationTimestamp: null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I don't think we need this, or L34 below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, we don't need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, will remove it!
test/e2e_test_policy_crd.sh
Outdated
set -ex | ||
echo '::group:: invalid policy: both glob and regex' | ||
|
||
cat > policy.yaml <<EOF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we might want to create something like:
./test/testadata/success
./test/testdata/failure
directories and then create files there with names like:
./test/testdata/failure/both-glob-and-regex.yaml
./test/testdata/failure/key-with-multiple-properties.yaml
And then the both-glob-and-regex.yaml would look like:
# Invalid policy: both glob and regex
apiVersion: cosigned.sigstore.dev/v1alpha1
kind: ClusterImagePolicy
metadata:
name: image-policy
spec:
images:
- glob: image**
regex: image.*
authorities:
- key:
data: "---somedata---"
Then we could have a for loop for both directories and for failures they should fail, and for successes they
should be created. For success case, then we could also delete after created, so that we don't have to deal
with conflicting names.
Just thinking that having those files might make it easier then to add new tests in the future as well as have some example configurations that could also serve as documentation. They could also be used for testing the validations for the fields. Just a thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go with the proposed filenames under testdata, I'd suggest to add a cosigned
prefix to know where they are been used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. I will push them to new files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kkavitha I checked the code, the e2e_test_cosigned.sh
are failing to reject invalid pods because the cluster image policy has not been installed. We'll need to install so the tests are working again,
test/e2e_test_policy_crd.sh
Outdated
|
||
set -ex | ||
|
||
echo '::group:: invalid policy: both glob and regex' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesomesauce! So, if we don't hand code these files, but use a for loop here:
for i in `ls ./test/testdata/cosigned/invalid/`
do
if kubectl create -f ./test/testdata/cosigned/invalid/$i ; then
then
echo $i failed when it should not have
exit 1
else $i rejected as expected
done
Or something like that. Then if new files are added to .../invalid/ directory, then we don't have to modify this file at all.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that sounds good. Will make the change!
Signed-off-by: Kavitha Krishnan <[email protected]> Signed-off-by: Adam Shamblin <[email protected]>
Signed-off-by: Kavitha Krishnan <[email protected]>
Signed-off-by: Adam Shamblin <[email protected]> Signed-off-by: Kavitha Krishnan <[email protected]>
Signed-off-by: Adam Shamblin <[email protected]> Signed-off-by: Kavitha Krishnan <[email protected]>
3c965b2
to
53670c8
Compare
|
||
set -ex | ||
|
||
echo '::group:: Invalid policy tests:' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is missing its ::endgroup::
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
@kkavitha In addition to #1548 (comment), I saw the ValidationWebhookConfiguration is not set for the |
Signed-off-by: Adam Shamblin <[email protected]>
Signed-off-by: Kavitha Krishnan <[email protected]>
Signed-off-by: Adam Shamblin <[email protected]>
Signed-off-by: Kavitha Krishnan <[email protected]>
59c8c81
to
524dfc4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
identities: | ||
- issuer: "issue-details1" | ||
- key: | ||
data: "---some-key---" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created this:
#1581
to track tighter validations.
But let's get this in, it's a great starting point!
* Register webhook and add configuration Signed-off-by: Kavitha Krishnan <[email protected]> * Add validation tests for policy crd Signed-off-by: Kavitha Krishnan <[email protected]> Signed-off-by: Adam Shamblin <[email protected]> Signed-off-by: Kavitha Krishnan <[email protected]> * Update clusterrole;Add ko local for webhook Signed-off-by: Adam Shamblin <[email protected]> Signed-off-by: Kavitha Krishnan <[email protected]> * Add e2e tests for policy creation Signed-off-by: Kavitha Krishnan <[email protected]> Signed-off-by: Adam Shamblin <[email protected]> * Move testdata to a separate folder; Remove current timestamp proeprty Signed-off-by: Kavitha Krishnan <[email protected]> * Move crd tests to a different step Signed-off-by: Adam Shamblin <[email protected]> Signed-off-by: Kavitha Krishnan <[email protected]> * Refactor policy crd test script Signed-off-by: Adam Shamblin <[email protected]> Signed-off-by: Kavitha Krishnan <[email protected]> * Separate policy webhooks from cosigned webhooks Signed-off-by: Adam Shamblin <[email protected]> * Fix lint Signed-off-by: Kavitha Krishnan <[email protected]> * Remove unused var Signed-off-by: Adam Shamblin <[email protected]> * Add policy webhook secrets Signed-off-by: Kavitha Krishnan <[email protected]> Co-authored-by: Adam Shamblin <[email protected]>
Summary
Create a validation webhook for policy CRD and their tests
Fixes: #1417
cc: @hectorj2f @mattmoor @vaikas