Skip to content

Commit

Permalink
Hotfix styles (#1076)
Browse files Browse the repository at this point in the history
* style guide hotfix

* Update fedramp-external-constraints.xml
  • Loading branch information
wandmagic authored Jan 8, 2025
1 parent 60b3c50 commit 18a02c9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 33 deletions.
30 changes: 19 additions & 11 deletions features/steps/fedramp_extensions_steps.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { BeforeAll, BeforeStep, Given, Then, When, setDefaultTimeout, world } from "@cucumber/cucumber";
import { BeforeAll, Given, Then, When, setDefaultTimeout } from "@cucumber/cucumber";
import { expect } from "chai";
import {
existsSync,
mkdirSync,
readFileSync,
readdirSync,
unlinkSync,
writeFileSync,
mkdirSync,
existsSync,
} from "fs";
import { load } from "js-yaml";
import { executeOscalCliCommand, resolveProfile, resolveProfileDocument, validateDocument} from "oscal";
import {checkServerStatus} from 'oscal/dist/server.js'
import { dirname, join,parse, resolve } from "path";
import { Exception, Log, Result } from "sarif";
import { JSDOM } from 'jsdom';
import { executeOscalCliCommand, formatSarifOutput, resolveProfileDocument, validateDocument } from "oscal";
import { checkServerStatus } from 'oscal/dist/server.js';
import { dirname, join, parse, resolve } from "path";
import { Log } from "sarif";
import { fileURLToPath } from "url";
import { parseString } from "xml2js";
import {JSDOM} from 'jsdom'
import { promisify } from "util";
import {formatSarifOutput} from 'oscal'
import { parseString } from "xml2js";
let executor: 'oscal-cli'|'oscal-server' = process.env.OSCAL_EXECUTOR as 'oscal-cli'|'oscal-server' || 'oscal-cli'
const quiet = process.env.OSCAL_TEST_QUIET === 'true'

Expand Down Expand Up @@ -686,6 +685,7 @@ Then('I should have valid results {string}', async function (fileToValidate) {

Then('I should verify that all constraints follow the style guide constraint', async function () {
const baseDir = join(__dirname, '..', '..');
const styleGuidePath = join(baseDir, 'src', 'validations', 'styleguides', 'fedramp-constraint-style.xml');
const constraintDir = join(baseDir, 'src', 'validations', 'constraints');
const constraintFiles = readdirSync(constraintDir).filter(file =>
file.startsWith('fedramp') && file.endsWith('.xml')
Expand All @@ -701,7 +701,15 @@ Then('I should verify that all constraints follow the style guide constraint', a
const fileContent = readFileSync(filePath, 'utf8');
const dom = new JSDOM(fileContent, { contentType: 'text/xml' });
const document = dom.window.document;

const {isValid,log} = await validateDocument(filePath,{flags:['disable-schema'],quiet,extensions:[styleGuidePath],module:"http://csrc.nist.gov/ns/oscal/metaschema/1.0"},executor)
writeFileSync(
join(
__dirname,
"../../sarif/",
fileName.split(".xml").join("").toString()+".sarif"
),JSON.stringify(log, null,"\t"))
const formattedErrors = (formatSarifOutput(log));
formattedErrors&&errors.push(formattedErrors)
// Process each 'constraints' block separately
document.querySelectorAll('constraints').forEach(constraintsNode => {
// Get direct child elements with IDs within this constraints block
Expand Down
34 changes: 12 additions & 22 deletions src/validations/constraints/fedramp-external-constraints.xml
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@
</expect>
<expect id="image-has-checksum" target="//component[@type='software' and ./prop[@name='asset-type' and @value='image']]" test="count(./prop[@name='checksum' and @ns='http://fedramp.gov/ns/oscal']) = 1" level="ERROR">
<formal-name>Container Image Has Checksum Property</formal-name>
<prop namespace="https://docs.oasis-open.org/sarif/sarif/v2.1.0" name="help-url" value="insert-help-url-here"/>
<prop namespace="https://docs.oasis-open.org/sarif/sarif/v2.1.0" name="help-url" value="https://automate.fedramp.gov/documentation/ssp/5-attachments/#system-inventory-approach"/>
<message>In a FedRAMP SSP, a component that describes a container or operating system image MUST define a checksum property.</message>
</expect>
<expect id="information-type-has-class" target="component/prop[@name='information-type' and @ns='http://fedramp.gov/ns/oscal']" test="exists(@class)" level="ERROR">
Expand All @@ -610,6 +610,11 @@
<prop namespace="https://docs.oasis-open.org/sarif/sarif/v2.1.0" name="help-url" value="https://automate.fedramp.gov/documentation/ssp/5-attachments/#system-inventory-approach"/>
<message>In a FedRAMP SSP, each inventory item and internal service component MUST state if they are public-facing.</message>
</expect>
<expect id="inventory-item-or-component-has-asset-id" target="(inventory-item)| (component[@type='software' and prop[@name='asset-type' and @value='image']])" test="count(prop[@name='asset-id']) = 1" level="ERROR">
<formal-name>Inventory Item or Component Has Asset ID</formal-name>
<prop namespace="https://docs.oasis-open.org/sarif/sarif/v2.1.0" name="help-url" value="https://automate.fedramp.gov/documentation/ssp/5-attachments/#system-inventory-approach"/>
<message>In a FedRAMP SSP, each inventory item and software image component MUST include the asset ID.</message>
</expect>
<expect id="leveraged-authorization-has-authorization-type" target="leveraged-authorization" test="count(prop[@name='authorization-type'][@ns='http://fedramp.gov/ns/oscal']) = 1" level="ERROR">
<formal-name>Leveraged Authorization Has Authorization Type</formal-name>
<prop namespace="https://docs.oasis-open.org/sarif/sarif/v2.1.0" name="help-url" value="https://automate.fedramp.gov/documentation/ssp/4-ssp-template-to-oscal-mapping/#leveraged-fedramp-authorized-services"/>
Expand Down Expand Up @@ -653,16 +658,6 @@
</constraints>
</context>

<context>
<metapath target="/system-security-plan/system-implementation"/>
<constraints>
<expect id="inventory-item-or-component-has-asset-id" target="(inventory-item)| (component[@type='software' and prop[@name='asset-type' and @value='image']])" test="count(prop[@name='asset-id']) = 1" level="ERROR">
<formal-name>Inventory Item or Component Has Asset ID</formal-name>
<prop namespace="https://docs.oasis-open.org/sarif/sarif/v2.1.0" name="help-url" value="https://automate.fedramp.gov/documentation/ssp/5-attachments/#system-inventory-approach"/>
<message>In a FedRAMP SSP, each inventory item and software image component MUST include the asset ID.</message>
</expect>
</constraints>
</context>

<context>
<metapath target="/system-security-plan/system-implementation/inventory-item"/>
Expand Down Expand Up @@ -761,6 +756,7 @@
'sc-1_smt.a' : 'at least one procedure that addresses System and Communications Protection MUST be associated with SC-1 part a.',
'si-1_smt.a' : 'at least one procedure that addresses System and Information Integrity MUST be associated with SI-1 part a.',
'sr-1_smt.a' : 'at least one procedure that addresses Supply Chain Risk Management MUST be associated with SR-1 part a.'}"/>
<let var="component-uuid" expression="by-component/@component-uuid"/>
<expect id="has-policy" target=".[@statement-id=$control-statement-ids]" test="some $uuid in $component-uuid satisfies count(../../../system-implementation/component[@uuid=$component-uuid and @type='policy']) >= 1" level="ERROR">
<formal-name>Has Policy</formal-name>
<prop namespace="https://docs.oasis-open.org/sarif/sarif/v2.1.0" name="help-url" value="https://automate.fedramp.gov/documentation/ssp/6-security-controls/#organization-policy-and-procedure-statements"/>
Expand All @@ -771,6 +767,11 @@
<prop namespace="https://docs.oasis-open.org/sarif/sarif/v2.1.0" name="help-url" value="https://automate.fedramp.gov/documentation/ssp/6-security-controls/#organization-policy-and-procedure-statements"/>
<message>In a FedRAMP SSP, {$procedure-messages(./@statement-id)}</message>
</expect>
<expect id="statement-has-this-system-component" target="." test="count(../../../system-implementation/component[@type='this-system' and @uuid=$component-uuid]) = 1" level="ERROR">
<formal-name>Statement Has This System Component</formal-name>
<prop namespace="https://docs.oasis-open.org/sarif/sarif/v2.1.0" name="help-url" value="https://automate.fedramp.gov/documentation/ssp/6-security-controls/#response-this-system-component"/>
<message>In a FedRAMP SSP, each control implementation statement MUST have one "this-system" by-component.</message>
</expect>
</constraints>
</context>

Expand All @@ -790,17 +791,6 @@
</constraints>
</context>

<context>
<metapath target="/system-security-plan/control-implementation/implemented-requirement/statement"/>
<constraints>
<let var="component-uuid" expression="by-component/@component-uuid"/>
<expect id="statement-has-this-system-component" target="." test="count(../../../system-implementation/component[@type='this-system' and @uuid=$component-uuid]) = 1" level="ERROR">
<formal-name>Statement Has This System Component</formal-name>
<prop namespace="https://docs.oasis-open.org/sarif/sarif/v2.1.0" name="help-url" value="https://automate.fedramp.gov/documentation/ssp/6-security-controls/#response-this-system-component"/>
<message>In a FedRAMP SSP, each control implementation statement MUST have one "this-system" by-component.</message>
</expect>
</constraints>
</context>

<context>
<metapath target="/system-security-plan/system-characteristics/authorization-boundary/diagram/link"/>
Expand Down

0 comments on commit 18a02c9

Please sign in to comment.