Chapter 6. Using artifact repositories in a restricted environment
By configuring technology stacks, you can work with artifacts from in-house repositories using self-signed certificates.
6.1. Using Maven artifact repositories Copy linkLink copied to clipboard!
Maven downloads artifacts that are defined in two locations:
-
Artifact repositories defined in a
pom.xml
file of the project. Configuring repositories inpom.xml
is not specific to Red Hat CodeReady Workspaces. For more information, see the Maven documentation about the POM. -
Artifact repositories defined in a
settings.xml
file. By default,settings.xml
is located at`~/.m2/settings.xml
.
6.1.1. Defining repositories in settings.xml Copy linkLink copied to clipboard!
To specify your own artifact repositories at example.server.org
, use the settings.xml
file. Ensure that settings.xml
is in all the containers that use Maven tools. In particular, ensure that it is in the Maven container and the Java plug-in container.
By default, settings.xml
is located at the <home dir>/.m2
directory which is already on persistent volume in Maven and Java plug-in containers and you don’t need to re-create the file each time you restart the workspace if it isn’t in ephemeral mode.
In case you have another container that uses Maven tools and you are about to share <home dir>/.m2
folder with this container, you have to specify the custom volume for this specific component in the devfile:
Procedure
Configure your
settings.xml
file to use artifact repositories atexample.server.org
:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
6.1.2. Defining Maven settings.xml file across workspaces Copy linkLink copied to clipboard!
To use your own settings.xml
file across all your workspaces, create a Secret object (with a name of your choice) in the same project as the workspace. Put the contents of the required settings.xml
in the data section of the Secret (possibly along with other files that should reside in the same directory). Labelling and annotating this Secret according to Section 3.10.1, “Mounting a secret as a file into a workspace container” ensures that the contents of the Secret is mounted into the workspace Pod. Note that you need to restart any previously running workspaces for them to use this Secret.
Prerequisites
This is required to set your private credentials to a Maven repository. See the Maven documentation Settings.xml#Servers for additional information.
To mount this settings.xml
:
Procedure
Convert
settings.xml
to base64:cat settings.xml | base64
$ cat settings.xml | base64
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the output to a new file,
secret.yaml
, which also defines needed annotations and labels:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create this secret in the cluster:
oc apply -f secret.yaml
$ oc apply -f secret.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Start a new workspace. The
maven
container contains a file/home/jboss/.m2/settings.xml
with your original content.
6.1.2.1. OpenShift 3.11 and OpenShift <1.13 Copy linkLink copied to clipboard!
On OpenShift 3.11 , it’s impossible to have multiple VolumeMounts at same path so having devfile with volume /home/jboss/.m2
and secret at /home/jboss/.m2/settings.xml
would resolve into the conflict. On these clusters use /home/jboss/.m2/repository
as a volume for maven repository in the devfile:
6.1.3. Using self-signed certificates in Maven projects Copy linkLink copied to clipboard!
Internal artifact repositories often do not have a certificate signed by an authority that is trusted by default in Java. They are mainly signed by an internal company authority or are self-signed. Configure your tools to accept these certificates by adding them to the Java truststore.
Procedure
Obtain a server certificate file from the repository server. It is customary for administrators to provide certificates of internal artifact servers as OpenShift secrets (see https://access.redhat.com/documentation/en-us/red_hat_codeready_workspaces/2.14/html-single/installation_guide/index#importing-untrusted-tls-certificates.adoc). The relevant server certificates will be mounted in
/public-certs
in every container in the workspace.Copy the original Java truststore file:
mkdir /projects/maven cp $JAVA_HOME/lib/security/cacerts /projects/maven/truststore.jks chmod +w /projects/maven/truststore.jks
$ mkdir /projects/maven $ cp $JAVA_HOME/lib/security/cacerts /projects/maven/truststore.jks $ chmod +w /projects/maven/truststore.jks
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Import the certificate into the Java truststore file
keytool -import -noprompt -file /public-certs/nexus.cer -alias nexus -keystore /projects/maven/truststore.jks -storepass changeit
$ keytool -import -noprompt -file /public-certs/nexus.cer -alias nexus -keystore /projects/maven/truststore.jks -storepass changeit Certificate was added to keystore
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Add the truststore file.
In the Maven container:
Add the
javax.net.ssl
system property to theMAVEN_OPTS
environment variable:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Restart the workspace.
In the Java plug-in container:
In the devfile, add the
javax.net.ssl
system property for the Java language server:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
6.2. Using Gradle artifact repositories Copy linkLink copied to clipboard!
This section describes how to download and configure Gradle.
6.2.1. Downloading different versions of Gradle Copy linkLink copied to clipboard!
The recommended way to download any version of Gradle is by using the Gradle Wrapper script. If your project does not have a gradle/wrapper
directory, run $ gradle wrapper
to configure the Wrapper.
Prerequisites
- The Gradle Wrapper is available in your project.
Procedure
To download a Gradle version from a non-standard location, change your Wrapper settings in /projects/<your_project>/gradle/wrapper/gradle-wrapper.properties
:
Change the
distributionUrl
property to point to a URL of the Gradle distributionZIP
file:properties distributionUrl=http://<url_to_gradle>/gradle-6.1-bin.zip
properties distributionUrl=http://<url_to_gradle>/gradle-6.1-bin.zip
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Alternatively, you may place a Gradle distribution zip file locally in /project/gradle
in your workspace.
Change the
distributionUrl
property to point to a local address of the Gradle distribution zip file:properties distributionUrl=file\:/projects/gradle/gradle-6.1-bin.zip
properties distributionUrl=file\:/projects/gradle/gradle-6.1-bin.zip
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
6.2.2. Configuring global Gradle repositories Copy linkLink copied to clipboard!
Use an initialization script to configure global repositories for the workspace. Gradle performs extra configuration before projects are evaluated, and this configuration is used in each Gradle project from the workspace.
Procedure
To set global repositories for Gradle that could be used in each Gradle project in the workspace, create an init.gradle
script in the ~/.gradle/
directory:
This file configures Gradle to use a local Maven repository with the given credentials.
The ~/.gradle
directory does not persist in the current Java plug-in versions, so you must create the init.gradle
script at each workspace start in the Java plug-in sidecar container.
6.2.3. Using self-signed certificates in Gradle projects Copy linkLink copied to clipboard!
Internal artifact repositories often do not have a certificate signed by an authority that is trusted by default in Java. They are mainly signed by an internal company authority or are self-signed. Configure your tools to accept these certificates by adding them to the Java truststore.
Procedure
Obtain a server certificate file from the repository server. It is customary for administrators to provide certificates of internal artifact servers as OpenShift secrets (see https://access.redhat.com/documentation/en-us/red_hat_codeready_workspaces/2.14/html-single/installation_guide/index#importing-untrusted-tls-certificates.adoc). The relevant server certificates will be mounted in
/public-certs
in every container in the workspace.Copy the original Java truststore file:
mkdir /projects/maven cp $JAVA_HOME/lib/security/cacerts /projects/maven/truststore.jks chmod +w /projects/maven/truststore.jks
$ mkdir /projects/maven $ cp $JAVA_HOME/lib/security/cacerts /projects/maven/truststore.jks $ chmod +w /projects/maven/truststore.jks
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Import the certificate into the Java truststore file
keytool -import -noprompt -file /public-certs/nexus.cer -alias nexus -keystore /projects/maven/truststore.jks -storepass changeit
$ keytool -import -noprompt -file /public-certs/nexus.cer -alias nexus -keystore /projects/maven/truststore.jks -storepass changeit Certificate was added to keystore
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Upload the truststore file to
/projects/gradle/truststore.jks
to make it available for all containers.
Add the truststore file in the Gradle container.
Add the
javax.net.ssl
system property to theJAVA_OPTS
environment variable:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Additional resources
6.3. Using Python artifact repositories Copy linkLink copied to clipboard!
6.3.1. Configuring Python to use a non-standard registry Copy linkLink copied to clipboard!
To specify a non-standard repository for use by the Python pip tool, set the PIP_INDEX_URL
environment variable.
Procedure
In your devfile, configure the
PIP_INDEX_URL
environment variable for the language support and for the development container components:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
6.3.2. Using self-signed certificates in Python projects Copy linkLink copied to clipboard!
Internal artifact repositories often do not have a self-signed TLS certificate signed by an authority that is trusted by default. They are mainly signed by an internal company authority or are self-signed. Configure your tools to accept these certificates.
Python uses certificates from a file defined in the PIP_CERT
environment variable.
Procedure
Obtain the certificate used by the pip server in the Privacy-Enhanced Mail (PEM) format. It is customary for administrators to provide certificates of internal artifact servers as OpenShift secrets (see https://access.redhat.com/documentation/en-us/red_hat_codeready_workspaces/2.14/html-single/installation_guide/index#importing-untrusted-tls-certificates.adoc). The relevant server certificates will be mounted in
/public-certs
in every container in the workspace.Notepip accepts certificates in the Privacy-Enhanced Mail (PEM) format only. Convert the certificate to the PEM format using OpenSSL if necessary.
Configure the devfile:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
6.4. Using Go artifact repositories Copy linkLink copied to clipboard!
To configure Go in a restricted environment, use the GOPROXY
environment variable and the Athens module data store and proxy.
6.4.1. Configuring Go to use a non-standard-registry Copy linkLink copied to clipboard!
Athens is a Go module data store and proxy with many configuration options. It can be configured to act only as a module data store and not as a proxy. An administrator can upload their Go modules to the Athens data store and have them available across their Go projects. If a project tries to access a Go module that is not in the Athens data store, the Go build fails.
To work with Athens, configure the
GOPROXY
environment variable in the devfile of your CLI container:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
6.4.2. Using self-signed certificates in Go projects Copy linkLink copied to clipboard!
Internal artifact repositories often do not have a self-signed TLS certificate signed by an authority that is trusted by default. They are typically signed by an internal company authority or are self-signed. Configure your tools to accept these certificates.
Go uses certificates from a file defined in the SSL_CERT_FILE
environment variable.
Procedure
-
Obtain the certificate used by the Athens server in the Privacy-Enhanced Mail (PEM) format. It is customary for administrators to provide certificates of internal artifact servers as OpenShift secrets (see https://access.redhat.com/documentation/en-us/red_hat_codeready_workspaces/2.14/html-single/installation_guide/index#importing-untrusted-tls-certificates.adoc). The relevant server certificates will be mounted in
/public-certs
in every container in the workspace. Add the appropriate environment variables to your devfile:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Additional resources
6.5. Using NuGet artifact repositories Copy linkLink copied to clipboard!
To configure NuGet in a restricted environment, modify the nuget.config
file and use the SSL_CERT_FILE
environment variable in the devfile to add self-signed certificates.
6.5.1. Configuring NuGet to use a non-standard artifact repository Copy linkLink copied to clipboard!
NuGet searches for configuration files anywhere between the solution directory and the driver root directory. If you put the nuget.config
file in the /projects
directory, the nuget.config
file defines NuGet behavior for all projects in /projects
.
Procedure
Create and place the
nuget.config
file in the/projects
directory.Example
nuget.config
with a Nexus repository hosted atnexus.example.org
:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
6.5.2. Using self-signed certificates in NuGet projects Copy linkLink copied to clipboard!
Internal artifact repositories often do not have a self-signed TLS certificate signed by an authority that is trusted by default. They are mainly signed by an internal company authority or are self-signed. Configure your tools to accept these certificates.
Procedure
-
Obtain the certificate used by the .NET server in the Privacy-Enhanced Mail (PEM) format. It is customary for administrators to provide certificates of internal artifact servers as OpenShift secrets (see https://access.redhat.com/documentation/en-us/red_hat_codeready_workspaces/2.14/html-single/installation_guide/index#importing-untrusted-tls-certificates.adoc). The relevant server certificates will be mounted in
/public-certs
in every container in the workspace. Specify the location of the certificate file in the
SSL_CERT_FILE
environment variable in your devfile for the OmniSharp plug-in and for the .NET container.Example of the devfile:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
6.6. Using npm artifact repositories Copy linkLink copied to clipboard!
The npm (Node Package Manager) package manager for the JavaScript programming language is configured using the npm config
command, by writing values to the .npmrc
files. However, configuration values can also be set using the environment variables beginning with NPM_CONFIG_
.
The Typescript plug-in used in Red Hat CodeReady Workspaces does not download any artifacts. It is enough to configure npm in the dev-machine component.
Use the following environment variables for configuration:
-
The URL for the artifact repository:
NPM_CONFIG_REGISTRY
-
For using a certificate from a file:
NODE_EXTRA_CA_CERTS
Obtain a server certificate file from the repository server. It is customary for administrators to provide certificates of internal artifact servers as OpenShift secrets (see https://access.redhat.com/documentation/en-us/red_hat_codeready_workspaces/2.14/html-single/installation_guide/index#importing-untrusted-tls-certificates.adoc). The relevant server certificates will be mounted in /public-certs
in every container in the workspace.
An example configuration for the use of an internal repository with a self-signed certificate:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow