6.3. 在受限环境中启用工件存储库


通过配置技术堆栈,您可以使用自签名证书从内部存储库中处理工件:

6.3.1. Maven

您可以在受限环境中运行的 Maven 工作区中启用 Maven 工件存储库。

先决条件

  • 您没有运行任何 Maven 工作区。
  • 您知道您的用户命名空间,即 < username&gt;-devspaces,其中 & lt;username& gt; 是您的 OpenShift Dev Spaces 用户名。

流程

  1. 在 & 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
    Copy to Clipboard Toggle word wrap
    1
    带有禁用行嵌套的 Base64 编码。
  2. 在 & 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>
    Copy to Clipboard Toggle word wrap
  3. 可选:在使用基于 JBoss EAP 的 devfile 时,在 < username>-devspaces 命名空间中应用第二个 settings-xml ConfigMap,并使用相同的内容、不同的名称和 /home/jboss/.m2 挂载路径。
  4. 在 & 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 changeit
    Copy to Clipboard Toggle word wrap

    Java 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
    Copy to Clipboard Toggle word wrap

  5. 启动 Maven 工作区。
  6. tools 容器中打开一个新的终端。
  7. 运行 ~/init-truststore.sh

6.3.2. gradle

您可以在受限环境中运行的 Gradle 工作区中启用 Gradle 工件存储库。

先决条件

  • 您没有运行任何 Gradle 工作区。

流程

  1. 为 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
    Copy to Clipboard Toggle word wrap
    1
    带有禁用行嵌套的 Base64 编码。
  2. 为 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
    Copy to Clipboard Toggle word wrap
  3. 为 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"
              }
            }
          }
        }
    Copy to Clipboard Toggle word wrap
  4. 启动一个 Gradle 工作区。
  5. tools 容器中打开一个新的终端。
  6. 运行 ~/init-truststore.sh

6.3.3. npm

您可以在受限环境中运行的 npm 工作区中启用 npm 工件存储库。

先决条件

  • 您没有运行任何 npm 工作区。
警告

应用设置环境变量的 ConfigMap 可能会导致工作区引导循环。

如果您遇到此行为,请删除 ConfigMap 并直接编辑 devfile。

流程

  1. 为 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
    Copy to Clipboard Toggle word wrap
    1
    带有禁用行嵌套的 Base64 编码。
  2. 应用 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/
    Copy to Clipboard Toggle word wrap

6.3.3.1. 禁用自签名证书验证

运行以下命令禁用 SSL/TLS,绕过自签名证书验证。请注意,这是一个潜在的安全风险。为获得更好的解决方案,请使用 NODE_EXTRA_CA_CERTS 配置您信任的自签名证书。

流程

  • 在终端中运行以下命令:

    npm config set strict-ssl false
    Copy to Clipboard Toggle word wrap

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`
    Copy to Clipboard Toggle word wrap
    1
    /public-certs/HEKETI.cer 是 Nexus 工件ory 自签名 SSL/TLS 证书的路径。

6.3.4. Python

您可以在受限环境中运行的 Python 工作区中启用 Python 工件存储库。

先决条件

  • 您没有运行任何 Python 工作区。
警告

应用设置环境变量的 ConfigMap 可能会导致工作区引导循环。

如果您遇到此行为,请删除 ConfigMap 并直接编辑 devfile。

流程

  1. 为 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
    Copy to Clipboard Toggle word wrap
    1
    带有禁用行嵌套的 Base64 编码。
  2. 应用 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
    Copy to Clipboard Toggle word wrap

6.3.5. Go

您可以在受限环境中运行的 Go 工作区中启用 Go 工件存储库。

先决条件

  • 您没有运行 Go 工作区。
警告

应用设置环境变量的 ConfigMap 可能会导致工作区引导循环。

如果您遇到此行为,请删除 ConfigMap 并直接编辑 devfile。

流程

  1. 为 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
    Copy to Clipboard Toggle word wrap
    1
    带有禁用行嵌套的 Base64 编码。
  2. 应用 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
    Copy to Clipboard Toggle word wrap

6.3.6. NuGet

您可以在受限环境中运行的 NuGet 工作区中启用 NuGet 工件存储库。

先决条件

  • 您没有运行任何 NuGet 工作区。
警告

应用设置环境变量的 ConfigMap 可能会导致工作区引导循环。

如果您遇到此行为,请删除 ConfigMap 并直接编辑 devfile。

流程

  1. 为 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
    Copy to Clipboard Toggle word wrap
    1
    带有禁用行嵌套的 Base64 编码。
  2. 应用 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
    Copy to Clipboard Toggle word wrap
  3. 应用 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>
    Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat