

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# AWS CloudFormation Guard 규칙에 대한 입력 데이터 검증
<a name="validating-rules"></a>

명령을 AWS CloudFormation Guard `validate` 사용하여 Guard 규칙에 대한 데이터를 검증할 수 있습니다. 파라미터 및 옵션을 포함하여 `validate` 명령에 대한 자세한 내용은 [검증](cfn-guard-validate.md)을 참조하세요.

## 사전 조건
<a name="validating-rules-prerequisites"></a>
+ 입력 데이터를 검증할 Guard 규칙을 작성합니다. 자세한 내용은 [Guard 규칙 작성](writing-rules.md) 단원을 참조하십시오.
+ 규칙을 테스트하여 의도한 대로 작동하는지 확인합니다. 자세한 내용은 [Guard 규칙 테스트](testing-rules.md) 단원을 참조하십시오.

## `validate` 명령 사용
<a name="validating-rules-walkthrough"></a>

 AWS CloudFormation 템플릿과 같은 Guard 규칙에 대해 입력 데이터를 검증하려면 Guard `validate` 명령을 실행합니다. `--rules` 파라미터에 규칙 파일의 이름을 지정합니다. `--data` 파라미터에 입력 데이터 파일의 이름을 지정합니다.

```
cfn-guard validate --rules {{rules.guard}} --data {{template.json}}
```

Guard가 템플릿을 성공적으로 검증하면 `validate` 명령은 종료 상태 `0` (`$?` bash)를 반환합니다. Guard가 규칙 위반을 식별하면 `validate` 명령은 실패한 규칙의 상태 보고서를 반환합니다. 요약 플래그(`-s all`)를 사용하여 Guard가 각 규칙을 평가한 방법을 보여주는 세부 평가 트리를 확인합니다.

```
template.json Status = FAIL
SKIP rules
rules.guard/aws_apigateway_deployment_checks    SKIP
rules.guard/aws_apigateway_stage_checks         SKIP
rules.guard/aws_dynamodb_table_checks           SKIP
PASS rules
rules.guard/aws_events_rule_checks              PASS
rules.guard/aws_iam_role_checks                 PASS
FAILED rules
rules.guard/aws_ec2_volume_checks               FAIL
rules.guard/mixed_types_checks                  FAIL
---
Evaluation of rules rules.guard against data template.json
--
Property [/Resources/vol2/Properties/Encrypted] in data [template.json] is not compliant with [rules.guard/aws_ec2_volume_checks] because provided value [false] did not match expected value [true]. Error Message []
Property traversed until [/Resources/vol2/Properties] in data [template.json] is not compliant with [rules.guard/aws_ec2_volume_checks] due to retrieval error. Error Message [Attempting to retrieve array index or key from map at path = /Resources/vol2/Properties , Type was not an array/object map, Remaining Query = Size]
Property [/Resources/vol2/Properties/Encrypted] in data [template.json] is not compliant with [rules.guard/mixed_types_checks] because provided value [false] did not match expected value [true]. Error Message []
--
Rule [rules.guard/aws_iam_role_checks] is compliant for data [template.json]
Rule [rules.guard/aws_events_rule_checks] is compliant for data [template.json]
--
Rule [rules.guard/aws_apigateway_deployment_checks] is not applicable for data [template.json]
Rule [rules.guard/aws_apigateway_stage_checks] is not applicable for data [template.json]
Rule [rules.guard/aws_dynamodb_table_checks] is not applicable for data [template.json]
```

## 여러 데이터 파일에 대해 여러 규칙 검증
<a name="validating-rules-overview"></a>

규칙을 유지 관리하는 데 도움이 되도록 규칙을 여러 파일에 작성하고 원하는 대로 규칙을 구성할 수 있습니다. 그런 다음 데이터 파일 또는 여러 데이터 파일에 대해 여러 규칙 파일을 검증할 수 있습니다. `validate` 명령은 `--data` 및 `--rules` 옵션에 대한 파일 디렉터리를 가져올 수 있습니다. 예를 들어가 하나 이상의 데이터 파일을 `/path/to/dataDirectory` 포함하고가 하나 이상의 규칙 파일을 `/path/to/ruleDirectory` 포함하는 다음 명령을 실행할 수 있습니다.

```
cfn-guard validate --data /path/to/dataDirectory --rules /path/to/ruleDirectory
```

여러 CloudFormation 템플릿에 정의된 다양한 리소스에 저장 시 암호화를 보장하는 적절한 속성 할당이 있는지 확인하는 규칙을 작성할 수 있습니다. 검색 및 유지 관리를 쉽게 하기 위해 경로가 인 디렉터리에서 , `s3_bucket_encryption.guard` `ec2_volume_encryption.guard`및 라는 별도의 파일에 있는 각 리소스`rds_dbinstance_encrytion.guard`의 저장 시 암호화를 확인하는 규칙을 가질 수 있습니다`~/GuardRules/encryption_at_rest`. 검증해야 하는 CloudFormation 템플릿은 경로가 인 디렉터리에 있습니다`~/CloudFormation/templates`. 이 경우 다음과 같이 `validate` 명령을 실행합니다.

```
cfn-guard validate --data ~/CloudFormation/templates --rules ~/GuardRules/encryption_at_rest
```