Skip to content

Commit 87d202b

Browse files
committed
Merge branch 'main' into secrets-low
2 parents 24cd194 + 810e5c9 commit 87d202b

File tree

6 files changed

+44
-82
lines changed

6 files changed

+44
-82
lines changed

eng/common/Dockerfile.syft

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
ARG SYFT_IMAGE_NAME
2+
ARG TARGET_IMAGE_NAME
3+
4+
FROM ${SYFT_IMAGE_NAME} AS syft
5+
FROM ${TARGET_IMAGE_NAME} AS scan-image
6+
7+
FROM syft AS run-scan
8+
ARG TARGET_IMAGE_NAME
9+
ENV SYFT_CHECK_FOR_APP_UPDATE=0 \
10+
SYFT_SOURCE_NAME=${TARGET_IMAGE_NAME}
11+
USER root
12+
RUN --mount=from=scan-image,source=/,target=/rootfs \
13+
["/syft", "scan", "/rootfs/", "--select-catalogers", "image", "--output", "spdx-json=/manifest.spdx.json"]
14+
15+
FROM scratch AS output
16+
COPY --from=run-scan /manifest.spdx.json /manifest.spdx.json

eng/common/Pull-Image.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env pwsh
2+
3+
[cmdletbinding()]
4+
param(
5+
[Parameter(Mandatory = $true, Position = 0)]
6+
[string]$Image,
7+
8+
[Parameter(Mandatory = $false)]
9+
[int]$Retries = 2,
10+
11+
[Parameter(Mandatory = $false)]
12+
[int]$WaitFactor = 6
13+
)
14+
15+
Set-StrictMode -Version Latest
16+
$ErrorActionPreference = 'Stop'
17+
18+
& "$PSScriptRoot/Invoke-WithRetry.ps1" "docker pull $Image" -Retries $Retries -WaitFactor $WaitFactor

eng/common/pull-image.sh

Lines changed: 0 additions & 37 deletions
This file was deleted.

eng/common/templates/jobs/build-images.yml

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -100,63 +100,27 @@ jobs:
100100
displayName: Publish Image Info File Artifact
101101
internalProjectName: ${{ parameters.internalProjectName }}
102102
publicProjectName: ${{ parameters.publicProjectName }}
103-
- ${{ if and(eq(variables['System.TeamProject'], parameters.internalProjectName), ne(variables['Build.Reason'], 'PullRequest')) }}:
104-
# The following task depends on the SBOM Manifest Generator task installed on the agent.
105-
# This task is auto-injected by 1ES Pipeline Templates so we don't need to install it ourselves.
103+
- ${{ if and(eq(variables['System.TeamProject'], parameters.internalProjectName), ne(variables['Build.Reason'], 'PullRequest'), eq(parameters.dockerClientOS, 'linux')) }}:
106104
- powershell: |
107105
$images = "$(BuildImages.builtImages)"
108106
if (-not $images) { return 0 }
109-
110-
# There can be leftover versions of the task left on the agent if it's not fresh. So find the latest version.
111-
$taskDir = $(Get-ChildItem -Recurse -Directory -Filter "ManifestGeneratorTask*" -Path '$(Agent.WorkFolder)')[-1].FullName
112-
113-
# There may be multiple version directories within the task directory. Use the latest.
114-
$taskVersionDir = $(Get-ChildItem -Directory $taskDir | Sort-Object)[-1].FullName
115-
116-
$manifestToolDllPath = $(Get-ChildItem -Recurse -File -Filter "Microsoft.ManifestTool.dll" -Path $taskVersionDir).FullName
117-
118-
# Check whether the manifest task installed its own version of .NET.
119-
# To be more robust, we'll handle varying implementations that it's had.
120-
# First check for a dotnet folder in the task location
121-
$dotnetDir = $(Get-ChildItem -Recurse -Directory -Filter "dotnet-*" -Path $taskVersionDir).FullName
122-
if (-not $dotnetDir) {
123-
# If it's not there, check in the agent tools location
124-
$dotnetDir = $(Get-ChildItem -Recurse -Directory -Filter "*dotnet-*" -Path "$(Agent.ToolsDirectory)").FullName
125-
}
126-
127-
# If the manifest task installed its own version of .NET use that; otherwise it's reusing an existing install of .NET
128-
# which is executable by default.
129-
if ($dotnetDir) {
130-
$dotnetPath = "$dotnetDir/dotnet"
131-
}
132-
else {
133-
$dotnetPath = "dotnet"
134-
}
135-
136-
# Call the manifest tool for each image to produce seperate SBOMs
137-
# Manifest tool docs: https://eng.ms/docs/cloud-ai-platform/devdiv/one-engineering-system-1es/1es-docs/secure-supply-chain/custom-sbom-generation-workflows
107+
$syftImageName = "${{ parameters.publishConfig.publicMirrorAcr.server }}/$(imageNames.syft)"
108+
& $(engCommonPath)/Pull-Image.ps1 $syftImageName
138109
$images -Split ',' | ForEach-Object {
139110
echo "Generating SBOM for $_";
140-
$formattedImageName = $_.Replace('${{ parameters.publishConfig.buildAcr.server }}/${{ parameters.publishConfig.buildAcr.repoPrefix }}', "").Replace('/', '_').Replace(':', '_');
111+
$targetImageName = "$_";
112+
$formattedImageName = $targetImageName.Replace('${{ parameters.publishConfig.buildAcr.server }}/${{ parameters.publishConfig.buildAcr.repoPrefix }}', "").Replace('/', '_').Replace(':', '_');
141113
$sbomChildDir = "$(sbomDirectory)/$formattedImageName";
142114
New-Item -Type Directory -Path $sbomChildDir > $null;
143-
& $dotnetPath "$manifestToolDllPath" `
144-
Generate `
145-
-BuildDropPath '$(Build.ArtifactStagingDirectory)' `
146-
-BuildComponentPath '$(Agent.BuildDirectory)' `
147-
-PackageName '.NET' `
148-
-PackageVersion '$(Build.BuildNumber)' `
149-
-ManifestDirPath $sbomChildDir `
150-
-DockerImagesToScan $_ `
151-
-Verbosity Information
115+
docker build --output=$sbomChildDir -f $(engCommonPath)/Dockerfile.syft --build-arg SYFT_IMAGE_NAME=$syftImageName --build-arg TARGET_IMAGE_NAME=$targetImageName -t syft-sbom $(engCommonPath);
152116
}
153117
displayName: Generate SBOMs
154118
condition: and(succeeded(), ne(variables['BuildImages.builtImages'], ''))
155119
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
156120
- template: /eng/common/templates/jobs/${{ format('../steps/test-images-{0}-client.yml', parameters.dockerClientOS) }}@self
157121
parameters:
158122
condition: ne(variables.testScriptPath, '')
159-
- ${{ if and(eq(variables['System.TeamProject'], parameters.internalProjectName), ne(variables['Build.Reason'], 'PullRequest')) }}:
123+
- ${{ if and(eq(variables['System.TeamProject'], parameters.internalProjectName), ne(variables['Build.Reason'], 'PullRequest'), eq(parameters.dockerClientOS, 'linux')) }}:
160124
- template: /eng/common/templates/steps/publish-artifact.yml@self
161125
parameters:
162126
path: $(sbomDirectory)

eng/common/templates/steps/init-docker-linux.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ steps:
2525
################################################################################
2626
- ${{ if eq(parameters.setupImageBuilder, 'true') }}:
2727

28-
- script: $(engCommonPath)/pull-image.sh $(imageNames.imageBuilder)
28+
- powershell: $(engCommonPath)/Pull-Image.ps1 $(imageNames.imageBuilder)
2929
displayName: Pull Image Builder
3030
condition: and(succeeded(), ${{ parameters.condition }})
3131

@@ -78,7 +78,7 @@ steps:
7878
# Setup Test Runner (Optional)
7979
################################################################################
8080
- ${{ if eq(parameters.setupTestRunner, 'true') }}:
81-
- script: $(engCommonPath)/pull-image.sh $(imageNames.testrunner)
81+
- powershell: $(engCommonPath)/Pull-Image.ps1 $(imageNames.testrunner)
8282
displayName: Pull Test Runner
8383
condition: and(succeeded(), ${{ parameters.condition }})
8484
- script: >

eng/common/templates/variables/docker-images.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ variables:
44
imageNames.imageBuilder.withrepo: imagebuilder-withrepo:$(Build.BuildId)-$(System.JobId)
55
imageNames.testRunner: mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux3.0-docker-testrunner
66
imageNames.testRunner.withrepo: testrunner-withrepo:$(Build.BuildId)-$(System.JobId)
7+
imageNames.syft: anchore/syft:v1.31.0-debug

0 commit comments

Comments
 (0)