- Pre-Requisites
- Enable Cloud Resource Manager API
- Configure the OAuth Consent Screen
- Create an OAuth Client ID
- Create and distributed the Java Keystore
- Enable GCP IAM authentication in Nexus
- Deploying
- Using Nexus with Google Cloud IAM Authentication
Enabling GCP IAM authentication in nexus-proxy
requires:
- Access to the Google Cloud Resource Manager API.
- An OAuth consent screen and client ID to be configured.
- A Java keystore to sign user tokens (JWT) to be created.
This document walks through the setup of each of these requirements in detail.
ATTENTION: For users to authenticate, they must be part of the GCP organization and must use their respective email address as the username. Each user must also have "Organization Viewer" permissions at organization-level (i.e., in the "IAM & Admin" section of the organization in the GCP UI), otherwise they won't be able to authenticate. For more details, consult the proxy requirements.
For one to enable the Cloud Resource Manager API, one must:
- Go to "Google Cloud Platform > APIs & services > Library".
- Search for "Google Cloud Resource Manager API" and click the link in the results box.
- Click the "Enable" button.
For one to configure the OAuth consent screen, one must:
- Go to "Google Cloud Platform > APIs & services > Credentials".
- Click "OAuth consent screen".
- Fill in the form with appropriate values (e.g., Nexus Repository Manager in Product name shown to users).
- Click "Save".
For one to create an OAuth Client ID, one must:
- Go to "Google Cloud Platform > APIs & services > Credentials".
- Click "Create Credentials > OAuth client ID".
- Select "Web application".
- Under "Name" specify "nexus-proxy".
- Under "Authorized JavaScript origins" add all the URLs one may be using to access Nexus (e.g. both http://nexus.example.com and https://nexus.example.com).
- Under "Authorized redirect URIs" add the HTTPS variant of
the URL suffixed with
/oauth/callback
(e.g., https://nexus.example.com/oauth/callback). - Take note of the resulting client ID and client secret.
A Java keystore is needed in order for the proxy to sign user tokens (JWT). One must create the keystore as follows:
$ keytool -genkey \
-keystore keystore.jceks \
-storetype jceks \
-keyalg RSA \
-keysize 2048 \
-alias RS256 \
-sigalg SHA256withRSA \
-dname "CN=,OU=,O=,L=,ST=,C=" \
-validity 3651
When prompted for two passwords, one must make sure the passwords match.
Also, one is free to change the value of the dname
, keystore
and validity
parameters.
For further details please refer to travelaudience/nexus-proxy.
After creating the keystore, it must be made available to the Kubernetes cluster, as follows:
-
Run the following command replacing,
/path/to/keystore.jceks
andKEYSTORE_PASSWORD
with the path to the keystore file created and the password chosen for the keystore, respectively:$ cat << EOF > nexus-proxy-ks-secret.yaml apiVersion: v1 kind: Secret metadata: name: nexus-proxy-ks type: Opaque data: keystore: $(cat /path/to/keystore.jceks | base64) password: $(echo -n KEYSTORE_PASSWORD | base64) EOF
This will create a Kubernetes secret containing the keystore file and the password, ready to be imported into the cluster and be accessible by Nexus.
-
Create the secret, as follows:
$ kubectl create -f nexus-proxy-ks-secret.yaml
In order to enable GCP IAM authentication for Nexus, one must first create the "Rut Auth" capability in the Nexus administration page, as follows:
- Inside Nexus, go to "Server Administration and Configuration > System > Capabilities".
- Click "Create capability" and choose "Rut Auth" on the list.
- When asked for "HTTP Header Name" enter
X-Forwarded-User
.
- Click "Create capability".
Then, one must edit the
nexus-iam-statefulset.yaml
descriptor, as follows:
- Set the value of
CLOUD_IAM_AUTH_ENABLED
to"true"
. - Set the value of
CLIENT_ID
to the value obtained in the last step of Create an OAuth Client ID. - Set the value of
CLIENT_SECRET
to the value obtained in the last step of Create an OAuth Client ID. - Set the value of
ORGANIZATION_ID
according to the desired authentication organization.- One can find this value by running
gcloud organizations list
.
- One can find this value by running
- Set the value of
REDIRECT_URL
, e.g.https://nexus.example.com/oauth/callback
. - Adjust the values of
AUTH_CACHE_TTL
andSESSION_TTL
according to one's needs.- Further description of these variables can be found here.
ATTENTION: The value of the NEXUS_RUT_HEADER
variable must match the value
defined in the "HTTP Header Name" field of the "Rut Auth" capability in the
Nexus configuration. If one has chosen a different value in step (3) above, one
must also update the value of this variable accordingly.
- If one hasn't done so, one must run
kubectl create -f nexus-proxy-ks-secret.yaml
. - Proceed as indicated in Deploying Nexus,
using
nexus-iam-statefulset.yaml
instead ofnexus-statefulset.yaml
.
When Google Cloud IAM authentication is enabled and one first browses Nexus, a consent screen asking for a few permissions will be presented. One must click "Allow" for the authentication process to succeed. This consent screen may continue to pop-up from time to time.
ATTENTION: A Google log-in page may appear before the abovementioned consent screen. One must use their organization credentials to log-in before proceeding.
For security reasons, the proxy and tools such as Maven or Docker shouldn't store
and use GCP organization credentials. The same credentials are used solely within
GCP domain. Therefore one needs a specific set of credentials that can be used
to authorize access to Nexus repositories.
After logging-in, these per-user credentials can be queried at
https://nexus.example.com/cli/credentials
.
If authentication with Google Cloud IAM is successful, a result like follows is returned:
{
"username": "[email protected]",
"password": "eyJ0eXA(...)"
}
These are the credentials one will use when setting-up their tools. Here's one example when configuring Docker:
$ docker login containers.example.com
Username: [email protected]
Password: eyJ0eXA(...) # Input will be hidden.
Login Suceeded
ATTENTION: The credentials obtained through this process are valid for one year, but will expire before that period if membership within the organization is revoked. When credentials expire, the user must request them them as described above.
ATTENTION: Every visit to https://nexus.example.com/cli/credentials will return a new authentication token, as the creation and expiration dates are encoded in the token itself. One may use different tokens in different tools but must be aware that these tokens will expire at different moments.