Code Monkey home page Code Monkey logo

nexus-kubernetes-openshift's Introduction

Kubernetes/OpenShift Provisioning Plugin For Sonatype Nexus

Coverage Vulnerabilities Bugs Code Smells Maintainability Rating Reliability Rating Security Rating

Purpose

  • Allow for BlobStores to be configured using ConfigMap objects labelled nexus-type==blobstore
  • Allow for Repositories to be configured using ConfigMap objects labelled nexus-type==repository
  • Allow for Admin password to be configured using Secret object named nexus

Installing

You can copy the bundle to /opt/sonatype/nexus/deploy on any running Nexus container, but it would not be persistent across restarts. The simplest option is to build a new container image based on the sonatype/nexus3 container and add the bundle JAR file to the new image. Here's how to create a container image:

## The Dockefiles are set to install from the GitHub Releases, no compilation required
docker build -t nexus-kubernetes -f Dockerfile . 

docker build -t nexus-openshift -f Dockerfile.rhel7 .

NOTE: To build the OpenShift image, you MUST have access to registry.connect.redhat.com and have Docker configured to authenticate to that registry.

Configuration

For the most part, you should NOT need to do anything to configure this plugin. It will detect if it is running inside of a Kubernetes/OpenShift cluster and default to using the service account settings and environment variables defined in the Pod/Container. If you need to run this outside of a cluster but want to point at K8s API for configuration, you can assume the code will:

  • If $KUBECONFIG is defined, use that config file.
  • If $HOME/.kube/config can be found, use that.
  • If the in-cluster service account can be found, assume in cluster config.
  • Default to localhost:8080 as a last resort.

Setting Admin Password

The Admin password can be set using a Secret named nexus which contains a key called password. For example:

apiVersion: v1
stringData:
  password: <MY SUPER SECRET PASSWORD>
kind: Secret
metadata:
  name: nexus
  namespace: labs-ci-cd
type: Opaque

Provisioning BlobStores

Right now, this ONLY supports File blobstores. Perhaps later, S3 blobstores can be supported.

Example ConfigMap

apiVersion: v1
data:
  type: 'File'
kind: ConfigMap
metadata:
  name: my-blobstore
  namespace: labs-ci-cd
  labels:
    nexus-type: blobstore

Provisioning Repositories

Nexus supports a number of different repository types, and each one has different required settings.

Example ConfigMap

apiVersion: v1
data:
  recipe: 'MavenProxy'
  remoteUrl: 'https://repo.maven.apache.org/maven2/'
  blobStoreName: 'default'
  strictContentTypeValidation: 'true'
  versionPolicy: 'RELEASE'
  layoutPolicy: 'STRICT'
kind: ConfigMap
metadata:
  name: maven-central
  namespace: labs-ci-cd
  labels:
    nexus-type: repository

More example ConfigMaps can be seen HERE

There are a few enumerated data types which you need to know as well:

Type Allowed Values
WritePolicy ALLOW, ALLOW_ONCE, DENY
VersionPolicy RELEASE, SNAPSHOT, MIXED
LayoutPolicy STRICT, PERMISSIVE

Listed below are the fields required for each repository type:

Repository Type Field Type Required Default Value
AptHosted description String false <N/A>
pgpPrivateKey String false <N/A>
pgpPassPhrase String false <N/A>
blobStoreName String true default
writePolicy WritePolicy true ALLOW
strictContentTypeValidation boolean true true
AptProxy remoteUrl String true <N/A>
blobStoreName String true default
distribution String false <N/A>
strictContentTypeValidation boolean true true
BowerGroup members List<String> (comma-separated list of repositories) false <N/A>
blobStoreName String true default
BowerHosted blobStoreName String true default
strictContentTypeValidation boolean true true
writePolicy WritePolicy true ALLOW
BowerProxy remoteUrl String true <N/A>
blobStoreName String true default
strictContentTypeValidation boolean true true
rewritePackageUrls boolean true true
DockerGroup httpPort Integer false <N/A>
httpsPort Integer false <N/A>
members List<String> (comma-separated list of repositories) false <N/A>
v1Enabled boolean true true
blobStoreName String true default
forceBasicAuth boolean true true
DockerHosted httpPort Integer false <N/A>
httpsPort Integer false <N/A>
blobStoreName String true default
strictContentTypeValidation boolean true true
v1Enabled boolean true true
writePolicy WritePolicy true ALLOW
forceBasicAuth boolean true true
DockerProxy remoteUrl String true <N/A>
indexType String true REGISTRY (Can be REGISTRY, HUB, CUSTOM; CUSTOM requires setting indexUrl below)
indexUrl String false <N/A>
httpPort Integer false <N/A>
httpsPort Integer false <N/A>
blobStoreName String true default
strictContentTypeValidation boolean true true
v1Enabled boolean true true
GitLfsHosted blobStoreName String null <N/A>
strictContentTypeValidation boolean true true
writePolicy WritePolicy true ALLOW
GolangGroup members List<String> (comma-separated list of repositories) false <N/A>
blobStoreName String true default
GolangHosted blobStoreName String true default
strictContentTypeValidation boolean true true
writePolicy WritePolicy true ALLOW
GolangProxy remoteUrl String true <N/A>
blobStoreName String true default
strictContentTypeValidation boolean true true
MavenGroup members List<String> (comma-separated list of repositories) false <N/A>
blobStoreName String true default
MavenHosted blobStoreName String true default
strictContentTypeValidation boolean true true
versionPolicy VersionPolicy true RELEASE
writePolicy WritePolicy true ALLOW_ONCE
layoutPolicy LayoutPolicy true STRICT
MavenProxy remoteUrl String true <N/A>
blobStoreName String true default
strictContentTypeValidation boolean true true
versionPolicy VersionPolicy true RELEASE
layoutPolicy LayoutPolicy true STRICT
NpmGroup members List<String> (comma-separated list of repositories) false <N/A>
blobStoreName String true default
NpmHosted blobStoreName String true default
strictContentTypeValidation boolean true true
writePolicy WritePolicy true ALLOW
NpmProxy remoteUrl String true <N/A>
blobStoreName String true default
strictContentTypeValidation boolean true true
NugetGroup members List<String> (comma-separated list of repositories) false <N/A>
blobStoreName String true default
NugetHosted blobStoreName String true default
strictContentTypeValidation boolean true true
writePolicy WritePolicy true ALLOW
NugetProxy remoteUrl String true <N/A>
blobStoreName String true default
strictContentTypeValidation boolean true true
PyPiGroup members List<String> (comma-separated list of repositories) false <N/A>
blobStoreName String true default
PyPiHosted blobStoreName String true default
strictContentTypeValidation boolean true true
writePolicy WritePolicy true ALLOW
PyPiProxy remoteUrl String true <N/A>
blobStoreName String true default
strictContentTypeValidation boolean true true
RawGroup members List<String> (comma-separated list of repositories) false <N/A>
blobStoreName String true default
RawHosted blobStoreName String true default
strictContentTypeValidation boolean true true
writePolicy WritePolicy true ALLOW
RawProxy remoteUrl String true <N/A>
blobStoreName String true default
strictContentTypeValidation boolean true true
RubygemsGroup members List<String> (comma-separated list of repositories) false <N/A>
blobStoreName String true default
RubygemsHosted blobStoreName String true default
strictContentTypeValidation boolean true true
writePolicy WritePolicy true ALLOW
RubygemsProxy remoteUrl String true <N/A>
blobStoreName String true default
strictContentTypeValidation boolean true true
YumGroup members List<String> (comma-separated list of repositories) false <N/A>
blobStoreName String true default
YumHosted blobStoreName String true default
strictContentTypeValidation boolean true true
writePolicy WritePolicy true ALLOW
depth Integer true <N/A>
YumProxy remoteUrl String true <N/A>
blobStoreName String true default
strictContentTypeValidation boolean true true

Requirements

  • Java >= 1.8
  • Maven >= 3.3
  • Maven Settings configured to use Sonatype Public Grid
    <settings>
      <profiles>
          <profile>
            <id>default</id>
            <repositories>
              <repository>
                <id>nexus-public-grid</id>
                <name>nexus-public-grid</name>
                <url>https://repository.sonatype.org/content/groups/sonatype-public-grid/</url>
                <releases/>
              </repository>
              <repository>
                <id>central</id>
                <name>central</name>
                <url>https://repo.maven.apache.org/maven2/</url>
                <releases/>
              </repository>
            </repositories>
          </profile>
      </profiles>
      
      <activeProfiles>
        <activeProfile>default</activeProfile>
      </activeProfiles>
    </settings>

Building

mvn clean package bundle:bundle

The BUNDLE jar file will be output in the project's root directory.

nexus-kubernetes-openshift's People

Contributors

dependabot[bot] avatar fundamental-bot avatar infosec812 avatar scherzhaft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nexus-kubernetes-openshift's Issues

Implement Watchers For Runtime Configuration

Implement Watchers which will have long-lived connections (and reconnect when dropped) to the Kubernetes/OpenShift API. These watchers will monitor for

  • ConfigMap[label=nexus-type==blobstore]
  • ConfigMap[label=nexus-type==repository]
  • Secret[name==nexus]

When new ConfigMaps are created, they will trigger the provisioning of the appropriate items (BlobStore or Repository)

When the Secret changes, the code will update the admin password.

Plugin fails to start

I tried deploying the jar deliverable in a NXRM 3.17 instance and got the following error in the nexus.log in the startup process:

2019-07-15 15:29:11,942-0500 ERROR [FelixDispatchQueue] *SYSTEM com.redhat.labs.nexus.openshift-plugin - FrameworkEvent ERROR - com.redhat.labs.nexus.openshift-plugin
org.osgi.framework.BundleException: Unable to resolve com.redhat.labs.nexus.openshift-plugin [53](R 53.0): missing requirement [com.redhat.labs.nexus.openshift-plugin [53](R 53.0)] osgi.wiring.package; (&(osgi.wiring.package=io.fabric8.kubernetes.api.model)(version>=4.3.0)) Unresolved requirements: [[com.redhat.labs.nexus.openshift-plugin [53](R 53.0)] osgi.wiring.package; (&(osgi.wiring.package=io.fabric8.kubernetes.api.model)(version>=4.3.0))]
	at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4132)
	at org.apache.felix.framework.Felix.startBundle(Felix.java:2117)
	at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1371)
	at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
	at java.lang.Thread.run(Thread.java:748)

I noticed that the jar is pretty small (22Kb), it doesn't have the dependencies shaded in it. I'm no expert on OSGi or karaf, but I tried to get a kar deliverable by adding the following to the pom:

     <plugin>
        <groupId>org.apache.karaf.tooling</groupId>
        <artifactId>karaf-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>kar</goal>
            </goals>
            <phase>package</phase>
          </execution>
        </executions>
      </plugin>

This produces a kar file with the dependencies included:

~/git/nexus-kubernetes-openshift(master ✗) ls -al target/nexus-openshift-plugin-3.17.0-01.kar
-rw-r--r--  1 nblair  staff  18342019 Jul 16 08:22 target/nexus-openshift-plugin-3.17.0-01.kar

But that still produces a similar error during startup:

WARN  [fileinstall-/Users/nblair/git/nexus-internal/target/nexus-professional-3.17.0-01/deploy] *SYSTEM org.apache.karaf.kar.internal.KarServiceImpl - Unable to install Kar feature nexus-openshift-plugin/3.17.0.01
org.osgi.service.resolver.ResolutionException: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=nexus-openshift-plugin; type=karaf.feature; version="[3.17.0.01,3.17.0.01]"; filter:="(&(osgi.identity=nexus-openshift-plugin)(type=karaf.feature)(version>=3.17.0.01)(version<=3.17.0.01))" [caused by: Unable to resolve nexus-openshift-plugin/3.17.0.01: missing requirement [nexus-openshift-plugin/3.17.0.01] osgi.identity; osgi.identity=io.fabric8.openshift-client; type=osgi.bundle; version="[4.3.0,4.3.0]"; resolution:=mandatory [caused by: Unable to resolve io.fabric8.openshift-client/4.3.0: missing requirement [io.fabric8.openshift-client/4.3.0] osgi.wiring.package; filter:="(&(osgi.wiring.package=io.fabric8.kubernetes.api.builder)(version>=4.3.0)(!(version>=5.0.0)))" [caused by: Unable to resolve io.fabric8.kubernetes-model/4.3.0: missing requirement [io.fabric8.kubernetes-model/4.3.0] osgi.wiring.package; filter:="(&(osgi.wiring.package=javax.validation)(version>=2.0.0)(!(version>=3.0.0)))"]]]
	at org.apache.felix.resolver.ResolutionError.toException(ResolutionError.java:42)
	at org.apache.felix.resolver.ResolverImpl.doResolve(ResolverImpl.java:389)
	at org.apache.felix.resolver.ResolverImpl.resolve(ResolverImpl.java:375)
	at org.apache.felix.resolver.ResolverImpl.resolve(ResolverImpl.java:347)
	at org.apache.karaf.features.internal.region.SubsystemResolver.resolve(SubsystemResolver.java:216)
	at org.apache.karaf.features.internal.service.Deployer.deploy(Deployer.java:263)
	at org.apache.karaf.features.internal.service.FeaturesServiceImpl.doProvision(FeaturesServiceImpl.java:1176)
	at org.apache.karaf.features.internal.service.FeaturesServiceImpl$1.call(FeaturesServiceImpl.java:1074)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

I'm not sure how to resolve bundling errors like this...

Improve Backward Compatibility

Need to update the field mappings in RepositoryConfigWatcher so that Nexus version information for both recipes AND fields are defined. This will then be used in new logic to help decide which recipes can and cannot be deployed on the given version of Nexus.

The plan is to inject an instance of org.sonatype.nexus.common.app.ApplicationVersion into OpenShiftConfigPlugin and pass the version value to the appropriate methods as needed. The we will use VersionComparator to filter to the appropriate versions of Nexus.

Bug in upstream Nexus Script prevents assigning non-default BlobStore for Nuget repositories

When provisioning Nuget repositories from Kubernetes ConfigMaps the BlobStore argument appears to be malfunctioning. The implementation HERE indicates that this should be a supported capability, but JUST for Nuget repositories it is not working. All other repository types seem to be provisioned correctly.

I have started a thread on the Nexus mailing list to see if we can find the root cause of this error as the Unit Tests in this project show that the methods are being called correctly but the expected result is not achieved.

Add validation to repository creation

  • Ensure requested blobstore exists
  • Ensure that Group lists contain valid types of repositories
    • e.g. Don't allow Maven and NPM repositories to be mixed in a Group
    • Ensure that group members actually exist

Add support for enabling/disabling Anonymous repository access

My first thought on this is a single ConfigMap which has keys for each repository to indicate if it should be accessible anonymously or not. For example:

apiVersion: v1
data:
  maven-central: 'true'
  myNugetRepo: 'true'
  myDockerGroup: 'false'
kind: ConfigMap
metadata:
  name: my-blobstore
  namespace: labs-ci-cd
  labels:
    nexus-type: anonymous

The plugin would read and parse the data, and set anonymous access appropriately. IF a repository is not listed, the plugin will not modify access for that repository.

Another possibility is allowing for a default which would set all repositories to either allow or disallow anonymous access globally.

[DepShield] (CVSS 5.5) Vulnerability due to usage of org.apache.commons:commons-compress:1.11

Vulnerabilities

DepShield reports that this application's usage of org.apache.commons:commons-compress:1.11 results in the following vulnerability(s):


Occurrences

org.apache.commons:commons-compress:1.11 is a transitive dependency introduced by the following direct dependency(s):

io.kubernetes:client-java:5.0.0
        └─ org.apache.commons:commons-compress:1.11

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

[DepShield] (CVSS 5.5) Vulnerability due to usage of org.apache.commons:commons-compress:1.11

Vulnerabilities

DepShield reports that this application's usage of org.apache.commons:commons-compress:1.11 results in the following vulnerability(s):


Occurrences

org.apache.commons:commons-compress:1.11 is a transitive dependency introduced by the following direct dependency(s):

io.kubernetes:client-java:5.0.0
        └─ org.apache.commons:commons-compress:1.11

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

[DepShield] (CVSS 10.0) Vulnerability due to usage of com.fasterxml.jackson.core:jackson-databind:2.9.2

Vulnerabilities

DepShield reports that this application's usage of com.fasterxml.jackson.core:jackson-databind:2.9.2 results in the following vulnerability(s):


Occurrences

com.fasterxml.jackson.core:jackson-databind:2.9.2 is a transitive dependency introduced by the following direct dependency(s):

org.sonatype.nexus:nexus-plugin-api:3.17.0-01
        └─ com.fasterxml.jackson.core:jackson-databind:2.9.2

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

Allow updating of Group repositories

Currently, the plugin will only allow creation of NEW repositories. IF a repository already exists, it cannot be modified by the plugin. This was a design decision to prevent updating a repository from one type to another and potentially losing data. In the case of Groups, it makes sense to be able to change the members of a group.

[DepShield] (CVSS 7.5) Vulnerability due to usage of com.thoughtworks.xstream:xstream:1.4.10

Vulnerabilities

DepShield reports that this application's usage of com.thoughtworks.xstream:xstream:1.4.10 results in the following vulnerability(s):


Occurrences

com.thoughtworks.xstream:xstream:1.4.10 is a transitive dependency introduced by the following direct dependency(s):

org.sonatype.nexus:nexus-plugin-testsupport:2.14.13-01
        └─ org.sonatype.nexus:nexus-test-common:3.17.0-01
              └─ org.sonatype.goodies:goodies-testsupport:2.3.0
                    └─ org.powermock:powermock-classloading-xstream:1.6.1
                          └─ com.thoughtworks.xstream:xstream:1.4.10

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

Plugin init fails on Nexus 3.28.0

The root cause seems to be https://issues.sonatype.org/browse/NEXUS-25162
"Note for release:

org.sonatype.nexus.repository.storage.WritePolicy has been moved to org.sonatype.nexus.repository.config.WritePolicy.

This will impact any groovy scripts using the org.sonatype.nexus.script.plugin.RepositoryApi to create repositories. The resolution is to change any references of org.sonatype.nexus.repository.storage.WritePolicy to org.sonatype.nexus.repository.config.WritePolicy in those scripts."

Use generated password for admin password change

In newer versions of Nexus, the Admin password is generated on the first start of the application. This means that the default admin password is no longer admin123 and as such the admin password change code no longer works on these newer versions of Nexus. Need to add code to support these newer versions of Nexus.

Fix permissions for RHEL Dockerfile

The Dockerfile.rhel7 is using user nexus and group nexus which is not compatible with OpenShift. Need to change this to user root and group root with 775 permissions.

Add support for roles

Nexus has a concept of "roles" and roles have various "privileges". It would be helpful to support creating/modifying/managing roles using this plugin via a declarative use of ConfigMaps or Custom Resource Definitions.

[DepShield] (CVSS 7.5) Vulnerability due to usage of io.netty:netty-all:4.0.36.Final

Vulnerabilities

DepShield reports that this application's usage of io.netty:netty-all:4.0.36.Final results in the following vulnerability(s):


Occurrences

io.netty:netty-all:4.0.36.Final is a transitive dependency introduced by the following direct dependency(s):

org.sonatype.nexus:nexus-plugin-testsupport:2.14.13-01
        └─ org.sonatype.nexus:nexus-test-common:3.17.0-01
              └─ org.littleshoot:littleproxy:1.1.0
                    └─ io.netty:netty-all:4.0.36.Final

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

[DepShield] (CVSS 5.9) Vulnerability due to usage of com.google.guava:guava:21.0

Vulnerabilities

DepShield reports that this application's usage of com.google.guava:guava:21.0 results in the following vulnerability(s):


Occurrences

com.google.guava:guava:21.0 is a transitive dependency introduced by the following direct dependency(s):

io.kubernetes:client-java:5.0.0
        └─ com.google.guava:guava:21.0

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

[DepShield] (CVSS 5.9) Vulnerability due to usage of com.google.guava:guava:21.0

Vulnerabilities

DepShield reports that this application's usage of com.google.guava:guava:21.0 results in the following vulnerability(s):


Occurrences

com.google.guava:guava:21.0 is a transitive dependency introduced by the following direct dependency(s):

io.kubernetes:client-java:5.0.0
        └─ com.google.guava:guava:21.0

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

[DepShield] (CVSS 5.9) Vulnerability due to usage of com.squareup.okhttp3:okhttp:3.12.0

Vulnerabilities

DepShield reports that this application's usage of com.squareup.okhttp3:okhttp:3.12.0 results in the following vulnerability(s):


Occurrences

com.squareup.okhttp3:okhttp:3.12.0 is a transitive dependency introduced by the following direct dependency(s):

io.fabric8:openshift-client:4.3.0
        └─ io.fabric8:kubernetes-client:4.3.0
              └─ com.squareup.okhttp3:okhttp:3.12.0

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.