Skip to content
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

feat(detectExecuteScan): Also scan images that are in the CPE #4678

Merged
merged 7 commits into from
Feb 12, 2024

Conversation

c0d1ngm0nk3y
Copy link
Member

@c0d1ngm0nk3y c0d1ngm0nk3y commented Nov 15, 2023

This has following prerequisites to jenkins-library (cherry-picked):

The enhances detectExecuteScan to not only scan the workspace, but also all images that can be found in the cpe. If kanikoExecute or cnbBuild produce images, the information will be written to the cpe. In order to do these scans, a sidecar is needed. The sidecar is different for the distro that is scanned. The user can configure this via the new parameter containerDistro (default "ubuntu").

The user can can use scanImages: false to prevent this.

Changes

  • Tests
  • Documentation

@c0d1ngm0nk3y c0d1ngm0nk3y force-pushed the enhance-detectExecuteScan branch from f176377 to 9a334ae Compare November 15, 2023 15:33
@c0d1ngm0nk3y
Copy link
Member Author

/it

@pbusko pbusko force-pushed the enhance-detectExecuteScan branch 5 times, most recently from 252f89c to c402207 Compare November 23, 2023 14:31
@pbusko pbusko force-pushed the enhance-detectExecuteScan branch 5 times, most recently from ab38479 to fe3f3b4 Compare November 27, 2023 10:22
@pbusko pbusko force-pushed the enhance-detectExecuteScan branch from d0682d3 to e805329 Compare December 12, 2023 09:58
@c0d1ngm0nk3y c0d1ngm0nk3y force-pushed the enhance-detectExecuteScan branch from 5d76dcf to 606a068 Compare December 13, 2023 12:47
@modulo11 modulo11 force-pushed the enhance-detectExecuteScan branch from 606a068 to 3fdefae Compare December 18, 2023 12:25
@modulo11 modulo11 marked this pull request as ready for review December 18, 2023 12:26
@modulo11 modulo11 requested a review from a team as a code owner December 18, 2023 12:26
@modulo11
Copy link
Member

/it-go

args = append(args, "--detect.docker.passthrough.shared.dir.path.local=/opt/blackduck/blackduck-imageinspector/shared/")
args = append(args, "--detect.docker.passthrough.shared.dir.path.imageinspector=/opt/blackduck/blackduck-imageinspector/shared")
args = append(args, fmt.Sprintf("--detect.docker.passthrough.imageinspector.service.distro.default=%s", config.ContainerDistro))
args = append(args, "--detect.docker.passthrough.imageinspector.service.start=false")
Copy link
Contributor

Choose a reason for hiding this comment

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

Here it is indicating that the inspector itself will not need to be started, in that case how the image inspector is being started and exposed ?

Choose a reason for hiding this comment

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

@pbusko pbusko force-pushed the enhance-detectExecuteScan branch from 3fdefae to 927d34b Compare January 5, 2024 09:11
Copy link

sonarqubecloud bot commented Jan 5, 2024

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

return errors.Wrap(err, "Unable to read cpe")
}

registryUser := piperenv.GetResourceParameter(cpePath, "container", "repositoryUsername")
Copy link

Choose a reason for hiding this comment

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

How repositoryUsername and repositoryPassword are created under CPE container path.
Looks like KanikoExecute only generates imageNameTags.json and registryUrl but not username/password. We referred this - https://github.com/SAP/jenkins-library/blob/master/resources/metadata/kanikoExecute.yaml#L309

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

Thanks @loewenstein.
Tried with the combination of kanikoExecute and sapCallStagingService For generating repositoryUsername/Password. But we are getting failure message as Wrong action.
Could you please suggest the right configuration for generating the credentials file under CPE container path.
cc @anilkeshav27 @c0d1ngm0nk3y

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

why do we need to read a CPE value from the file system, instead we could allow new params and have cpe references like ? https://github.com/SAP/jenkins-library/pull/4804/files#diff-da165ed834ab60bb2fc7bc2fed1e93646b0f36264f16e79b160b4361781207ef

with the new params, we also introduce the possibility to scan images that run outside the build, if the image lives in a private registry then users can bring in their registry url, password (maybe we would need a vault reference as well) and username . will be a good selling feature as well ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@loewenstein It sounds good to extend support for external registries as well. With this enhancement, the behaviour of both Mend and DetectScan will align with each other.

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 second to use another PR for any additional features

Copy link
Member

@anilkeshav27 anilkeshav27 Feb 8, 2024

Choose a reason for hiding this comment

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

i would leave the final decision to @t-vijayan , who owns the piper step , since resourceRef is the standard way to read the CPE values

Copy link
Member Author

Choose a reason for hiding this comment

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

@anilkeshav27

why do we need to read a CPE value from the file system, instead we could allow new params and have cpe references like?

Because we need 4 values from the cpe: user, password, registry AND images. Since images is an array and can't be mapped (right?), it would be pointless and very confusing to expose those parameters. If we can map all 4 to the cpe, it would be preferable over reading it manually of course.

Copy link
Member

Choose a reason for hiding this comment

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

yes we should be able to map all 4 cpe the imageNameTags is the tricky bit , since there can be one image or multiple build, if it ties back to the cnbBuild / kaniko and if we fill this cpe

- name: container/imageNameTags
type: "[]string"
in all cases then it must be fine.

i know in kaniko we fill this list even in single image is built and i am assuming its the same in cnbBuild

return errors.Wrap(err, "Unable to read cpe")
}

registryUser := piperenv.GetResourceParameter(cpePath, "container", "repositoryUsername")
Copy link
Member

Choose a reason for hiding this comment

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

why do we need to read a CPE value from the file system, instead we could allow new params and have cpe references like ? https://github.com/SAP/jenkins-library/pull/4804/files#diff-da165ed834ab60bb2fc7bc2fed1e93646b0f36264f16e79b160b4361781207ef

with the new params, we also introduce the possibility to scan images that run outside the build, if the image lives in a private registry then users can bring in their registry url, password (maybe we would need a vault reference as well) and username . will be a good selling feature as well ?

cmd/detectExecuteScan.go Show resolved Hide resolved
resources/metadata/detectExecuteScan.yaml Outdated Show resolved Hide resolved
@modulo11 modulo11 force-pushed the enhance-detectExecuteScan branch from 927d34b to 851022c Compare February 7, 2024 11:42
@c0d1ngm0nk3y
Copy link
Member Author

We tested it with no scanContainerDistro and scanContainerDistro: ubuntu and it worked fine for us.

@c0d1ngm0nk3y c0d1ngm0nk3y force-pushed the enhance-detectExecuteScan branch from 4df39b8 to 4d83e0c Compare February 8, 2024 11:42
@modulo11
Copy link
Member

modulo11 commented Feb 8, 2024

/it-go

@c0d1ngm0nk3y c0d1ngm0nk3y force-pushed the enhance-detectExecuteScan branch from f171d11 to 1789f0f Compare February 8, 2024 13:03
@modulo11
Copy link
Member

modulo11 commented Feb 8, 2024

/it-go

@loewenstein
Copy link

@anilkeshav27 @t-vijayan @vijayanjay Anything we could or should do? From our perspective, this is good to go.

@c0d1ngm0nk3y
Copy link
Member Author

Anything we could or should do? From our perspective, this is good to go.

I still want to look at this comment - I think this is still suboptimal.

@c0d1ngm0nk3y c0d1ngm0nk3y force-pushed the enhance-detectExecuteScan branch from 5043035 to be744f3 Compare February 9, 2024 09:13
@c0d1ngm0nk3y
Copy link
Member Author

/it-go

@c0d1ngm0nk3y c0d1ngm0nk3y force-pushed the enhance-detectExecuteScan branch from be744f3 to fb51f13 Compare February 9, 2024 11:25
c0d1ngm0nk3y and others added 6 commits February 9, 2024 12:26
Co-authored-by: Johannes Dillmann <[email protected]>
Signed-off-by: Ralf Pannemans <[email protected]>
Co-authored-by: Ralf Pannemans <[email protected]>
Co-authored-by: Pavel Busko <[email protected]>
Co-authored-by: Ralf Pannemans <[email protected]>
Signed-off-by: Ralf Pannemans <[email protected]>
Co-authored-by: Johannes Dillmann <[email protected]>
Co-authored-by: Johannes Dillmann <[email protected]>
Signed-off-by: Johannes Dillmann <[email protected]>
Co-authored-by: Ralf Pannemans <[email protected]>
@c0d1ngm0nk3y c0d1ngm0nk3y force-pushed the enhance-detectExecuteScan branch from fb51f13 to 1dd12f6 Compare February 9, 2024 11:26
@c0d1ngm0nk3y
Copy link
Member Author

/it-go

Copy link
Member

@anilkeshav27 anilkeshav27 left a comment

Choose a reason for hiding this comment

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

lgtm, i am not sure about the actual scan logic and the error handling , but i trust that this has been tested well enough

from the overall cpe auto wiring and side car logic it looks good to me

cc @t-vijayan @vijayanjay would also share your thoughts

Signed-off-by: Pavel Busko <[email protected]>
Co-authored-by: Ralf Pannemans <[email protected]>
Signed-off-by: Ralf Pannemans <[email protected]>
Co-authored-by: Pavel Busko <[email protected]>
Signed-off-by: Pavel Busko <[email protected]>
@c0d1ngm0nk3y c0d1ngm0nk3y force-pushed the enhance-detectExecuteScan branch from 1dd12f6 to bd957bb Compare February 9, 2024 12:12
Copy link

sonarqubecloud bot commented Feb 9, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@c0d1ngm0nk3y
Copy link
Member Author

/it-go

Copy link
Contributor

@vijayanjay vijayanjay left a comment

Choose a reason for hiding this comment

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

@c0d1ngm0nk3y @anilkeshav27 With the latest changes able to trigger detect scan for the docker images built by kaniko and able to verify the scan results.
changes looks good to me.

@c0d1ngm0nk3y c0d1ngm0nk3y enabled auto-merge (squash) February 12, 2024 07:49
@c0d1ngm0nk3y
Copy link
Member Author

@anilkeshav27 The failing integration tests seem not to be related at the first glance. WDYT? Also the the mention https://api.github.com/repos/OliverNocon/piper-integration/releases which is a bit weird, isn't it?

@c0d1ngm0nk3y c0d1ngm0nk3y merged commit 49b8080 into master Feb 12, 2024
12 checks passed
@c0d1ngm0nk3y c0d1ngm0nk3y deleted the enhance-detectExecuteScan branch February 12, 2024 07:56
maxatsap pushed a commit to maxatsap/jenkins-library that referenced this pull request Jul 23, 2024
feat(detectExecuteScan): Also scan images that are in the cpe

Signed-off-by: Ralf Pannemans <[email protected]>
Signed-off-by: Johannes Dillmann <[email protected]>
Signed-off-by: Pavel Busko <[email protected]>
Co-authored-by: Johannes Dillmann <[email protected]>
Co-authored-by: Pavel Busko <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants