You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 5, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/how-to-guides/Secure-your-supply-chain/proc_java_dependencies.adoc
+69-54Lines changed: 69 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,27 +8,27 @@ The Java Virtual Machine Build Service (JBS or JVM Build Service) is a controlle
8
8
9
9
The Java ecosystem uses a binary distribution model, where binary jar files are downloaded from central repositories, such as Maven Central. This distribution model means that the only way to ensure an application is completely built from source is to rebuild all its component libraries from source in a trusted environment. Due to the Java ecosystem, you would need to manually rebuild the component libraries.
10
10
11
-
Although the Java binary distribution model is very convenient, it does mean that you will inevitably use untrusted dependencies with unknown provenance maintained by external communities. In general, you don't know who has uploaded these artifacts, the environment that was used to build them, or how that build environment might be compromised. Building from source in a secure environment means that you can be be completely sure as to where the code you are running has come from.
11
+
The Java binary distribution model relies on dependencies with unknown provenance maintained by external communities. This means that you can't be sure who uploaded these artifacts or the build environment, so you can't be sure of their flaws or vulnerabilities. The only way to know that you're building from clean, logical code in a secure environment is to build from source code.
12
12
13
13
JBS automates this process as much as possible, making it much less time-consuming to create builds that are build from source in a controlled environment.
14
14
15
15
=== Workflow Description
16
16
17
-
When using the JVM Build Service the end user workflow is as follows:
17
+
When using the JVM Build Service, the user workflow is as follows:
18
18
19
-
- The system builds your application by using community dependencies.
19
+
* The system builds your application by using community dependencies.
20
20
21
-
- The JVM Build Service analyzes your application and determines the dependencies that the system needs to rebuild.
21
+
* The JVM Build Service analyzes your application and determines which dependencies the system needs to rebuild.
22
22
23
-
- The JVM Build Service generates `ArtifactBuild` objects to represent each artifact in your application before determining to which repository the artifacts belong. The JVM Build Service tags from which systems the artifacts derive.
23
+
* The JVM Build Service generates `ArtifactBuild` objects to represent each artifact in your application before determining to which repository the artifacts belong. The JVM Build Service tags from which systems the artifacts derive.
24
24
25
-
- The system analyzes the repository and uses the results to find a build strategy. For example, if the system cannot find the JDK version to use, the system uses all versions to determine the most effective version to use.
25
+
* The system analyzes the repository and uses the results to find a build strategy. For example, if the system cannot find the JDK version to use, the system uses all versions to determine the most effective version to use.
26
26
27
-
- The system attempts to build all the dependencies and stores them in container images in an image registry, and `quay.io` is the default.
27
+
* The system attempts to build all the dependencies and stores them in container images in an image registry, and `quay.io` is the default.
28
28
29
-
- When the system has completed all its builds, you can rebuild your application.
29
+
* When the system has completed all its builds, you can rebuild your application.
30
30
31
-
- If all the builds are successful, your application's SBOM displays that none of the dependencies came from third-party repositories. However, you may need to troubleshoot when some dependencies fail to build.
31
+
* If all the builds are successful, your application's SBOM displays that none of the dependencies came from third-party repositories. However, you may need to troubleshoot when some dependencies fail to build.
32
32
33
33
== Setup
34
34
@@ -38,37 +38,55 @@ All interactions with the JVM Build Service require you to be logged into the Op
38
38
39
39
.Procedure
40
40
41
-
Copy the login command from: https://registration-service-toolchain-host-operator.apps.stone-prd-host1.wdlc.p1.openshiftapps.com/
41
+
* Copy the login command from: https://registration-service-toolchain-host-operator.apps.stone-prd-host1.wdlc.p1.openshiftapps.com/
42
42
43
43
=== Setting up the CLI
44
44
45
-
Many of the commands below can be setup using the JVM Build Service CLI.
45
+
Many of the commands can be setup using the JVM Build Service CLI. The CLI is currently distributed as a docker image.
46
46
47
-
The CLI is currently distributed as a docker image. To use the docker image, create the following alias:
47
+
.Prerequisite
48
48
49
+
* Log into your OpenShift namespace.
50
+
51
+
.Procedure
52
+
53
+
. To use the Docker image, create the following alias:
54
+
55
+
+
49
56
```
50
57
alias jbs='docker run --mount type=bind,source=$HOME/.kube/config,target=/kube --mount type=bind,source=$HOME/.github,target=/root/.github --env KUBECONFIG=/kube -it --rm quay.io/redhat-appstudio/hacbs-jvm-cli:latest'
51
58
```
52
59
53
-
To update the latest version, create an update alias. You can run this alias to pull the latest version of the docker image:
60
+
. To update the latest version, create an updated alias.
61
+
. To pull the latest version of the Docker image, run the updated alias:
54
62
63
+
+
55
64
```
56
65
alias update-jbs='docker pull quay.io/redhat-appstudio/hacbs-jvm-cli:latest'
57
66
```
58
67
59
-
The CLI supports tab completion and all the commands have a --help option to show usage.
68
+
. To show the usage, run commands with `--help` option.
69
+
. To modify build recipes, like commands that fix failing builds, create a file like, `$HOME/.github`, that is specified at https://github-api.kohsuke.org/[].
70
+
71
+
== Configuring The JVM Rebuild Service
60
72
61
-
Note that this CLI also requires you to be logged in as described above.
73
+
You can set up the JVM Build Service in the following ways:
62
74
63
-
To use commands that modify build recipes (i.e. commands that are used to fix failing builds) you will need to create a `$HOME/.github` file as specified at https://github-api.kohsuke.org/[].
75
+
* Setting up with the CLI
76
+
* Setting up without Quay.io configuration
77
+
* Setting up with Quay.io configuration
64
78
65
-
== Configuring The JVM Rebuild Service
79
+
=== Setting up with the CLI
66
80
67
-
There are three ways to setup the JVM Build Service, they are listed below.
81
+
If you do not require explicit quay.io configuration, you can simply set up the JVM Build Service. The JVM Build service automatically creates rebuilds for you and creates a query repository to store your rebuilt artifacts.
68
82
69
-
=== Setting up using the CLI
83
+
.Prerequisite
70
84
71
-
If you do not require explicit quay.io configuration, and you have setup the CLI this is the simplest way to setup the JVM Build Service. To do this run the `setup rebuilds` command in the CLI:
85
+
* You have setup the CLI.
86
+
87
+
.Procedure
88
+
89
+
* In the CLI, run the `setup rebuilds` commmand:
72
90
73
91
[source]
74
92
----
@@ -78,14 +96,15 @@ found .dockerconfigjson secret with appropriate token keys in namespace sdouglas
78
96
Rebuilds setup successfully
79
97
----
80
98
81
-
This will automatically perform the steps detailed below and setup rebuilds for you. The JVM Build Service will automatically create a quary repository to store your rebuilt artifacts.
99
+
The `setup rebuilds` command automatically performs the steps detailed below and creates rebuilds for you. The JVM Build Service automatically creates a query repository to store your rebuilt artifacts.
82
100
83
-
=== Manual Setup Without Quay.io Configuration*
101
+
=== Setting up without Quay.io configuration*
84
102
85
-
If you do not want to use the CLI this method creates the Kubernetes objects to setup the JVM Build Service directory using `kubectl`.
103
+
If you do not want to use the CLI, use the `kubectl` command to create the Kubernetes objects to set up the JVM Build Service directory.
86
104
87
-
. Create a file, for example, `config.yaml`.
105
+
.Procedure
88
106
107
+
. Create a file, for example, `config.yaml`.
89
108
. In the `config.yaml` file, create a `JBSConfig` resource with the following data:
90
109
91
110
+
@@ -102,12 +121,13 @@ spec:
102
121
. Run `kubectl apply -f config.yaml`
103
122
104
123
105
-
=== Manual Procedure With Explicit Quay.io Config
124
+
=== Setting up with explicit Quay.io configuration
106
125
107
-
This is required if you want to specify where the rebuilt artifacts are stored. It is more complex you must also provision a secret to allow the JVM Build Service to push to the repository.
126
+
If you want to specify where the rebuilt artfiacts are stored, you must use the Quay.io configuration to configure your JVM Build Service. You must also provision a secret to allow the JVM Build Service to push to the repository.
108
127
109
-
. Create a file, for example, `config.yaml`.
128
+
.Procedure
110
129
130
+
. Create a file, for example, `config.yaml`.
111
131
. In the `config.yaml` file, create a *JBSConfig* resource with the following data:
<1> To enable and configure the rebuild dependencies function you need to add enable-rebuilds: "true" to the `JBSConfig` object.
151
+
<1> To enable and configure the rebuild dependencies function, add enable-rebuilds: "true" to the `JBSConfig` object.
132
152
<2> The URL of the registry that holds the images of your rebuild dependencies.
133
153
<3> The organization ID.
134
154
<4> The repository to store the images in.
135
155
<5> List any additional Maven repositories here.
136
156
137
-
. Run `kubectl apply -f config.yaml` while logged into the build namespace.
138
-
139
-
Now we have added the configuration we need to setup the Quay.io credentials to be able to push to our repository. The JVM
140
-
Build Service uses the https://github.com/redhat-appstudio/service-provider-integration-operator[Service Provider Integration Operator] to store credentials in AWS Secrets Manager.
141
-
142
-
To upload our secret first we need to run a command to get the name of the `SPIAccessToken` we need to update, to do this
143
-
run the following command:
157
+
. While logged into the build namespace, run `kubectl apply -f config.yaml`.
158
+
. Add the configuration to set up the Quay.io credentials to be able to push to the repository. To store credentials in AWS Secrets Manager, the JVM
159
+
Build Service uses the https://github.com/redhat-appstudio/service-provider-integration-operator[Service Provider Integration Operator].
160
+
. To upload the secret first, run a command to get the name of the `SPIAccessToken` that you need to update. Run the following command:
144
161
145
162
----
146
163
kubectl get spiaccesstokenbindings.appstudio.redhat.com jvm-build-image-secrets -o yaml`
@@ -189,30 +206,34 @@ status:
189
206
----
190
207
<1> This is the name of the APIAccessToken we need to upload the secret
191
208
192
-
Record the name of the `linkedAccessTokenName` (in this case `generated-spi-access-token-px5w8`), this
193
-
will be referred to as $ACCESS_TOKEN in the examples below.
209
+
. Record the name of the `linkedAccessTokenName`. In this case, `generated-spi-access-token-px5w8`. This is referenced as
210
+
$ACCESS_TOKEN in the examples below.
211
+
212
+
==== Creating a secret with specific configuration
194
213
195
-
Now we need to create a secret with specific config that will be uploaded to AWS Secrets Manager.
214
+
Create a secret with specific configuration that uploads to AWS Secrets Manager. You need a quay.io username and password. The best way to get a username and password is to log in,
215
+
create a robot account, and then record the username and password. For the purposes
216
+
of the examples below, the username and password are referred to as $QUAY_USERNAME and $QUAY_PASSWORD.
196
217
197
-
For the next step we need a quay.io username and password. The best way to get these is to log in
198
-
and create a robot account, and record the username and password after account creation. For the purposes
199
-
of the examples below these will be referred to as $QUAY_USERNAME and $QUAY_PASSWORD.
Once these steps are completed the secret should disappear, and the system is ready to use.
234
+
After you complete these steps, the secret should disappear, and the system is ready to use.
214
235
215
-
== Examining the System State
236
+
== Examining the system state
216
237
217
238
After you have run your first java build with rebuilds enabled you can use `kubectl` to view the state of the rebuilds.
218
239
@@ -245,7 +266,7 @@ NAME URL
245
266
246
267
The names of the `PipelineRun` objects begin with the build name. This enables you to view logs for each `PipelineRun`.
247
268
248
-
=== Re-Running Builds [[rebuilding_artifacts]]
269
+
=== Rerunning builds [[rebuilding_artifacts]]
249
270
250
271
To rebuild an artifact, you need to annotate the `ArtifactBuild` object with `jvmbuildservice.io/rebuild=true`. For example, to rebuild the `zookeeper.3.6.3-8fc126b0` `ArtifactBuild`, you would run:
Generally, when you are trying to fix a failure, you must manually run the builds yourself.
265
286
266
-
== Dealing With failed Builds
287
+
== Dealing wth failed builds
267
288
268
289
In order to see why the build failed, look at the results from the JVM Build Service.
269
290
@@ -377,12 +398,9 @@ To fix failed builds, first look at the build logs and figure out why it failed.
377
398
*Procedure*
378
399
379
400
. Identify the correct `DependencyBuild` object.
380
-
381
401
. Run `kubectl get dependencybuilds` to list the objects.
382
-
383
402
. Pick the object you are interested in. Generally each `DependencyBuild` will have multiple pipeline
384
403
runs, named using the pattern `<dependency-build-name>-build-<n>`.
385
-
386
404
. View the logs by using the command `tkn pr logs <name>`:
387
405
388
406
[source]
@@ -400,9 +418,7 @@ If there are no builds at all, then the analyser could not find a build file to
400
418
*Procedure*
401
419
402
420
. Create a fork of the repository.
403
-
404
421
. Change the build system to Maven.
405
-
406
422
. Build from the fork.
407
423
408
424
To see an example, go to https://github.com/jvm-build-service-code/cs-au-dk-dk.brics.automaton[this Java package project] on GitHub.
@@ -464,7 +480,6 @@ which allows the namespace administrator to control where dependencies come from
464
480
.*Procedure*
465
481
466
482
. Browse to an appropriate directory and create a file, for example, `config.yaml`.
467
-
468
483
. In the `config.yaml` file, create a *ConfigMap* resource with the following data:
469
484
470
485
+
@@ -483,7 +498,7 @@ spec:
483
498
----
484
499
<1> To add a maven repository the key in the map must follow a set pattern, which is, maven-repository-$priority-$name: $repo-url. Additionally, Maven central has a priority of 200; therefore the system tries anything with a lower priority before maven central. The rebuilt artifacts if they are in use have a priority of 100.
485
500
486
-
=== Clearing the Cache
501
+
=== Clearing the cache
487
502
488
503
If for some reason you need to clear the cache you can do it by applying an annotation to the `JBSConfig` object:
0 commit comments