Files
kata-containers/src/tools/genpolicy/src/no_policy.rs
Dan Mihai 48829120b6 policy: initial genpolicy commit
Add application that infers K8s user's intentions based on user's
K8s YAML file, and generates a Rego/OPA based policy for that YAML.

Just Pod YAML files are supported as input using this initial source
code. Support for other types of YAML files will come with upcoming
commits.

Fixes: #7673

Signed-off-by: Dan Mihai <dmihai@microsoft.com>
2023-12-22 15:35:05 +00:00

71 lines
1.5 KiB
Rust

// Copyright (c) 2023 Microsoft Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
// Allow K8s YAML field names.
#![allow(non_snake_case)]
use crate::pod;
use crate::policy;
use crate::settings;
use crate::yaml;
use async_trait::async_trait;
use protocols::agent;
use std::collections::BTreeMap;
#[derive(Clone, Debug)]
pub struct NoPolicyResource {
pub yaml: String,
}
#[async_trait]
impl yaml::K8sResource for NoPolicyResource {
async fn init(
&mut self,
_use_cache: bool,
_doc_mapping: &serde_yaml::Value,
_silent_unsupported_fields: bool,
) {
}
fn get_sandbox_name(&self) -> Option<String> {
panic!("Unsupported");
}
fn get_namespace(&self) -> String {
panic!("Unsupported");
}
fn get_container_mounts_and_storages(
&self,
_policy_mounts: &mut Vec<policy::KataMount>,
_storages: &mut Vec<agent::Storage>,
_container: &pod::Container,
_settings: &settings::Settings,
) {
panic!("Unsupported");
}
fn generate_policy(&self, _agent_policy: &policy::AgentPolicy) -> String {
return "".to_string();
}
fn serialize(&mut self, _policy: &str) -> String {
self.yaml.clone()
}
fn get_containers(&self) -> &Vec<pod::Container> {
panic!("Unsupported");
}
fn get_annotations(&self) -> &Option<BTreeMap<String, String>> {
panic!("Unsupported");
}
fn use_host_network(&self) -> bool {
panic!("Unsupported");
}
}