-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Create compliance build #16286
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
Merged
TravisEz13
merged 18 commits into
PowerShell:master
from
TravisEz13:create-compliance-build
Oct 28, 2021
Merged
Create compliance build #16286
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9c3db18
inital compliance pipeline
TravisEz13 df21a05
fix parentJobs
TravisEz13 726eb5e
fix stage deps
TravisEz13 02719ec
variable group need to authorize first
TravisEz13 1c30981
update credscan version
TravisEz13 3e2e4d6
don't run credscan and poliCheck in official builds
TravisEz13 877d48f
use API to generate notice
TravisEz13 f0b08e4
convert to secure string
TravisEz13 5fc1ae8
remove extra stuff
TravisEz13 3608c72
log uri
TravisEz13 23ce917
fix uri
TravisEz13 f5c6d1b
switch to windows
TravisEz13 194a72f
disable binskim upload in compliance build
TravisEz13 a5a2166
don't upload binskim
TravisEz13 dbb7001
Add header to additional attributions
TravisEz13 11cc873
Add comments for CG functions
TravisEz13 83e439f
Update tools/releaseBuild/azureDevOps/templates/compliance/generateNo…
TravisEz13 5be65ec
Address PR Comments
TravisEz13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| Class CgData { | ||
| [pscredential]$Pat | ||
| [string]$Organization | ||
| [string]$Project | ||
|
|
||
| CgData ([pscredential]$Pat, [string]$Organization, [string]$Project) { | ||
| $this.Pat = $Pat | ||
| $this.Organization = $Organization | ||
| $this.Project = $Project | ||
| } | ||
| } | ||
|
|
||
| # Get the Component Governance data needed to connect to the API | ||
| function Get-CgData { | ||
| if($Script:cgData){return $Script:cgData} | ||
| throw "First call Set-CgCredentials" | ||
| } | ||
|
|
||
| # Get a Component Governance API URI | ||
| function Get-Uri { | ||
| param( | ||
| [Parameter(Mandatory=$true)] | ||
| [string]$PathPortion | ||
| ) | ||
| $cgData = Get-CgData | ||
| $baseUri = "https://governance.dev.azure.com/$($cgData.Organization)/$($cgData.Project)/_apis/componentgovernance/$PathPortion" | ||
| Write-Verbose "uri: $baseUri" -Verbose | ||
| return $baseUri | ||
| } | ||
|
|
||
| # A class representing a Component Governance repository | ||
| class CgRepository { | ||
| #Json formatted summary information about this repository. Currently contains number of active nuget.config alerts. | ||
| [Object] $additionalInformation | ||
|
|
||
| #The associations for this governed repository. For example, all service tree related entries. | ||
| [Object] $associations | ||
|
|
||
| #Creator of the governed repository. | ||
| [Object] $createdBy | ||
|
|
||
| [string] $createdDate | ||
|
|
||
| [int] $id | ||
|
|
||
| [string] $modifiedBy | ||
|
|
||
| [string] $modifiedDate | ||
|
|
||
| [string] $name | ||
|
|
||
| #The policies that are configured in the governed repository. | ||
| [object[]] $policies | ||
|
|
||
| [object] $projectReference | ||
|
|
||
| [string] $repositoryMoniker | ||
|
|
||
| [object] $repositoryOptions | ||
|
|
||
| [object] $type | ||
|
|
||
| [string] $url | ||
|
|
||
| [object] $userRole | ||
| } | ||
|
|
||
| # Gets a list of all repositories governed in the current project | ||
| function Get-CgRepositories { | ||
| $uri = Get-Uri -PathPortion "governedrepositories?api-version=6.1-preview.1" | ||
| $cgData = Get-CgData | ||
| [CgRepository[]] (Invoke-RestMethod -Uri $uri -Authentication Basic -Credential $cgData.Pat).value | ||
| } | ||
|
|
||
| # Gets this PowerShell master repository | ||
| Function Get-CgPsRepository { | ||
| Get-CgRepositories | Where-Object {$_.name -eq 'PowerShell' -and $_.repositoryMoniker -notlike '*/*'} | ||
| } | ||
|
|
||
| # Gets the Component Governance Snapshot Type (unique to each Pipeline and Job) in the repository | ||
| function Get-CgSnapshotType { | ||
| param( | ||
| [CgRepository] | ||
| $CgRepository | ||
| ) | ||
|
|
||
| $id = $CgRepository.Id | ||
| $uri = Get-Uri -PathPortion "GovernedRepositories/$id/snapshottypes?api-version=6.1-preview.1" | ||
| $cgData = Get-CgData | ||
| (Invoke-RestMethod -Authentication Basic -Credential $cgData.Pat -Uri $uri).Value | ||
| } | ||
|
|
||
| # Gets a Component Governance Notice for a given snapshot type | ||
| function Get-CgNotice { | ||
| param( | ||
| [CgRepository] | ||
| $CgRepository, | ||
| [int] | ||
| $SnapshotTypeId | ||
| ) | ||
|
|
||
| $id = $CgRepository.Id | ||
| $uri = Get-Uri -PathPortion "GovernedRepositories/${id}/notice?snapshotTypeId=${SnapshotTypeId}&api-version=6.1-preview.1" | ||
| $cgData = Get-CgData | ||
| (Invoke-RestMethod -Authentication Basic -Credential $cgData.Pat -Uri $uri).content | ||
| } | ||
|
|
||
| # Sets the Component Governance credentials used by other functions to connect to the API | ||
| function Set-CgCredentials { | ||
| param( | ||
| [Parameter(Mandatory=$true)] | ||
| [securestring] $Pat, | ||
|
|
||
| [Parameter(Mandatory=$true)] | ||
| [string] $Organization, | ||
|
|
||
| [Parameter(Mandatory=$true)] | ||
| [string] $Project | ||
| ) | ||
|
|
||
| $pscred = [PSCredential]::new("PAT",$Pat) | ||
| $script:cgData = [CgData]::new($pscred, $Organization, $Project) | ||
| } | ||
|
|
||
| Export-ModuleMember -Function @( | ||
| 'Get-CgRepositories' | ||
| 'Set-CgCredentials' | ||
| 'Get-CgRepository' | ||
| 'Get-CgPsRepository' | ||
| 'Get-CgSnapshotType' | ||
| 'Get-CgNotice' | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| name: Compliance-$(Build.BuildId) | ||
|
|
||
| trigger: none | ||
| pr: none | ||
|
|
||
| schedules: | ||
| # Chrontab format, see https://en.wikipedia.org/wiki/Cron | ||
| # this is in UTC | ||
| - cron: '0 13 * * *' | ||
TravisEz13 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| branches: | ||
| include: | ||
| - master | ||
|
|
||
| resources: | ||
| repositories: | ||
| - repository: ComplianceRepo | ||
| type: github | ||
| endpoint: ComplianceGHRepo | ||
| name: PowerShell/compliance | ||
| ref: master | ||
|
|
||
| variables: | ||
| - name: DOTNET_CLI_TELEMETRY_OPTOUT | ||
| value: 1 | ||
| - name: POWERSHELL_TELEMETRY_OPTOUT | ||
| value: 1 | ||
| - name: NugetSecurityAnalysisWarningLevel | ||
| value: none | ||
| # Defines the variables AzureFileCopySubscription, StorageAccount, StorageAccountKey, StorageResourceGroup, StorageSubscriptionName | ||
| - group: 'Azure Blob variable group' | ||
| # Defines the variables CgPat, CgOrganization, and CgProject | ||
| - group: 'ComponentGovernance' | ||
|
|
||
| stages: | ||
| - stage: compliance | ||
| dependsOn: [] | ||
| jobs: | ||
| - template: templates/compliance/compliance.yml | ||
| parameters: | ||
| parentJobs: [] | ||
| - template: templates/compliance/generateNotice.yml | ||
| parameters: | ||
| parentJobs: [] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
tools/releaseBuild/azureDevOps/templates/compliance/compliance.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| parameters: | ||
| - name: parentJobs | ||
| type: jobList | ||
|
|
||
| jobs: | ||
| - job: compliance | ||
| variables: | ||
| - name: runCodesignValidationInjection | ||
| value : false | ||
| - name: NugetSecurityAnalysisWarningLevel | ||
| value: none | ||
|
|
||
| # Defines the variables APIScanClient, APIScanTenant and APIScanSecret | ||
| - group: PS-PS-APIScan | ||
|
|
||
| displayName: Compliance | ||
| dependsOn: | ||
| ${{ parameters.parentJobs }} | ||
| pool: | ||
| name: PowerShell1ES | ||
| demands: | ||
| - ImageOverride -equals MMS2019 | ||
|
|
||
| # APIScan can take a long time | ||
| timeoutInMinutes: 180 | ||
|
|
||
| steps: | ||
| - checkout: self | ||
| clean: true | ||
|
|
||
| - task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@3 | ||
| displayName: 'Run CredScan' | ||
| inputs: | ||
| suppressionsFile: tools/credScan/suppress.json | ||
| debugMode: false | ||
| continueOnError: true | ||
|
|
||
| - task: securedevelopmentteam.vss-secure-development-tools.build-task-policheck.PoliCheck@1 | ||
| displayName: 'Run PoliCheck' | ||
| inputs: | ||
| # targetType F means file or folder and is the only applicable value and the default | ||
| targetType: F | ||
| # 1 to enable source code comment scanning, which is what we should do for open source | ||
| optionsFC: 1 | ||
| # recurse | ||
| optionsXS: 1 | ||
| # run for severity 1, 2, 3 and 4 issues | ||
| optionsPE: '1|2|3|4' | ||
| # disable history management | ||
| optionsHMENABLE: 0 | ||
| # Excluclusion access database | ||
| optionsRulesDBPath: '$(Build.SourcesDirectory)\tools\terms\PowerShell-Terms-Rules.mdb' | ||
| # Terms Exclusion xml file | ||
| optionsUEPath: $(Build.SourcesDirectory)\tools\terms\TermsExclusion.xml | ||
| continueOnError: true | ||
|
|
||
| - task: securedevelopmentteam.vss-secure-development-tools.build-task-publishsecurityanalysislogs.PublishSecurityAnalysisLogs@2 | ||
| displayName: 'Publish Security Analysis Logs to Build Artifacts' | ||
| continueOnError: true | ||
|
|
||
| - task: securedevelopmentteam.vss-secure-development-tools.build-task-uploadtotsa.TSAUpload@1 | ||
| displayName: 'TSA upload to Codebase: PowerShellCore_201906' | ||
| inputs: | ||
| tsaVersion: TsaV2 | ||
| codeBaseName: 'PowerShellCore_201906' | ||
| uploadFortifySCA: false | ||
| uploadFxCop: false | ||
| uploadModernCop: false | ||
| uploadPREfast: false | ||
| uploadRoslyn: false | ||
| uploadTSLint: false | ||
| uploadCredScan: true | ||
| uploadPoliCheck: true | ||
| uploadBinSkim: false | ||
|
|
||
| - task: securedevelopmentteam.vss-secure-development-tools.build-task-report.SdtReport@1 | ||
| displayName: 'Create Security Analysis Report' | ||
| inputs: | ||
| TsvFile: false | ||
| APIScan: false | ||
| BinSkim: false | ||
| CredScan: true | ||
| PoliCheck: true | ||
| PoliCheckBreakOn: Severity2Above | ||
|
|
||
| - task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0 | ||
| displayName: 'Component Detection' | ||
| inputs: | ||
| sourceScanPath: '$(Build.SourcesDirectory)' | ||
| snapshotForceEnabled: true |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.