PyPI Connector
PyPI Connector 是一个平台无关的连接器,您可以使用它连接到任何 PyPI 注册表。
您可以使用 PyPI Connector 在 CICD 流水线中安全地执行 PyPI 操作,或者在 kubernetes 工作负载中使用它执行无凭证的 PyPI 操作。
此外,您可以集中管理跨命名空间的 PyPI 访问配置,避免在每个命名空间中重复配置 PyPI 凭证。
目录
OverviewIntegration RequirementsCreating a simple PyPI connectorFields ReferenceCapabilities of PyPI ConnectorAuthentication使用基本认证Credential Permissions RequiredProxy and pip.conf, .pypirc ConfigurationProxy Addresspip.conf configuration file.pypirc configuration fileUsing Connectors CSI Driver to mount pip.conf and .pypirc fileFurther ReadingReferencesOverview
本文档涵盖:
- 集成要求:目标 PyPI 注册表的前提条件
- 创建 PyPI Connector
- 高级功能:关于 PyPI Connector 的代理功能和配置能力
Integration Requirements
PyPI 注册表前提条件
- PyPI 注册表必须支持 Simple Repository API
Creating a simple PyPI connector
以下是创建基础 PyPI Connector 的方法:
Fields Reference
spec.connectorClassName:
pypi(固定值),指定用于 PyPI 集成的 ConnectorClass 名称。
spec.address:
目标 PyPI 注册表地址,例如:https://pypi.org。
spec.auth(可选):
指定 PyPI 注册表的认证方式
-
spec.auth.name:PyPI Connector 应为basicAuth。 -
spec.auth.secretRef:指定包含 PyPI 注册表认证信息的 Secret,该 Secret 应创建在与 Connector 相同的命名空间中。如果您的 PyPI 注册表不需要认证,可以省略此字段。
可选元数据字段:
-
cpaas.io/description:PyPI Connector 的描述信息,例如:
Capabilities of PyPI Connector
Authentication
PyPI Connector 支持以下认证类型:
basicAuth:基于用户名和密码的认证,对应的 Secret 类型为:kubernetes.io/basic-auth
使用基本认证
例如:
如果 Secret 不正确,PyPI Connector 中的 status.conditions 字段将显示错误信息。
有关完整状态信息,请参见 Connector Status Documentation。
如果 PyPI 注册表不需要认证,可以省略 secretRef 字段:
Credential Permissions Required
配置凭证所需的权限取决于您打算如何在 Pods/Pipelines 中使用它。
例如:
- 安装软件包:如果您仅需使用
pip install安装软件包,凭证只需对目标 PyPI 注册表具有读取权限。 - 上传软件包:如果您需要使用
twine upload或类似工具上传软件包,凭证必须对目标注册表具有读写权限。
出于安全最佳实践,建议创建权限最小化的凭证。当需要额外权限时,创建具有更高权限的独立 Connector,并通过命名空间隔离控制用户访问各个 Connector。
Proxy and pip.conf, .pypirc Configuration
为了让客户端能够无凭证访问 PyPI 注册表,PyPI Connector 提供了一个代理服务器,用于自动注入认证信息。
客户端可以通过该代理服务器访问 PyPI 注册表,无需在客户端配置凭证。
为简化使用,PyPI ConnectorClass 提供了可通过 CSI 挂载到 Pod 中的 pip.conf 和 .pypirc 文件。在 Pod 中执行 PyPI 操作时,代理服务可自动注入认证信息。
Proxy Address
创建 Connector 后,系统会自动为目标 PyPI 注册表配置一个代理服务。
代理端点记录在 status.proxy.httpAddress 中:
例如:
pip.conf configuration file
PyPI Connector 提供以下配置:
pip.conf:
- 提供一个
pip.conf配置文件。结合 connector-csi-driver,该配置文件将挂载到 Pod 中,使得通过代理访问 PyPI 注册表时无需在客户端配置凭证。
Pod 中生成的配置文件示例:
.pypirc configuration file
-
提供一个
.pypirc配置文件。结合 connector-csi-driver,该配置文件将挂载到 Pod 中,使得通过代理访问 PyPI 注册表时无需在客户端配置凭证。
有关代理机制的详细信息,请参见快速入门指南中的 How It Works。
Using Connectors CSI Driver to mount pip.conf and .pypirc file
PyPI Connector 提供了可通过 Connector CSI Driver 挂载到 Pod 中的 pip.conf 和 .pypirc 文件。
例如:
参数说明:
csi.readOnly:固定值truecsi.driver:Connector CSI Driver,固定为connectors-csicsi.volumeAttributes:CSI 卷属性connector.name:PyPI Connector 名称connector.namespace:PyPI Connector 所在命名空间;若未指定,则使用 Pod 所在命名空间configuration.names:配置名称,由 PyPI Connector 提供。支持pipconf和pypirc。
关于如何通过 connectors-csi-driver 在 Pod 中使用 pip.conf 和 .pypirc 文件的详细信息,请参见 Using PyPI Connectors in kubernetes jobs
Further Reading
- Using PyPI Connectors as Distribution Management Repository
- Using PyPI Connectors in Tekton Pipelines