Skip to content
Merged
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
30 changes: 4 additions & 26 deletions policy-controller/runtime/src/admission.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::validation;
use crate::k8s::policy::{
httproute, AuthorizationPolicy, AuthorizationPolicySpec, EgressNetwork, EgressNetworkSpec,
HttpLocalRateLimitPolicy, HttpRoute, HttpRouteSpec, LocalTargetRef, MeshTLSAuthentication,
HttpLocalRateLimitPolicy, HttpRoute, HttpRouteSpec, MeshTLSAuthentication,
MeshTLSAuthenticationSpec, NamespacedTargetRef, Network, NetworkAuthentication,
NetworkAuthenticationSpec, RateLimitPolicySpec, Server, ServerAuthorization,
ServerAuthorizationSpec, ServerSpec,
Expand Down Expand Up @@ -228,30 +228,6 @@ fn parse_spec<T: DeserializeOwned>(req: AdmissionRequest) -> Result<(DynamicObje
Ok((obj, spec))
}

/// Validates the target of an `AuthorizationPolicy`.
fn validate_policy_target(ns: &str, tgt: &LocalTargetRef) -> Result<()> {
if tgt.targets_kind::<Server>() {
return Ok(());
}

if tgt.targets_kind::<HttpRoute>() {
return Ok(());
}

if tgt.targets_kind::<gateway::GRPCRoute>() {
return Ok(());
}

if tgt.targets_kind::<Namespace>() {
if tgt.name != ns {
bail!("cannot target another namespace: {}", tgt.name);
}
return Ok(());
}

bail!("invalid targetRef kind: {}", tgt.canonical_kind());
}

#[async_trait::async_trait]
impl Validate<AuthorizationPolicySpec> for Admission {
async fn validate(
Expand All @@ -261,7 +237,9 @@ impl Validate<AuthorizationPolicySpec> for Admission {
_annotations: &BTreeMap<String, String>,
spec: AuthorizationPolicySpec,
) -> Result<()> {
validate_policy_target(ns, &spec.target_ref)?;
if spec.target_ref.targets_kind::<Namespace>() && spec.target_ref.name != ns {
bail!("cannot target another namespace: {}", &spec.target_ref.name);
}

let mtls_authns_count = spec
.required_authentication_refs
Expand Down