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

[StepSecurity] Apply security best practices #17

Closed
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
43 changes: 43 additions & 0 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Test a branch on canary
on:
workflow_dispatch:
inputs:
COMMIT_SHA:
description: 'Commit SHA to be tested'
required: true

env:
COMMIT_SHA: ${{ github.event.inputs.COMMIT_SHA }}
defaults:
run:
shell: pwsh

permissions: # added using https://github.com/step-security/secure-workflows
contents: read

jobs:
update_tag:
name: Update the rc tag to ${{ github.event.inputs.COMMIT_SHA }} commit
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v1
with:
egress-policy: audit
allowed-endpoints:
api.github.com:443
github.com:443

- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v2
- name: Update the rc tag
uses: step-security/publish-action@b438f840875fdcb7d1de4fc3d1d30e86cf6acb5d
with:
rc-sha: ${{ env.COMMIT_SHA }}
rc: true

- name: Canary test
uses: docker://ghcr.io/step-security/integration-test/int:latest@sha256:cd10adbca15cf7e07d9ae5d623109899ded50687cabd7b952dfeb2daa76d6347
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Medium]Use approved base images in containers

The base image for the canary test container is not specified and may not be approved. Always specify a base image that is approved.

env:
PAT: ${{ secrets.PAT }}
canary: true
23 changes: 23 additions & 0 deletions .github/workflows/code-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Code Review
on:
pull_request:
permissions:
contents: read
jobs:
code-review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
int.api.stepsecurity.io:443

- name: Code Review
uses: step-security/ai-codewise@ab9fe138367d6094b2df7f8469ddc2c5a79c9cf4 # int
78 changes: 78 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Low]Add comments to explain what the workflow does

The workflow file is missing comments explaining what it does. This will help others understand the purpose of the file and the steps in it. Add comments above each step to explain what it does and why it's necessary. Add a comment at the top of the file that explains the purpose of the workflow.


on:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
schedule:
- cron: '17 0 * * 2'

permissions: # added using https://github.com/step-security/secure-workflows
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Medium]Avoid exposing unnecessary permissions in actions

The workflow specifies permissions for contents, actions and security-events, which might be more permissive than necessary. It's recommended to only include the necessary permissions. Only list the necessary permissions in the workflow file. For example, if the workflow file doesn't need to push to the repository, remove the contents permission.

contents: read

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support

steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@cdcdbb579706841c47f7063dda365e292e5cad7a
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@cdcdbb579706841c47f7063dda365e292e5cad7a

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Low]Remove commented-out code

The workflow file contains commented-out code in the Autobuild step. This can be confusing and should be removed. Remove the commented-out lines.

# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@cdcdbb579706841c47f7063dda365e292e5cad7a
24 changes: 24 additions & 0 deletions .github/workflows/recurring-int-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Recurring INT tests
on:
workflow_dispatch:
schedule:
- cron: '0 */2 * * *' # every other hour

permissions:
contents: read

jobs:
int-tests:
name: int tests
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- name: Canary test
uses: docker://ghcr.io/step-security/integration-test/int:latest@sha256:cd10adbca15cf7e07d9ae5d623109899ded50687cabd7b952dfeb2daa76d6347
env:
PAT: ${{ secrets.PAT }}
canary: true
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit

- uses: actions/checkout@v3
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- uses: ./
with:
name: "new-json-file.json"
Expand Down
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ repos:
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.38.0
hooks:
- id: eslint