-
Notifications
You must be signed in to change notification settings - Fork 39
Modularize the generators #702
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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ed56a00
first step
shaobo-he-aws 8c86f23
make the generators driven by Cedar types instead of json schema types
shaobo-he-aws 87050e1
Merge remote-tracking branch 'origin/main' into feature/shaobo/real-t…
shaobo-he-aws 1cf26cf
removed commented functions
shaobo-he-aws 0c8bdf9
remove more functions
shaobo-he-aws 55ae913
fixes
shaobo-he-aws 33747a5
Merge remote-tracking branch 'origin/feature/shaobo/real-types' into …
shaobo-he-aws a1ffb83
updates
shaobo-he-aws b1905c1
simplify hierarchy generation
shaobo-he-aws 7e076d1
Merge remote-tracking branch 'origin/feature/shaobo/real-types' into …
shaobo-he-aws 3e383e1
first draft
shaobo-he-aws 40bf2d5
updates
shaobo-he-aws 2206218
request generation
shaobo-he-aws b6d313f
Merge remote-tracking branch 'origin/main' into feature/shaobo/modula…
shaobo-he-aws fce0a88
fixes
shaobo-he-aws 1ea3b85
Removed main file
shaobo-he-aws 580be70
review feedback
shaobo-he-aws File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| /* | ||
| * Copyright Cedar Contributors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #![no_main] | ||
| use cedar_drt::logger::initialize_log; | ||
|
|
||
| use cedar_drt_inner::{fuzz_target, schemas}; | ||
|
|
||
| use cedar_policy::{Authorizer, Entities, PolicySet, Schema}; | ||
| use std::str::FromStr; | ||
| use std::sync::LazyLock; | ||
|
|
||
| use cedar_policy_generators::{ | ||
| abac::ABACRequest, | ||
| err::Error, | ||
| hierarchy::HierarchyGenerator, | ||
| schema, | ||
| schema_gen::{SchemaGen, ValidatorSchema}, | ||
| settings::ABACSettings, | ||
| }; | ||
|
|
||
| use libfuzzer_sys::arbitrary::{self, Arbitrary, MaxRecursionReached, Unstructured}; | ||
| use log::debug; | ||
| use std::convert::TryFrom; | ||
|
|
||
| /// Input expected by this fuzz target: | ||
| /// An ABAC hierarchy and 8 associated requests | ||
| #[derive(Debug, Clone)] | ||
| pub struct FuzzTargetInput { | ||
| /// generated entity slice | ||
| pub entities: Entities, | ||
| /// the requests to try for this hierarchy and policy. We try 8 requests per | ||
| /// policy/hierarchy | ||
| pub requests: [ABACRequest; 8], | ||
| } | ||
|
|
||
| static SCHEMA: LazyLock<Schema> = LazyLock::new(|| { | ||
| let schema_file = | ||
| std::env::var("CEDAR_SCHEMA_FILE").expect("CEDAR_SCHEMA_FILE environment variable not set"); | ||
| let schema_content = std::fs::read_to_string(schema_file).expect("Failed to read schema file"); | ||
| Schema::from_str(&schema_content).expect("Failed to parse schema") | ||
| }); | ||
|
|
||
| static POLICY_SET: LazyLock<PolicySet> = LazyLock::new(|| { | ||
| let policy_file = | ||
| std::env::var("CEDAR_POLICY_FILE").expect("CEDAR_POLICY_FILE environment variable not set"); | ||
| let policy_content = std::fs::read_to_string(policy_file).expect("Failed to read policy file"); | ||
| PolicySet::from_str(&policy_content).expect("Failed to parse policy set") | ||
| }); | ||
|
|
||
| /// settings for this fuzz target | ||
| /// settings for this fuzz target | ||
| const SETTINGS: ABACSettings = ABACSettings { | ||
| enable_additional_attributes: true, | ||
| ..ABACSettings::type_directed() | ||
| }; | ||
|
|
||
| impl<'a> Arbitrary<'a> for FuzzTargetInput { | ||
| fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> { | ||
| let schema: ValidatorSchema = ValidatorSchema::new(SCHEMA.as_ref(), &SETTINGS, u)?; | ||
| let hierarchy = schema.arbitrary_hierarchy(u)?; | ||
|
|
||
| let requests = [ | ||
| schema.arbitrary_request(&hierarchy, u)?, | ||
| schema.arbitrary_request(&hierarchy, u)?, | ||
| schema.arbitrary_request(&hierarchy, u)?, | ||
| schema.arbitrary_request(&hierarchy, u)?, | ||
| schema.arbitrary_request(&hierarchy, u)?, | ||
| schema.arbitrary_request(&hierarchy, u)?, | ||
| schema.arbitrary_request(&hierarchy, u)?, | ||
| schema.arbitrary_request(&hierarchy, u)?, | ||
| ]; | ||
| let entities = Entities::try_from(hierarchy).map_err(|_| Error::NotEnoughData)?; | ||
| let entities = schemas::add_actions_to_entities(&SCHEMA, entities)?; | ||
| Ok(Self { entities, requests }) | ||
| } | ||
|
|
||
| fn try_size_hint( | ||
| depth: usize, | ||
| ) -> std::result::Result<(usize, Option<usize>), MaxRecursionReached> { | ||
| Ok(arbitrary::size_hint::and_all(&[ | ||
| HierarchyGenerator::size_hint(depth), | ||
| schema::Schema::arbitrary_request_size_hint(depth), | ||
| schema::Schema::arbitrary_request_size_hint(depth), | ||
| schema::Schema::arbitrary_request_size_hint(depth), | ||
| schema::Schema::arbitrary_request_size_hint(depth), | ||
| schema::Schema::arbitrary_request_size_hint(depth), | ||
| schema::Schema::arbitrary_request_size_hint(depth), | ||
| schema::Schema::arbitrary_request_size_hint(depth), | ||
| schema::Schema::arbitrary_request_size_hint(depth), | ||
| ])) | ||
| } | ||
| } | ||
|
|
||
| // Type-directed fuzzing of ABAC hierarchy/policy/requests. | ||
| fuzz_target!(|input: FuzzTargetInput| { | ||
| initialize_log(); | ||
|
|
||
| let requests = input | ||
| .requests | ||
| .into_iter() | ||
| .map(Into::into) | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| let entities = input.entities.into(); | ||
|
|
||
| for request in requests.iter() { | ||
| debug!("Request : {request}"); | ||
|
|
||
| let authorizer = Authorizer::new(); | ||
| authorizer.is_authorized(request, &*POLICY_SET, &entities); | ||
| } | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.