The NPM connector is a platform-agnostic connector that you can use to connect to any NPM registry.
You can use the NPM Connector to securely perform NPM operations in CICD pipelines, or use it in kubernetes workloads to perform NPM operations without credentials.
Additionally, you can centralize the management of NPM access configurations across namespaces, avoiding the need to repeat the NPM credentials in each namespace.
This document covers:
NPM Registries Prerequisites
Here's how to create a basic NPM Connector:
spec.connectorClassName:
npm (constant), specifies the ConnectorClass name for NPM integration.
spec.address:
Target NPM registry address, for example: https://registry.npmjs.org.
When using Nexus as the npm registry, you need to configure the repository address, for example: https://nexus.example.com/repository/npm-public.
spec.auth(optional):
specifies the authentication method of the NPM registry
spec.auth.name: should be basicAuth for NPM connector.
spec.auth.secretRef: specifies the secret that contains the authentication information of the NPM registry, the secret should be created in the same namespace as the connector. If your NPM registry does not require authentication, you can omit this field.
Optional Metadata fields:
cpaas.io/description: Description information for the NPM connector, for example:
spec.params(optional):
NMP Connector support parameters, which is used to control the behavior of connector configuration.
spec.params[].name: The parameter name, which must match a parameter name defined in the corresponding ConnectorClass.spec.params[].value: The parameter value. The value type must match the parameter type defined in the ConnectorClass.supported parameters:
strict-ssl: whether to write .npmrc/.yarnrc.yml file with strict-ssl parameter for the NPM registry. default value is true. supports true and false.For example:
The NPM connector supports the following authentication types:
basicAuth: Username and password-based authentication, corresponding secret type: kubernetes.io/basic-authFor example:
For comprehensive status information, see Connector Status Documentation.
If the NPM registry does not require authentication, you can omit the secretRef field:
The required permissions for the configured credential depend on how you intend to use it in your Pods/Pipelines.
For example:
npm install, the credential only require read permissions for the target NPM repository.npm publish, the credentials must have both read and write permissions for the target repository.For security best practices, we recommend creating credentials with minimal required permissions. When additional privileges are needed, create separate Connectors with more privileged secret and use namespace isolation to control which users can access each Connector.
To provide clients with the ability to access NPM registry without credentials, the NPM connector provides a proxy server to automatically inject authentication information.
Clients can use this proxy server to access NPM registry without needing to configure credentials on the client side.
To simplify usage, the NPM connectorclass provides .npmrc and .yarnrc.yml files that can be mounted into Pods via CSI. In the Pod, when executing NPM operations, the proxy service can automatically inject authentication information.
The .yarnrc.yml file is only supported in the Yarn 2.x version.
Upon Connector creation, the system automatically provisions a proxy service for the target NPM registry.
The proxy endpoint is recorded in status.proxy.httpAddress:
For example:
The NPM connector provides the following configuration:
.npmrc:
.npmrc configuration file. Combined with the connector-csi-driver, this configuration file will be mounted into the Pod, allowing access to the NPM registry through the proxy without needing to configure credentials on the client side.Example of the configuration file generated in the Pod:
Provides a .yarnrc.yml configuration file. Combined with the connector-csi-driver, this configuration file will be mounted into the Pod, allowing access to the NPM registry through the proxy without needing to configure credentials on the client side.
For detailed proxy mechanics, see How It Works in the Quick Start guide.
When using yarn with HTTPS registry, you need to configure yarn with the Connector Proxy certificate trust through environment variables, otherwise certificate errors will occur.
The certificate configuration for yarn is as follows:
The NPM connector also provides a ca.cert file containing the Connector Proxy's CA certificate. This file can be mounted into the Pod via Connector CSI Driver to establish TLS trust when accessing the proxy over HTTPS.
The NPM connector provides a .npmrc, .yarnrc.yml and ca.cert file that can be mounted into the Pod via Connector CSI Driver.
For example:
parameter descriptions:
csi.readOnly: Fixed value truecsi.driver: The Connector CSI Driver, fixed as connectors-csi.csi.volumeAttributes: CSI Volume attributes
connector.name: Name of the NPM Connectorconnector.namespace: Namespace of the NPM Connector; if not specified, the Pod's namespace is usedconfiguration.names: Configuration name, provided by the NPM Connector. As above, npmrc and yarnrc are supported.For detailed information about how to use the .npmrc and .yarnrc.yml file in the Pod by connectors-csi-driver, please refer to Using NPM Connectors in kubernetes jobs