Maven Connector
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.
TOC
OverviewIntegration RequirementsCreating a simple Maven connectorFields ReferenceCapabilities of Maven ConnectorAuthenticationUsing Basic AuthenticationCredential Permissions RequiredProxy and settings.xml ConfigurationProxy Addresssettings.xml configuration fileca.cert fileUsing Connectors CSI Driver to mount settings.xml and ca.cert fileFurther ReadingReferencesOverview
This document covers:
- Integration Requirements: Prerequisites for target Maven registries
- Creating Maven connector
- Advanced Features: Proxy capabilities and configuration capabilities about Maven connector
Integration Requirements
Maven Registries Prerequisites
- The maven registry must be able to support the maven operations, like
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.certfile to your client's truststore before executing mvn operations. Generally, you can usekeytool -importcertcommand to import theca.certfile 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=wagonparameter to the mvn command or set theMAVEN_OPTSenvironment variable to-Dmaven.resolver.transport=wagon.
Creating a simple Maven connector
Here's how to create a basic Maven Connector:
Fields Reference
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 bebasicAuthfor 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:
Capabilities of Maven Connector
Authentication
The Maven connector supports the following authentication types:
basicAuth: Username and password-based authentication, corresponding secret type:kubernetes.io/basic-auth
Using Basic Authentication
For 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:
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
mvn packageormvn install, the credential only require read permissions for the target Maven repository. - Package and Deploy operations: If you need to publish artifacts using
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.
Proxy and settings.xml Configuration
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.
Proxy Address
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:
settings.xml configuration file
The Maven connector provides the following configuration:
settings.xml:
- Provides a
settings.xmlconfiguration 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.
ca.cert file
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.
Using Connectors CSI Driver to mount settings.xml and ca.cert file
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 valuetruecsi.driver: The Connector CSI Driver, fixed asconnectors-csi.csi.volumeAttributes: CSI Volume attributesconnector.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,settingsis 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
Further Reading
- Using Maven Connectors as Distribution Management Repository
- Using Maven Connectors as Maven Registry Mirror
- Using Maven Connectors in Tekton Pipelines