Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions eng/common/Dockerfile.syft
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ARG SYFT_IMAGE_NAME
ARG TARGET_IMAGE_NAME

FROM ${SYFT_IMAGE_NAME} AS syft
FROM ${TARGET_IMAGE_NAME} AS target

RUN --mount=from=syft,source=/,target=/syft /syft/syft scan / --select-catalogers image -o spdx-json=/manifest.spdx.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work for distroless images? Since it's using shell form and not exec form.

Here's the dotnet-docker test implementation, for reference: https://github.com/dotnet/dotnet-docker/blob/8e0a89c21c0eedc9658c3e4e9019693711869828/tests/Microsoft.DotNet.Docker.Tests/SyftHelper.cs#L138-L150

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it doesn't. I followed your pattern the tests. Fixed with 8fb672e. You should be able to consume this Dockerfile from the tests. I solved the issue of setting the source name by using an environment variable so I don't need to pass it in and have the value resolution problem.


FROM scratch
COPY --from=target /manifest.spdx.json /manifest.spdx.json
18 changes: 18 additions & 0 deletions eng/common/Pull-Image.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env pwsh

[cmdletbinding()]
param(
[Parameter(Mandatory = $true, Position = 0)]
[string]$Image,

[Parameter(Mandatory = $false)]
[int]$Retries = 2,

[Parameter(Mandatory = $false)]
[int]$WaitFactor = 6
)

Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

& "$PSScriptRoot/Invoke-WithRetry.ps1" "docker pull $Image" -Retries $Retries -WaitFactor $WaitFactor
37 changes: 0 additions & 37 deletions eng/common/pull-image.sh

This file was deleted.

50 changes: 7 additions & 43 deletions eng/common/templates/jobs/build-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,63 +100,27 @@ jobs:
displayName: Publish Image Info File Artifact
internalProjectName: ${{ parameters.internalProjectName }}
publicProjectName: ${{ parameters.publicProjectName }}
- ${{ if and(eq(variables['System.TeamProject'], parameters.internalProjectName), ne(variables['Build.Reason'], 'PullRequest')) }}:
# The following task depends on the SBOM Manifest Generator task installed on the agent.
# This task is auto-injected by 1ES Pipeline Templates so we don't need to install it ourselves.
- ${{ if and(eq(variables['System.TeamProject'], parameters.internalProjectName), ne(variables['Build.Reason'], 'PullRequest'), eq(parameters.dockerClientOS, 'linux')) }}:
- powershell: |
$images = "$(BuildImages.builtImages)"
if (-not $images) { return 0 }

# There can be leftover versions of the task left on the agent if it's not fresh. So find the latest version.
$taskDir = $(Get-ChildItem -Recurse -Directory -Filter "ManifestGeneratorTask*" -Path '$(Agent.WorkFolder)')[-1].FullName

# There may be multiple version directories within the task directory. Use the latest.
$taskVersionDir = $(Get-ChildItem -Directory $taskDir | Sort-Object)[-1].FullName

$manifestToolDllPath = $(Get-ChildItem -Recurse -File -Filter "Microsoft.ManifestTool.dll" -Path $taskVersionDir).FullName

# Check whether the manifest task installed its own version of .NET.
# To be more robust, we'll handle varying implementations that it's had.
# First check for a dotnet folder in the task location
$dotnetDir = $(Get-ChildItem -Recurse -Directory -Filter "dotnet-*" -Path $taskVersionDir).FullName
if (-not $dotnetDir) {
# If it's not there, check in the agent tools location
$dotnetDir = $(Get-ChildItem -Recurse -Directory -Filter "*dotnet-*" -Path "$(Agent.ToolsDirectory)").FullName
}

# If the manifest task installed its own version of .NET use that; otherwise it's reusing an existing install of .NET
# which is executable by default.
if ($dotnetDir) {
$dotnetPath = "$dotnetDir/dotnet"
}
else {
$dotnetPath = "dotnet"
}

# Call the manifest tool for each image to produce seperate SBOMs
# Manifest tool docs: https://eng.ms/docs/cloud-ai-platform/devdiv/one-engineering-system-1es/1es-docs/secure-supply-chain/custom-sbom-generation-workflows
$syftImageName = "${{ parameters.publishConfig.publicMirrorAcr.server }}/$(imageNames.syft)"
docker pull $syftImageName
$images -Split ',' | ForEach-Object {
echo "Generating SBOM for $_";
$formattedImageName = $_.Replace('${{ parameters.publishConfig.buildAcr.server }}/${{ parameters.publishConfig.buildAcr.repoPrefix }}', "").Replace('/', '_').Replace(':', '_');
$targetImageName = "$_"
$formattedImageName = $targetImageName.Replace('${{ parameters.publishConfig.buildAcr.server }}/${{ parameters.publishConfig.buildAcr.repoPrefix }}', "").Replace('/', '_').Replace(':', '_');
$sbomChildDir = "$(sbomDirectory)/$formattedImageName";
New-Item -Type Directory -Path $sbomChildDir > $null;
& $dotnetPath "$manifestToolDllPath" `
Generate `
-BuildDropPath '$(Build.ArtifactStagingDirectory)' `
-BuildComponentPath '$(Agent.BuildDirectory)' `
-PackageName '.NET' `
-PackageVersion '$(Build.BuildNumber)' `
-ManifestDirPath $sbomChildDir `
-DockerImagesToScan $_ `
-Verbosity Information
docker build --output=$sbomChildDir -f $(engCommonPath)/Dockerfile.syft --build-arg SYFT_IMAGE_NAME=$syftImageName --build-arg TARGET_IMAGE_NAME=$targetImageName -t syft-sbom $(engCommonPath)
}
displayName: Generate SBOMs
condition: and(succeeded(), ne(variables['BuildImages.builtImages'], ''))
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
- template: /eng/common/templates/jobs/${{ format('../steps/test-images-{0}-client.yml', parameters.dockerClientOS) }}@self
parameters:
condition: ne(variables.testScriptPath, '')
- ${{ if and(eq(variables['System.TeamProject'], parameters.internalProjectName), ne(variables['Build.Reason'], 'PullRequest')) }}:
- ${{ if and(eq(variables['System.TeamProject'], parameters.internalProjectName), ne(variables['Build.Reason'], 'PullRequest'), eq(parameters.dockerClientOS, 'linux')) }}:
- template: /eng/common/templates/steps/publish-artifact.yml@self
parameters:
path: $(sbomDirectory)
Expand Down
4 changes: 2 additions & 2 deletions eng/common/templates/steps/init-docker-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ steps:
################################################################################
- ${{ if eq(parameters.setupImageBuilder, 'true') }}:

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

Expand Down Expand Up @@ -78,7 +78,7 @@ steps:
# Setup Test Runner (Optional)
################################################################################
- ${{ if eq(parameters.setupTestRunner, 'true') }}:
- script: $(engCommonPath)/pull-image.sh $(imageNames.testrunner)
- powershell: $(engCommonPath)/Pull-Image.ps1 $(imageNames.testrunner)
displayName: Pull Test Runner
condition: and(succeeded(), ${{ parameters.condition }})
- script: >
Expand Down
1 change: 1 addition & 0 deletions eng/common/templates/variables/docker-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ variables:
imageNames.imageBuilder.withrepo: imagebuilder-withrepo:$(Build.BuildId)-$(System.JobId)
imageNames.testRunner: mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux3.0-docker-testrunner
imageNames.testRunner.withrepo: testrunner-withrepo:$(Build.BuildId)-$(System.JobId)
imageNames.syft: anchore/syft:v1.26.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will this stay updated? Is there a way we can utilize dependabot or renovate here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will log a follow-up issue to handle the automatic updating of the syft image tag that is defined in the YAML file.

Yes, Renovate could be used here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update to v1.32.0-debug at least? That's the latest.

Suggested change
imageNames.syft: anchore/syft:v1.26.1
imageNames.syft: anchore/syft:v1.32.0-debug

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with 865cb63.

Loading