NPM Connector
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.
TOC
OverviewIntegration RequirementsCreating a simple NPM connectorFields ReferenceCapabilities of NPM ConnectorAuthenticationCredential Permissions RequiredNPM Connector Proxy and Configuration with npmrc and yarnrc.yml filesProxy Address.npmrc configuration file.yarnrc.yml configuration fileca.cert fileUsing Connectors CSI Driver to mount .npmrc and .yarnrc.yml fileFurther ReadingReferencesOverview
This document covers:
- Integration Requirements: Prerequisites for target NPM registries
- Creating NPM connector
- Advanced Features: Proxy capabilities and configuration capabilities about NPM connector
Integration Requirements
NPM Registries Prerequisites
- The NPM registry must be able to support NPM Registry API
Creating a simple NPM connector
Here's how to create a basic NPM Connector:
Fields Reference
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 bebasicAuthfor 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 correspondingConnectorClass.spec.params[].value: The parameter value. The value type must match the parameter type defined in theConnectorClass.
supported parameters:
strict-ssl: whether to write .npmrc/.yarnrc.yml file withstrict-sslparameter for the NPM registry. default value istrue. supportstrueandfalse.
For example:
Capabilities of NPM Connector
Authentication
The NPM connector supports the following authentication types:
basicAuth: Username and password-based authentication, corresponding secret type:kubernetes.io/basic-auth
For example:
For comprehensive status information, see Connector Status Documentation.
If the NPM registry does not require authentication, you can omit the secretRef field:
Credential Permissions Required
The required permissions for the configured credential depend on how you intend to use it in your Pods/Pipelines.
For example:
- Package operations: If you only need to download dependencies using
npm install, the credential only require read permissions for the target NPM repository. - Package and Deploy operations: If you need to publish artifacts using
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.
NPM Connector Proxy and Configuration with npmrc and yarnrc.yml files
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.
Proxy Address
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:
.npmrc configuration file
The NPM connector provides the following configuration:
.npmrc:
- Provides a
.npmrcconfiguration 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:
.yarnrc.yml configuration file
-
Provides a
.yarnrc.ymlconfiguration 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:
ca.cert file
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.
Using Connectors CSI Driver to mount .npmrc and .yarnrc.yml file
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 valuetruecsi.driver: The Connector CSI Driver, fixed asconnectors-csi.csi.volumeAttributes: CSI Volume attributesconnector.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,npmrcandyarnrcare 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