Skip to content

Commit

Permalink
[StepSecurity] Apply security best practices (#1379)
Browse files Browse the repository at this point in the history
- Add https://github.com/gitleaks/gitleaks to pre commit config
- Add missing top-level permissions and harden runner steps
- Add Scorecard analysis

StepSecurity analysis:
step-security-bot@f79b588#diff-63a9c44a44acf85fea213a857769990937107cf072831e1a26808cfde9d096b9
  • Loading branch information
mazhelez authored Jan 8, 2025
1 parent 7700ec4 commit 9564abf
Show file tree
Hide file tree
Showing 46 changed files with 248 additions and 110 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ defaults:
run:
shell: pwsh

permissions:
contents: read

jobs:
Test:
runs-on: [ ubuntu-latest ]
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Run Tests
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/CleanupTempRepos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ defaults:
run:
shell: pwsh

permissions:
contents: read

jobs:
Check:
runs-on: [ ubuntu-latest ]
outputs:
githubOwner: ${{ steps.check.outputs.githubOwner }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Check secrets
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/Deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ jobs:
createRelease: ${{ steps.CreateInputs.outputs.createRelease }}
defaultBcContainerHelperVersion: ${{ steps.CreateInputs.outputs.defaultBcContainerHelperVersion }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- name: Create inputs
id: CreateInputs
run: |
Expand All @@ -72,6 +77,11 @@ jobs:
runs-on: [ ubuntu-latest ]
needs: [ Inputs ]
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- name: Check successful end 2 end tests have run
if: github.repository_owner == 'microsoft' && needs.Inputs.outputs.requireEndToEndTests == 'true'
env:
Expand Down Expand Up @@ -104,6 +114,11 @@ jobs:
permissions:
contents: write
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- name: Validate Deployment
if: github.repository_owner == 'microsoft'
env:
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/E2E.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@ defaults:
run:
shell: pwsh

permissions:
contents: read

jobs:
Check:
runs-on: [ ubuntu-latest ]
outputs:
maxParallel: ${{ steps.check.outputs.maxParallel }}
githubOwner: ${{ steps.check.outputs.githubOwner }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Check secrets
Expand Down Expand Up @@ -92,6 +100,11 @@ jobs:
perTenantExtensionRepo: ${{ steps.setup.outputs.perTenantExtensionRepo }}
appSourceAppRepo: ${{ steps.setup.outputs.appSourceAppRepo }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.inputs.ref }}
Expand All @@ -111,6 +124,11 @@ jobs:
releases: ${{ steps.Analyze.outputs.releases }}
scenarios: ${{ steps.Analyze.outputs.scenarios }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.inputs.ref }}
Expand Down Expand Up @@ -187,6 +205,11 @@ jobs:
if: github.event.inputs.runScenarios == 'true'
strategy: ${{ fromJson(needs.Analyze.outputs.scenarios) }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.inputs.ref }}
Expand Down Expand Up @@ -218,6 +241,11 @@ jobs:
if: github.event.inputs.runScenarios == 'true'
strategy: ${{ fromJson(needs.Analyze.outputs.scenarios) }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.inputs.ref }}
Expand Down Expand Up @@ -249,6 +277,11 @@ jobs:
if: github.event.inputs.runTestMatrix == 'true'
strategy: ${{ fromJson(needs.Analyze.outputs.publictestruns) }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.inputs.ref }}
Expand Down Expand Up @@ -292,6 +325,11 @@ jobs:
if: github.event.inputs.runTestMatrix == 'true' && github.event.inputs.includePrivateRepos == 'true'
strategy: ${{ fromJson(needs.Analyze.outputs.privatetestruns) }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.inputs.ref }}
Expand Down Expand Up @@ -336,6 +374,11 @@ jobs:
if: github.event.inputs.runUpgradeTests == 'true'
strategy: ${{ fromJson(needs.Analyze.outputs.releases) }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.inputs.ref }}
Expand Down Expand Up @@ -376,6 +419,11 @@ jobs:
needs: [ Check, SetupRepositories, TestAlGoPublic, TestAlGoPrivate, TestAlGoUpgrade, ScenariosOnWindows, ScenariosOnLinux ]
if: always() && (!Cancelled()) && (needs.SetupRepositories.result == 'Success') && (needs.TestAlGoPublic.result == 'Success' || needs.TestAlGoPublic.result == 'Skipped') && (needs.TestAlGoPrivate.result == 'Success' || needs.TestAlGoPrivate.result == 'Skipped') && (needs.TestAlGoUpgrade.result == 'Success' || needs.TestAlGoUpgrade.result == 'Skipped') && (needs.Scenario.result == 'Success' || needs.Scenario.result == 'Skipped')
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.inputs.ref }}
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/powershell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ jobs:
name: PSScriptAnalyzer
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Run PSScriptAnalyzer
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ on:
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
pre-commit:
runs-on: windows-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/scorecard-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Scorecard Analysis
on:
branch_protection_rule:
schedule:
- cron: "0 8 * * 4" # Weekly on Thursday at 08:00 UTC
push:
branches: ["main"]

permissions: read-all

jobs:
analysis:
name: Scorecard analysis
runs-on: ubuntu-latest
permissions:
security-events: write # Needed to upload the results to code-scanning dashboard.
id-token: write # Needed to publish results and get a badge (see publish_results below).

steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- name: "Checkout code"
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@dc50aa9510b46c811795eb24b2f1ba02a914e534 # v2.3.3
with:
results_file: results.sarif
results_format: sarif
publish_results: true

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@48ab28a6f5dbc2a99bf1e0131198dd8f1df78169 # v3.28.0
with:
sarif_file: results.sarif
9 changes: 7 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

repos:
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
rev: 0.7.21
hooks:
- id: mdformat
args: [--end-of-line=keep]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -22,3 +22,8 @@ repos:
- id: trailing-whitespace
- id: mixed-line-ending
- id: sort-simple-yaml

- repo: https://github.com/gitleaks/gitleaks
rev: v8.16.3
hooks:
- id: gitleaks
2 changes: 1 addition & 1 deletion Actions/ReadSecrets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ none
| Name | Description |
| :-- | :-- |
| Secrets | A compressed json construct with all requested secrets base64 encoded. Secrets preceded by an asterisk (\*) are encrypted before base64 encoding. The secret value + the base64 value of the secret value are masked in the log |
| TokenForPush | The token to use when workflows are pushing changes (either directly, or via pull requests). This is either the GITHUB_TOKEN or the GhTokenWorkflow secret (based on the env variable useGhTokenWorkflowForPush) |
| TokenForPush | The token to use when workflows are pushing changes (either directly, or via pull requests). This is either the GITHUB_TOKEN or the GhTokenWorkflow secret (based on the env variable useGhTokenWorkflowForPush) |
2 changes: 1 addition & 1 deletion Actions/ReadSettings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ none
| :-- | :-- |
| Settings | A compressed JSON structure with ALL AL-Go settings, independent of the get parameter. If project was not specified, this will only include repository settings. |

> \[!NOTE\]
> [!NOTE]
> This method creates individual environment variables for every setting specified in the get parameter.
### OUTPUT variables
Expand Down
4 changes: 2 additions & 2 deletions Actions/RunPipeline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Run pipeline in AL-Go repository
| artifact | | ArtifactUrl to use for the build | settings.artifact |
| project | | Project name if the repository is setup for multiple projects | . |
| buildMode | | Specifies a mode to use for the build steps | Default |
| installAppsJson | | A JSON-formatted list of apps to install | \[\] |
| installTestAppsJson | | A JSON-formatted list of test apps to install | \[\] |
| installAppsJson | | A JSON-formatted list of apps to install | [] |
| installTestAppsJson | | A JSON-formatted list of test apps to install | [] |

## OUTPUT

Expand Down
2 changes: 1 addition & 1 deletion Actions/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If you believe you have found a security vulnerability in any Microsoft-owned re

Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).

If you prefer to submit without logging in, send email to [[email protected]](mailto:[email protected]). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
If you prefer to submit without logging in, send email to [[email protected]](mailto:[email protected]). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).

You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Try out the [AL-Go workshop](https://aka.ms/algoworkshop) for an in-depth worksh
A. [Migrate a repository from Azure DevOps to AL-Go for GitHub without history](Scenarios/MigrateFromAzureDevOpsWithoutHistory.md)<br />
B. [Migrate a repository from Azure DevOps to AL-Go for GitHub with history](Scenarios/MigrateFromAzureDevOpsWithHistory.md)

> \[!NOTE\]
> [!NOTE]
> Please refer to [this description](Scenarios/settings.md) to learn about the settings file and how you can modify default behaviors.
# This project
Expand All @@ -58,7 +58,7 @@ This project in the main source repository for AL-Go for GitHub. This project is

Please read [this document](Scenarios/Contribute.md) to understand how to contribute to AL-Go for GitHub.

This project welcomes contributions and suggestions. Most contributions require you to agree to a
This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit [https://cla.opensource.microsoft.com](https://cla.opensource.microsoft.com).

Expand Down
Loading

0 comments on commit 9564abf

Please sign in to comment.