diff --git a/.github/workflows/automatePR.yml b/.github/workflows/automatePR.yml new file mode 100644 index 0000000..62ad28d --- /dev/null +++ b/.github/workflows/automatePR.yml @@ -0,0 +1,32 @@ +name: Automate PR +on: + issues: + types: + - labeled + +permissions: + contents: read + +jobs: + Automate: + if: github.event.label.name == 'Automate' + runs-on: ubuntu-latest + permissions: + issues: write + actions: write + + steps: + - name: Harden Runner + uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 + with: + egress-policy: audit + + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + repository: step-security/secure-repo + + - name: Automate PR + uses: step-security/secure-repo/Automate-PR@98ff385ea512d8ac7a1445f95e199f6864f439e1 + with: + github-token: ${{secrets.PAT }} + issue-id: ${{ github.event.issue.number}} \ No newline at end of file diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..32fc2e5 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,81 @@ +# 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" + +on: + push: + branches: ["main"] + pull_request: + # The branches below must be a subset of the branches above + branches: ["main"] + schedule: + - cron: "35 17 * * 4" + +permissions: # added using https://github.com/step-security/secure-repo + contents: read + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: ["go"] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Harden Runner + uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 + with: + egress-policy: audit + + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@bc02a25f6449997c5e9d5a368879b28f56ae19a1 + 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. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + # 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@bc02a25f6449997c5e9d5a368879b28f56ae19a1 + + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@bc02a25f6449997c5e9d5a368879b28f56ae19a1 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/int.yml b/.github/workflows/int.yml new file mode 100644 index 0000000..2562cfc --- /dev/null +++ b/.github/workflows/int.yml @@ -0,0 +1,90 @@ +name: Cfnrelease-int + +on: + push: + branches: + - int + +permissions: # added using https://github.com/step-security/secure-repo + contents: read + +jobs: + publish-test: + permissions: + contents: read + id-token: write + runs-on: ubuntu-latest + steps: + - name: Harden Runner + uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 + with: + egress-policy: audit + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 + with: + go-version: 1.17 + + - run: go test ./... -coverpkg=./... + env: + PAT: ${{ secrets.PAT }} + + - uses: step-security/wait-for-secrets@084b3ae774c0e0003a9307ae4f487c10f1f998fe + id: wait-for-secrets + with: + slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }} + secrets: | + AWS_ACCESS_KEY_ID_INT: + name: 'AWS access key id' + description: 'Access key id for secure-repo int' + AWS_SECRET_ACCESS_KEY_INT: + name: 'AWS secret access key' + description: 'Secret access key for secure-repo int' + AWS_SESSION_TOKEN_INT: + name: 'AWS session token' + description: 'Session token for secure-repo int' + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@b47578312673ae6fa5b5096b330d9fbac3d116df + with: + aws-access-key-id: ${{ steps.wait-for-secrets.outputs.AWS_ACCESS_KEY_ID_INT }} + aws-secret-access-key: ${{ steps.wait-for-secrets.outputs.AWS_SECRET_ACCESS_KEY_INT }} + aws-session-token: ${{ steps.wait-for-secrets.outputs.AWS_SESSION_TOKEN_INT }} + aws-region: us-west-2 + + - name: Deploy to AWS CloudFormation + uses: aws-actions/aws-cloudformation-github-deploy@33527b83bddcf6b3f0b135d9550bde8475325c73 + with: + name: secure-workflow-api-ecr + template: cloudformation/ecr.yml + parameter-overrides: "ResourceName=secure-workflow-api" + no-fail-on-empty-changeset: "1" + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 + + - name: Build, tag, and push image to Amazon ECR + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: secure-workflow-api + IMAGE_TAG: ${{ github.sha }} + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + + - name: Deploy to AWS CloudFormation + uses: aws-actions/aws-cloudformation-github-deploy@33527b83bddcf6b3f0b135d9550bde8475325c73 + with: + name: secure-workflow-api + template: cloudformation/resources.yml + parameter-overrides: >- + ResourceName=secure-workflow-api, + ImageTag=${{ github.sha }}, + PAT=${{ secrets.PAT }} + no-fail-on-empty-changeset: "1" + + diff --git a/.github/workflows/kb-test.yml b/.github/workflows/kb-test.yml new file mode 100644 index 0000000..3f2f6c8 --- /dev/null +++ b/.github/workflows/kb-test.yml @@ -0,0 +1,38 @@ +name: Knowledge-base Test +on: + push: + branches: + - knowledge-base # to test new KBs + +permissions: # added using https://github.com/step-security/secure-workflows + contents: read +concurrency: + group: ${{ github.workflow }} +jobs: + test: + permissions: + contents: read + runs-on: ubuntu-latest + steps: + - uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 + with: + allowed-endpoints: > + api.github.com:443 + github.com:443 + proxy.golang.org:443 + sum.golang.org:443 + storage.googleapis.com:443 + objects.githubusercontent.com:443 + golang.org:443 + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Set up Go + uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 + with: + go-version: 1.17 + - name: Run coverage + run: go test ./... -coverpkg=./... -race -coverprofile=coverage.txt -covermode=atomic + env: + PAT: ${{ secrets.PAT }} \ No newline at end of file diff --git a/.github/workflows/kbanalysis.yml b/.github/workflows/kbanalysis.yml new file mode 100644 index 0000000..90491fa --- /dev/null +++ b/.github/workflows/kbanalysis.yml @@ -0,0 +1,56 @@ +name: KBAnalysis +on: + workflow_dispatch: + inputs: + owner: + type: string + description: owner of the missing KB + repo: + type: string + description: repo of the missing KB + +permissions: + contents: read + +jobs: + Analysis: + runs-on: ubuntu-latest + permissions: + issues: write + contents: write + pull-requests: write + + steps: + - name: Harden Runner + uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 + with: + egress-policy: audit + + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + repository: step-security/secure-repo + + - name: KBAnalysis + uses: step-security/secure-workflows/kbanalysis@main + with: + github-token: ${{secrets.PAT}} + owner: ${{inputs.owner}} + repo : ${{inputs.repo}} + + - id: get-action + uses: actions/github-script@5d03ada4b0a753e9460b312e61cc4f8fdeacf163 + with: + script: | + var id = "${{github.event.issue.title}}".split(' ')[6] + core.setOutput('id', id) + + - name: Create Pull Request + uses: peter-evans/create-pull-request@18f7dc018cc2cd597073088f7c7591b9d1c02672 + with: + token: ${{secrets.PAT}} # need to use PAT since GITHUB_TOKEN does not initiate workflows + commit-message: "added action-security.yml for ${{inputs.owner}}/${{inputs.repo}}" + title: "[KB] Add GitHub token permissions for ${{inputs.owner}}/${{inputs.repo}}" + branch: "kb-${{inputs.owner}}-${{inputs.repo}}" + base: "knowledge-base" + body: "PR added by kb-analysis workflow" + labels: "knowledge-base" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7b4af1b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,89 @@ +name: Cfnrelease + +on: + workflow_dispatch: + push: + branches: + - main + +permissions: # added using https://github.com/step-security/secure-repo + contents: read + +jobs: + publish-test: + permissions: + contents: read + id-token: write + runs-on: ubuntu-latest + steps: + - name: Harden Runner + uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 + with: + egress-policy: audit + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 + with: + go-version: 1.17 + + - run: go test ./... -coverpkg=./... + env: + PAT: ${{ secrets.PAT }} + + - uses: step-security/wait-for-secrets@084b3ae774c0e0003a9307ae4f487c10f1f998fe + id: wait-for-secrets + with: + slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }} + secrets: | + AWS_ACCESS_KEY_ID: + name: 'AWS access key id' + description: 'Access key id for secure-repo prod' + AWS_SECRET_ACCESS_KEY: + name: 'AWS secret access key' + description: 'Secret access key for secure-repo prod' + AWS_SESSION_TOKEN: + name: 'AWS session token' + description: 'Session token for secure-repo prod' + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@b47578312673ae6fa5b5096b330d9fbac3d116df + with: + aws-access-key-id: ${{ steps.wait-for-secrets.outputs.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ steps.wait-for-secrets.outputs.AWS_SECRET_ACCESS_KEY }} + aws-session-token: ${{ steps.wait-for-secrets.outputs.AWS_SESSION_TOKEN }} + aws-region: us-west-2 + + - name: Deploy to AWS CloudFormation + uses: aws-actions/aws-cloudformation-github-deploy@33527b83bddcf6b3f0b135d9550bde8475325c73 + with: + name: secure-workflow-api-ecr + template: cloudformation/ecr.yml + parameter-overrides: "ResourceName=secure-workflow-api" + no-fail-on-empty-changeset: "1" + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 + + - name: Build, tag, and push image to Amazon ECR + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: secure-workflow-api + IMAGE_TAG: ${{ github.sha }} + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + + - name: Deploy to AWS CloudFormation + uses: aws-actions/aws-cloudformation-github-deploy@33527b83bddcf6b3f0b135d9550bde8475325c73 + with: + name: secure-workflow-api + template: cloudformation/resources.yml + parameter-overrides: >- + ResourceName=secure-workflow-api, + ImageTag=${{ github.sha }}, + PAT=${{ secrets.PAT }} + no-fail-on-empty-changeset: "1" diff --git a/.github/workflows/scorecards.yml b/.github/workflows/scorecards.yml new file mode 100644 index 0000000..0b9c845 --- /dev/null +++ b/.github/workflows/scorecards.yml @@ -0,0 +1,77 @@ +# This workflow uses actions that are not certified by GitHub. They are provided +# by a third-party and are governed by separate terms of service, privacy +# policy, and support documentation. + +name: Scorecard supply-chain security +on: + # For Branch-Protection check. Only the default branch is supported. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection + branch_protection_rule: + # To guarantee Maintained check is occasionally updated. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained + schedule: + - cron: '33 16 * * 3' + push: + branches: [ "main" ] + +# Declare default permissions as read only. +permissions: read-all + +jobs: + analysis: + name: Scorecard analysis + runs-on: ubuntu-latest + permissions: + # Needed to upload the results to code-scanning dashboard. + security-events: write + # Needed to publish results and get a badge (see publish_results below). + id-token: write + # Uncomment the permissions below if installing in a private repository. + # contents: read + # actions: read + + steps: + - name: Harden Runner + uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 + with: + egress-policy: audit + + - name: "Checkout code" + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + persist-credentials: false + + - name: "Run analysis" + uses: ossf/scorecard-action@f49aabe0b5af0936a0987cfb85d86b75731b0186 # v2.4.1 + with: + results_file: results.sarif + results_format: sarif + # (Optional) "write" PAT token. Uncomment the `repo_token` line below if: + # - you want to enable the Branch-Protection check on a *public* repository, or + # - you are installing Scorecard on a *private* repository + # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat. + # repo_token: ${{ secrets.SCORECARD_TOKEN }} + + # Public repositories: + # - Publish results to OpenSSF REST API for easy access by consumers + # - Allows the repository to include the Scorecard badge. + # - See https://github.com/ossf/scorecard-action#publishing-results. + # For private repositories: + # - `publish_results` will always be set to `false`, regardless + # of the value entered here. + publish_results: true + + # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF + # format to the repository Actions tab. + - name: "Upload artifact" + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: SARIF file + path: results.sarif + retention-days: 5 + + # Upload the results to GitHub's code scanning dashboard. + - name: "Upload to code-scanning" + uses: github/codeql-action/upload-sarif@bc02a25f6449997c5e9d5a368879b28f56ae19a1 + with: + sarif_file: results.sarif diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..e2312af --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,47 @@ +name: Test +on: + pull_request: + branches: + - main + push: + branches: + - main # to update code coverage + +permissions: # added using https://github.com/step-security/secure-repo + contents: read + +jobs: + test: + permissions: + contents: read + runs-on: ubuntu-latest + steps: + - uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 + with: + egress-policy: audit + allowed-endpoints: > + api.github.com:443 + cli.codecov.io:443 + codecov.io:443 + uploader.codecov.io:443 + github.com:443 + proxy.golang.org:443 + sum.golang.org:443 + storage.googleapis.com:443 + objects.githubusercontent.com:443 + golang.org:443 + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Set up Go + uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 + with: + go-version: 1.17 + - name: Run coverage + run: go test ./... -coverpkg=./... -race -coverprofile=coverage.txt -covermode=atomic + env: + PAT: ${{ secrets.GITHUB_TOKEN }} + - uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..cba0860 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +repos: +- repo: https://github.com/gitleaks/gitleaks + rev: v8.16.3 + hooks: + - id: gitleaks +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace