The Maven connector is a platform-agnostic connector that you can use to connect to any Maven registry.
You can use the Maven Connector to securely perform maven operations in CICD pipelines, or use it in kubernetes workloads to perform maven operations without credentials.
Additionally, you can centralize the management of maven access configurations across namespaces, avoiding the need to repeat the maven credentials in each namespace.
This document covers:
Maven Registries Prerequisites
mvn deploy, mvn install, mvn package, etc. it must be one of maven snapshots repository or maven release repository or maven proxy repository. like maven central, maven repository hosted by nexus, artifactory, etc.There are some prerequisites for the client to use the Maven connector:
Client Prerequisites
The client should trust the connectors proxy server's certificate, so you should import the ca.cert file to your client's truststore before executing mvn operations. Generally, you can use keytool -importcert command to import the ca.cert file to your client's truststore. for example:
The mvn client should use transport=wagon to execute mvn operations. it could achieve by add the -Dmaven.resolver.transport=wagon parameter to the mvn command or set the MAVEN_OPTS environment variable to -Dmaven.resolver.transport=wagon.
Here's how to create a basic Maven Connector:
spec.connectorClassName:
maven (constant), specifies the ConnectorClass name for Maven integration.
spec.address:
Target Maven registry address, for example: https://nexus.example.com/repository/maven-snapshots or https://repo.maven.apache.org/maven2. It must be one of maven snapshots repository or maven release repository or maven proxy repository.
spec.auth:
specifies the authentication method of the maven registry
spec.auth.name: should be basicAuth for maven connector.
spec.auth.secretRef: specifies the secret that contains the authentication information of the maven registry, the secret should be created in the same namespace as the connector. If your maven registry does not require authentication, you can omit this field.
Optional Metadata fields:
cpaas.io/description: Description information for the maven connector, for example:
The Maven connector supports the following authentication types:
basicAuth: Username and password-based authentication, corresponding secret type: kubernetes.io/basic-authFor example:
If the secret is not correct, the status.conditions field in the maven connector will show the error message.
For comprehensive status information, see Connector Status Documentation.
If the Maven 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:
mvn package or mvn install, the credential only require read permissions for the target Maven repository.mvn deploy, 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 maven registry without credentials, the Maven connector provides a proxy server to automatically inject authentication information.
Clients can use this proxy server to access maven registry without needing to configure credentials on the client side.
To simplify usage, the Maven connectorclass provides settings.xml files that can be mounted into Pods via CSI. In the Pod, when executing maven operations, the proxy service can be automatically inject authentication information.
Upon Connector creation, the system automatically provisions a proxy service for the target maven registry.
The proxy endpoint is recorded in status.proxy.httpAddress:
For example:
The Maven connector provides the following configuration:
settings.xml:
settings.xml configuration file. Combined with the connector-csi-driver, this configuration file will be mounted into the Pod, allowing access to the maven registry through the proxy without needing to configure credentials on the client side.Example of the configuration file generated in the Pod:
For detailed proxy mechanics, see How It Works in the Quick Start guide.
The Maven connector provides a ca.cert file that can be mounted into the Pod via Connector CSI Driver. It is used to trust the connectors proxy server, so you should import the ca.cert file to your client's truststore before executing mvn operations.
The Maven connector provides a settings.xml 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 Maven Connectorconnector.namespace: Namespace of the Maven Connector; if not specified, the Pod's namespace is usedconfiguration.names: Configuration name, provide by the Maven Connector. As above, settings is supported.For detailed information about how to use the settings file in the Pod by connectors-csi-driver, please refer to Using Maven Connectors in kubernetes jobs