├── CODEOWNERS ├── backup-lifecycle ├── gsutil-lifecycle-set.sh ├── 07-days-retention-policy.json └── 30-days-retention-policy.json ├── docs ├── admin │ ├── pypi-all.png │ ├── backup-1-task.png │ ├── backup-2-task.png │ ├── docker-hosted.png │ ├── maven-central.png │ ├── maven-public.png │ ├── pypi-hosted.png │ ├── pypi-proxied.png │ ├── proxied-blob-store.png │ ├── rut-auth-capability-1.png │ ├── rut-auth-capability-2.png │ ├── rut-auth-capability-3.png │ ├── configuring-nexus.md │ └── configuring-nexus-proxy.md └── usage │ ├── using-nexus-with-gradle.md │ ├── using-nexus-with-sbt.md │ ├── using-nexus-with-python.md │ ├── using-nexus-with-docker.md │ └── using-nexus-with-maven.md ├── kubernetes ├── nexus-secret.yaml ├── nexus-proxy-svc.yaml ├── nexus-ingress.yaml ├── nexus-statefulset.yaml └── nexus-iam-statefulset.yaml ├── cert-manager ├── issuer.yaml └── certificate.yaml ├── LICENSE └── README.md /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @travelaudience/core-services 2 | -------------------------------------------------------------------------------- /backup-lifecycle/gsutil-lifecycle-set.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | gsutil lifecycle set "${1}" "${2}" 4 | -------------------------------------------------------------------------------- /docs/admin/pypi-all.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travelaudience/kubernetes-nexus/HEAD/docs/admin/pypi-all.png -------------------------------------------------------------------------------- /docs/admin/backup-1-task.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travelaudience/kubernetes-nexus/HEAD/docs/admin/backup-1-task.png -------------------------------------------------------------------------------- /docs/admin/backup-2-task.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travelaudience/kubernetes-nexus/HEAD/docs/admin/backup-2-task.png -------------------------------------------------------------------------------- /docs/admin/docker-hosted.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travelaudience/kubernetes-nexus/HEAD/docs/admin/docker-hosted.png -------------------------------------------------------------------------------- /docs/admin/maven-central.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travelaudience/kubernetes-nexus/HEAD/docs/admin/maven-central.png -------------------------------------------------------------------------------- /docs/admin/maven-public.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travelaudience/kubernetes-nexus/HEAD/docs/admin/maven-public.png -------------------------------------------------------------------------------- /docs/admin/pypi-hosted.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travelaudience/kubernetes-nexus/HEAD/docs/admin/pypi-hosted.png -------------------------------------------------------------------------------- /docs/admin/pypi-proxied.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travelaudience/kubernetes-nexus/HEAD/docs/admin/pypi-proxied.png -------------------------------------------------------------------------------- /docs/admin/proxied-blob-store.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travelaudience/kubernetes-nexus/HEAD/docs/admin/proxied-blob-store.png -------------------------------------------------------------------------------- /docs/admin/rut-auth-capability-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travelaudience/kubernetes-nexus/HEAD/docs/admin/rut-auth-capability-1.png -------------------------------------------------------------------------------- /docs/admin/rut-auth-capability-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travelaudience/kubernetes-nexus/HEAD/docs/admin/rut-auth-capability-2.png -------------------------------------------------------------------------------- /docs/admin/rut-auth-capability-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travelaudience/kubernetes-nexus/HEAD/docs/admin/rut-auth-capability-3.png -------------------------------------------------------------------------------- /kubernetes/nexus-secret.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | data: 3 | nexus.authorization: QmFzaWMgWVdSdGFXNDZZV1J0YVc0eE1qTT0= 4 | type: Opaque 5 | kind: Secret 6 | metadata: 7 | name: nexus 8 | -------------------------------------------------------------------------------- /backup-lifecycle/07-days-retention-policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "rule": [ 3 | { 4 | "action": { 5 | "type": "Delete" 6 | }, 7 | "condition": { 8 | "age": 7 9 | } 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /backup-lifecycle/30-days-retention-policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "rule": [ 3 | { 4 | "action": { 5 | "type": "Delete" 6 | }, 7 | "condition": { 8 | "age": 30 9 | } 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /kubernetes/nexus-proxy-svc.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: nexus-proxy 5 | spec: 6 | ports: 7 | - name: nexus-proxy 8 | nodePort: 30011 9 | port: 8080 10 | protocol: TCP 11 | targetPort: 8080 12 | selector: 13 | app: nexus 14 | type: NodePort 15 | -------------------------------------------------------------------------------- /cert-manager/issuer.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: certmanager.k8s.io/v1alpha1 2 | kind: Issuer 3 | metadata: 4 | name: letsencrypt-production 5 | spec: 6 | acme: 7 | server: https://acme-v02.api.letsencrypt.org/directory 8 | email: john.doe@example.com 9 | privateKeySecretRef: 10 | name: letsencrypt-production 11 | http01: {} 12 | -------------------------------------------------------------------------------- /cert-manager/certificate.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: certmanager.k8s.io/v1alpha1 2 | kind: Certificate 3 | metadata: 4 | name: nexus-tls 5 | spec: 6 | secretName: nexus-tls 7 | issuerRef: 8 | name: letsencrypt-production 9 | kind: Issuer 10 | dnsNames: 11 | - containers.example.com 12 | - nexus.example.com 13 | acme: 14 | config: 15 | - http01: 16 | ingress: nexus 17 | domains: 18 | - containers.example.com 19 | - nexus.example.com 20 | -------------------------------------------------------------------------------- /kubernetes/nexus-ingress.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: extensions/v1beta1 2 | kind: Ingress 3 | metadata: 4 | annotations: 5 | kubernetes.io/ingress.allow-http: "true" # NOTE: Can't use 'false' due to https://github.com/jetstack/kube-lego/issues/173. 6 | kubernetes.io/ingress.class: gce 7 | kubernetes.io/ingress.global-static-ip-name: your-static-ip-name 8 | kubernetes.io/tls-acme: "true" 9 | name: nexus 10 | spec: 11 | rules: 12 | - host: containers.example.com 13 | http: 14 | paths: 15 | - backend: 16 | serviceName: nexus-proxy 17 | servicePort: 8080 18 | path: /* 19 | - host: nexus.example.com 20 | http: 21 | paths: 22 | - backend: 23 | serviceName: nexus-proxy 24 | servicePort: 8080 25 | path: /* 26 | tls: 27 | - hosts: 28 | - containers.example.com 29 | - nexus.example.com 30 | secretName: nexus-tls 31 | -------------------------------------------------------------------------------- /kubernetes/nexus-statefulset.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: StatefulSet 3 | metadata: 4 | labels: 5 | app: nexus 6 | name: nexus 7 | spec: 8 | replicas: 1 9 | serviceName: nexus 10 | selector: 11 | matchLabels: 12 | app: nexus 13 | template: 14 | metadata: 15 | labels: 16 | app: nexus 17 | spec: 18 | containers: 19 | - name: nexus 20 | image: "quay.io/travelaudience/docker-nexus:3.19.1" 21 | imagePullPolicy: Always 22 | env: 23 | - name: INSTALL4J_ADD_VM_PARAMS 24 | value: "-Xms1200M -Xmx1200M -XX:MaxDirectMemorySize=2G -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap" 25 | resources: 26 | requests: 27 | cpu: 250m 28 | # Based on https://support.sonatype.com/hc/en-us/articles/115006448847#mem 29 | # and https://twitter.com/analytically/status/894592422382063616: 30 | # Xms == Xmx 31 | # Xmx <= 4G 32 | # MaxDirectMemory >= 2G 33 | # Xmx + MaxDirectMemory <= RAM * 2/3 (hence the request for 4800Mi) 34 | # MaxRAMFraction=1 is not being set as it would allow the heap 35 | # to use all the available memory. 36 | memory: 4800Mi 37 | ports: 38 | - containerPort: 5003 39 | name: nexus-docker-g 40 | - containerPort: 8081 41 | name: nexus-http 42 | volumeMounts: 43 | - mountPath: /nexus-data 44 | name: nexus-data 45 | - mountPath: /nexus-data/backup 46 | name: nexus-data-backup 47 | - name: nexus-proxy 48 | image: "quay.io/travelaudience/docker-nexus-proxy:2.5.0" 49 | imagePullPolicy: Always 50 | env: 51 | - name: ALLOWED_USER_AGENTS_ON_ROOT_REGEX 52 | value: "GoogleHC" 53 | - name: CLOUD_IAM_AUTH_ENABLED 54 | value: "false" 55 | - name: BIND_PORT 56 | value: "8080" 57 | - name: ENFORCE_HTTPS 58 | value: "false" 59 | - name: NEXUS_DOCKER_HOST 60 | value: "containers.example.com" 61 | - name: NEXUS_HTTP_HOST 62 | value: "nexus.example.com" 63 | - name: UPSTREAM_DOCKER_PORT 64 | value: "5003" 65 | - name: UPSTREAM_HTTP_PORT 66 | value: "8081" 67 | - name: UPSTREAM_HOST 68 | value: "localhost" 69 | ports: 70 | - containerPort: 8080 71 | name: nexus-proxy 72 | - name: nexus-backup 73 | image: "quay.io/travelaudience/docker-nexus-backup:1.5.0" 74 | imagePullPolicy: Always 75 | env: 76 | - name: NEXUS_AUTHORIZATION 77 | valueFrom: 78 | secretKeyRef: 79 | key: nexus.authorization 80 | name: nexus 81 | - name: NEXUS_BACKUP_DIRECTORY 82 | value: /nexus-data/backup 83 | - name: NEXUS_DATA_DIRECTORY 84 | value: /nexus-data 85 | - name: NEXUS_LOCAL_HOST_PORT 86 | value: "localhost:8081" 87 | - name: OFFLINE_REPOS 88 | value: "maven-central maven-public maven-releases maven-snapshots" 89 | - name: TARGET_BUCKET 90 | value: "gs://nexus-backup" 91 | - name: GRACE_PERIOD 92 | value: "60" 93 | - name: TRIGGER_FILE 94 | value: .backup 95 | volumeMounts: 96 | - mountPath: /nexus-data 97 | name: nexus-data 98 | - mountPath: /nexus-data/backup 99 | name: nexus-data-backup 100 | terminationGracePeriodSeconds: 10 101 | volumeClaimTemplates: 102 | - metadata: 103 | name: nexus-data 104 | spec: 105 | accessModes: 106 | - ReadWriteOnce 107 | resources: 108 | requests: 109 | storage: 1024Gi 110 | storageClassName: standard 111 | - metadata: 112 | name: nexus-data-backup 113 | spec: 114 | accessModes: 115 | - ReadWriteOnce 116 | resources: 117 | requests: 118 | storage: 32Gi 119 | storageClassName: standard 120 | -------------------------------------------------------------------------------- /docs/usage/using-nexus-with-gradle.md: -------------------------------------------------------------------------------- 1 | # Using Nexus with Gradle 2 | 3 | Configuring Gradle to download artifacts from Nexus instead of Maven Central 4 | will, most of the time, not only speed up build processes by 5 | caching commonly used dependencies but also help ensuring reproducible builds, 6 | since one only depends on their Nexus availability and not the public repositories. 7 | 8 | Gradle can also be configured to upload artifacts to Nexus, enabling the management 9 | of artifacts private to an organization. 10 | 11 | ## Downloading artifacts from Nexus 12 | 13 | In order to enable Gradle to to download artifacts from Nexus, one is to add the 14 | following to `build.gradle`: 15 | 16 | ```groovy 17 | repositories { 18 | maven { 19 | url "${nexusUrl}/repository/maven-public/" 20 | } 21 | } 22 | ``` 23 | 24 | Also, one may often find `mavenCentral()` statements scattered around existing 25 | `build.gradle` files. As a rule of the thumb, one should replace it with something 26 | like: 27 | 28 | ```groovy 29 | maven { 30 | url "${nexusUrl}/repository/maven-public/" 31 | } 32 | ``` 33 | 34 | Finally, one must set `nexusUrl` either in the project-local `gradle.properties` 35 | file or in the global `~/.gradle/gradle.properties` file: 36 | 37 | ``` 38 | nexusUrl=https://nexus.example.com 39 | ``` 40 | 41 | ## Uploading artifacts to Nexus 42 | 43 | In order to upload private artifacts to Nexus, one must use the `maven-publish` 44 | plugin and configure the `publishing` extension as follows: 45 | 46 | ```groovy 47 | apply plugin: 'maven-publish' 48 | 49 | publishing { 50 | publications { 51 | maven(MavenPublication) { 52 | artifactId '' 53 | from components.java 54 | groupId '' 55 | version project.version 56 | } 57 | } 58 | repositories { 59 | maven { 60 | credentials { 61 | username nexusUsername 62 | password nexusPassword 63 | } 64 | if (!project.version.endsWith('-SNAPSHOT')) { 65 | url "${nexusUrl}/repository/maven-releases" 66 | } else { 67 | url "${nexusUrl}/repository/maven-snapshots" 68 | } 69 | } 70 | } 71 | } 72 | ``` 73 | 74 | Then, to upload built artifacts to Nexus, one is to run: 75 | 76 | ```shell 77 | $ gradle publish 78 | ``` 79 | 80 | **Note**: one must define their Nexus credentials in `gradle.properties`: 81 | 82 | ``` 83 | nexusUrl=https://nexus.example.com 84 | nexusUsername=john.doe@example.com 85 | nexusPassword=s4f3#p4ssw0rd! 86 | ``` 87 | 88 | **Attention:** If GCP IAM authentication is enabled, [username and password 89 | **are not** the GCP organization credentials](../admin/configuring-nexus-proxy.md/#usage). 90 | 91 | ### Encrypting credentials 92 | 93 | **Note**: Encrypting credentials is a security best-pratice. 94 | 95 | Although Gradle doesn't provide a built-in way to encrypt credentials, there's 96 | a [Gradle plugin](https://plugins.gradle.org/plugin/nu.studer.credentials) 97 | which may come in handy. To use it, one must add the following to `build.gradle`: 98 | 99 | ```groovy 100 | plugins { 101 | id 'nu.studer.credentials' version '1.0.3' 102 | } 103 | ``` 104 | 105 | Then, add their Nexus password to the plugin's "keychain": 106 | 107 | ```shell 108 | ./gradlew addCredentials -PcredentialsKey="encryptedNexusPassword" -PcredentialsValue="" 109 | ``` 110 | 111 | and adjust `build.gradle` accordingly: 112 | 113 | ```groovy 114 | def nexusPassword = credentials.encryptedNexusPassword 115 | 116 | publishing { 117 | publications { 118 | maven(MavenPublication) { 119 | artifactId '' 120 | from components.java 121 | groupId '' 122 | version project.version 123 | } 124 | } 125 | repositories { 126 | maven { 127 | credentials { 128 | username nexusUsername 129 | password nexusPassword 130 | } 131 | if (!project.version.endsWith('-SNAPSHOT')) { 132 | url "${nexusUrl}/repository/maven-releases" 133 | } else { 134 | url "${nexusUrl}/repository/maven-snapshots" 135 | } 136 | } 137 | } 138 | } 139 | ``` 140 | 141 | **Attention:** If GCP IAM authentication is enabled, [username and password 142 | **are not** the GCP organization credentials](../admin/configuring-nexus-proxy.md/#usage). -------------------------------------------------------------------------------- /docs/usage/using-nexus-with-sbt.md: -------------------------------------------------------------------------------- 1 | # Using Nexus with sbt 2 | 3 | Configuring `sbt` to download artifacts from Nexus instead of Maven Central 4 | will, most of the time, not only speed up build processes by 5 | caching commonly used dependencies but also help ensuring reproducible builds, 6 | since one only depends on their Nexus availability and not the public repositories. 7 | 8 | `sbt` can also be configured to upload artifacts to Nexus, enabling the management 9 | of artifacts private to an organization. 10 | 11 | ## Providing Credentials 12 | The best way is to store and load the credentials from `~/.ivy2/.credentials`: 13 | 14 | ```scala 15 | credentials += Credentials(Path.userHome / ".ivy2" / ".credentials") 16 | ``` 17 | 18 | `~/.ivy2/.credentials` should look like follows: 19 | 20 | ``` 21 | realm=nexus-proxy 22 | host=nexus.example.com 23 | user= 24 | password= 25 | ``` 26 | 27 | with sbt 1.x one can also load the credentials as a global plugin. For that store your nexus credentials 28 | in a file `~/.sbt/1.0/plugins/nexus-credentials.sbt`. The contents look like: 29 | 30 | ``` 31 | credentials += Credentials( 32 | realm = "nexus-proxy", 33 | host = "nexus.example.com", 34 | userName = "", 35 | passwd = "" 36 | ) 37 | ``` 38 | 39 | To check if its working, run: 40 | `sbt "show allCredentials" ` 41 | 42 | **Attention:** If GCP IAM authentication is enabled, [username and password 43 | **are not** the GCP organization credentials](../admin/configuring-nexus-proxy.md/#usage). 44 | 45 | ### Encrypting credentials 46 | **Note**: Encrypting credentials is a security best-pratice. 47 | 48 | Unfortunately, unlike Maven or Gradle, `sbt` doesn't seem to provide a built-in 49 | or community-provided mechanism to encrypt credentials. 50 | 51 | ## Downloading artifacts from Nexus 52 | 53 | In order to enable `sbt` to download artifacts from Nexus, one is to add the 54 | following to `build.sbt`: 55 | 56 | ```scala 57 | // This will use Nexus as a resolver. 58 | resolvers += "My Nexus" at "https://nexus.example.com/repository/maven-public/" 59 | // This will prevent access to Maven Central. 60 | externalResolvers := Resolver.withDefaultResolvers(resolvers.value, mavenCentral = false) 61 | ``` 62 | if you are using sbt 1.x, you need to use `combineDefaultResolvers` method instead: 63 | 64 | ``` 65 | externalResolvers := Resolver.combineDefaultResolvers(resolvers.value.toVector, false) 66 | ``` 67 | 68 | 69 | (If not using coursier as dependency resolver) one can check if their configuration is 70 | working by deleting the `~/.ivy2/cache` directory and running: 71 | 72 | ```shell 73 | $ sbt run 74 | (...) 75 | [info] downloading https://nexus.example.com/repository/maven-public/org/scala-lang/scala-library/2.12.1/scala-library-2.12.1.jar ... 76 | [info] [SUCCESSFUL ] org.scala-lang#scala-library;2.12.1!scala-library.jar (776ms) 77 | [info] downloading https://nexus.example.com/repository/maven-public/org/scalatest/scalatest_2.12/3.0.1/scalatest_2.12-3.0.1.jar ... 78 | [info] [SUCCESSFUL ] org.scalatest#scalatest_2.12;3.0.1!scalatest_2.12.jar(bundle) (889ms) 79 | (...) 80 | ``` 81 | 82 | If you are using couriser, check [here](https://get-coursier.io/docs/cache) for locating 83 | the right cache for your environment. 84 | 85 | ## Uploading artifacts to Nexus 86 | 87 | In order to enable `sbt` to upload build artifacts to Nexus, one must configure 88 | the `publish` task as follows: 89 | 90 | ```scala 91 | publishTo := { 92 | val nexus = "https://nexus.example.com" 93 | 94 | if (isSnapshot.value) 95 | Some("snapshots" at nexus + "/repository/maven-snapshots") 96 | else 97 | Some("releases" at nexus + "/repository/maven-releases") 98 | } 99 | ``` 100 | 101 | For sbt 1.x one should disable gigahorse setting because of [this issue](https://github.com/sbt/sbt/issues/3570) with GCloud hosting Nexus 102 | ``` 103 | updateOptions := updateOptions.value.withGigahorse(false), 104 | ``` 105 | 106 | A similar issue happens when assemblying a fat jar so one should not use: 107 | ``` 108 | addArtifact(artifact in (Compile, assembly), assembly) 109 | ``` 110 | 111 | Now, running the `publish` task will look like follows: 112 | 113 | ```shell 114 | $ sbt publish 115 | (...) 116 | [info] published dojo-nexus-sbt_2.12 to https://nexus.example.com/repository/maven-snapshots/com/example/dojo-nexus-sbt_2.12/1.0.0-SNAPSHOT/dojo-nexus-sbt_2.12-1.0.0-SNAPSHOT.pom 117 | [info] published dojo-nexus-sbt_2.12 to https://nexus.example.com/repository/maven-snapshots/com/example/dojo-nexus-sbt_2.12/1.0.0-SNAPSHOT/dojo-nexus-sbt_2.12-1.0.0-SNAPSHOT.jar 118 | [info] published dojo-nexus-sbt_2.12 to https://nexus.example.com/repository/maven-snapshots/com/example/dojo-nexus-sbt_2.12/1.0.0-SNAPSHOT/dojo-nexus-sbt_2.12-1.0.0-SNAPSHOT-sources.jar 119 | [info] published dojo-nexus-sbt_2.12 to https://nexus.example.com/repository/maven-snapshots/com/example/dojo-nexus-sbt_2.12/1.0.0-SNAPSHOT/dojo-nexus-sbt_2.12-1.0.0-SNAPSHOT-javadoc.jar 120 | (...) 121 | ``` 122 | -------------------------------------------------------------------------------- /docs/usage/using-nexus-with-python.md: -------------------------------------------------------------------------------- 1 | # Using Nexus with Python 2 | 3 | Configuring [`pip`](https://pip.pypa.io) to download artifacts from Nexus instead 4 | of Pypi will, most of the time, not only speed up build processes by 5 | caching commonly used dependencies but also help ensuring reproducible builds, 6 | since one only depends on their Nexus availability and not the public repositories. 7 | 8 | `pip` can also be configured to upload artifacts to Nexus, enabling the management 9 | of artifacts private to an organization. 10 | 11 | ## Downloading packages from Nexus 12 | 13 | In order to enable `pip` to download packages from Nexus, it is necessary to 14 | edit `pip` configuration file. This can be done on a per-user, per-_virtualenv_ 15 | or system-wide basis. 16 | For the remainder of this section we will assume a _per-user_ configuration. 17 | To use a different configuration, one should refer to 18 | [`pip`'s documentation](https://pip.pypa.io/en/stable/user_guide/#config-file). 19 | 20 | The per-user configuration file is located in different places on different OS'es: 21 | 22 | * On Mac OS: `${HOME}/Library/Application Support/pip/pip.conf`. 23 | * On Linux: `${HOME}/.config/pip/pip.conf`. 24 | * On Windows: `%APPDATA%\pip\pip.ini`. 25 | 26 | Edit the corresponding file as follows: 27 | 28 | ```ini 29 | [global] 30 | index = https://nexus.example.com/repository/pypi-all/pypi 31 | index-url = https://nexus.example.com/repository/pypi-all/simple 32 | no-cache-dir = false 33 | ``` 34 | 35 | This will instruct `pip` to search for and install packages from the `pypi-all` 36 | group, previously configured in Nexus. 37 | One can check if their configuration is correct by running: 38 | 39 | ```shell 40 | $ pip2 search -vvv polyline 41 | ``` 42 | 43 | One should see feedback like: 44 | 45 | ``` 46 | Starting new HTTPS connection (1): nexus.example.com 47 | "POST /repository/pypi-all/pypi HTTP/1.1" 200 2742 48 | cGPolyEncode (0.1.1) - Google Maps Polyline encoding (C++ extension) 49 | GPolyEncode (0.1.1) - Google Maps Polyline encoding (pure Python) 50 | gpolyline (0.0.3) - Converts a series of latitude/longitude points to an encoded string for use with Google Maps 51 | polyline (1.3.2) - A Python implementation of Google's Encoded Polyline Algorithm Format. 52 | pypolyline (0.1.11) - Fast Google Polyline encoding and decoding using Rust FFI 53 | SkyLinesPolyEncode (0.1.3) - SkyLines Polyline encoding (C++ extension) 54 | time_aware_polyline (0.1.2) - Time aware encoded polyline for geospatial data 55 | ``` 56 | 57 | There may be some scenarios in which the Nexus is deployed behind a proxy which requires authentication. In these scenarios, the only way to preemptively convey authentication information is by specifying the credentials in the URL: 58 | 59 | ```ini 60 | [global] 61 | index = https://username:password@nexus.example.com/repository/pypi-all/pypi 62 | index-url = https://username:password@nexus.example.com/repository/pypi-all/simple 63 | no-cache-dir = false 64 | ``` 65 | 66 | **Attention:** If GCP IAM authentication is enabled, [username and password 67 | **are not** the GCP organization credentials](../admin/configuring-nexus-proxy.md/#usage). 68 | 69 | From this moment on, it is of course recommended to keep `pip.conf` as safe as possible. 70 | On Unix systems one should `chmod 600` the configuration file. Also, one is to make sure 71 | to use `pip`'s verbose mode with caution, as credentials may end up in `stdout`/`stderr` 72 | or in some log file. 73 | 74 | ## Uploading packages to Nexus 75 | 76 | Unlike other tools, such as Maven or Docker, package uploading in Python is handled 77 | not by the `pip` tool, the tool we adopted to manage Python depdencies, but by a different tool. 78 | Currently, [`twine`](https://github.com/pypa/twine) is the [recommended tool](https://github.com/pypa/twine#why-should-i-use-this). 79 | We recommend that one refers to [Packaging and Distributing Projects](https://packaging.python.org/tutorials/distributing-packages/#initial-files) for detailed steps on how a project structure should look like. 80 | 81 | To upload packages to Nexus, one must include the following in `${HOME}/.pypirc` (create it it if necessary): 82 | 83 | ```ini 84 | [distutils] 85 | index-servers = 86 | nexus 87 | 88 | [nexus] 89 | repository = https://nexus.example.com/repository/pypi-hosted/ 90 | username = the-username 91 | password = the-pasword 92 | ``` 93 | 94 | **Attention:** If GCP IAM authentication is enabled, [username and password 95 | **are not** the GCP organization credentials](../admin/configuring-nexus-proxy.md/#usage). 96 | 97 | Then, prepare the package for binary distribution: 98 | 99 | ```shell 100 | $ python setup.py sdist bdist_wheel 101 | ``` 102 | 103 | The above will generate a `dist/` directory in the project's root containing all 104 | the necessary artifacts for uploading. One is to upload the same artifacts to 105 | Nexus using `twine`: 106 | 107 | ```shell 108 | $ twine upload dist/* -r nexus 109 | ``` 110 | 111 | Once the package is uploaded, it can be downloaded from other machines using `pip` 112 | for as long as it's configured as instructed above. 113 | -------------------------------------------------------------------------------- /kubernetes/nexus-iam-statefulset.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: StatefulSet 3 | metadata: 4 | labels: 5 | app: nexus 6 | name: nexus 7 | spec: 8 | replicas: 1 9 | serviceName: nexus 10 | selector: 11 | matchLabels: 12 | app: nexus 13 | template: 14 | metadata: 15 | labels: 16 | app: nexus 17 | spec: 18 | containers: 19 | - name: nexus 20 | image: "quay.io/travelaudience/docker-nexus:3.19.1" 21 | imagePullPolicy: Always 22 | env: 23 | - name: INSTALL4J_ADD_VM_PARAMS 24 | value: "-Xms1200M -Xmx1200M -XX:MaxDirectMemorySize=2G -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap" 25 | resources: 26 | requests: 27 | cpu: 250m 28 | # Based on https://support.sonatype.com/hc/en-us/articles/115006448847#mem 29 | # and https://twitter.com/analytically/status/894592422382063616: 30 | # Xms == Xmx 31 | # Xmx <= 4G 32 | # MaxDirectMemory >= 2G 33 | # Xmx + MaxDirectMemory <= RAM * 2/3 (hence the request for 4800Mi) 34 | # MaxRAMFraction=1 is not being set as it would allow the heap 35 | # to use all the available memory. 36 | memory: 4800Mi 37 | ports: 38 | - containerPort: 5003 39 | name: nexus-docker-g 40 | - containerPort: 8081 41 | name: nexus-http 42 | volumeMounts: 43 | - mountPath: /nexus-data 44 | name: nexus-data 45 | - mountPath: /nexus-data/backup 46 | name: nexus-data-backup 47 | - name: nexus-proxy 48 | image: "quay.io/travelaudience/docker-nexus-proxy:2.5.0" 49 | imagePullPolicy: Always 50 | env: 51 | - name: ALLOWED_USER_AGENTS_ON_ROOT_REGEX 52 | value: "GoogleHC" 53 | - name: CLOUD_IAM_AUTH_ENABLED 54 | value: "true" 55 | - name: JWT_REQUIRES_MEMBERSHIP_VERIFICATION 56 | value: "false" 57 | - name: BIND_PORT 58 | value: "8080" 59 | - name: ENFORCE_HTTPS 60 | value: "true" 61 | - name: NEXUS_DOCKER_HOST 62 | value: "containers.example.com" 63 | - name: NEXUS_HTTP_HOST 64 | value: "nexus.example.com" 65 | - name: NEXUS_RUT_HEADER 66 | value: "X-Forwarded-User" 67 | - name: UPSTREAM_DOCKER_PORT 68 | value: "5003" 69 | - name: UPSTREAM_HTTP_PORT 70 | value: "8081" 71 | - name: UPSTREAM_HOST 72 | value: "localhost" 73 | - name: CLIENT_ID 74 | value: "REPLACE_ME" 75 | - name: CLIENT_SECRET 76 | value: "REPLACE_ME" 77 | - name: ORGANIZATION_ID 78 | value: "REPLACE_ME" 79 | - name: REDIRECT_URL 80 | value: "https://nexus.example.com/oauth/callback" 81 | - name: KEYSTORE_PASS 82 | valueFrom: 83 | secretKeyRef: 84 | name: nexus-proxy-ks 85 | key: password 86 | - name: KEYSTORE_PATH 87 | value: "/nexus-proxy-ks/keystore" 88 | - name: AUTH_CACHE_TTL 89 | value: "60000" 90 | - name: SESSION_TTL 91 | value: "86400000" 92 | ports: 93 | - containerPort: 8080 94 | name: nexus-proxy 95 | volumeMounts: 96 | - mountPath: /nexus-proxy-ks 97 | name: nexus-proxy-ks 98 | readOnly: true 99 | - name: nexus-backup 100 | image: "quay.io/travelaudience/docker-nexus-backup:1.5.0" 101 | imagePullPolicy: Always 102 | env: 103 | - name: NEXUS_AUTHORIZATION 104 | valueFrom: 105 | secretKeyRef: 106 | key: nexus.authorization 107 | name: nexus 108 | - name: NEXUS_BACKUP_DIRECTORY 109 | value: /nexus-data/backup 110 | - name: NEXUS_DATA_DIRECTORY 111 | value: /nexus-data 112 | - name: NEXUS_LOCAL_HOST_PORT 113 | value: "localhost:8081" 114 | - name: OFFLINE_REPOS 115 | value: "maven-central maven-public maven-releases maven-snapshots" 116 | - name: TARGET_BUCKET 117 | value: "gs://nexus-backup" 118 | - name: GRACE_PERIOD 119 | value: "60" 120 | - name: TRIGGER_FILE 121 | value: .backup 122 | volumeMounts: 123 | - mountPath: /nexus-data 124 | name: nexus-data 125 | - mountPath: /nexus-data/backup 126 | name: nexus-data-backup 127 | terminationGracePeriodSeconds: 10 128 | volumes: 129 | - name: nexus-proxy-ks 130 | secret: 131 | secretName: nexus-proxy-ks 132 | volumeClaimTemplates: 133 | - metadata: 134 | name: nexus-data 135 | spec: 136 | accessModes: 137 | - ReadWriteOnce 138 | resources: 139 | requests: 140 | storage: 1024Gi 141 | storageClassName: standard 142 | - metadata: 143 | name: nexus-data-backup 144 | spec: 145 | accessModes: 146 | - ReadWriteOnce 147 | resources: 148 | requests: 149 | storage: 32Gi 150 | storageClassName: standard 151 | -------------------------------------------------------------------------------- /docs/usage/using-nexus-with-docker.md: -------------------------------------------------------------------------------- 1 | # Using Nexus with Docker 2 | 3 | Nexus includes a Docker registry where private images may be hosted so that they 4 | can be shared across teams. To configure Docker, one must first login using one's 5 | Nexus credentials: 6 | 7 | ``` 8 | $ docker login containers.example.com 9 | ``` 10 | 11 | **ATTENTION:** If GCP IAM authentication is enabled, [username and password 12 | **are not** the GCP organization credentials](../admin/configuring-nexus-proxy.md/#usage). 13 | 14 | ## Publishing a Docker image 15 | 16 | To publish a Docker image to the Nexus Docker registry one must tag the image 17 | as follows: 18 | 19 | ``` 20 | containers.example.com//: 21 | ``` 22 | 23 | After the image is built and tagged, one must run the following to publish it to 24 | the Nexus registry: 25 | 26 | ``` 27 | $ docker push containers.example.com//: 28 | ``` 29 | 30 | Here's a concrete example of how to build and publish a private container image: 31 | 32 | ``` 33 | $ docker build -t containers.example.com/devops/docker-nexus:3.3.2 . 34 | (...) 35 | Successfully built 5f1d02765ee9 36 | Successfully tagged containers.example.com/devops/docker-nexus:3.3.2 37 | $ docker push containers.example.com/devops/docker-nexus:3.3.2 38 | The push refers to a repository [containers.example.com/devops/docker-nexus] 39 | (...) 40 | 3.3.2: digest: sha256:20878f8dda88b4ca1207d830b5445264847ccc234ded8febebb8f9e6d6483115 size: 2817 41 | ``` 42 | 43 | ## Pulling a Docker image 44 | 45 | Pulling a Docker image from the Nexus Docker registry is as simple as running: 46 | 47 | ``` 48 | $ docker pull containers.example.com//: 49 | ``` 50 | 51 | Here's a concrete example of how to pull a private container image: 52 | 53 | ``` 54 | $ docker pull containers.example.com/devops/docker-nexus:3.3.2 55 | 3.3.1: Pulling from devops/docker-nexus 56 | (...) 57 | Digest: sha256:20878f8dda88b4ca1207d830b5445264847ccc234ded8febebb8f9e6d6483115 58 | Status: Downloaded newer image for containers.example.com/devops/docker-nexus:3.3.2 59 | ``` 60 | 61 | The image has been pulled successfully and is now available locally. 62 | 63 | ## Pulling a Docker image from within Kubernetes 64 | 65 | For Kubernetes to be able to pull a private container image, a secret containing 66 | the necessary Docker configuration must be created. Below one can see 2 different ways of doing the first part which is getting the **auth** field. 67 | 68 | ### Linux 69 | 70 | ```shell 71 | $ cat ~/.docker/config.json 72 | ``` 73 | 74 | The result should look as below: 75 | 76 | ```json 77 | { 78 | "auths": { 79 | "containers.example.com": { 80 | "auth": "YWRtaW46YWRtaW4xMjM=" 81 | } 82 | } 83 | } 84 | ``` 85 | 86 | ### OSX 87 | 88 | Since OSX uses keychain one cannot use the info in the `config.json` file. 89 | Instead the **auth** content can be generated with the command below: 90 | ```bash 91 | echo -n "username:password" | base64 92 | ``` 93 | 94 | Example: 95 | ```bash 96 | echo -n "admin:admin123" | base64 97 | YWRtaW46YWRtaW4xMjM= 98 | ``` 99 | 100 | ## Using secret type `kubernetes.io/dockercfg` 101 | 102 | One is to copy the base-64 encoded value of key `auth` and run: 103 | 104 | ```bash 105 | $ cat << EOF | base64 106 | { 107 | "auths": { 108 | "containers.example.com": { 109 | "email": "john.doe@example.com", 110 | "auth": "YWRtaW46YWRtaW4xMjM=" 111 | } 112 | } 113 | } 114 | EOF 115 | ewogICJjb250YWluZXJzLmV4YW1wbGUuY29tIjogewogICAgInVzZXJuYW1lIjogInVzZXJuYW1lIiwKICAgICJwYXNzd29yZCI6ICJwYXNzd29yZCIsCiAgICAiZW1haWwiOiAiam9obi5kb2VAZXhhbXBsZS5jb20iLAogICAgImF1dGgiOiAiZFhObGNtNWhiV1U2Y0dGemMzZHZjbVE9IgogIH0KfQo= 116 | ``` 117 | 118 | **ATTENTION**: one must replace the keys and values above according to one's 119 | environment, i.e. replace `containers.example.com` with the right hostname. 120 | 121 | Now, one is to copy the resulting base-64 encoded value and create the following 122 | Kubernetes secret descriptor: 123 | 124 | ```yaml 125 | apiVersion: v1 126 | data: 127 | .dockercfg: ewogICJjb250YWluZXJzLmV4YW1wbGUuY29tIjogewogICAgInVzZXJuYW1lIjogInVzZXJuYW1lIiwKICAgICJwYXNzd29yZCI6ICJwYXNzd29yZCIsCiAgICAiZW1haWwiOiAiam9obi5kb2VAZXhhbXBsZS5jb20iLAogICAgImF1dGgiOiAiZFhObGNtNWhiV1U2Y0dGemMzZHZjbVE9IgogIH0KfQo= 128 | kind: Secret 129 | metadata: 130 | name: nexus-docker 131 | type: kubernetes.io/dockercfg 132 | ``` 133 | 134 | Store the secret: 135 | 136 | ```bash 137 | $ kubectl create -f nexus-docker.yaml 138 | secret "nexus-docker" created 139 | ``` 140 | 141 | Now, whenever one need to use a private image in a pod, one just need to 142 | reference the newly created secret: 143 | 144 | ```yaml 145 | apiVersion: v1 146 | kind: Pod 147 | metadata: 148 | name: my-pod 149 | spec: 150 | containers: 151 | - 152 | image: containers.example.com/devops/docker-nexus:3.3.2 153 | name: my-container 154 | imagePullSecrets: 155 | - 156 | name: nexus-docker 157 | ``` 158 | 159 | ## Using secret type `kubernetes.io/dockerconfigjson` 160 | 161 | One is to copy the base-64 encoded value of key `auth` and run: 162 | 163 | ```bash 164 | $ cat << EOF | base64 165 | { 166 | "auths": { 167 | "containers.example.com": { 168 | "email": "john.doe@example.com", 169 | "auth": "YWRtaW46YWRtaW4xMjM=" 170 | } 171 | } 172 | } 173 | EOF 174 | ewogICJhdXRocyI6IHsKICAgICJjb250YWluZXJzLmV4YW1wbGUuY29tIjogewogICAgICAiZW1haWwiOiAiam9obi5kb2VAZXhhbXBsZS5jb20iLAogICAgICAiYXV0aCI6ICJZV1J0YVc0NllXUnRhVzR4TWpNPSIKICAgIH0KICB9Cn0K 175 | ``` 176 | 177 | **ATTENTION**: one must replace the keys and values above according to one's 178 | environment, i.e. replace `containers.example.com` with the right hostname. 179 | 180 | Now, one is to copy the resulting base-64 encoded value and create the following 181 | Kubernetes secret descriptor: 182 | 183 | ```yaml 184 | apiVersion: v1 185 | data: 186 | .dockerconfigjson: ewogICJhdXRocyI6IHsKICAgICJjb250YWluZXJzLmV4YW1wbGUuY29tIjogewogICAgICAiZW1haWwiOiAiam9obi5kb2VAZXhhbXBsZS5jb20iLAogICAgICAiYXV0aCI6ICJZV1J0YVc0NllXUnRhVzR4TWpNPSIKICAgIH0KICB9Cn0K 187 | kind: Secret 188 | metadata: 189 | name: nexus-docker 190 | type: kubernetes.io/dockerconfigjson 191 | ``` 192 | 193 | Store the secret: 194 | 195 | ```bash 196 | $ kubectl create -f nexus-docker.yaml 197 | secret "nexus-docker" created 198 | ``` 199 | 200 | Now, whenever one need to use a private image in a pod, one just need to 201 | reference the newly created secret: 202 | 203 | ```yaml 204 | apiVersion: v1 205 | kind: Pod 206 | metadata: 207 | name: my-pod 208 | spec: 209 | containers: 210 | - 211 | image: containers.example.com/devops/docker-nexus:3.3.2 212 | name: my-container 213 | imagePullSecrets: 214 | - 215 | name: nexus-docker 216 | ``` 217 | -------------------------------------------------------------------------------- /docs/admin/configuring-nexus.md: -------------------------------------------------------------------------------- 1 | # Configuring Nexus 2 | 3 | ## Table of Contents 4 | 5 | * [Reset administrative user](#change-credentials) 6 | * [Create a blob store to host proxied artifacts](#create-proxy-repo) 7 | * [Configure `maven-central` proxy to use the `proxied` blob store](#maven-central-proxy) 8 | * [Configure the `docker-hosted` repository](#docker-hosted) 9 | * [Configure the `pypi-all` repository group](#pypi-all) 10 | * [Configure backup tasks and create backup scripts](#configure-backup) 11 | 12 | 13 | 14 | ## Reset administrative user 15 | 16 | One is to log-in as `admin` (the default password is `admin123`) and head over 17 | to _Administration/Security/Users_. 18 | Click the `admin` user and change its password by pointing to 19 | _More > Change password_. Make sure to change the email address as well. 20 | 21 | 22 | 23 | ## Create a blob store to host proxied artifacts 24 | 25 | Nexus comes pre-configured with a `default` blob store which is used by all 26 | repositories. Since this blob store is backed-up periodically, it is 27 | recommended to create a new blob store to host proxied/cached artifacts that do 28 | not require backup (e.g., those coming from Maven Central). 29 | 30 | In order to do so, one is to head over to _Administration/Blob Stores_, click 31 | _Create blob store_ and configure the new blob store as follows: 32 | 33 | ![proxied-blob-store](proxied-blob-store.png) 34 | 35 | Finally, one is to click _Create blob store_ to finish the process. 36 | 37 | 38 | 39 | ## Configure `maven-central` proxy to use the `proxied` blob store 40 | 41 | Once the `proxied` blob store is created, one must configure the `maven-central` 42 | proxy to use the new blob store. Unfortunately it is not possible to change the 43 | blob store associated with an already existing repository, so one must delete 44 | the `maven-central` repository and re-create it. 45 | 46 | In order to do so, one is to head over to _Administration/Repositories_, 47 | click _Create repository_, choose the `maven2 (proxy)` recipe and configure it 48 | as follows: 49 | 50 | ![maven-central](maven-central.png) 51 | 52 | One is to make sure to choose `proxied` as the underlying blob store. 53 | 54 | After re-creating the `maven-central` repository, it is necessary to edit the 55 | `maven-public` group. In order to do so, one is to head over to `maven-public` 56 | and add `maven-central` to the list of _Member repositories_ as follows: 57 | 58 | ![maven-public](maven-public.png) 59 | 60 | 61 | 62 | ## Configure the `docker-hosted` repository 63 | 64 | For using Nexus as a Docker registry, an hosted repository must be created. 65 | In order to do so, one is to head over to _Administration/Repositories_, click 66 | _Create repository_, choose the `docker (hosted)` recipe and configure it 67 | as follows: 68 | 69 | ![docker-hosted](docker-hosted.png) 70 | 71 | One is to make sure to choose `5003` as the port for the HTTP connector and 72 | `default` as the underlying blob store. 73 | Finally, one is to click _Create repository_ to finish the process. 74 | 75 | 76 | 77 | ## Configure the `pypi-all` repository group 78 | 79 | For Nexus to act as a repository for Python software, it is necessary to 80 | create a `pypi-all` virtual repository that will group two other repositories: 81 | * `pypi-proxied` repository, which will proxy packages from 82 | [PyPI](https://pypi.python.org/pypi), and 83 | * `pypi-hosted` repository, which will host private (our own) packages. 84 | 85 | ### Configuring `pypi-proxied` 86 | 87 | One is to head over to _Administration/Repositories_, click _Create repository_, 88 | choose the `pypi (proxy)` recipe and configure it as follows: 89 | 90 | ![pypi-proxied](pypi-proxied.png) 91 | 92 | One is to make sure to choose `proxied` as the underlying blob store. 93 | Finally, one is to click _Create repository_ to finish the process. 94 | 95 | ### Configuring `pypi-hosted` 96 | 97 | One is to head over to _Administration/Repositories_, click _Create repository_, 98 | choose the `pypi (hosted)` recipe and configure it as follows: 99 | 100 | ![pypi-hosted](pypi-hosted.png) 101 | 102 | One is to make sure to choose `default` as the underlying blob store. 103 | Finally, one is to click _Create repository_ to finish the process. 104 | 105 | ### Configuring `pypi-all` 106 | 107 | One is to head over to _Administration/Repositories_, click _Create repository_, 108 | choose the `pypi (group)` recipe and configure it as follows: 109 | 110 | ![pypi-all](pypi-all.png) 111 | 112 | One is to make sure to choose `default` as the underlying blob store. 113 | Finally, one is to click _Create repository_ to finish the process. 114 | 115 | 116 | 117 | ## Configure backup tasks and create backup scripts 118 | 119 | For the implemented backup process to work as expected, one must create a couple 120 | of periodic tasks. 121 | 122 | **Attention**: Nexus provides default intervals, e.g. daily, but also supports 123 | [CRON notation](https://en.wikipedia.org/wiki/Cron) for advanced configuration. 124 | While this tool tries to amenize any misconfigurations, __be warned that erroneous 125 | cron expressions may lead to corrupt backups or even no backups at all__. 126 | 127 | >One clear example of this was one tester who wanted thirty (30) minute intervals 128 | between backups, defined the cron expression as `* */30 * * *` instead of 129 | `0 0/30 * * *`. This resulted in a backup process being queued every second, 130 | instead. 131 | For more details check [Configuring and Executing Tasks](https://help.sonatype.com/display/HSC/Configuration+-+NXRM+3#Configuration-NXRM3-ConfiguringandExecutingTasks). 132 | 133 | The first task, called `backup-1`, is responsible for triggering the backup 134 | procedure itself. 135 | In order to create it, one is to head over to _Administration/Tasks_, click 136 | _Create task_, choose _Execute script_ and proceed as detailed below: 137 | 138 | ![backup-1-task](backup-1-task.png) 139 | 140 | In this example, Nexus will `touch` the `/nexus-data/backup/.backup` file everyday 141 | at 4am UTC, triggering the backup process - there's a process monitoring this 142 | file that reacts to changes and starts the process. 143 | 144 | The second task, called `backup-2`, is responsible for backing-up the Nexus 145 | databases, configurations and metadata. 146 | In order to create it, one is to head over to _Administration/Tasks_, click 147 | _Create task_, choose _Export databases for backup_ and proceed 148 | as detailed below: 149 | 150 | ![backup-2-task](backup-2-task.png) 151 | 152 | In this example, Nexus will backup its internal databases everyday at 4am UTC. 153 | The abovementioned process waits for the task to complete and includes the 154 | resulting file in the backup bundle. 155 | -------------------------------------------------------------------------------- /docs/usage/using-nexus-with-maven.md: -------------------------------------------------------------------------------- 1 | # Using Nexus with Maven 2 | 3 | Configuring Maven to download artifacts from Nexus instead of Maven Central 4 | will, most of the time, not only speed up build processes by 5 | caching commonly used dependencies but also help ensuring reproducible builds, 6 | since one only depends on their Nexus availability and not the public repositories. 7 | 8 | Maven can also be configured to upload artifacts to Nexus, enabling the management 9 | of artifacts private to an organization. 10 | 11 | ## Configuring credentials 12 | 13 | To be able to upload/download artifacts, first it is required to specify the credentials to the `nexus` repository in the global Maven configuration (the `~/.m2/settings.xml`): 14 | 15 | ```xml 16 | 17 | 18 | 19 | 20 | nexus 21 | the-username 22 | the-password 23 | 24 | 25 | (...) 26 | 27 | ``` 28 | 29 | **Attention:** If GCP IAM authentication is enabled, username and password 30 | **are not the GCP organization credentials** but are instead the [credentials obtained with Nexus cli](../admin/configuring-nexus-proxy.md#using-command-line-tools). 31 | 32 | ### Encrypting credentials 33 | 34 | **Note**: Encrypting credentials is a security best-pratice. 35 | 36 | Maven provides an easy way to encrypt passwords for securely storing the 37 | credentials needed to access private repositories. In order to do so, one must 38 | create a _master password_ as follows: 39 | 40 | ```shell 41 | $ mvn --encrypt-master-password 42 | Master password: 43 | {sY/CwSgHqY8HeC4obv5H1zPBYwjt5F8k1SjeegD3/vw=} 44 | ``` 45 | 46 | One is to copy the resulting hash value and store it in `~/.m2/security-settings.xml`: 47 | 48 | ```xml 49 | 50 | 51 | {sY/CwSgHqY8HeC4obv5H1zPBYwjt5F8k1SjeegD3/vw=} 52 | 53 | ``` 54 | 55 | Now, one can start encrypting passwords by running: 56 | 57 | ``` 58 | $ mvn --encrypt-password 59 | Password: 60 | {idR6S1+DYEMHFO56avrFg3NHGHOt74zdFjfKl8Cm3Bg=} 61 | ``` 62 | 63 | Replacing `the-password` in `~/.m2/settings.xml` with this value will still 64 | allow one to deploy private artifacts to Nexus while keeping one's credentials 65 | secure. 66 | For further information, please refer to 67 | [Password Encryption](https://maven.apache.org/guides/mini/guide-encryption.html). 68 | 69 | **Attention:** If GCP IAM authentication is enabled, username and password 70 | **are not the GCP organization credentials** but are instead the [credentials obtained with Nexus cli](../admin/configuring-nexus-proxy.md#using-command-line-tools). 71 | 72 | ## Downloading artifacts from Nexus 73 | 74 | In order to enable Maven to download artifacts from Nexus, one is to edit the 75 | the user's global Maven configuration (which lives in `~/.m2/settings.xml`) as 76 | follows: 77 | 78 | ```xml 79 | 80 | 81 | 82 | 83 | nexus 84 | * 85 | https://nexus.example.com/repository/maven-public/ 86 | 87 | 88 | 89 | 90 | nexus 91 | 92 | 93 | central 94 | https://central 95 | 96 | true 97 | 98 | 99 | true 100 | 101 | 102 | 103 | 104 | 105 | central 106 | https://central 107 | 108 | true 109 | 110 | 111 | true 112 | 113 | 114 | 115 | 116 | 117 | 118 | nexus 119 | 120 | 121 | ``` 122 | 123 | Above, a single profile called `nexus` includes both a `repository` and a 124 | `pluginRepository` with the ID `central` in order to override the defaults 125 | defined in the Maven super-POM. 126 | 127 | One can check if their configuration is working by deleting the `~/.m2/repository` 128 | directory and running: 129 | 130 | ```shell 131 | $ mvn package 132 | ``` 133 | 134 | on any given Maven project. Public dependencies should now be downloaded from Nexus 135 | instead of the public repositories: 136 | 137 | ``` 138 | $ mvn compile 139 | /Users/the-user/Workspace/dojo-nexus 140 | [INFO] Scanning for projects... 141 | Downloading: https://nexus.example.com/repository/maven-public/org/springframework/boot/spring-boot-starter-parent/1.5.3.RELEASE/spring-boot-starter-parent-1.5.3.RELEASE.pom 142 | Downloaded: https://nexus.example.com/repository/maven-public/org/springframework/boot/spring-boot-starter-parent/1.5.3.RELEASE/spring-boot-starter-parent-1.5.3.RELEASE.pom (7.5 kB at 11 kB/s) 143 | Downloading: https://nexus.example.com/repository/maven-public/org/springframework/boot/spring-boot-dependencies/1.5.3.RELEASE/spring-boot-dependencies-1.5.3.RELEASE.pom 144 | Downloaded: https://nexus.example.com/repository/maven-public/org/springframework/boot/spring-boot-dependencies/1.5.3.RELEASE/spring-boot-dependencies-1.5.3.RELEASE.pom (89 kB at 378 kB/s) 145 | (...) 146 | ``` 147 | 148 | ## Uploading artifacts to Nexus 149 | 150 | In order to upload private artifacts to Nexus, one must configure the 151 | `distributionManagement` section of the root `pom.xml` as follows: 152 | 153 | ```xml 154 | 155 | 156 | nexus 157 | Releases 158 | https://nexus.example.com/repository/maven-releases 159 | 160 | 161 | nexus 162 | Snapshot 163 | https://nexus.example.com/repository/maven-snapshots 164 | 165 | 166 | ``` 167 | 168 | After one is done with Maven configuration, publishing private artifacts should 169 | be as easy as running: 170 | 171 | ``` 172 | $ mvn deploy 173 | 174 | (...) 175 | [INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ dojo-nexus --- 176 | Downloading: https://nexus.example.com/repository/maven-snapshots/com/example/dojo/dojo-nexus/2.0.0-SNAPSHOT/maven-metadata.xml 177 | Downloaded: https://nexus.example.com/repository/maven-snapshots/com/example/dojo/dojo-nexus/2.0.0-SNAPSHOT/maven-metadata.xml (781 B at 1.8 kB/s) 178 | Downloading: https://nexus.example.com/repository/maven-snapshots/com/example/dojo/dojo-nexus/2.0.0-SNAPSHOT/maven-metadata.xml 179 | Downloaded: https://nexus.example.com/repository/maven-snapshots/com/example/dojo/dojo-nexus/2.0.0-SNAPSHOT/maven-metadata.xml (781 B at 8.1 kB/s) 180 | Uploading: https://nexus.example.com/repository/maven-snapshots/com/example/dojo/dojo-nexus/2.0.0-SNAPSHOT/dojo-nexus-2.0.0-20170610.093044-6.jar 181 | Uploaded: https://nexus.example.com/repository/maven-snapshots/com/example/dojo/dojo-nexus/2.0.0-SNAPSHOT/dojo-nexus-2.0.0-20170610.093044-6.jar (6.6 MB at 5.7 MB/s) 182 | Uploading: https://nexus.example.com/repository/maven-snapshots/com/example/dojo/dojo-nexus/2.0.0-SNAPSHOT/dojo-nexus-2.0.0-20170610.093044-6.pom 183 | Uploaded: https://nexus.example.com/repository/maven-snapshots/com/example/dojo/dojo-nexus/2.0.0-SNAPSHOT/dojo-nexus-2.0.0-20170610.093044-6.pom (1.7 kB at 5.3 kB/s) 184 | (...) 185 | ``` 186 | -------------------------------------------------------------------------------- /docs/admin/configuring-nexus-proxy.md: -------------------------------------------------------------------------------- 1 | # Configuring `nexus-proxy` GCP IAM Authentication 2 | 3 | ## Table of Contents 4 | 5 | * [Pre-Requisites](#pre-requisites) 6 | * [Enable Cloud Resource Manager API](#enable-crm-api) 7 | * [Configure the OAuth Consent Screen](#configure-consent) 8 | * [Create an OAuth Client ID](#create-oauth-client) 9 | * [Create and distributed the Java Keystore](#java-keystore) 10 | * [Enable GCP IAM authentication in Nexus](#enable-gcp-iam-auth) 11 | * [Deploying](#deploying) 12 | * [Using Nexus with Google Cloud IAM Authentication](#usage) 13 | 14 | ## Pre-Requisites 15 | 16 | Enabling GCP IAM authentication in `nexus-proxy` requires: 17 | 18 | * Access to the _Google Cloud Resource Manager API_. 19 | * An OAuth consent screen and client ID to be configured. 20 | * A Java keystore to sign user tokens (JWT) to be created. 21 | 22 | This document walks through the setup of each of these requirements in detail. 23 | 24 | **ATTENTION**: For users to authenticate, **they must be** part of the GCP 25 | organization and must use their respective email address as the username. 26 | Each user **must also** have "_Organization Viewer_" permissions 27 | [**at organization-level**](https://cloud.google.com/iam/docs/resource-hierarchy-access-control) 28 | (i.e., in the "_IAM & Admin_" section of the organization in the GCP UI), 29 | otherwise they won't be able to authenticate. 30 | For more details, consult the 31 | [proxy requirements](https://github.com/travelaudience/nexus-proxy#before-proceeding). 32 | 33 | 34 | 35 | ## Enable Cloud Resource Manager API 36 | 37 | For one to enable the Cloud Resource Manager API, one must: 38 | 39 | 1. Go to "_Google Cloud Platform_ > _APIs & services_ > _Library_". 40 | 1. Search for "_Google Cloud Resource Manager API_" and click the link in the 41 | results box. 42 | 1. Click the "_Enable_" button. 43 | 44 | 45 | 46 | ## Configure the OAuth Consent Screen 47 | 48 | For one to configure the OAuth consent screen, one must: 49 | 50 | 1. Go to "_Google Cloud Platform_ > _APIs & services_ > _Credentials_". 51 | 1. Click "_OAuth consent screen_". 52 | 1. Fill in the form with appropriate values (e.g., 53 | _Nexus Repository Manager_ in _Product name shown to users_). 54 | 1. Click "_Save_". 55 | 56 | 57 | 58 | ## Create an OAuth Client ID 59 | 60 | For one to create an OAuth Client ID, one must: 61 | 62 | 1. Go to "_Google Cloud Platform_ > _APIs & services_ > _Credentials_". 63 | 1. Click "_Create Credentials_ > _OAuth client ID_". 64 | 1. Select "_Web application_". 65 | 1. Under "_Name_" specify "_nexus-proxy_". 66 | 1. Under "_Authorized JavaScript origins_" add all the URLs one may be using to 67 | access Nexus (e.g. both http://nexus.example.com and https://nexus.example.com). 68 | 1. Under "_Authorized redirect URIs_" add the HTTPS variant of 69 | the URL suffixed with `/oauth/callback` 70 | (e.g., https://nexus.example.com/oauth/callback). 71 | 1. Take note of the resulting _client ID_ and _client secret_. 72 | 73 | 74 | 75 | ## Create and distribute the Java Keystore 76 | 77 | A Java keystore is needed in order for the proxy to sign user tokens (JWT). 78 | One must create the keystore as follows: 79 | 80 | ```bash 81 | $ keytool -genkey \ 82 | -keystore keystore.jceks \ 83 | -storetype jceks \ 84 | -keyalg RSA \ 85 | -keysize 2048 \ 86 | -alias RS256 \ 87 | -sigalg SHA256withRSA \ 88 | -dname "CN=,OU=,O=,L=,ST=,C=" \ 89 | -validity 3651 90 | ``` 91 | 92 | When prompted for two passwords, one must make sure the passwords match. 93 | Also, one is free to change the value of the `dname`, `keystore` and `validity` 94 | parameters. 95 | For further details please refer to [travelaudience/nexus-proxy](https://github.com/travelaudience/nexus-proxy#generating-the-keystore). 96 | 97 | After creating the keystore, it must be made available to the Kubernetes cluster, 98 | as follows: 99 | 100 | 1. Run the following command replacing, 101 | `/path/to/keystore.jceks` and `KEYSTORE_PASSWORD` with the path to the 102 | keystore file created and the password chosen for the keystore, 103 | respectively: 104 | 105 | ```bash 106 | $ cat << EOF > nexus-proxy-ks-secret.yaml 107 | apiVersion: v1 108 | kind: Secret 109 | metadata: 110 | name: nexus-proxy-ks 111 | type: Opaque 112 | data: 113 | keystore: $(cat /path/to/keystore.jceks | base64) 114 | password: $(echo -n KEYSTORE_PASSWORD | base64) 115 | EOF 116 | ``` 117 | 118 | This will create a Kubernetes secret containing the keystore file and 119 | the password, ready to be imported into the cluster and be accessible 120 | by Nexus. 121 | 1. Create the secret, as follows: 122 | 123 | ```bash 124 | $ kubectl create -f nexus-proxy-ks-secret.yaml 125 | ``` 126 | 127 | 128 | 129 | ## Enable GCP IAM authentication in Nexus 130 | 131 | In order to enable GCP IAM authentication for Nexus, one must first create the 132 | "_Rut Auth_" capability in the Nexus administration page, as follows: 133 | 134 | 1. Inside Nexus, go to "_Server Administration and Configuration_ > _System_ > 135 | _Capabilities_". 136 | 137 | ![rut-auth-capability-1](./rut-auth-capability-1.png) 138 | 139 | 1. Click "_Create capability_" and choose "_Rut Auth_" on the list. 140 | 141 | ![rut-auth-capability-2](./rut-auth-capability-2.png) 142 | 143 | 1. When asked for "_HTTP Header Name_" enter `X-Forwarded-User`. 144 | 145 | ![rut-auth-capability-3](./rut-auth-capability-3.png) 146 | 147 | 1. Click "_Create capability_". 148 | 149 | Then, one must edit the 150 | `nexus-iam-statefulset.yaml` descriptor, as follows: 151 | 152 | 1. Set the value of `CLOUD_IAM_AUTH_ENABLED` to `"true"`. 153 | 1. Set the value of `CLIENT_ID` to the value obtained in 154 | the last step of [Create an OAuth Client ID](#create-oauth-client). 155 | 1. Set the value of `CLIENT_SECRET` to the value obtained 156 | in the last step of [Create an OAuth Client ID](#create-oauth-client). 157 | 1. Set the value of `ORGANIZATION_ID` according to the desired authentication 158 | organization. 159 | * One can find this value by running `gcloud organizations list`. 160 | 1. Set the value of `REDIRECT_URL`, e.g. `https://nexus.example.com/oauth/callback`. 161 | 1. Adjust the values of `AUTH_CACHE_TTL` and `SESSION_TTL` according to one's 162 | needs. 163 | * Further description of these variables can be found [here](https://github.com/travelaudience/nexus-proxy#environment-variables). 164 | 165 | **ATTENTION:** The value of the `NEXUS_RUT_HEADER` variable must match the value 166 | defined in the "_HTTP Header Name_" field of the "_Rut Auth_" capability in the 167 | Nexus configuration. If one has chosen a different value in step (3) above, one 168 | must also update the value of this variable accordingly. 169 | 170 | ## Deploying 171 | 172 | 1. If one hasn't done so, one must run `kubectl create -f nexus-proxy-ks-secret.yaml`. 173 | 1. Proceed as indicated in [Deploying Nexus](../../README.md#deploying-nexus), 174 | using `nexus-iam-statefulset.yaml` instead of `nexus-statefulset.yaml`. 175 | 176 | 177 | 178 | 179 | ## Using Nexus with Google Cloud IAM Authentication 180 | 181 | When Google Cloud IAM authentication is enabled and one first browses Nexus, a 182 | consent screen asking for a few permissions will be presented. One must click 183 | "_Allow_" for the authentication process to succeed. This consent screen may 184 | continue to pop-up from time to time. 185 | 186 | **ATTENTION:** A Google log-in page may appear before the abovementioned consent 187 | screen. One must use their organization credentials to log-in before proceeding. 188 | 189 | ## Using Command-Line Tools 190 | 191 | For security reasons, the proxy and tools such as Maven or Docker shouldn't store 192 | and use GCP organization credentials. **The same credentials are used solely within 193 | GCP domain**. Therefore one needs a specific set of credentials that can be used 194 | to authorize access to Nexus repositories. 195 | After logging-in, these per-user credentials can be queried at 196 | `https://nexus.example.com/cli/credentials`. 197 | 198 | If authentication with Google Cloud IAM is successful, a result like follows 199 | is returned: 200 | 201 | ```json 202 | { 203 | "username": "john.doe@example.com", 204 | "password": "eyJ0eXA(...)" 205 | } 206 | ``` 207 | 208 | These are the credentials one will use when setting-up their tools. 209 | Here's one example when configuring Docker: 210 | 211 | ```bash 212 | $ docker login containers.example.com 213 | Username: john.doe@example.com 214 | Password: eyJ0eXA(...) # Input will be hidden. 215 | Login Suceeded 216 | ``` 217 | 218 | **ATTENTION:** The credentials obtained through this process are valid for one year, 219 | but will expire before that period if membership within the organization is 220 | revoked. When credentials expire, the user must request them them as described above. 221 | 222 | **ATTENTION:** Every visit to https://nexus.example.com/cli/credentials will return a 223 | new authentication token, as the creation and expiration dates are encoded in 224 | the token itself. One may use different tokens in different tools **but must** 225 | **be aware** that these tokens will expire at different moments. 226 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kubernetes-nexus 2 | 3 | Nexus Repository Manager OSS (3.19.1) on top of Kubernetes. 4 | 5 | ## Table of Contents 6 | 7 | - [Pre-Requisites](#pre-requisites) 8 | - [Deployment](#deployment) 9 | - [Deploying Nexus](#deploying-nexus) 10 | - [Securing Nexus with HTTPS](#securing-nexus-with-https) 11 | - [Configuring Nexus](#configuring-nexus) 12 | - [Configuring Backup Retention](#configuring-backup-retention) 13 | - [Using Nexus](#usage) 14 | - [Docker](#usage-docker) 15 | - [Maven](#usage-maven) 16 | - [Gradle](#usage-gradle) 17 | - [sbt](#usage-sbt) 18 | - [Python](#usage-python) 19 | - [Backup and Restore](#backup-and-restore) 20 | - [Backup](#backup) 21 | - [Restore](#restore) 22 | 23 | ## Pre-Requisites 24 | 25 | - A working Kubernetes cluster (v1.10.7 or newer) with Cloud Storage read-write 26 | permissions enabled (`https://www.googleapis.com/auth/devstorage.read_write` scope) 27 | - A working installation of `kubectl` configured to access the 28 | cluster. 29 | - A working installation of `gcloud` configured to access the Google Cloud 30 | Platform project. 31 | - A global static IPv4 address (e.g., `static-ip-name`). 32 | - A DNS A record `nexus.example.com` pointing to this IPv4 address. 33 | - A DNS CNAME record `containers.example.com` pointing to 34 | `nexus.example.com`. 35 | - A [Google Cloud Storage](https://cloud.google.com/storage/) bucket (e.g., 36 | `nexus-backup`). 37 | 38 | 39 | **Attention**: On RBAC-enabled clusters, and due to [the way GKE checks permissions](https://cloud.google.com/container-engine/docs/role-based-access-control#defining_permissions_in_a_role), one must also grant themselves the `cluster-admin` role *manually* before proceeding: 40 | 41 | ```bash 42 | $ MY_GCLOUD_USER=$(gcloud info | grep Account | awk -F'[][]' '{print $2}') 43 | $ kubectl create clusterrolebinding ${MY_GCLOUD_USER} --clusterrole=cluster-admin --user=${MY_GCLOUD_USER} 44 | ``` 45 | 46 | ## Deployment 47 | 48 | ### Deploying Nexus 49 | 50 | The very first thing one **must do** after deploying Nexus is to log-in into the 51 | Nexus UI with the default credentials (`admin:admin123` ) and proceed to change 52 | the password to something more secure. But one **must not** do it right away! 53 | One will do it after [securing Nexus with HTTPS](#securing-nexus-with-https). 54 | 55 | The `nexus-backup` container uses the aforementioned credentials to 56 | access the Nexus API and execute backups. The same credentials are provided 57 | during deployment. Therefore, before deploying Nexus, logging-in and changing 58 | the password as instructed above, one **must** decide what password will be set 59 | and create a Kubernetes secret containing it, and only then deploy Nexus. 60 | That can be done as follows: 61 | 62 | ```bash 63 | $ cd kubernetes/ 64 | $ NEXUS_CREDENTIALS=$(echo -n 'admin:' | base64) 65 | $ NEXUS_AUTH=$(echo -n "Basic ${NEXUS_CREDENTIALS}" | base64) 66 | $ sed -i.bkp "s/QmFzaWMgWVdSdGFXNDZZV1J0YVc0eE1qTT0=/${NEXUS_AUTH}/" nexus-secret.yaml 67 | ``` 68 | 69 | One must also update the contents of `nexus-statefulset.yaml` and `nexus-ingress.yaml` according to one's setup _before_ proceeding. 70 | 71 | After updating `nexus-secret.yaml`, `nexus-statefulset.yaml` and `nexus-ingress.yaml`, one may deploy Nexus as follows: 72 | 73 | **Attention**: If one wants to have GCP IAM authentication enabled, one must 74 | follow [these instructions](docs/admin/configuring-nexus-proxy.md) instead. 75 | 76 | ```bash 77 | $ kubectl create -f nexus-secret.yaml 78 | $ kubectl create -f nexus-statefulset.yaml 79 | $ kubectl create -f nexus-proxy-svc.yaml 80 | $ kubectl create -f nexus-ingress.yaml 81 | ``` 82 | 83 | One should allow for 5 to 10 minutes for GCLB to update. Nexus should then 84 | become available over HTTP at http://nexus.example.com. 85 | 86 | ### Securing Nexus with HTTPS 87 | 88 | In order to secure Nexus external access one must configure HTTPS access. 89 | The easiest and cheapest way to obtain a trusted TLS certificate is using 90 | [Let's Encrypt](https://letsencrypt.org/), and the easiest way to automate the 91 | process of obtaining and renewing certificates from Let's Encrypt is by using 92 | [`cert-manager`](https://github.com/jetstack/cert-manager): 93 | 94 | The easiest way is to install `cert-manager` via Helm, but a static manifest is available as well. 95 | One can follow [these](https://cert-manager.readthedocs.io/en/latest/getting-started/2-installing.html) installation instructions. 96 | 97 | As soon as it starts, `cert-manager` will start monitoring _Ingress_ resources and 98 | requesting certificates from Let's Encrypt. 99 | 100 | After installation, one will need to setup an issuer and actually request a certificate for Nexus: 101 | 102 | **Attention:** One must edit the `certificate.yaml` file according to one's setup _before_ running the following commands. 103 | 104 | ```bash 105 | $ cd ../cert-manager/ 106 | $ kubectl create -f issuer.yaml 107 | $ kubectl create -f certificate.yaml 108 | ``` 109 | 110 | **NOTE**: Let's Encrypt must be able to reach port `80` on domains for which 111 | certificates are requested, hence the annotation `kubernetes.io/ingress.allow-http` 112 | in [`nexus-ingress.yaml`](kubernetes/nexus-ingress.yaml) must be set to `"true"`. 113 | 114 | If everything goes well, after a while one will 115 | be able to access https://nexus.example.com securely **and** proceed to log-in 116 | into Nexus with the default credentials (`admin:admin123`), and finally change 117 | the `admin` password to the secure password one decided above. 118 | 119 | ### Configuring Nexus 120 | 121 | One should head over to 122 | [`docs/admin/configuring-nexus.md`](docs/admin/configuring-nexus.md) 123 | for information on how to configure Nexus. 124 | 125 | ### Configuring Backup Retention 126 | 127 | **Attention**: As mentioned in the pre-requisites, the GKE cluster needs read-write 128 | permissions on GCP Cloud Storage in order to upload backups. 129 | 130 | The backup procedure uses Google Cloud Storage to save backups. In order to 131 | configure a backup retention policy, one should head over to the `backup-lifecycle` 132 | directory and install one of the available policies by running: 133 | 134 | ```bash 135 | $ ./gsutil-lifecycle-set 136 | ``` 137 | 138 | Google Cloud Storage will then automatically purge backups older than the number 139 | of days specified. 140 | 141 | 142 | 143 | ## Using Nexus 144 | 145 | Below are linked detailed instructions on how to configure a bunch of tools 146 | in order to download and upload artifacts from and to Nexus. 147 | 148 | 149 | 150 | ### Docker 151 | 152 | Please, read [Using Nexus with Docker](docs/usage/using-nexus-with-docker.md). 153 | 154 | 155 | 156 | ### Maven 157 | 158 | Please, read [Using Nexus with Maven](docs/usage/using-nexus-with-maven.md). 159 | 160 | 161 | 162 | ### Gradle 163 | 164 | Please, read [Using Nexus with Gradle](docs/usage/using-nexus-with-gradle.md). 165 | 166 | 167 | 168 | ### sbt 169 | 170 | Please, read [Using Nexus with sbt](docs/usage/using-nexus-with-sbt.md). 171 | 172 | 173 | 174 | ### Python 175 | 176 | Please, read [Using Nexus with Python](docs/usage/using-nexus-with-python.md). 177 | 178 | ## Backup and Restore 179 | 180 | **Attention**: As mentioned in the pre-requisites, the GKE cluster needs read-write 181 | permissions on GCP Cloud Storage in order to upload backups. 182 | 183 | ### Backup 184 | 185 | Nexus has a built-in 186 | [_Export databases for backup_](https://help.sonatype.com/repomanager3/backup-and-restore/configure-and-run-the-backup-task) task which can be used to backup configuration and metadata. However, the generated backup doesn't include [blob stores](https://help.sonatype.com/repomanager3/high-availability/configuring-blob-stores), rendering it semi-useless in a disaster recovery scenario. It is thus of the utmost importance to backup blob stores separately and at roughly the same time this task runs in order to achieve consistent backups. 187 | 188 | This is the role of the 189 | [`nexus-backup`](https://github.com/travelaudience/docker-nexus-backup) 190 | container — a container with a script which makes backups of the `default` 191 | blob store and then uploads them on a Google Cloud Storage bucket alongside the 192 | data generated by Nexus built-in backup task. These backups are triggered by 193 | a Nexus task of type _Execute script_ (to be configured as described in 194 | [`docs/admin/configuring-nexus.md`](docs/admin/configuring-nexus.md#configure-backup-tasks-and-create-backup-scripts)). 195 | The script reacts to changes made to 196 | 197 | ``` 198 | /nexus-data/backup/.backup 199 | ``` 200 | 201 | and initiates the backup process: 202 | 203 | 1. Check if Nexus can be reached. Proceed only if Nexus is reached successfully. 204 | 1. Retrieve the current timestamp in order to tag the backup appropriately. 205 | 1. Make sure that the scripts used to start/stop repositories are installed. 206 | 1. Stop all the repositories so that no writes are made during the backup. 207 | 1. Give Nexus a _grace period_ for the configuration and metadata backup task to 208 | complete. 209 | 1. Archive the `default` blob store using `tar`, 210 | [_streaming_](https://cloud.google.com/storage/docs/streaming) the resulting 211 | file to the target bucket. 212 | 1. Archive the backup files generated by Nexus using `tar`, _streaming_ the 213 | resulting file to the target bucket. 214 | 1. Cleanup all leftover `*.bak` files in `/nexus-data/backup`. 215 | 1. Start all the repositories so that Nexus can become available again. 216 | 217 | It is advisable to configure this backup procedure to run at off-peak hours, as 218 | described in the aforementioned document. 219 | 220 | ### Restore 221 | 222 | In a disaster recovery scenario, the latest backup made by the `nexus-backup` 223 | container should be restored. In order to achieve this, Nexus must be stopped. 224 | The procedure goes as follows: 225 | 226 | ``` 227 | $ kubectl exec -i -t nexus-0 --container nexus -- sh # Enter the container. 228 | $ mv /etc/service/nexus/ /nexus-service/ # Prevent `runsvdir` from respawning Nexus after the next step is performed. 229 | $ pkill java # Ask for Nexus to terminate gracefully. 230 | ``` 231 | 232 | **Attention**: after terminating Nexus, with the default readiness/liveness probe settings in the chart kubernetes will restart the nexus pod before you've been able to untar the back-up files. If you meet that problem (the `sh` into the `nexus` container terminates abruptly with exit code 137), you may overcome it by extending the time limits of the readiness/liveness probes: `kubectl edit statefulset nexus` and change `spec.template.spec.containers.livenessProbe.failureThreshold` and `spec.template.spec.containers.readinessProbe.failureThreshold` for the `nexus` container to a large value, e.g. 100. Once you're done with the restore, don't forget to reset those values to their initial setting!! 233 | 234 | At this point, Nexus is stopped but the container is still running, giving one a 235 | chance to perform the restore procedure. 236 | 237 | **Attention**: One must not close this terminal window just yet. 238 | 239 | One should now open another terminal window and login into the `nexus-backup` container in order to use `gsutil` to retrieve the desired backup. 240 | 241 | ```shell 242 | $ kubectl exec -i -t nexus-0 --container nexus-backup -- /bin/bash 243 | ``` 244 | 245 | Now one should go as follows: 246 | 247 | 1. Retrieve from GCS the `blobstore.tar` and `databases.tar` files 248 | from the last known good backup. 249 | 1. Remove everything _under_ `/nexus-data/backup/`, 250 | `/nexus-data/blobs/default/` and `/nexus-data/db/` 251 | 1. Run `tar -xvf blobstore.tar --strip-components 3 -C /nexus-data/blobs/default/`. 252 | 1. Run `tar -xvf databases.tar --strip-components 2 -C /nexus-data/restore-from-backup/`. 253 | 254 | At this point the backup is ready to be restored by Nexus and one can leave the _nexus-backup_ container. 255 | One must now go back to the terminal of the `nexus` container and run the following commands: 256 | 257 | ``` 258 | $ mv /nexus-service/ /etc/service/nexus/ # Make `runsvdir` start Nexus again. 259 | $ exit # Bye! 260 | ``` 261 | 262 | This will automatically start Nexus and perform the restore process. 263 | 264 | If one watches the `nexus` container logs as it boots, one should see an indication 265 | that a restore procedure is in place. After a few minutes access should be 266 | restored with the last known good backup in place. 267 | --------------------------------------------------------------------------------