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

Generate a canonical coordinator resource #141

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,32 @@ rec {
exit 1
'';
};

# write-coordinator-yaml prints a Nunki Coordinator deployment including the default policy.
# It's intended for two purposes: (1) releasing a portable coordinator.yaml and (2) updating the embedded policy hash.
write-coordinator-yaml = writeShellApplication {
name = "print-coordinator-policy";
runtimeInputs = [
yq-go
genpolicy
];
text = ''
imageRef=$1:v${version}
tmpdir=$(mktemp -d)
trap 'rm -rf $tmpdir' EXIT
# TODO(burgerdev): consider a dedicated coordinator template instead of the simple one
yq < deployments/simple/coordinator.yml > "$tmpdir/coordinator.yml" \
"del(.metadata.namespace) | (select(.kind == \"Deployment\") | .spec.template.spec.containers[0].image) = \"$imageRef\""
pushd "$tmpdir" >/dev/null
# TODO(burgerdev): this should not be dev, but there are unknown env vars
cp ${genpolicy.settings-dev}/genpolicy-settings.json .
cp ${genpolicy.rules-coordinator}/genpolicy-rules.rego rules.rego
genpolicy < "$tmpdir/coordinator.yml"
popd >/dev/null
'';
};

}
5 changes: 5 additions & 0 deletions packages/genpolicy_msft.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ rustPlatform.buildRustPackage rec {
recursiveHash = true;
postFetch = "install -D $downloadedFile $out/genpolicy-rules.rego";
};

rules-coordinator = applyPatches {
src = rules;
patches = [ ./genpolicy_msft_rules_coordinator.patch ];
};
};

meta = {
Expand Down
15 changes: 15 additions & 0 deletions packages/genpolicy_msft_rules_coordinator.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/genpolicy-rules.rego b/genpolicy-rules.rego
index e1954e9..fb508bc 100644
--- a/genpolicy-rules.rego
+++ b/genpolicy-rules.rego
@@ -137,9 +137,9 @@ allow_by_sandbox_name(p_oci, i_oci, p_storages, i_storages, s_name) {
p_namespace := p_oci.Annotations[s_namespace]
i_namespace := i_oci.Annotations[s_namespace]
print("allow_by_sandbox_name: p_namespace =", p_namespace, "i_namespace =", i_namespace)
- p_namespace == i_namespace
+ regex.match("^[a-z0-9-]{1,63}$", i_namespace)

- allow_by_container_types(p_oci, i_oci, s_name, p_namespace)
+ allow_by_container_types(p_oci, i_oci, s_name, i_namespace)
allow_by_bundle_or_sandbox_id(p_oci, i_oci, p_storages, i_storages)
allow_process(p_oci, i_oci, s_name)
Loading