Quick Start
This document will help you quickly understand how to create a maven connector to connect to a maven registry and perform mvn operations securely without directly handling credentials.
We will create a maven connector, and use it to perform mvn deploy without directly handling credentials in client side.
TOC
Estimated Reading TimePrerequisitesProcess OverviewSteps to OperateStep 1: Create NamespaceStep 2: Create Maven Registry Credentials and ConnectorStep 3: Create a Job to Performmvn deployKey settingsStep 4: Verify OperationWhat happens under the hoodKey NotesAuthentication FlowSettings VolumeTroubleshootingFurther ReadingReferencesEstimated Reading Time
15 minutes
Prerequisites
- Kubernetes cluster with Connectors system installed (Operator, ConnectorsCore and ConnectorsMaven components). See the Installation Guide for details on installing these components.
- maven registry address (snapshots) and credentials
- Basic knowledge of Kubernetes and Maven
Process Overview
Steps to Operate
Step 1: Create Namespace
Create a dedicated namespace for this demonstration:
Step 2: Create Maven Registry Credentials and Connector
Create both the Secret containing maven registry credentials and the maven connector resource. Your maven registry should be a snapshots repository.
For more detailed information about creating and configuring connectors, please refer to the Connectors Quick Start Guide.
Verify that the connector is in "Ready" status:
The output should show:
Step 3: Create a Job to Perform mvn deploy
Create a job that uses the connector to perform maven operations:
Key settings
MAVEN_OPTS in container environment:
Set to MAVEN_OPTS=-Dmaven.resolver.transport=wagon
Scripts in container:
Using the keytool command to import the ca.cert file to your client's truststore for trust the connector proxy server before executing mvn operations.
volumes[].volumeAttributes
connector.name: The name of your maven connectorconfiguration.names: Set to "settings", which references a specific configuration template defined in the maven connectorClass. This template is used to generate the "settings.xml" file with the appropriate settings for authentication.
Step 4: Verify Operation
Check the job's logs to confirm the mvn deploy operations were successfully performed:
You should see the mvn deploy operations completing successfully and upload the jar to the maven repository.
Example output:
What happens under the hood
The maven connector works by:
- Creating a proxy service that sits between your maven client and the target maven registry
- Injecting authentication information when requests pass through the proxy
- Providing
settings.xmlfiles for client to perform mvn operations with the proxy
To demonstrate this mechanism, let's inspect the generated settings.xml file:
View the generated files in /opt/maven/:
View the generated settings.xml file:
Example output:
Key Notes
- Two files are mounted into the Pod via Connectors CSI Driver:
settings.xmlandca.cert. - The
settings.xmlfile contains the proxy configuration section, it provides ability to connect to the maven registry via the proxy. The proxy will inject the authentication information when requests pass through the proxy. - The
settings.xmlfile contains no original secret and mount to the Pod via Connectors CSI Driver.
Authentication Flow
The inspect-mvn-deploy pod contains no original cluster tokens. When maven makes HTTPS requests to the maven registry, the proxy server intercepts these requests, injects authentication credentials from the maven-connector, and forwards the authenticated requests to the backend maven registry server.
Settings Volume
The settings.xml file is mounted into the Pod via Connectors CSI Driver.
In the above example, the settings.xml and ca.cert file is mounted into the Pod via Connectors CSI Driver.
- The
settings.xmlfile contains the proxy configuration section, it provides ability to connect to the maven registry via the proxy. The proxy will inject the authentication information when requests pass through the proxy. - The
ca.certfile is used to trust the connectors proxy server, so you should import theca.certfile to your client's truststore before executing mvn operations.
For volumes parameters, please refer to Using Connectors CSI Driver to mount settings.xml file in Maven Connector Concepts document.
Troubleshooting
If your mvn deploy operation fails, check the following:
-
Connector Status: Ensure the connector is in "Ready" state:
-
Verify the connectors deployment status: ensure all components are deployed and in "Ready" state
Further Reading
After successfully performing mvn deploy operations using the maven connector, you can:
- Learn more about Concepts of Maven Connectors
- Using Maven Connectors as Maven Registry Mirror
- Using Maven Connectors in Tekton Pipelines