Skip to content

Commit c7bcce2

Browse files
joshfried-awsakshayraneAkshay Ranerazcloudbenbridts
authored
3.0.0 (#382)
* bumping up to 3.0.0-alpha (#347) * bumping up to 3.0.0 alpha * typo * updating workflow * Populated filename in the output (#358) * Populated filename in the output * Changed FileData into DataFile and handle error differently * Refactored to use existing DataFile struct --------- Co-authored-by: Akshay Rane <[email protected]> * Support for some function expressions / stateful rules (#361) * init commit for function resolution / stateful rules * more tests + making test rules better * fixed bugs with validation of functions * small cleanup * fixes as per comments * cleanup * add todo * typos * fixed logical error breaking tests * added test for test command with a function * fixed unit test * added comment to clearly explain whats happening in regex_replace cause no one actually understands regex * Combined structured output and updated default rule clause name to include file name (#360) * Populated filename in the output * Structured combine * Changed FileData into DataFile and handle error differently * Resolved lifetime issue with FileReport combine method * Updated status and method * Refactored to use existing DataFile struct * Changed FileData into DataFile and handle error differently * Refactored to use existing DataFile struct * Merged file report * Interim commit for structured * Resolved unit tests * Temporary commit for default rule names * Working prototype for formatting issue --------- Co-authored-by: Akshay Rane <[email protected]> * Clap Autocompletions (#340) * temp * fixing commands * cleanup * temp * cleanup * adding valuehints * adding valuehints * removed powershell * cleanup * removing derive * removed unecessary ArgActions * bumping up version * refactor to use a function to generate commands * removing unused imports * removed random println * updating readme * fixes * typo * cleanup * typo * adding documentation for functions (#362) * adding documentation for functions * Combined structured output and updated default rule clause name to include file name (#360) * Populated filename in the output * Structured combine * Changed FileData into DataFile and handle error differently * Resolved lifetime issue with FileReport combine method * Updated status and method * Refactored to use existing DataFile struct * Changed FileData into DataFile and handle error differently * Refactored to use existing DataFile struct * Merged file report * Interim commit for structured * Resolved unit tests * Temporary commit for default rule names * Working prototype for formatting issue --------- Co-authored-by: Akshay Rane <[email protected]> * clarifying docs --------- Co-authored-by: Akshay Rane <[email protected]> Co-authored-by: Akshay Rane <[email protected]> * Deprecated migrate and previous engine (#364) * Deprecated migrate and previous engine * Removed a unit test for old engine --------- Co-authored-by: Akshay Rane <[email protected]> * 3.0.0 beta release changes (#365) * Bump up version to 3.0.0-beta * Updated README.md * Add instances to rules integration tests (#351) * Added 2 runners to integration tests for rules registry * Fixed indent * Added explicit shell name * Moved shell to job parameters * Added powershell commands for windows * Removed test branch * Updated README.md (#352) * Updated README for Guard 3.0 * Update README.md Co-authored-by: Ben Bridts <[email protected]> --------- Co-authored-by: Ben Bridts <[email protected]> --------- Co-authored-by: Akshay Rane <[email protected]> Co-authored-by: razcloud <[email protected]> Co-authored-by: Ben Bridts <[email protected]> * feat: Add cfn-guard-lambda deployment with SAM CLI (#354) * feat: Add cfn-guard-lambda deployment with SAM CLI * Renamed the logical ID for lambda in template & updated README.md * Updated the instructions and added least privileged IAM access policy --------- Co-authored-by: Ben Bridts <[email protected]> Co-authored-by: Akshay Rane <[email protected]> * Revert "Added deprecated short flag for print-json in parse-tree" This reverts commit 93548a4 * Updated names of binaries to reflect v3 * Updated README.md to add new features * Added rogue_one branch to docker workflow * Bump enumflags2 to 0.7.7 --------- Co-authored-by: Akshay Rane <[email protected]> Co-authored-by: razcloud <[email protected]> Co-authored-by: Ben Bridts <[email protected]> Co-authored-by: Ben Bridts <[email protected]> * 3.0.0 Beta release (#366) (#369) * bumping up to 3.0.0-alpha (#347) * bumping up to 3.0.0 alpha * typo * updating workflow * Populated filename in the output (#358) * Populated filename in the output * Changed FileData into DataFile and handle error differently * Refactored to use existing DataFile struct --------- * Support for some function expressions / stateful rules (#361) * init commit for function resolution / stateful rules * more tests + making test rules better * fixed bugs with validation of functions * small cleanup * fixes as per comments * cleanup * add todo * typos * fixed logical error breaking tests * added test for test command with a function * fixed unit test * added comment to clearly explain whats happening in regex_replace cause no one actually understands regex * Combined structured output and updated default rule clause name to include file name (#360) * Populated filename in the output * Structured combine * Changed FileData into DataFile and handle error differently * Resolved lifetime issue with FileReport combine method * Updated status and method * Refactored to use existing DataFile struct * Changed FileData into DataFile and handle error differently * Refactored to use existing DataFile struct * Merged file report * Interim commit for structured * Resolved unit tests * Temporary commit for default rule names * Working prototype for formatting issue --------- * Clap Autocompletions (#340) * temp * fixing commands * cleanup * temp * cleanup * adding valuehints * adding valuehints * removed powershell * cleanup * removing derive * removed unecessary ArgActions * bumping up version * refactor to use a function to generate commands * removing unused imports * removed random println * updating readme * fixes * typo * cleanup * typo * adding documentation for functions (#362) * adding documentation for functions * Combined structured output and updated default rule clause name to include file name (#360) * Populated filename in the output * Structured combine * Changed FileData into DataFile and handle error differently * Resolved lifetime issue with FileReport combine method * Updated status and method * Refactored to use existing DataFile struct * Changed FileData into DataFile and handle error differently * Refactored to use existing DataFile struct * Merged file report * Interim commit for structured * Resolved unit tests * Temporary commit for default rule names * Working prototype for formatting issue --------- * clarifying docs --------- * Deprecated migrate and previous engine (#364) * Deprecated migrate and previous engine * Removed a unit test for old engine --------- * 3.0.0 beta release changes (#365) * Bump up version to 3.0.0-beta * Updated README.md * Add instances to rules integration tests (#351) * Added 2 runners to integration tests for rules registry * Fixed indent * Added explicit shell name * Moved shell to job parameters * Added powershell commands for windows * Removed test branch * Updated README.md (#352) * Updated README for Guard 3.0 * Update README.md --------- --------- * feat: Add cfn-guard-lambda deployment with SAM CLI (#354) * feat: Add cfn-guard-lambda deployment with SAM CLI * Renamed the logical ID for lambda in template & updated README.md * Updated the instructions and added least privileged IAM access policy --------- * Revert "Added deprecated short flag for print-json in parse-tree" This reverts commit 93548a4 * Updated names of binaries to reflect v3 * Updated README.md to add new features * Added rogue_one branch to docker workflow * Bump enumflags2 to 0.7.7 --------- --------- Co-authored-by: Akshay Rane <[email protected]> Co-authored-by: Akshay Rane <[email protected]> Co-authored-by: razcloud <[email protected]> Co-authored-by: Ben Bridts <[email protected]> Co-authored-by: Ben Bridts <[email protected]> * removed uneeded printing of error parser error on parse-tree command (#368) * improve error message for templates that cause an error (#370) * improve erro message for empty templates * addressing clippy lints for validate.rs * addressed comment, removed uneeded code paths, and cleaned some stuff up * Clippy lints + ci (#371) * init * aws_meta_appender_tests.rs clippy lints * parser.rs clippy lints * cfn_reporter.rs clippy lints * files.rs clippy lints * tf.rs clippy lints * tracker.rs clippy lints * operator.rs clippy lints * values.rs clippy lints * traversal.rs clippy lints * path_value.rs clippy lints * rules/mod.rs clippy lints * eval.rs clippy lints * rulegen.rs clippy lints * summary_table.rs clippy lints * aws_meta_appender.rs clippy lints * path_value_tests.rs clippy lints * eval_tests.rs clippy lints * utils.mod.rs clippy lints * parser_tests.rs clippy lints * traversal_tests.rs clippy lints * generic_summary.rs clippy lints * a bunch of misc clippy lints * tests/utils.rs clippy lints * test_command.rs clippy lints * main.rs clippy lints * tests/validate.rs clippy lints * tests/parse_tree.rs clippy lints * functional.rs clippy lints * helper.rs clippy lints * eval_context clippy lints * cfn.rs clippy lints * value_tests.rs clippy lints * last of the lints * adding linting to ci * last few lints * evaluate_tests.rs lints * fix for bug when introduced when rule fails and resource is not the parent of the node where the failure occurs + misc tests (#372) * Updating reporters to all use serde for both json and yaml + misc improvements (#373) * modifying json/yaml responses to ALL use serde_yaml/json for serialization * adding type information to error message * [Bugfix] Fixing improper console output when using single line summary (#378) * changing count.rs to return a pathawarevalue instead of a primitive * temp * adding unit test for show summary all when failing using count fn * removing unecesssary file * [Enhancement] creating a new error code for rule failures (#379) * temp * adding new exit code for when a rule fails * added integration test to validate error code for a failing test * cleanup * rebase + fix test * removed unecessary double 0 * Refined documentation for functions, join path bugfix & version bump (#381) * Updated table of contents and added a writeup for functions * Bug fix for set path for returned PathAwareValue for join function * Refined documentation for functions * Version bump to 3.0.0 * Added more detailed explanation for function usage limitation * Added integration test for join path bugfix --------- Co-authored-by: Akshay Rane <[email protected]> * 3.0.0 release changes (#383) * 3.0.0 Beta release (#366) * bumping up to 3.0.0-alpha (#347) * bumping up to 3.0.0 alpha * typo * updating workflow * Populated filename in the output (#358) * Populated filename in the output * Changed FileData into DataFile and handle error differently * Refactored to use existing DataFile struct --------- Co-authored-by: Akshay Rane <[email protected]> * Support for some function expressions / stateful rules (#361) * init commit for function resolution / stateful rules * more tests + making test rules better * fixed bugs with validation of functions * small cleanup * fixes as per comments * cleanup * add todo * typos * fixed logical error breaking tests * added test for test command with a function * fixed unit test * added comment to clearly explain whats happening in regex_replace cause no one actually understands regex * Combined structured output and updated default rule clause name to include file name (#360) * Populated filename in the output * Structured combine * Changed FileData into DataFile and handle error differently * Resolved lifetime issue with FileReport combine method * Updated status and method * Refactored to use existing DataFile struct * Changed FileData into DataFile and handle error differently * Refactored to use existing DataFile struct * Merged file report * Interim commit for structured * Resolved unit tests * Temporary commit for default rule names * Working prototype for formatting issue --------- Co-authored-by: Akshay Rane <[email protected]> * Clap Autocompletions (#340) * temp * fixing commands * cleanup * temp * cleanup * adding valuehints * adding valuehints * removed powershell * cleanup * removing derive * removed unecessary ArgActions * bumping up version * refactor to use a function to generate commands * removing unused imports * removed random println * updating readme * fixes * typo * cleanup * typo * adding documentation for functions (#362) * adding documentation for functions * Combined structured output and updated default rule clause name to include file name (#360) * Populated filename in the output * Structured combine * Changed FileData into DataFile and handle error differently * Resolved lifetime issue with FileReport combine method * Updated status and method * Refactored to use existing DataFile struct * Changed FileData into DataFile and handle error differently * Refactored to use existing DataFile struct * Merged file report * Interim commit for structured * Resolved unit tests * Temporary commit for default rule names * Working prototype for formatting issue --------- Co-authored-by: Akshay Rane <[email protected]> * clarifying docs --------- Co-authored-by: Akshay Rane <[email protected]> Co-authored-by: Akshay Rane <[email protected]> * Deprecated migrate and previous engine (#364) * Deprecated migrate and previous engine * Removed a unit test for old engine --------- Co-authored-by: Akshay Rane <[email protected]> * 3.0.0 beta release changes (#365) * Bump up version to 3.0.0-beta * Updated README.md * Add instances to rules integration tests (#351) * Added 2 runners to integration tests for rules registry * Fixed indent * Added explicit shell name * Moved shell to job parameters * Added powershell commands for windows * Removed test branch * Updated README.md (#352) * Updated README for Guard 3.0 * Update README.md Co-authored-by: Ben Bridts <[email protected]> --------- Co-authored-by: Ben Bridts <[email protected]> --------- Co-authored-by: Akshay Rane <[email protected]> Co-authored-by: razcloud <[email protected]> Co-authored-by: Ben Bridts <[email protected]> * feat: Add cfn-guard-lambda deployment with SAM CLI (#354) * feat: Add cfn-guard-lambda deployment with SAM CLI * Renamed the logical ID for lambda in template & updated README.md * Updated the instructions and added least privileged IAM access policy --------- Co-authored-by: Ben Bridts <[email protected]> Co-authored-by: Akshay Rane <[email protected]> * Revert "Added deprecated short flag for print-json in parse-tree" This reverts commit 93548a4 * Updated names of binaries to reflect v3 * Updated README.md to add new features * Added rogue_one branch to docker workflow * Bump enumflags2 to 0.7.7 --------- Co-authored-by: Akshay Rane <[email protected]> Co-authored-by: razcloud <[email protected]> Co-authored-by: Ben Bridts <[email protected]> Co-authored-by: Ben Bridts <[email protected]> --------- Co-authored-by: Akshay Rane <[email protected]> Co-authored-by: Akshay Rane <[email protected]> Co-authored-by: razcloud <[email protected]> Co-authored-by: Ben Bridts <[email protected]> Co-authored-by: Ben Bridts <[email protected]> * Removed unused import --------- Co-authored-by: Josh Fried <[email protected]> Co-authored-by: Akshay Rane <[email protected]> Co-authored-by: razcloud <[email protected]> Co-authored-by: Ben Bridts <[email protected]> Co-authored-by: Ben Bridts <[email protected]> * removing unused import --------- Co-authored-by: Akshay Rane <[email protected]> Co-authored-by: Akshay Rane <[email protected]> Co-authored-by: razcloud <[email protected]> Co-authored-by: Ben Bridts <[email protected]> Co-authored-by: Ben Bridts <[email protected]>
1 parent a3992ca commit c7bcce2

File tree

80 files changed

+1762
-1380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1762
-1380
lines changed

.github/workflows/pr.yml

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Rust
22

33
on:
44
push:
5-
branches: [ main, development, rogue_one ]
5+
branches: [main, development, rogue_one]
66
pull_request:
7-
branches: [ main, development, rogue_one ]
7+
branches: [main, development, rogue_one]
88

99
env:
1010
CARGO_TERM_COLOR: always
@@ -14,19 +14,19 @@ jobs:
1414
name: Build all crates & run unit tests
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v2
18-
- name: Build all crates
19-
run: cargo build --release --verbose
20-
- name: Run unit tests
21-
run: cargo test --verbose
17+
- uses: actions/checkout@v2
18+
- name: Build all crates
19+
run: cargo build --release --verbose
20+
- name: Run unit tests
21+
run: cargo test --verbose
2222

2323
shellcheck:
2424
name: Shellcheck
2525
runs-on: ubuntu-latest
2626
steps:
27-
- uses: actions/checkout@v2
28-
- name: Shellcheck
29-
run: shellcheck install-guard.sh
27+
- uses: actions/checkout@v2
28+
- name: Shellcheck
29+
run: shellcheck install-guard.sh
3030

3131
formatting:
3232
name: Formatting check (cargo fmt)
@@ -39,10 +39,26 @@ jobs:
3939
- name: Rustfmt Check
4040
uses: actions-rust-lang/rustfmt@v1
4141

42+
linting:
43+
name: Linting check (clippy)
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v3
47+
- uses: actions-rs/toolchain@v1
48+
with:
49+
toolchain: stable
50+
override: true
51+
components: clippy
52+
- uses: actions-rs/clippy-check@v1
53+
with:
54+
token: ${{ secrets.GITHUB_TOKEN }}
55+
56+
args: -- -D warnings
57+
4258
aws-guard-rules-registry-integration-tests-linux:
4359
strategy:
4460
matrix:
45-
os: [ ubuntu-latest, macos-latest ]
61+
os: [ubuntu-latest, macos-latest]
4662
runs-on: ${{ matrix.os }}
4763
name: Integration tests against aws-guard-rules-registry
4864
steps:
@@ -141,10 +157,10 @@ jobs:
141157
- name: Run integration tests using parse-tree command
142158
run: |
143159
cd aws-guard-rules-registry/rules
144-
160+
145161
$FAILED_RULES = @()
146162
$SKIPPED_RULES = @()
147-
163+
148164
$rules = @(Get-ChildItem -Path .\ -Filter *.guard -Recurse -File)
149165
150166
Foreach ($rule in $rules) {
@@ -158,19 +174,19 @@ jobs:
158174
$FAILED_RULES += "$rule"
159175
}
160176
}
161-
177+
162178
$SKIPPED_RULE_COUNT = $SKIPPED_RULES.Length
163179
if ($SKIPPED_RULE_COUNT -gt 0) {
164180
echo "The following `$SKIPPED_RULE_COUNT.Length` rule(s) were skipped because they contained only comments:"
165181
echo $SKIPPED_RULES
166182
}
167-
183+
168184
$FAILED_RULE_COUNT = $FAILED_RULES.Length
169-
185+
170186
if ($FAILED_RULE_COUNT -gt 0) {
171187
echo "The following $FAILED_RULE_COUNT rule(s) have failed the parse-tree integration tests with a non-zero error code:"
172188
echo $FAILED_RULES
173189
exit 1
174190
} else {
175191
echo "All the rules have succeeded the parse-tree integration tests."
176-
}
192+
}

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Guard can be used for the following domains:
3535
* [Guard CLI](#guard-cli)
3636
* [Installation](#installation)
3737
* [How does Guard CLI work?](#how-does-guard-cli-work?)
38+
* [Rule authoring references](#references)
39+
* [Built-in functions & stateful rules](#functions)
40+
* [AWS Rule Registry](#registry)
41+
* [Use Guard as a Docker Image](#docker)
3842
* [License](#license)
3943

4044
## FAQs
@@ -222,7 +226,7 @@ Check `help` to see if it is working.
222226

223227
```bash
224228
$ cfn-guard help
225-
cfn-guard 3.0.0-beta
229+
cfn-guard 3.0.0
226230

227231
Guard is a general-purpose tool that provides a simple declarative syntax to define
228232
policy-as-code as rules to validate against any structured hierarchical data (like JSON/YAML).
@@ -489,7 +493,7 @@ cfn-guard test -r api_gateway_private_access.guard -t api_gateway_private_access
489493
490494
Read [Guard: Unit Testing](docs/UNIT_TESTING.md) for more information on unit testing. To know about other commands read the [Readme in the guard directory](guard/README.md).
491495
492-
## Rule authoring references
496+
## <a name="references"></a> Rule authoring references
493497
494498
As a starting point for writing Guard rules for yourself or your organisation we recommend following [this official guide](https://docs.aws.amazon.com/cfn-guard/latest/ug/writing-rules.html)
495499
@@ -507,15 +511,54 @@ As a starting point for writing Guard rules for yourself or your organisation we
507511
9. [Composing named-rule blocks in AWS CloudFormation Guard](https://docs.aws.amazon.com/cfn-guard/latest/ug/named-rule-block-composition.html)
508512
10. [Writing clauses to perform context-aware evaluations](https://docs.aws.amazon.com/cfn-guard/latest/ug/context-aware-evaluations.html)
509513
514+
## <a name="functions"></a> Built-in functions & stateful rules
510515
511-
## AWS Rule Registry
516+
Guard 3.0 introduces support for functions, allowing for stateful rules that can run on a value that's evaluated based
517+
on some properties extracted out of a data template.
518+
519+
### Sample template
520+
521+
Imagine we have a property in our template which consists of a list called as `Collection` and we need to ensure
522+
it has at least 3 items in it.
523+
524+
```yaml
525+
Resources:
526+
newServer:
527+
Type: AWS::New::Service
528+
Collection:
529+
- a
530+
- b
531+
```
532+
### Sample rule
533+
534+
We can write a rule to check this condition as follows:
535+
536+
```
537+
let server = Resources.*[ Type == 'AWS::New::Service' ]
538+
rule COUNT_CHECK when %server !empty {
539+
let collection = %server.Collection.*
540+
let count_of_items = count(%collection)
541+
%count_of_items >= 3
542+
<<
543+
Violation: Collection should contain at least 3 items
544+
>>
545+
}
546+
```
547+
548+
Expected outcome is that rule fails showing us the violation message since our template is non-compliant.
549+
550+
For detailed documentation regarding all supported functions, please [follow this link](./docs/FUNCTIONS.md). For limitations of functions usage, please read [this note](./docs/KNOWN_ISSUES.md#function-limitation).
551+
552+
## <a name="registry"></a> AWS Rule Registry
512553

513554
As a reference for Guard rules and rule-sets that contain (on a best-effort basis) the compliance policies that adhere
514555
to the industry best practices around usages across AWS resources, we have recently launched
515556
[AWS Guard Rules Registry](https://github.com/aws-cloudformation/aws-guard-rules-registry).
516557

517558

518-
## Guard Docker Image launched on [ECR public gallery](https://gallery.ecr.aws/aws-cloudformation/cloudformation-guard)
559+
## <a name="docker"></a> Use Guard as a Docker Image
560+
561+
Guard is also published as an ECR image in [ECR public gallery](https://gallery.ecr.aws/aws-cloudformation/cloudformation-guard) and can be used as an image in a docker container.
519562

520563
### Prerequisites
521564

@@ -541,6 +584,7 @@ We should see the evaluation result emitted out on the console.
541584
542585
* We use the tag `latest` for the most recent docker image that gets published in sync with `main` branch of the `cloudformation-guard` GitHub repository.
543586
* We use the convention `<branch_name>.<github_shorthand_commit_hash>` for tags of historical docker images
587+
544588
## License
545589
546590
This project is licensed under the Apache-2.0 License.

0 commit comments

Comments
 (0)