6.3. 在受限环境中启用工件存储库
通过配置技术堆栈,您可以使用自签名证书从内部存储库中处理工件:
6.3.1. Maven 复制链接链接已复制到粘贴板!
您可以在受限环境中运行的 Maven 工作区中启用 Maven 工件存储库。
先决条件
- 您没有运行任何 Maven 工作区。
-
您知道您的用户命名空间,即 <
username>-devspaces,其中 <username> 是您的 OpenShift Dev Spaces 用户名。
流程
在 &
lt;username>-devspaces命名空间中,为 TLS 证书应用 Secret:kind: Secret apiVersion: v1 metadata: name: tls-cer annotations: controller.devfile.io/mount-path: /home/user/certs controller.devfile.io/mount-as: file labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-secret: 'true' data: tls.cer: >- <Base64_encoded_content_of_public_cert>1 - 1
- 带有禁用行嵌套的 Base64 编码。
在 &
lt;username>-devspaces命名空间中,应用 ConfigMap 来创建settings.xml文件:kind: ConfigMap apiVersion: v1 metadata: name: settings-xml annotations: controller.devfile.io/mount-as: subpath controller.devfile.io/mount-path: /home/user/.m2 labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: settings.xml: | <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository/> <interactiveMode/> <offline/> <pluginGroups/> <servers/> <mirrors> <mirror> <id>redhat-ga-mirror</id> <name>Red Hat GA</name> <url>https://<maven_artifact_repository_route>/repository/redhat-ga/</url> <mirrorOf>redhat-ga</mirrorOf> </mirror> <mirror> <id>maven-central-mirror</id> <name>Maven Central</name> <url>https://<maven_artifact_repository_route>/repository/maven-central/</url> <mirrorOf>maven-central</mirrorOf> </mirror> <mirror> <id>jboss-public-repository-mirror</id> <name>JBoss Public Maven Repository</name> <url>https://<maven_artifact_repository_route>/repository/jboss-public/</url> <mirrorOf>jboss-public-repository</mirrorOf> </mirror> </mirrors> <proxies/> <profiles/> <activeProfiles/> </settings>-
可选:在使用基于 JBoss EAP 的 devfile 时,在 <
username>-devspaces命名空间中应用第二个settings-xmlConfigMap,并使用相同的内容、不同的名称和/home/jboss/.m2挂载路径。 在 &
lt;username>-devspaces命名空间中,为 TrustStore 初始化脚本应用 ConfigMap:Java 8
kind: ConfigMap apiVersion: v1 metadata: name: init-truststore annotations: controller.devfile.io/mount-as: subpath controller.devfile.io/mount-path: /home/user/ labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: init-java8-truststore.sh: | #!/usr/bin/env bash keytool -importcert -noprompt -file /home/user/certs/tls.cer -trustcacerts -keystore ~/.java/current/jre/lib/security/cacerts -storepass changeitJava 11
kind: ConfigMap apiVersion: v1 metadata: name: init-truststore annotations: controller.devfile.io/mount-as: subpath controller.devfile.io/mount-path: /home/user/ labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: init-java11-truststore.sh: | #!/usr/bin/env bash keytool -importcert -noprompt -file /home/user/certs/tls.cer -cacerts -storepass changeit- 启动 Maven 工作区。
-
在
tools容器中打开一个新的终端。 -
运行
~/init-truststore.sh。
6.3.2. gradle 复制链接链接已复制到粘贴板!
您可以在受限环境中运行的 Gradle 工作区中启用 Gradle 工件存储库。
先决条件
- 您没有运行任何 Gradle 工作区。
流程
为 TLS 证书应用 Secret:
kind: Secret apiVersion: v1 metadata: name: tls-cer annotations: controller.devfile.io/mount-path: /home/user/certs controller.devfile.io/mount-as: file labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-secret: 'true' data: tls.cer: >- <Base64_encoded_content_of_public_cert>1 - 1
- 带有禁用行嵌套的 Base64 编码。
为 TrustStore 初始化脚本应用 ConfigMap:
kind: ConfigMap apiVersion: v1 metadata: name: init-truststore annotations: controller.devfile.io/mount-as: subpath controller.devfile.io/mount-path: /home/user/ labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: init-truststore.sh: | #!/usr/bin/env bash keytool -importcert -noprompt -file /home/user/certs/tls.cer -cacerts -storepass changeit为 Gradle 初始化脚本应用 ConfigMap:
kind: ConfigMap apiVersion: v1 metadata: name: init-gradle annotations: controller.devfile.io/mount-as: subpath controller.devfile.io/mount-path: /home/user/.gradle labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: init.gradle: | allprojects { repositories { mavenLocal () maven { url "https://<gradle_artifact_repository_route>/repository/maven-public/" credentials { username "admin" password "passwd" } } } }- 启动一个 Gradle 工作区。
-
在
tools容器中打开一个新的终端。 -
运行
~/init-truststore.sh。
6.3.3. npm 复制链接链接已复制到粘贴板!
您可以在受限环境中运行的 npm 工作区中启用 npm 工件存储库。
先决条件
- 您没有运行任何 npm 工作区。
应用设置环境变量的 ConfigMap 可能会导致工作区引导循环。
如果您遇到此行为,请删除 ConfigMap 并直接编辑 devfile。
流程
为 TLS 证书应用 Secret:
kind: Secret apiVersion: v1 metadata: name: tls-cer annotations: controller.devfile.io/mount-path: /public-certs controller.devfile.io/mount-as: file labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-secret: 'true' data: nexus.cer: >- <Base64_encoded_content_of_public_cert>__1 - 1
- 带有禁用行嵌套的 Base64 编码。
应用 ConfigMap 在
工具容器中设置以下环境变量:kind: ConfigMap apiVersion: v1 metadata: name: disconnected-env annotations: controller.devfile.io/mount-as: env labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: NPM_CONFIG_REGISTRY: >- https://<npm_artifact_repository_route>/repository/npm-all/
6.3.3.1. 禁用自签名证书验证 复制链接链接已复制到粘贴板!
运行以下命令禁用 SSL/TLS,绕过自签名证书验证。请注意,这是一个潜在的安全风险。为获得更好的解决方案,请使用 NODE_EXTRA_CA_CERTS 配置您信任的自签名证书。
步骤
在终端中运行以下命令:
npm config set strict-ssl false
6.3.3.2. 配置 NODE_EXTRA_CA_CERTS 以使用证书 复制链接链接已复制到粘贴板!
使用以下命令,将 NODE_EXTRA_CA_CERTS 设置为指向您具有 SSL/TLS 证书的位置。
步骤
在终端中运行以下命令:
`export NODE_EXTRA_CA_CERTS=/public-certs/nexus.cer`1 `npm install`- 1
/public-certs/HEKETI.cer是 Nexus 工件ory 自签名 SSL/TLS 证书的路径。
6.3.4. Python 复制链接链接已复制到粘贴板!
您可以在受限环境中运行的 Python 工作区中启用 Python 工件存储库。
先决条件
- 您没有运行任何 Python 工作区。
应用设置环境变量的 ConfigMap 可能会导致工作区引导循环。
如果您遇到此行为,请删除 ConfigMap 并直接编辑 devfile。
流程
为 TLS 证书应用 Secret:
kind: Secret apiVersion: v1 metadata: name: tls-cer annotations: controller.devfile.io/mount-path: /home/user/certs controller.devfile.io/mount-as: file labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-secret: 'true' data: tls.cer: >- <Base64_encoded_content_of_public_cert>1 - 1
- 带有禁用行嵌套的 Base64 编码。
应用 ConfigMap 在
工具容器中设置以下环境变量:kind: ConfigMap apiVersion: v1 metadata: name: disconnected-env annotations: controller.devfile.io/mount-as: env labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: PIP_INDEX_URL: >- https://<python_artifact_repository_route>/repository/pypi-all/ PIP_CERT: /home/user/certs/tls.cer
6.3.5. Go 复制链接链接已复制到粘贴板!
您可以在受限环境中运行的 Go 工作区中启用 Go 工件存储库。
先决条件
- 您没有运行 Go 工作区。
应用设置环境变量的 ConfigMap 可能会导致工作区引导循环。
如果您遇到此行为,请删除 ConfigMap 并直接编辑 devfile。
流程
为 TLS 证书应用 Secret:
kind: Secret apiVersion: v1 metadata: name: tls-cer annotations: controller.devfile.io/mount-path: /home/user/certs controller.devfile.io/mount-as: file labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-secret: 'true' data: tls.cer: >- <Base64_encoded_content_of_public_cert>1 - 1
- 带有禁用行嵌套的 Base64 编码。
应用 ConfigMap 在
工具容器中设置以下环境变量:kind: ConfigMap apiVersion: v1 metadata: name: disconnected-env annotations: controller.devfile.io/mount-as: env labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: GOPROXY: >- http://<athens_proxy_route> SSL_CERT_FILE: /home/user/certs/tls.cer
6.3.6. NuGet 复制链接链接已复制到粘贴板!
您可以在受限环境中运行的 NuGet 工作区中启用 NuGet 工件存储库。
先决条件
- 您没有运行任何 NuGet 工作区。
应用设置环境变量的 ConfigMap 可能会导致工作区引导循环。
如果您遇到此行为,请删除 ConfigMap 并直接编辑 devfile。
流程
为 TLS 证书应用 Secret:
kind: Secret apiVersion: v1 metadata: name: tls-cer annotations: controller.devfile.io/mount-path: /home/user/certs controller.devfile.io/mount-as: file labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-secret: 'true' data: tls.cer: >- <Base64_encoded_content_of_public_cert>1 - 1
- 带有禁用行嵌套的 Base64 编码。
应用 ConfigMap 为
工具容器中的 TLS 证书文件的路径设置环境变量:kind: ConfigMap apiVersion: v1 metadata: name: disconnected-env annotations: controller.devfile.io/mount-as: env labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: SSL_CERT_FILE: /home/user/certs/tls.cer应用 ConfigMap 以创建
nuget.config文件:kind: ConfigMap apiVersion: v1 metadata: name: init-nuget annotations: controller.devfile.io/mount-as: subpath controller.devfile.io/mount-path: /projects labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' data: nuget.config: | <?xml version="1.0" encoding="UTF-8"?> <configuration> <packageSources> <add key="nexus2" value="https://<nuget_artifact_repository_route>/repository/nuget-group/"/> </packageSources> <packageSourceCredentials> <nexus2> <add key="Username" value="admin" /> <add key="Password" value="passwd" /> </nexus2> </packageSourceCredentials> </configuration>