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

genpolicy: Update oci_distribution to 0.10.0 #129

Merged
merged 2 commits into from
Dec 21, 2023
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
2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/configmap/pod-cm1.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/configmap/pod-cm2.yaml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/job/test-job.yaml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/pod/pod-exec.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/pod/pod-lifecycle.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/pod/pod-one-container.yaml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/pod/pod-spark.yaml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions src/agent/samples/policy/yaml/pod/pod-ubuntu.yaml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/stateful-set/web.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/webhook/webhook-pod1.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/webhook/webhook-pod2.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/webhook/webhook-pod3.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/webhook/webhook-pod4.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/webhook/webhook-pod5.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/webhook/webhook-pod6.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/webhook/webhook-pod7.yaml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/webhook2/webhook-pod8.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/webhook2/webhook-pod9.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/webhook3/dns-test.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/agent/samples/policy/yaml/webhook3/many-layers.yaml

Large diffs are not rendered by default.

108 changes: 75 additions & 33 deletions src/tools/genpolicy/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/tools/genpolicy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ anyhow = "1.0.32"
async-trait = "0.1.68"
docker_credential = "1.2.0"
flate2 = { version = "1.0.26", features = ["zlib-ng"], default-features = false }
oci-distribution = { version = "0.9.4" }
oci-distribution = { version = "0.10.0" }
openssl = { version = "0.10.54", features = ["vendored"] }
serde_ignored = "0.1.7"
serde_json = "1.0.39"
Expand Down
1 change: 1 addition & 0 deletions src/tools/genpolicy/genpolicy-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
"regex": []
},
"ReadStreamRequest": true,
"UpdateEphemeralMountsRequest": false,
"WriteStreamRequest": false
}
}
2 changes: 2 additions & 0 deletions src/tools/genpolicy/policy_samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"deployment/deployment-azure-vote-back.yaml",
"deployment/deployment-azure-vote-front.yaml",
"deployment/deployment-busybox.yaml",
"deployment/deployment-docker-busybox.yaml",
"job/test-job.yaml",
"kubernetes/conformance/conformance-e2e.yaml",
"kubernetes/conformance/csi-hostpath-plugin.yaml",
Expand Down Expand Up @@ -37,6 +38,7 @@
"pod/pod-same-containers.yaml",
"pod/pod-spark.yaml",
"pod/pod-three-containers.yaml",
"pod/pod-ubuntu.yaml",
"replica-set/replica-busy.yaml",
"secrets/azure-file-secrets.yaml",
"stateful-set/web.yaml"
Expand Down
6 changes: 5 additions & 1 deletion src/tools/genpolicy/rules.rego
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ default SignalProcessRequest := true
default StartContainerRequest := true
default StatsContainerRequest := true
default TtyWinResizeRequest := true
default UpdateEphemeralMountsRequest := true
default UpdateEphemeralMountsRequest := false
default UpdateInterfaceRequest := true
default UpdateRoutesRequest := true
default WaitProcessRequest := true
Expand Down Expand Up @@ -1115,6 +1115,10 @@ ReadStreamRequest {
policy_data.request_defaults.ReadStreamRequest == true
}

UpdateEphemeralMountsRequest {
policy_data.request_defaults.UpdateEphemeralMountsRequest == true
}

WriteStreamRequest {
policy_data.request_defaults.WriteStreamRequest == true
}
3 changes: 3 additions & 0 deletions src/tools/genpolicy/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ pub struct RequestDefaults {
/// Allow Host reading from Guest containers stdout and stderr.
pub ReadStreamRequest: bool,

/// Allow Host to update Guest mounts.
pub UpdateEphemeralMountsRequest: bool,

/// Allow Host writing to Guest containers stdin.
pub WriteStreamRequest: bool,
}
Expand Down
30 changes: 10 additions & 20 deletions src/tools/genpolicy/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ use crate::verity;

use anyhow::{anyhow, Result};
use docker_credential::{CredentialRetrievalError, DockerCredential};
use fs2::FileExt;
use log::warn;
use log::{debug, info, LevelFilter};
use oci_distribution::client::{linux_amd64_resolver, ClientConfig};
use oci_distribution::{manifest, secrets::RegistryAuth, Client, Reference};
use serde::{Deserialize, Serialize};
use sha2::{digest::typenum::Unsigned, digest::OutputSizeUser, Sha256};
use std::{io, io::Seek, io::Write, path::Path};
use tokio::{io::AsyncWriteExt};
use std::io::{BufWriter};
use std::fs::OpenOptions;
use fs2::FileExt;

use std::io::BufWriter;
use std::{io, io::Seek, io::Write, path::Path};
use tokio::io::AsyncWriteExt;

/// Container image properties obtained from an OCI repository.
#[derive(Clone, Debug, Default)]
Expand Down Expand Up @@ -233,6 +232,7 @@ async fn get_image_layers(
if layer
.media_type
.eq(manifest::IMAGE_DOCKER_LAYER_GZIP_MEDIA_TYPE)
|| layer.media_type.eq(manifest::IMAGE_LAYER_GZIP_MEDIA_TYPE)
{
if layer_index < config_layer.rootfs.diff_ids.len() {
layers.push(ImageLayer {
Expand Down Expand Up @@ -297,9 +297,7 @@ async fn get_verity_hash(
)
.await
{
error_message = format!(
"Failed to create verity hash for {layer_digest}, error {e}"
);
error_message = format!("Failed to create verity hash for {layer_digest}, error {e}");
error = true
};

Expand Down Expand Up @@ -332,11 +330,7 @@ async fn get_verity_hash(
}

// the store is a json file that matches layer hashes to verity hashes
fn add_verity_to_store(
cache_file: &str,
diff_id: &str,
verity_hash: &str,
) -> Result<()> {
fn add_verity_to_store(cache_file: &str, diff_id: &str, verity_hash: &str) -> Result<()> {
// open the json file in read mode, create it if it doesn't exist
let read_file = OpenOptions::new()
.read(true)
Expand All @@ -352,7 +346,7 @@ fn add_verity_to_store(
};

// Add new data to the deserialized JSON
data.push(ImageLayer{
data.push(ImageLayer {
diff_id: diff_id.to_string(),
verity_hash: verity_hash.to_string(),
});
Expand All @@ -361,9 +355,7 @@ fn add_verity_to_store(
let serialized = serde_json::to_string_pretty(&data)?;

// Open the JSON file to write
let file = OpenOptions::new()
.write(true)
.open(cache_file)?;
let file = OpenOptions::new().write(true).open(cache_file)?;

// try to lock the file, if it fails, get the error
let result = file.try_lock_exclusive();
Expand All @@ -387,9 +379,7 @@ fn read_verity_from_store(cache_file: &str, diff_id: &str) -> Result<String> {
return Ok("".to_string());
}

let file = OpenOptions::new()
.read(true)
.open(cache_file)?;
let file = OpenOptions::new().read(true).open(cache_file)?;

// If the file is empty, return empty string
if file.metadata()?.len() == 0 {
Expand Down
Loading