Skip to content

Commit

Permalink
Add checkov GitHub actions (#962)
Browse files Browse the repository at this point in the history
### Feature or Bugfix
- Feature

### Detail
#### Checkov
Add checkov github action on PRs and push to `main`
Checkov scans ignore the paths: tests/, .github, compose/, docker/dev/
that contain support or local development files.

The PR ignores the findings, which should (or not) be handled in a
separate PR
- CKV_DOCKER_2, CKV_DOCKER_4 are skipped in the checkov github action
definition. They are LOW severity recommendations
-
[CKV_DOCKER_2](https://docs.prismacloud.io/en/enterprise-edition/policy-reference/docker-policies/docker-policy-index/ensure-that-healthcheck-instructions-have-been-added-to-container-images)
- Healthcheck instructions have not been added to container images
-
[CKV_DOCKER_4](https://docs.prismacloud.io/en/enterprise-edition/policy-reference/docker-policies/docker-policy-index/ensure-that-copy-is-used-instead-of-add-in-dockerfiles)
- Copy is not used instead of Add in Dockerfiles
- Some CloudFormation findings on the pivot role and in the cdk
execution role YAML templated are skipped with `# checkov:skip=`
comments. We should review each finding one by one.

In addition, other next steps include the assessment of how we can
synthesize cdk templates so that checkov scans them.

#### Other changes
- upgraded all Python version to 3.9 in all actions
- removed duplicated `static-checking.yaml` test in favor of `flake8`
(Renamed from `Lint`
- standardize names

### Relates
- #881 

### Security
Please answer the questions below briefly where applicable, or write
`N/A`. Based on
[OWASP 10](https://owasp.org/Top10/en/).

- Does this PR introduce or modify any input fields or queries - this
includes
fetching data from storage outside the application (e.g. a database, an
S3 bucket)?
  - Is the input sanitized?
- What precautions are you taking before deserializing the data you
consume?
  - Is injection prevented by parametrizing queries?
  - Have you ensured no `eval` or similar functions are used?
- Does this PR introduce any functionality or component that requires
authorization?
- How have you ensured it respects the existing AuthN/AuthZ mechanisms?
  - Are you logging failed auth attempts?
- Are you using or adding any cryptographic features?
  - Do you use a standard proven implementations?
  - Are the used keys controlled by the customer? Where are they stored?
- Are you introducing any new policies/roles/users?
  - Have you used the least-privilege principle? How?


By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
  • Loading branch information
dlpzx authored Jan 11, 2024
1 parent b2c721c commit 50d6ac0
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: Validate DB migration with alembic

name: alembic migration tests
on:
workflow_dispatch:
pull_request:
Expand All @@ -17,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.8 ]
python-version: [ 3.9 ]
services:
postgres:
image: postgres
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: [3.9]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bandit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
bandit:
strategy:
matrix:
python-version: [3.8]
python-version: [3.9]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cdk-nag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
cdk-nag:
strategy:
matrix:
python-version: [3.8]
python-version: [3.9]
env:
CDK_DEFAULT_REGION: eu-west-1
CDK_DEFAULT_ACCOUNT: 111111111111
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/checkov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: checkov

on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main
- v2m*

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Test with Checkov
id: checkov
uses: bridgecrewio/checkov-action@master
with:
directory: .
quiet: true
skip_path: tests/, .github, compose/, docker/dev/
hard_fail_on: MEDIUM
soft_fail_on: LOW
skip_check: CKV_DOCKER_2,CKV_DOCKER_4
2 changes: 1 addition & 1 deletion .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run eslint
name: eslint

on:
workflow_dispatch:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml → .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Lint
name: flake8

on:
workflow_dispatch:
Expand All @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: [3.9]

steps:
- uses: actions/checkout@v2
Expand All @@ -28,5 +28,5 @@ jobs:
python -m pip install --upgrade pip
python -m pip install isort
python -m pip install flake8
- name: Lint
- name: flake8
run: python -m flake8 --exclude cdk.out,blueprints --ignore E402,E501,F841,W503,F405,F403,F401,E712,E203 backend/
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Coverage
name: Integration tests

on:
workflow_dispatch:
Expand All @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.8 ]
python-version: [ 3.9 ]
services:
postgres:
image: postgres
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npm-audit.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run npm-audit
name: npm-audit

on:
workflow_dispatch:
Expand Down
35 changes: 0 additions & 35 deletions .github/workflows/semgrep-schedule.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/semgrep.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Semgrep
name: semgrep

on:
workflow_dispatch:
Expand Down
32 changes: 0 additions & 32 deletions .github/workflows/static-checking.yml

This file was deleted.

4 changes: 4 additions & 0 deletions deploy/cdk_exec_policy/cdkExecPolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Parameters:
Resources:
CDKCustomExecutionPolicy0:
Type: 'AWS::IAM::ManagedPolicy'
# checkov:skip=CKV_AWS_107:Ensure IAM policies does not allow credentials exposure
# checkov:skip=CKV_AWS_109:Ensure IAM policies does not allow permissions management without constraints
# checkov:skip=CKV_AWS_110:Ensure IAM policies does not allow privilege escalation
# checkov:skip=CKV_AWS_111:Ensure IAM policies does not allow write access without constraints
Properties:
ManagedPolicyName: !Ref PolicyName
PolicyDocument:
Expand Down
5 changes: 5 additions & 0 deletions deploy/pivot_role/pivotRole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Resources:
]
PivotRolePolicy0:
Type: 'AWS::IAM::ManagedPolicy'
# checkov:skip=CKV_AWS_109:Ensure IAM policies does not allow permissions management without constraints
# checkov:skip=CKV_AWS_111:Ensure IAM policies does not allow write access without constraints
Properties:
PolicyDocument:
Version: 2012-10-17
Expand Down Expand Up @@ -221,6 +223,8 @@ Resources:

PivotRolePolicy1:
Type: 'AWS::IAM::ManagedPolicy'
# checkov:skip=CKV_AWS_109:Ensure IAM policies does not allow permissions management without constraints
# checkov:skip=CKV_AWS_111:Ensure IAM policies does not allow write access without constraints
Properties:
PolicyDocument:
Version: 2012-10-17
Expand Down Expand Up @@ -421,6 +425,7 @@ Resources:

PivotRolepolicy3:
Type: 'AWS::IAM::ManagedPolicy'
# checkov:skip=CKV_AWS_109:Ensure IAM policies does not allow permissions management without constraints
Properties:
PolicyDocument:
Version: 2012-10-17
Expand Down

0 comments on commit 50d6ac0

Please sign in to comment.