Skip to content

Commit

Permalink
feat(bandit): Add Bandit to CI pipeline
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Schreckengaust <[email protected]>
  • Loading branch information
scottschreckengaust committed Nov 16, 2023
1 parent 8ed1d22 commit 0661fe3
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes

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

33 changes: 33 additions & 0 deletions .github/workflows/bandit.yml

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

1 change: 1 addition & 0 deletions .gitignore

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

1 change: 1 addition & 0 deletions .projen/files.json

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

2 changes: 2 additions & 0 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
buildAutoApproveWorkflow,
buildOrtToolkitWorkflow,
runSemGrepWorkflow,
runBanditWorkflow,
} from './projenrc/github-workflows';

// Constants
Expand Down Expand Up @@ -94,6 +95,7 @@ buildUpdateContributorsWorkflow(project);
buildAutoApproveWorkflow(project);
buildOrtToolkitWorkflow(project);
runSemGrepWorkflow(project);
runBanditWorkflow(project);

// Add specific overrides https://projen.io/github.html#actions-versions
project.github?.actions.set("actions/checkout@v3", "actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744");
Expand Down
76 changes: 76 additions & 0 deletions projenrc/github-workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,79 @@ export function runSemGrepWorkflow(project: AwsCdkConstructLibrary) {
}
}
}

/**
* https://github.com/mdegis/bandit-action
* Runs Bandit on the repository.
* @param project AwsCdkConstructLibrary
*/
export function runBanditWorkflow(project: AwsCdkConstructLibrary) {
const bandit: Job = {
name: 'bandit/ci',
runsOn: ['ubuntu-latest'],
// container: {
// image: 'returntocorp/semgrep',
// },
permissions: {
contents: JobPermission.READ,
pullRequests: JobPermission.READ,
securityEvents: JobPermission.WRITE,
actions: JobPermission.READ,
},
if: "(github.actor != 'dependabot[bot]')",

steps: [
{
name: 'Checkout project',
uses: 'actions/checkout@v3',
},
{
name: 'Setup Python',
uses: 'actions/setup-python@v4',
},
{
name: 'Run Bandit',
run: 'bandit --recursive --format html --output bandit-report.html .',
},
{
name: 'Store Bandit as Artifact',
uses: 'actions/upload-artifact@v3',
with: {
name: 'bandit-report.html',
path: 'bandit-report.html',
},
},
// `awslabs` has the Advanced Security disabled.
// {
// name: 'Upload SARIF file for GitHub Advanced Security Dashboard',
// uses: 'github/codeql-action/upload-sarif@v2',
// with: {
// sarif_file: 'semgrep.sarif',
// },
// if: 'always()',
// },
],
};

if (project.github) {
const workflow = project.github.addWorkflow('bandit');
if (workflow) {
workflow.on({
pullRequest: {},
workflowDispatch: {
},
push: {
branches: [
'main',
],
},
schedule: [
{ cron: '20 17 * * *' },
],
});
workflow.addJobs({
bandit: bandit,
});
}
}
}

0 comments on commit 0661fe3

Please sign in to comment.