Skip to content
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

Add policy init and reconcile policy support for artifacts #844

Merged
merged 6 commits into from
Sep 5, 2023

Conversation

jhrozek
Copy link
Contributor

@jhrozek jhrozek commented Sep 4, 2023

The PR contains some fixes, removing one unused field from the Artifact protobuf
struct or renaming an ambiguous field in the same struct. The core of the PR
is evaluating policies on policy init for artifacts and on reconcile so that we
get a policy result at the time when the policy is instantiated or when the repo
is registered.

Also some small fixes that I found while testing the latest refactor.

Fixes: #804

@@ -44,14 +44,14 @@ SELECT * FROM artifact_versions WHERE artifact_id = $1 AND sha = $2;
SELECT * FROM artifact_versions
WHERE artifact_id = $1
ORDER BY created_at DESC
LIMIT $2;
LIMIT COALESCE(sqlc.narg('limit')::int, 2147483647);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yrobla I wasn't able to force sqlc to accept an NULL argument here without the COALESCE. I was trying to just use LIMIT sqlc::narg('limit') here because Postgres uses NULL value in limit as "no limit", but sqlc wasn't just generating the query parameter at all unless I coalesced it. Have you run into a similar issue earlier?

internal/engine/reconciler.go Outdated Show resolved Hide resolved
internal/engine/executor.go Outdated Show resolved Hide resolved
internal/engine/executor.go Outdated Show resolved Hide resolved
@jhrozek
Copy link
Contributor Author

jhrozek commented Sep 5, 2023

This needs to be rebased atop #841 (already done locally, the rebase just needs to be pushed)

In some cases, like evaluating all results, we want to really list all
the versions, but our API expected a limit. Rather than letting the user
pass in a large enough number, let's let them pass NULL and get all the
artifacts.
The field was not used anywhere and I'm not sure if it's actually useful
for the clients. Let's remove it.
On artifact reconcile, call the policy evaluation so that artifacts would get
evaluated against policies right when a repo is registered with mediator.
Call policy evaluation on artifacts, too, so that when an artifact
policy is created after a repo is enrolled and after the initial
reconcile, we still get the policy evaluation result.

Fixes: #599
…tect bugs

The code was mixing up artifactr ID coming from GH with the primary key
of the database rows. Let's rename the artifact to avoid such bugs in
the future.
@JAORMX JAORMX merged commit 823279b into mindersec:main Sep 5, 2023
13 checks passed
@JAORMX JAORMX deleted the artifact_init_reconcile branch September 5, 2023 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants