Skip to content
This repository has been archived by the owner on Oct 27, 2024. It is now read-only.

Adding Framework/Skip-Framework functionality #134

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@
"title": "Skip SSL cert verification",
"markdownDescription": "Skip SSL certificate verification. Use this to bypass errors related to SSL certificates. Warning: this should only be used for testing purposes. Skipping certificate verification is dangerous as invalid and falsified certificates cannot be detected.",
"type": "boolean"
},
"checkov.skipFrameworks": {
"title": "Skip Frameworks",
"markdownDescription": "Filter scan to skip specific frameworks (e.g., 'arm json secrets serverless'). \n Add multiple frameworks using spaces. \n See [Checkov Frameworks](https://www.checkov.io/2.Basics/CLI%20Command%20Reference.html) for more information. \n You may need to run the extension command 'Clear Checkov results cache' after modifying this setting.",
"type": "string"
},
"checkov.frameworks": {
"title": "Frameworks",
"markdownDescription": "Filter scan to run only on specific frameworks (e.g., 'arm json secrets serverless'). \n Add multiple frameworks using spaces. \n See [Checkov Frameworks](https://www.checkov.io/2.Basics/CLI%20Command%20Reference.html) for more information. \n You may need to run the extension command 'Clear Checkov results cache' after modifying this setting.",
"type": "string"
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/checkov/checkovRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const cleanupStdout = (stdout: string) => stdout.replace(/.\[0m/g,''); // Clean

export const runCheckovScan = (logger: Logger, checkovInstallation: CheckovInstallation, extensionVersion: string, fileName: string, token: string,
certPath: string | undefined, useBcIds: boolean | undefined, debugLogs: boolean | undefined, noCertVerify: boolean | undefined, cancelToken: vscode.CancellationToken,
configPath: string | undefined, checkovVersion: string, prismaUrl: string | undefined, externalChecksDir: string | undefined): Promise<CheckovResponse> => {
configPath: string | undefined, checkovVersion: string, prismaUrl: string | undefined, externalChecksDir: string | undefined, skipFrameworks: string[] | undefined, frameworks: string[] | undefined): Promise<CheckovResponse> => {
return new Promise((resolve, reject) => {
const { checkovInstallationMethod, checkovPath } = checkovInstallation;
const timestamp = Date.now();
Expand All @@ -75,11 +75,13 @@ export const runCheckovScan = (logger: Logger, checkovInstallation: CheckovInsta
const noCertVerifyParam: string[] = noCertVerify ? ['--no-cert-verify'] : [];
const skipCheckParam: string[] = skipChecks.length ? ['--skip-check', skipChecks.join(',')] : [];
const externalChecksParams: string[] = externalChecksDir && checkovInstallationMethod !== 'docker' ? ['--external-checks-dir', externalChecksDir] : [];
const frameworkParams: string[] = frameworks ? ['--framework', frameworks.join(' ')] : [];
const skipFrameworkParams: string[] = skipFrameworks ? ['--skip-framework', skipFrameworks.join(' ')] : [];
const workingDir = vscode.workspace.rootPath;
getGitRepoName(logger, vscode.window.activeTextEditor?.document.fileName).then((repoName) => {
const repoIdParams = repoName ? ['--repo-id', repoName] : [];
const checkovArguments: string[] = [...dockerRunParams, ...certificateParams, ...bcIdParam, ...noCertVerifyParam, '-s', '--bc-api-key', token,
...repoIdParams, ...filePathParams, ...skipCheckParam, '-o', 'json', ...pipRunParams, ...externalChecksParams];
...repoIdParams, ...filePathParams, ...skipCheckParam, '-o', 'json', ...pipRunParams, ...externalChecksParams, ...frameworkParams, ...skipFrameworkParams];
logger.info('Running checkov:');
logger.info(`${checkovPath} ${checkovArguments.map(argument => argument === token ? '****' : argument).join(' ')}`);

Expand Down
13 changes: 13 additions & 0 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ export const getNoCertVerify = (): boolean | undefined => {
return noCertVerify;
};

export const getSkipFrameworks = (): string[] | undefined => {
const configuration: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration('checkov');
const skipFrameworks = configuration.get<string>('skipFrameworks');
return skipFrameworks ? skipFrameworks.split(' ').map(entry => entry.trim()) : undefined;
};

export const getFrameworks = (): string[] | undefined => {
const configuration: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration('checkov');
const frameworks = configuration.get<string>('frameworks');
return frameworks ? frameworks.split(' ').map(entry => entry.trim()) : undefined;
};


export const getCheckovVersion = async (logger: Logger): Promise<string> => {

const configuration: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration('checkov');
Expand Down
10 changes: 6 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from 'vscode';
import { TextEncoder } from 'util';

Check warning on line 2 in src/extension.ts

View workflow job for this annotation

GitHub Actions / lint

'TextEncoder' is defined but never used
import debounce from 'lodash/debounce';
import { Logger } from 'winston';
import { CheckovInstallation, FailedCheckovCheck, installOrUpdateCheckov, runCheckovScan } from './checkov';
Expand All @@ -7,13 +7,13 @@
import { fixCodeActionProvider, providedCodeActionKinds } from './suggestFix';
import { getLogger, saveCheckovResult, isSupportedFileType, extensionVersion, runVersionCommand, getFileHash, saveCachedResults, getCachedResults, clearCache, checkovVersionKey } from './utils';
import { initializeStatusBarItem, setErrorStatusBarItem, setPassedStatusBarItem, setReadyStatusBarItem, setSyncingStatusBarItem, showAboutCheckovMessage, showContactUsDetails } from './userInterface';
import { assureTokenSet, getCheckovVersion, shouldDisableErrorMessage, getPathToCert, getUseBcIds, getPrismaUrl, getUseDebugLogs, getExternalChecksDir, getNoCertVerify } from './configuration';
import { assureTokenSet, getCheckovVersion, shouldDisableErrorMessage, getPathToCert, getUseBcIds, getPrismaUrl, getUseDebugLogs, getExternalChecksDir, getNoCertVerify, getSkipFrameworks, getFrameworks } from './configuration';
import { CLEAR_RESULTS_CACHE, GET_INSTALLATION_DETAILS_COMMAND, INSTALL_OR_UPDATE_CHECKOV_COMMAND, OPEN_CHECKOV_LOG, OPEN_CONFIGURATION_COMMAND, OPEN_EXTERNAL_COMMAND, REMOVE_DIAGNOSTICS_COMMAND, RUN_FILE_SCAN_COMMAND } from './commands';
import { getConfigFilePath } from './parseCheckovConfig';

export const CHECKOV_MAP = 'checkovMap';
const logFileName = 'checkov.log';
const tempScanFile = 'temp.tf';

Check warning on line 16 in src/extension.ts

View workflow job for this annotation

GitHub Actions / lint

'tempScanFile' is assigned a value but never used

// this method is called when extension is activated
export function activate(context: vscode.ExtensionContext): void {
Expand Down Expand Up @@ -147,6 +147,8 @@
const noCertVerify = getNoCertVerify();
const checkovVersion = await getCheckovVersion(logger);
const externalChecksDir = getExternalChecksDir();
const skipFrameworks = getSkipFrameworks();
const frameworks = getFrameworks();
vscode.commands.executeCommand(REMOVE_DIAGNOSTICS_COMMAND);
if (!fileUri && vscode.window.activeTextEditor && !isSupportedFileType(vscode.window.activeTextEditor.document.fileName, true))
return;
Expand All @@ -164,11 +166,11 @@
logger.debug(`useCache is true, but did not find cached results for file: ${vscode.window.activeTextEditor.document.fileName}, hash: ${hash}`);
}
}
await runScan(vscode.window.activeTextEditor, token, certPath, useBcIds, debugLogs, noCertVerify, checkovRunCancelTokenSource.token, checkovVersion, prismaUrl, externalChecksDir, fileUri);
await runScan(vscode.window.activeTextEditor, token, certPath, useBcIds, debugLogs, noCertVerify, checkovRunCancelTokenSource.token, checkovVersion, prismaUrl, externalChecksDir, fileUri, skipFrameworks, frameworks);
}
};

const runScan = debounce(async (editor: vscode.TextEditor, token: string, certPath: string | undefined, useBcIds: boolean | undefined, debugLogs: boolean | undefined, noCertVerify: boolean | undefined, cancelToken: vscode.CancellationToken, checkovVersion: string, prismaUrl: string | undefined, externalChecksDir: string | undefined, fileUri?: vscode.Uri): Promise<void> => {
const runScan = debounce(async (editor: vscode.TextEditor, token: string, certPath: string | undefined, useBcIds: boolean | undefined, debugLogs: boolean | undefined, noCertVerify: boolean | undefined, cancelToken: vscode.CancellationToken, checkovVersion: string, prismaUrl: string | undefined, externalChecksDir: string | undefined, fileUri?: vscode.Uri, skipFrameworks?: string[] | undefined, frameworks?: string[] | undefined): Promise<void> => {
logger.info('Starting to scan.');
try {
setSyncingStatusBarItem(checkovInstallation?.version, 'Checkov scanning');
Expand All @@ -180,7 +182,7 @@
return;
}

const checkovResponse = await runCheckovScan(logger, checkovInstallation, extensionVersion, filePath, token, certPath, useBcIds, debugLogs, noCertVerify, cancelToken, configPath, checkovVersion, prismaUrl, externalChecksDir);
const checkovResponse = await runCheckovScan(logger, checkovInstallation, extensionVersion, filePath, token, certPath, useBcIds, debugLogs, noCertVerify, cancelToken, configPath, checkovVersion, prismaUrl, externalChecksDir, skipFrameworks, frameworks);
handleScanResults(filePath, editor, context.workspaceState, checkovResponse.results.failedChecks, logger);
} catch (error) {
if (cancelToken.isCancellationRequested) {
Expand Down
Loading