Skip to content

Commit 7d1fc93

Browse files
authored
Update links, cleanup whitespaces and update image name (#10)
* Update links, cleanup whitespaces and update image name * Add README for Jenkins examples
1 parent 18fd642 commit 7d1fc93

File tree

12 files changed

+153
-37
lines changed

12 files changed

+153
-37
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# Sysdig Secure Inline Scan Examples
22

3-
This repository contains examples and information about **how to use** [Sysdig Secure inline scan](https://github.com/sysdiglabs/secure-inline-scan) in different integrations and use case scenarios.
3+
This repository contains examples and information about **how to use** [Sysdig Secure inline scan](https://docs.sysdig.com/en/integrate-with-ci-cd-tools.html) in different integrations and use case scenarios.
44

55
Continue reading the public webpage content of this repository here:
66

77
* [sysdiglabs.github.io/secure-inline-scan-examples](https://sysdiglabs.github.io/secure-inline-scan-examples)
88

9-
It is not a comprehensive catalog of _examples_ for all integrations available, but a live document where we continually publish more information as we see users need it. We do try to keep a list of links to all integrations and other related websites that you may find useful.
9+
It is not a comprehensive _example_ catalog for every available integration, but a live document where we continually publish more information as we see users need it. We try to keep a list of links to all integrations and other convenient and related websites.
1010

1111
## Issues and pull requests
1212

13-
If you find a related topic lacks enough information, or some problem with any of the existing examples, please file a issue in this repository. Pull requests to amend any existing information or examples are also welcomed.
13+
If you find a related topic that lacks enough information or some problem with any of the existing examples, please file an issue in this repository. Pull requests to amend any existing information or examples are also welcome.
1414

1515
## More information
1616

1717
* Sysdig.com
1818
* [Sysdig Documentation website - Image Scanning](https://docs.sysdig.com/en/image-scanning.html)
19-
* [Sysdig Secure inline scan repository](https://github.com/sysdiglabs/secure-inline-scan)
19+
* [Image Scanning - Integrate with CI/CD Tools](https://docs.sysdig.com/en/integrate-with-ci-cd-tools.html)
2020

deprecated-jenkins-inline-scan-v1/Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pipeline{
2121
script {
2222
sh "docker pull ${IMAGE_NAME}"
2323
}
24-
24+
2525
}
2626
}
2727
}

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ These integrations have a specific entry in their respective CI/CD catalogs:
158158

159159
Official documentation pages must be current to the features provided by the inline scanner, but their explanations may be brief:
160160

161-
* [Registry Scanning](https://sysdig.com/products/kubernetes-security/image-scanning/) (main Sysdig web page)
161+
* [CI/CD and Registry Scanning with Runtime Vulnerability Reporting](https://sysdig.com/products/secure/image-scanning/) (main Sysdig web page)
162162
* [Image Scanning](https://docs.sysdig.com/en/image-scanning.html) (Sysdig Documentation website)
163-
* [Sysdig Secure inline scan repository](https://github.com/sysdiglabs/secure-inline-scan) (main project code repository's readme)
163+
* [Image Scanning - Integrate with CI/CD Tools](https://docs.sysdig.com/en/integrate-with-ci-cd-tools.html)
164164

165165
## Blog articles
166166

jenkins/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Inline Scan in Jenkins
2+
3+
## Sysdig Secure Jenkins plugin
4+
5+
The [Sysdig Secure Jenkins plugin](https://plugins.jenkins.io/sysdig-secure/) can be used in a Pipeline job, or added as a build step to a Freestyle job to automate the process of running an image analysis, evaluating custom policies against images, and performing security scans.
6+
7+
The plugin supports both backend and inline scanning and scan result integration. It publishes the scan report as part of the Jenkins job results, directly available from the UI.
8+
9+
However, the current version requires a working Docker environment (Docker socket must be available) for inline scanning. This requirement doesn't fit all scenarios, like running the Jenkins worker as a Pod when using the Kubernetes plugin, unless you use [Docker-in-Docker, which is discouraged](https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/).
10+
11+
See more information at the plugin page: https://plugins.jenkins.io/sysdig-secure/
12+
13+
## Using the Kubernetes plugin (podTemplate)
14+
15+
The inline scanner runs as a container `quay.io/sysdig/secure-inline-scan:2`, but it does not depend on the Docker socket being available (except for scanning local Docker images). So the inline scan container can be executed as part of a [Kubernetes plugin](https://plugins.jenkins.io/kubernetes/) podTemplate.
16+
17+
The following pipelines show different usage examples. All they have in common is the `quay.io/sysdig/secure-inline:2` container is added as an additional container inside the podTemplate executing the Jenkins worker. The container entrypoint is changed to `cat` so the container is started in a "paused" state. At some point in the pipeline, the `/sysdig-inline-scan.sh` script (the original entrypoint) is executed inside the inline-scan container.
18+
19+
* [Scan from repository](jenkins-scan-from-repo/)
20+
* [Build and scan](jenkins-build-and-scan/)
21+
* [Build, push and scan from repository](jenkins-build-push-scan-from-repo/)
22+
* [Build, push and scan using Openshift internal registry](jenkins-openshift-internal-registry/)
23+
24+
### Troubleshooting
25+
26+
#### Execution of `/sysdig-inline-scan.sh` getting stuck
27+
28+
In case the execution of the:
29+
30+
```
31+
container("inline-scan") {
32+
sh "/sysdig-inline-scan.sh -k ${SECURE_API_KEY_PSW} ${IMAGE_NAME}"
33+
}
34+
```
35+
36+
is stuck for a while, and then finishes with:
37+
38+
```
39+
...
40+
process apparently never started in /tmp/workspace/test-sysdig-inline-scan@tmp/durable-c48f0134
41+
(running Jenkins temporarily with -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true might make the problem clearer)
42+
```
43+
44+
you can enable launch diagnostics as described in the error message to get further information. You might find one of the following problems.
45+
46+
**UID mismatch**
47+
48+
Described in the [Kubernetes plugin page](https://plugins.jenkins.io/kubernetes/):
49+
50+
> this problem usually happens when the UID of the user in the JNLP container differs from the one in other container(s). All containers you use should have the same UID of the user, also this can be achieved by setting *securityContext*
51+
52+
For example, if the *jnlp* container runs as UID 1001, and the inline-scan container runs with the default UID 1000, the `sh` step will fail due to permissions when writing the output:
53+
54+
```
55+
sh: can't create /home/jenkins/agent/workspace/thejob@tmp/durable-e0b7cd27/jenkins-log.txt: Permission denied
56+
sh: can't create /home/jenkins/agent/workspace/thejob@tmp/durable-e0b7cd27/jenkins-result.txt.tmp: Permission denied
57+
mv: can't rename '/home/jenkins/agent/workspace/thejob@tmp/durable-e0b7cd27/jenkins-result.txt.tmp': No such file or directory
58+
touch: /home/jenkins/agent/workspace/thejob@tmp/durable-e0b7cd27/jenkins-log.txt: Permission denied
59+
touch: /home/jenkins/agent/workspace/thejob@tmp/durable-e0b7cd27/jenkins-log.txt: Permission denied
60+
touch: /home/jenkins/agent/workspace/thejob@tmp/durable-e0b7cd27/jenkins-log.txt: Permission denied
61+
```
62+
63+
You can fix it by making all the containers execute using the same UID using the [securityContext parameter](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/) in the podTemplate
64+
65+
**Working directory**
66+
67+
If the `workingDir` of the container is not specified, it could be set to an invalid path that causes problems when mounting. Try setting `workingDir: /tmp`.

jenkins/jenkins-build-and-scan/Jenkinsfile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ pipeline {
22
agent {
33
kubernetes {
44
yaml """
5-
apiVersion: v1
6-
kind: Pod
7-
metadata:
5+
apiVersion: v1
6+
kind: Pod
7+
metadata:
88
name: inline-scan-worker
9-
spec:
10-
containers:
9+
spec:
10+
containers:
1111
- name: jnlp
1212
- name: maven
1313
image: maven:3.6-jdk-11
@@ -25,14 +25,14 @@ spec:
2525
}
2626
}
2727

28-
parameters {
29-
string(name: 'IMAGE_NAME', defaultValue: 'docker.io/sysdiglabs/test-maven-app', description: 'Name of the image to be built andscanned (e.g.: myrepo/dummy-app)')
28+
parameters {
29+
string(name: 'IMAGE_NAME', defaultValue: 'docker.io/sysdiglabs/test-maven-app', description: 'Name of the image to be built andscanned (e.g.: myrepo/dummy-app)')
3030
}
31-
31+
3232
environment {
3333
SECURE_API_KEY = credentials('sysdig-secure-api-credentials')
3434
}
35-
35+
3636
stages {
3737
stage('Checkout') {
3838
steps {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Build and scan example
2+
3+
This [example pipeline](Jenkinsfile) shows how to build, scan and push a Docker image in a dockerless environment, by creating a podTemplate with 4 containers:
4+
* **jnlp** container. Required for the Jenkins agent.
5+
* **maven** container for building a Java application.
6+
* **builder** container, using [Kaniko](https://github.com/GoogleContainerTools/kaniko) to build a Docker image without requiring the Docker daemon. The `--no-push` option tells Kaniko not to push the image to a registry, and just store it locally in the `oci` folder inside the workspace.
7+
* **inline-scan** container, where the pipeline executes the `inline-scan.sh` script to analyze the image built in the previous step locally from the `oci` folder in the workspace.
8+
9+
Finally, an optional 5th step could be included to push the image to the registry, if the scan is successful, by using [Skopeo](https://github.com/containers/skopeo).
10+
11+
See [Jenkins examples README.md](../README.md) for common usage tips and troubleshooting.

jenkins/jenkins-build-push-scan-from-repo/Jenkinsfile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ pipeline {
22
agent {
33
kubernetes {
44
yaml """
5-
apiVersion: v1
6-
kind: Pod
7-
metadata:
5+
apiVersion: v1
6+
kind: Pod
7+
metadata:
88
name: inline-scan-worker
9-
spec:
10-
containers:
9+
spec:
10+
containers:
1111
- name: jnlp
1212
- name: maven
1313
image: maven:3.6-jdk-11
@@ -25,15 +25,15 @@ spec:
2525
}
2626
}
2727

28-
parameters {
29-
string(name: 'IMAGE_NAME', defaultValue: 'docker.io/sysdiglabs/test-maven-app', description: 'Name of the image to be built andscanned (e.g.: myrepo/dummy-app)')
28+
parameters {
29+
string(name: 'IMAGE_NAME', defaultValue: 'docker.io/sysdiglabs/test-maven-app', description: 'Name of the image to be built andscanned (e.g.: myrepo/dummy-app)')
3030
}
31-
31+
3232
environment {
3333
DOCKER = credentials('docker-repository-credentials')
3434
SECURE_API_KEY = credentials('sysdig-secure-api-credentials')
3535
}
36-
36+
3737
stages {
3838
stage('Checkout') {
3939
steps {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Build, push and scan from repository example
2+
3+
This [example pipeline](Jenkinsfile) shows how to build, push, and then scan the Docker image in a dockerless environment, by creating a podTemplate with 4 containers:
4+
* **jnlp** container. Required for the Jenkins agent.
5+
* **maven** container for building a Java application.
6+
* **builder** container, using [Kaniko](https://github.com/GoogleContainerTools/kaniko) to build a Docker image without requiring the Docker daemon. Once build, the image is pushed to the destination target registry and repository.
7+
* **inline-scan** container, where the pipeline executes the `inline-scan.sh` script to analyze the image pushed to the repository in the previous step.
8+
9+
See [Jenkins examples README.md](../README.md) for common usage tips and troubleshooting.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Build, push and scan from Openshift internal registry
2+
3+
This [example pipeline](Jenkinsfile) shows how to build, push, and then scan the Docker image in Openshift, using the service account credentials to push and scan from the Openshift internal registry.
4+
5+
The podTemplate in the example is composed by 4 containers:
6+
* **jnlp** container. Required for the Jenkins agent. Also, we mount the service account secret in `/home/jenkins/agent/.dockercfg` to convert the old dockercfg format to the new config.json format required by Kaniko and the Inline Scanner:
7+
8+
```
9+
sh "echo -n \"{ \\\"auths\\\": \" > /home/jenkins/agent/config.json"
10+
sh "cat /home/jenkins/agent/.dockercfg >> /home/jenkins/agent/config.json"
11+
sh "echo \"}\" >>/home/jenkins/agent/config.json"
12+
```
13+
14+
* **maven** container for building a Java application.
15+
* **builder** container, using [Kaniko](https://github.com/GoogleContainerTools/kaniko) to build a Docker image without requiring the Docker daemon. Once build, the image is pushed to the internal Openshift registry, using the credentials at `/home/jenkins/agent/config.json`.
16+
* **inline-scan** container, where the pipeline executes the `inline-scan.sh` script to analyze the image pushed to the internal Openshift registry, using the credentials from /home/jenkins/agent/config.json.
17+
18+
See [Jenkins examples README.md](../README.md) for common usage tips and troubleshooting.

jenkins/jenkins-scan-from-repo/Jenkinsfile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@ pipeline {
22
agent {
33
kubernetes {
44
yaml """
5-
apiVersion: v1
6-
kind: Pod
7-
metadata:
5+
apiVersion: v1
6+
kind: Pod
7+
metadata:
88
name: inline-scan-worker
9-
spec:
10-
containers:
9+
spec:
10+
containers:
1111
- name: jnlp
1212
- name: inline-scan
13-
image: sysdiglabs/secure-inline-scan:2
13+
image: quay.io/sysdig/secure-inline-scan:2
1414
command: ['cat']
1515
tty: true
1616
"""
1717
}
1818
}
1919

20-
parameters {
21-
string(name: 'IMAGE_NAME', defaultValue: 'sysdiglabs/dummy-vuln-app', description: 'Name of the image to be built andscanned (e.g.: myrepo/dummy-app)')
20+
parameters {
21+
string(name: 'IMAGE_NAME', defaultValue: 'sysdiglabs/dummy-vuln-app', description: 'Name of the image to be built andscanned (e.g.: myrepo/dummy-app)')
2222
}
23-
23+
2424
environment {
2525
SECURE_API_KEY = credentials('sysdig-secure-api-credentials')
2626
}
27-
27+
2828
stages {
2929
stage('Scanning Image pulled from repository') {
3030
steps {

0 commit comments

Comments
 (0)