From d5773c50e25d80b13e056d302d8d25a548d8c7ae Mon Sep 17 00:00:00 2001 From: "stepsecurity-int[bot]" <185740846+stepsecurity-int[bot]@users.noreply.github.com> Date: Fri, 8 Aug 2025 15:37:28 +0000 Subject: [PATCH] Apply security best practicesSigned-off-by: StepSecurity Bot --- .github/workflows/automatePR.yml | 32 ++++++++++++ .github/workflows/int.yml | 90 ++++++++++++++++++++++++++++++++ .github/workflows/kb-test.yml | 38 ++++++++++++++ .github/workflows/kbanalysis.yml | 56 ++++++++++++++++++++ .github/workflows/release.yml | 89 +++++++++++++++++++++++++++++++ 5 files changed, 305 insertions(+) create mode 100644 .github/workflows/automatePR.yml create mode 100644 .github/workflows/int.yml create mode 100644 .github/workflows/kb-test.yml create mode 100644 .github/workflows/kbanalysis.yml create mode 100644 .github/workflows/release.yml 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/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"