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

feat(jans-cedarling): implement CEDARLING_ID_TOKEN_TRUST_MODE #10585

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
4 changes: 4 additions & 0 deletions jans-cedarling/bindings/cedarling_python/PYTHON_TYPES.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ ___
Error encountered while parsing all entities to json for logging
___

# authorize_errors.IdTokenTrustModeError
Error encountered while running on strict id token trust mode
___

# authorize_errors.ProcessTokens
Error encountered while processing JWT token data
___
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ create_exception!(
"Error encountered while parsing all entities to json for logging"
);

create_exception!(
authorize_errors,
IdTokenTrustModeError,
AuthorizeError,
"Error encountered while running on strict id token trust mode"
);

create_exception!(
authorize_errors,
AddEntitiesIntoContextError,
Expand Down Expand Up @@ -179,7 +186,8 @@ errors_functions! {
UserRequestValidation => UserRequestValidationError,
BuildContext => AddEntitiesIntoContextError,
Entities => EntitiesError,
EntitiesToJson => EntitiesToJsonError
EntitiesToJson => EntitiesToJsonError,
IdTokenTrustMode => IdTokenTrustModeError
}

pub fn authorize_errors_module(m: &Bound<'_, PyModule>) -> PyResult<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
//
// Copyright (c) 2024, Gluu, Inc.

use std::collections::{HashMap, HashSet};

use cedarling::{
AuthorizationConfig, BootstrapConfig, Cedarling, IdTokenTrustMode, JwtConfig, LogConfig,
LogLevel, LogTypeConfig, PolicyStoreConfig, PolicyStoreSource, Request, ResourceData,
TokenValidationConfig, Tokens, WorkloadBoolOp,
AuthorizationConfig, BootstrapConfig, Cedarling, JwtConfig, LogConfig, LogLevel, LogTypeConfig,
PolicyStoreConfig, PolicyStoreSource, Request, ResourceData, TokenValidationConfig, Tokens,
WorkloadBoolOp,
};
use jsonwebtoken::Algorithm;
use std::collections::{HashMap, HashSet};

static POLICY_STORE_RAW_YAML: &str =
include_str!("../../test_files/policy-store_with_trusted_issuers_ok.yaml");
Expand All @@ -23,7 +22,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
jwks: None,
jwt_sig_validation: true,
jwt_status_validation: false,
id_token_trust_mode: IdTokenTrustMode::None,
signature_algorithms_supported: HashSet::from_iter([Algorithm::HS256, Algorithm::RS256]),
access_token_config: TokenValidationConfig::access_token(),
id_token_config: TokenValidationConfig::id_token(),
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed in a7a888e

Empty file.
10 changes: 10 additions & 0 deletions jans-cedarling/cedarling/src/authz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::io::Cursor;
use std::str::FromStr;
use std::sync::Arc;

use crate::authorization_config::IdTokenTrustMode;
use crate::bootstrap_config::AuthorizationConfig;
use crate::common::app_types;
use crate::common::cedar_schema::cedar_json::{BuildJsonCtxError, FindActionError};
Expand All @@ -26,6 +27,7 @@ use crate::log::{

mod authorize_result;
mod merge_json;
mod trust_mode;

pub(crate) mod entities;
pub(crate) mod request;
Expand All @@ -42,6 +44,7 @@ use entities::{
use merge_json::{merge_json_values, MergeError};
use request::Request;
use serde_json::Value;
use trust_mode::*;

/// Configuration to Authz to initialize service without errors
pub(crate) struct AuthzConfig {
Expand Down Expand Up @@ -124,6 +127,10 @@ impl Authz {
let schema = &self.config.policy_store.schema;
let tokens = self.decode_tokens(&request)?;

if let IdTokenTrustMode::Strict = self.config.authorization.id_token_trust_mode {
enforce_id_tkn_trust_mode(&tokens)?;
}

// Parse action UID.
let action = cedar_policy::EntityUid::from_str(request.action.as_str())
.map_err(AuthorizeError::Action)?;
Expand Down Expand Up @@ -552,6 +559,9 @@ pub enum AuthorizeError {
/// Error encountered while building the context for the request
#[error("Failed to build context: {0}")]
BuildContext(#[from] BuildContextError),
/// Error encountered while building the context for the request
#[error("error while running on strict id token trust mode: {0}")]
IdTokenTrustMode(#[from] IdTokenTrustModeError),
}

#[derive(Debug, thiserror::Error)]
Expand Down
Loading
Loading