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

YAML Syntax Errors in Continuous Audit Metrics #57

Open
aj-stein-nist opened this issue Aug 3, 2022 · 7 comments
Open

YAML Syntax Errors in Continuous Audit Metrics #57

aj-stein-nist opened this issue Aug 3, 2022 · 7 comments
Assignees
Labels

Comments

@aj-stein-nist
Copy link

aj-stein-nist commented Aug 3, 2022

Per discussion in #52 (comment), there are some YAML syntax and formatting errors that need to be addressed. There are probably a few methods to test this out yourself, but I happened to encounter this because I occasionally use VS Code and use the YAML Language Support Plugin, ID: redhat.vscode-yaml and it presented the following errors. Since they are JSON-like, I will embed them in a code snippet below.

If you want assistance from outside contributors, feel free to indicate and I can try to assist, time permitting and if you are interested.

[{
	"resource": "/c:/Users/myusername/path/to/code/continuous-audit-metrics/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#6",
	"severity": 8,
	"message": "Implicit keys need to be on a single line",
	"source": "YAML",
	"startLineNumber": 1222,
	"startColumn": 3,
	"endLineNumber": 1222,
	"endColumn": 78
}]
[{
	"resource": "/c:/Users/myusername/path/to/code/continuous-audit-metrics/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#6",
	"severity": 8,
	"message": "Implicit map keys need to be followed by map values",
	"source": "YAML",
	"startLineNumber": 1222,
	"startColumn": 3,
	"endLineNumber": 1222,
	"endColumn": 78
}]
[{
	"resource": "/c:/Users/myusername/path/to/code/continuous-audit-metrics/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#6",
	"severity": 8,
	"message": "Missing closing 'quote",
	"source": "YAML",
	"startLineNumber": 1301,
	"startColumn": 1,
	"endLineNumber": 1301,
	"endColumn": 2
}]
[{
	"resource": "/c:/Users/myusername/path/to/code/continuous-audit-metrics/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#6",
	"severity": 8,
	"message": "Implicit map keys need to be followed by map values",
	"source": "YAML",
	"startLineNumber": 1302,
	"startColumn": 1,
	"endLineNumber": 1302,
	"endColumn": 3
}]
[{
	"resource": "/c:/Users/myusername/path/to/code/continuous-audit-metrics/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#6",
	"severity": 8,
	"message": "Missing closing 'quote",
	"source": "YAML",
	"startLineNumber": 1302,
	"startColumn": 2,
	"endLineNumber": 1302,
	"endColumn": 3
}]
[{
	"resource": "/c:/Users/myusername/path/to/code/continuous-audit-metrics/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#6",
	"severity": 8,
	"message": "Map keys must be unique",
	"source": "YAML",
	"startLineNumber": 1303,
	"startColumn": 1,
	"endLineNumber": 1303,
	"endColumn": 14
}]
[{
	"resource": "/c:/Users/myusername/path/to/code/continuous-audit-metrics/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#6",
	"severity": 8,
	"message": "Implicit map keys need to be followed by map values",
	"source": "YAML",
	"startLineNumber": 1371,
	"startColumn": 1,
	"endLineNumber": 1371,
	"endColumn": 3
}]
[{
	"resource": "/c:/Users/myusername/path/to/code/continuous-audit-metrics/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#6",
	"severity": 8,
	"message": "Missing closing 'quote",
	"source": "YAML",
	"startLineNumber": 1371,
	"startColumn": 2,
	"endLineNumber": 1371,
	"endColumn": 3
}]
[{
	"resource": "/c:/Users/myusername/path/to/code/continuous-audit-metrics/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#6",
	"severity": 8,
	"message": "Implicit keys need to be on a single line",
	"source": "YAML",
	"startLineNumber": 1381,
	"startColumn": 1,
	"endLineNumber": 1381,
	"endColumn": 3
}]
[{
	"resource": "/c:/Users/myusername/path/to/code/continuous-audit-metrics/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#6",
	"severity": 8,
	"message": "Implicit map keys need to be followed by map values",
	"source": "YAML",
	"startLineNumber": 1381,
	"startColumn": 1,
	"endLineNumber": 1381,
	"endColumn": 3
}]
[{
	"resource": "/c:/Users/myusername/path/to/code/continuous-audit-metrics/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#6",
	"severity": 8,
	"message": "Missing closing 'quote",
	"source": "YAML",
	"startLineNumber": 1415,
	"startColumn": 1,
	"endLineNumber": 1415,
	"endColumn": 1
}]
@rajkrishnamurthy
Copy link
Collaborator

Refer to PR #59. Fixed the schema related issues.

@pritikin
Copy link
Collaborator

Sounds like we should also add yamllint to the actions.

E.g.

jobs:
validate-yaml:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Validate YAML file
run: yamllint abc.yml

@rajkrishnamurthy
Copy link
Collaborator

Agree w/ @pritikin. Should we additional rules for the CAM yaml in addition to foundational yaml linting? Are there any such rules that we want to advance in validation as part of github actions?

@apannetrat
Copy link
Collaborator

Some syntax errors are just the result of working on new metrics as a draft.

The tool we built already does a form of YAML syntax verification. I'm not sure it was effectively used recently, which might explain some syntax errors. The objective is, however, to run that validation tool automatically each time the YAML dataset is updated.

But having valid YAML is only half the problem: we also need to check that the YAML dataset complies with our "schema". For example, relatedControlIds: should be a list of IDs. So any value other than a list, such as a string or a number, should be rejected. This is already partially done by our validation tool: by trying to generate HTML from the YAML dataset, it implicitly checks that the YAML file follows a specific structure, and it will fail when there is a problem. We could tighten these implicit checks further.

@apannetrat
Copy link
Collaborator

I added a YAML schema validator in PR #63

@apannetrat
Copy link
Collaborator

I did some tests with yamllint.

If you run yamllint -f parsable primary-dataset.yml, you get what looks like a lot of errors:

primary-dataset.yml:4:81: [error] line too long (86 > 80 characters) (line-length)
primary-dataset.yml:8:1: [error] wrong indentation: expected 2 but found 0 (indentation)
primary-dataset.yml:8:16: [error] trailing spaces (trailing-spaces)
primary-dataset.yml:12:81: [error] line too long (83 > 80 characters) (line-length)
primary-dataset.yml:17:5: [error] wrong indentation: expected 6 but found 4 (indentation)
primary-dataset.yml:19:81: [error] line too long (82 > 80 characters) (line-length)
primary-dataset.yml:23:81: [error] line too long (81 > 80 characters) (line-length)
primary-dataset.yml:25:81: [error] line too long (81 > 80 characters) (line-length)
primary-dataset.yml:26:81: [error] line too long (84 > 80 characters) (line-length)
primary-dataset.yml:27:79: [error] trailing spaces (trailing-spaces)
primary-dataset.yml:32:81: [error] line too long (83 > 80 characters) (line-length)
primary-dataset.yml:33:81: [error] line too long (86 > 80 characters) (line-length)
primary-dataset.yml:37:16: [error] trailing spaces (trailing-spaces)
primary-dataset.yml:40:3: [error] wrong indentation: expected 4 but found 2 (indentation)
primary-dataset.yml:41:81: [error] line too long (83 > 80 characters) (line-length)
primary-dataset.yml:42:81: [error] line too long (90 > 80 characters) (line-length)
primary-dataset.yml:46:5: [error] wrong indentation: expected 6 but found 4 (indentation)
primary-dataset.yml:48:81: [error] line too long (82 > 80 characters) (line-length)
primary-dataset.yml:49:81: [error] line too long (88 > 80 characters) (line-length)
primary-dataset.yml:52:81: [error] line too long (81 > 80 characters) (line-length)

[631 more lines follow...]

But in reality, these are not YAML errors. yamllint enforces certain best practices that are not canonical rules of
the YAML standard. For example, by default, yamllint requires YAML list items to be indented but many people
consider the '-' that precedes a list item is a form of indentation, and the YAML standard allows it as well. The same thing applies with line with (YAML does not requires 80 characters max).

If we disable these checks, and re-run the yamllint with the command yamllint -f parsable -d "{extends: default, rules: {trailing-spaces: disable, indentation: {indent-sequences: whatever}, line-length: disable}}" primary-dataset.yml we get no issues.

This seems to suggest that running an additional linter for YAML is not necessary.

@pritikin
Copy link
Collaborator

pritikin commented Oct 6, 2022

PR #66 fixes the remaining closing quote issues. I think the rest are fixed at this point. Using the schema in PR #66 I see the following errors. They are related to metrics that do not have sloRecommendations (something starred on the wiki and maintained as required in the JSON schema) or rules without any text (also mandated but missing in some current metrics). Similarly implementationGuidelines are missing for two metrics.

[{
	"resource": "/Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "Incorrect type. Expected \"sloRecommendations\".",
	"source": "yaml-schema: file:///Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/tools/primary-dataset.schema.json",
	"startLineNumber": 212,
	"startColumn": 22,
	"endLineNumber": 212,
	"endColumn": 22
},{
	"resource": "/Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "Incorrect type. Expected \"string\".",
	"source": "yaml-schema: file:///Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/tools/primary-dataset.schema.json",
	"startLineNumber": 353,
	"startColumn": 10,
	"endLineNumber": 353,
	"endColumn": 10
},{
	"resource": "/Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "Incorrect type. Expected \"string\".",
	"source": "yaml-schema: file:///Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/tools/primary-dataset.schema.json",
	"startLineNumber": 866,
	"startColumn": 10,
	"endLineNumber": 866,
	"endColumn": 10
},{
	"resource": "/Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "Incorrect type. Expected \"sloRecommendations\".",
	"source": "yaml-schema: file:///Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/tools/primary-dataset.schema.json",
	"startLineNumber": 961,
	"startColumn": 22,
	"endLineNumber": 961,
	"endColumn": 22
},{
	"resource": "/Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "Incorrect type. Expected \"string\".",
	"source": "yaml-schema: file:///Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/tools/primary-dataset.schema.json",
	"startLineNumber": 988,
	"startColumn": 10,
	"endLineNumber": 988,
	"endColumn": 10
},{
	"resource": "/Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "Incorrect type. Expected \"string\".",
	"source": "yaml-schema: file:///Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/tools/primary-dataset.schema.json",
	"startLineNumber": 1009,
	"startColumn": 10,
	"endLineNumber": 1009,
	"endColumn": 10
},{
	"resource": "/Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "Incorrect type. Expected \"sloRecommendations\".",
	"source": "yaml-schema: file:///Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/tools/primary-dataset.schema.json",
	"startLineNumber": 1112,
	"startColumn": 22,
	"endLineNumber": 1112,
	"endColumn": 22
},{
	"resource": "/Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "Missing property \"implementationGuidelines\".",
	"source": "yaml-schema: file:///Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/tools/primary-dataset.schema.json",
	"startLineNumber": 1220,
	"startColumn": 3,
	"endLineNumber": 1220,
	"endColumn": 4
},{
	"resource": "/Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "Incorrect type. Expected \"sloRecommendations\".",
	"source": "yaml-schema: file:///Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/tools/primary-dataset.schema.json",
	"startLineNumber": 1236,
	"startColumn": 22,
	"endLineNumber": 1236,
	"endColumn": 22
},{
	"resource": "/Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "Missing property \"implementationGuidelines\".",
	"source": "yaml-schema: file:///Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/tools/primary-dataset.schema.json",
	"startLineNumber": 1241,
	"startColumn": 3,
	"endLineNumber": 1241,
	"endColumn": 4
},{
	"resource": "/Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/data/primary-dataset.yml",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "Incorrect type. Expected \"sloRecommendations\".",
	"source": "yaml-schema: file:///Users/pritikin/Documents/github/continuous-audit-metrics.pritikin/tools/primary-dataset.schema.json",
	"startLineNumber": 1257,
	"startColumn": 22,
	"endLineNumber": 1257,
	"endColumn": 22
}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants