|
| 1 | +--- |
| 2 | +weight: 20 |
| 3 | +--- |
| 4 | + |
| 5 | +# PyPI Connector |
| 6 | + |
| 7 | +The PyPI connector is a platform-agnostic connector that you can use to connect to any PyPI registry. |
| 8 | + |
| 9 | +You can use the PyPI Connector to securely perform PyPI operations in CICD pipelines, or use it in kubernetes workloads to perform PyPI operations without credentials. |
| 10 | + |
| 11 | +Additionally, you can centralize the management of PyPI access configurations across namespaces, avoiding the need to repeat the PyPI credentials in each namespace. |
| 12 | + |
| 13 | +## Overview |
| 14 | + |
| 15 | +This document covers: |
| 16 | + |
| 17 | +- **Integration Requirements**: Prerequisites for target PyPI registries |
| 18 | +- **Creating PyPI connector** |
| 19 | +- **Advanced Features**: Proxy capabilities and configuration capabilities about PyPI connector |
| 20 | + |
| 21 | +## Integration Requirements |
| 22 | + |
| 23 | +**PyPI Registries Prerequisites** |
| 24 | + |
| 25 | +- The PyPI registry must be able to support [Simple Repository API](https://peps.python.org/pep-0503/) |
| 26 | + |
| 27 | +## Creating a simple PyPI connector |
| 28 | + |
| 29 | +Here's how to create a basic PyPI Connector: |
| 30 | + |
| 31 | +```yaml |
| 32 | +# PyPI Connector |
| 33 | +apiVersion: connectors.alauda.io/v1alpha1 |
| 34 | +kind: Connector |
| 35 | +metadata: |
| 36 | + name: pypi-connector |
| 37 | +spec: |
| 38 | + connectorClassName: pypi |
| 39 | + address: https://pypi.org |
| 40 | +``` |
| 41 | +
|
| 42 | +## Fields Reference |
| 43 | +
|
| 44 | +**spec.connectorClassName**: |
| 45 | +
|
| 46 | +`pypi` (constant), specifies the ConnectorClass name for PyPI integration. |
| 47 | + |
| 48 | +**spec.address**: |
| 49 | + |
| 50 | +Target PyPI registry address, for example: `https://pypi.org`. |
| 51 | + |
| 52 | +**spec.auth(optional)**: |
| 53 | + |
| 54 | +specifies the authentication method of the PyPI registry |
| 55 | + |
| 56 | +- `spec.auth.name`: should be `basicAuth` for PyPI connector. |
| 57 | + |
| 58 | +- `spec.auth.secretRef`: specifies the secret that contains the authentication information of the PyPI registry, the secret should be created in the same namespace as the connector. If your PyPI registry does not require authentication, you can omit this field. |
| 59 | + |
| 60 | +**Optional Metadata fields**: |
| 61 | + |
| 62 | +- `cpaas.io/description`: Description information for the PyPI connector, for example: |
| 63 | + |
| 64 | + ```yaml |
| 65 | + apiVersion: connectors.alauda.io/v1alpha1 |
| 66 | + kind: Connector |
| 67 | + metadata: |
| 68 | + name: pypi-connector |
| 69 | + annotations: |
| 70 | + cpaas.io/description: "Connect to team development PyPI registry" |
| 71 | + ``` |
| 72 | + |
| 73 | +## Capabilities of PyPI Connector |
| 74 | + |
| 75 | +### Authentication |
| 76 | + |
| 77 | +The PyPI connector supports the following authentication types: |
| 78 | + |
| 79 | +- `basicAuth`: Username and password-based authentication, corresponding secret type: `kubernetes.io/basic-auth` |
| 80 | + |
| 81 | +For example: |
| 82 | + |
| 83 | +```yaml |
| 84 | +apiVersion: v1 |
| 85 | +stringData: |
| 86 | + username: your-pypi-registry-username |
| 87 | + password: your-pypi-registry-password |
| 88 | +kind: Secret |
| 89 | +metadata: |
| 90 | + name: pypi-secret |
| 91 | +type: kubernetes.io/basic-auth |
| 92 | +``` |
| 93 | + |
| 94 | +For comprehensive status information, see [Connector Status Documentation](../../connectors/concepts/connector.mdx#status-information). |
| 95 | + |
| 96 | +### Proxy and pip.conf, .pypirc Configuration |
| 97 | + |
| 98 | +To provide clients with the ability to access PyPI registry without credentials, the PyPI connector provides a proxy server to automatically inject authentication information. |
| 99 | + |
| 100 | +Clients can use this proxy server to access PyPI registry without needing to configure credentials on the client side. |
| 101 | + |
| 102 | +To simplify usage, the PyPI connectorclass provides `pip.conf` and `.pypirc` files that can be mounted into Pods via CSI. In the Pod, when executing PyPI operations, the proxy service can be automatically inject authentication information. |
| 103 | + |
| 104 | +#### Proxy Address |
| 105 | + |
| 106 | +Upon Connector creation, the system automatically provisions a proxy service for the target PyPI registry. |
| 107 | + |
| 108 | +The proxy endpoint is recorded in `status.proxy.httpAddress`: |
| 109 | + |
| 110 | +For example: |
| 111 | + |
| 112 | +```yaml |
| 113 | +apiVersion: connectors.alauda.io/v1alpha1 |
| 114 | +kind: Connector |
| 115 | +metadata: |
| 116 | + name: pypi-connector |
| 117 | +spec: |
| 118 | + # connector spec fields |
| 119 | +status: |
| 120 | + conditions: |
| 121 | + # status conditions |
| 122 | + proxy: |
| 123 | + httpAddress: |
| 124 | + url: http://c-pypi-connector.default.svc.cluster.local |
| 125 | +``` |
| 126 | + |
| 127 | +#### pip.conf configuration file \{#pipconf-configuration-file} |
| 128 | + |
| 129 | +The PyPI connector provides the following configuration: |
| 130 | + |
| 131 | +**pip.conf**: |
| 132 | + |
| 133 | +- Provides a `pip.conf` configuration file. Combined with the connector-csi-driver, this configuration file will be mounted into the Pod, allowing access to the PyPI registry through the proxy without needing to configure credentials on the client side. |
| 134 | + |
| 135 | +Example of the configuration file generated in the Pod: |
| 136 | + |
| 137 | + ```ini |
| 138 | + [global] |
| 139 | + index-url = http://connectors-pypi-demo-pypi-connector:eyJhbGciOiJEnEZaTQ@c-pypi-connector.connectors-pypi-demo.svc.cluster.local/simple/ |
| 140 | + timeout = 30 |
| 141 | + |
| 142 | + [install] |
| 143 | + trusted-host = c-pypi-connector.connectors-pypi-demo.svc.cluster.local |
| 144 | + ``` |
| 145 | + |
| 146 | +#### .pypirc configuration file \{#pypirc-configuration-file} |
| 147 | + |
| 148 | +- Provides a `.pypirc` configuration file. Combined with the connector-csi-driver, this configuration file will be mounted into the Pod, allowing access to the PyPI registry through the proxy without needing to configure credentials on the client side. |
| 149 | + |
| 150 | + ```ini |
| 151 | + [distutils] |
| 152 | + index-servers = connectors-pypi |
| 153 | + |
| 154 | + [connectors-pypi] |
| 155 | + repository = http://c-pypi-connector.connectors-pypi-demo.svc.cluster.local/ |
| 156 | + username = connectors-pypi-demo-pypi-connector |
| 157 | + password = eyJhbGciOiJEnEZaTQ |
| 158 | + ``` |
| 159 | + |
| 160 | +For detailed proxy mechanics, see [How It Works](../quick_start.mdx#what-happens-under-the-hood) in the Quick Start guide. |
| 161 | + |
| 162 | + |
| 163 | +#### Using Connectors CSI Driver to mount pip.conf and .pypirc file \{#using-connectors-csi-driver-to-mount-pipconf-file} |
| 164 | + |
| 165 | +The PyPI connector provides a `pip.conf` and `.pypirc` file that can be mounted into the Pod via Connector CSI Driver. |
| 166 | + |
| 167 | +For example: |
| 168 | + |
| 169 | +``` yaml |
| 170 | +spec: |
| 171 | + volumes: |
| 172 | + - name: pip.conf |
| 173 | + csi: |
| 174 | + readOnly: true |
| 175 | + driver: connectors-csi |
| 176 | + volumeAttributes: |
| 177 | + connector.name: "pypi-connector" |
| 178 | + configuration.names: "pipconf" |
| 179 | + - name: pypirc |
| 180 | + csi: |
| 181 | + readOnly: true |
| 182 | + driver: connectors-csi |
| 183 | + volumeAttributes: |
| 184 | + connector.name: "pypi-connector" |
| 185 | + configuration.names: "pypirc" |
| 186 | +``` |
| 187 | + |
| 188 | +parameter descriptions: |
| 189 | + |
| 190 | +- `csi.readOnly`: Fixed value `true` |
| 191 | +- `csi.driver`: The Connector CSI Driver, fixed as `connectors-csi`. |
| 192 | +- `csi.volumeAttributes`: CSI Volume attributes |
| 193 | + - `connector.name`: Name of the PyPI Connector |
| 194 | + - `connector.namespace`: Namespace of the PyPI Connector; if not specified, the Pod's namespace is used |
| 195 | + - `configuration.names`: Configuration name, provide by the PyPI Connector. As above, `pipconf` and `pypirc` are supported. |
| 196 | + |
| 197 | +For detailed information about how to use the `pip.conf` and `.pypirc` file in the Pod by connectors-csi-driver, please refer to [Using PyPI Connectors in kubernetes jobs](../quick_start.mdx) |
| 198 | + |
| 199 | +## Further Reading |
| 200 | + |
| 201 | +- [Using PyPI Connectors as Distribution Management Repository](../quick_start.mdx) |
| 202 | +- [Using PyPI Connectors in Tekton Pipelines](../how_to/using-in-tekton-task.mdx) |
| 203 | + |
| 204 | +## References |
| 205 | + |
| 206 | +- [Concepts of Connector](../../connectors/concepts/connector.mdx) |
| 207 | +- [Connector Proxy](../../connectors/concepts/connectors_proxy.mdx) |
| 208 | +- [Connector CSI Driver](../../connectors/concepts/connectors_csi.mdx) |
| 209 | +- [Kubernetes CSI Volume](https://kubernetes.io/docs/concepts/storage/volumes/#csi) |
0 commit comments