Skip to content

Commit 43eeb2d

Browse files
authored
Merge pull request #8 from mcanoy/ocp4-user
use groups to identify access
2 parents aff25e1 + 1e68f41 commit 43eeb2d

18 files changed

Lines changed: 331 additions & 177 deletions

README.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Description
44

5-
This plugin enables user authentication and Single Sign-On via OpenShift. It is heavily based on the code by Julien Lancelot. Tested on version 7 of Sonarqube and OCP 3.11. It is intended to run deployed in a pod on OpenShift.
5+
This plugin enables user authentication and Single Sign-On via OpenShift. It is based on the code by Julien Lancelot. Tested on version 7 of Sonarqube and OCP 3.11. It is intended to run deployed in a pod on OpenShift.
66

77
This plugin is designed to work out of the box without configuration. During plugin deployment, it looks up oauth information from OpenShift's well-known information and takes advantage of information already on the running pod.
88

@@ -16,7 +16,7 @@ During deployment the plugin will:
1616

1717
## Installation
1818

19-
This plugin is not currently hosted anywhere. So build and place this plugin on to the volume where Sonarqube reads plugins at startup. Typically, this might be `/opt/sonarqube/data/plugins`.
19+
This plugin is currently hosted at [rht-labs](https://github.com/rht-labs/sonar-auth-openshift/releases/latest). The latest jar is [here](https://github.com/rht-labs/sonar-auth-openshift/releases/latest/download/sonar-auth-openshift-plugin.jar). You can build it locally and place this plugin on to the volume where Sonarqube reads plugins at startup if modifying it. Typically, this might be `/opt/sonarqube/data/plugins`.
2020

2121
The service account can be used as the oauth client in OpenShift. The service account that runs Sonarqube should have a redirect uri that references the route that Sonarqube is using. You must specify this service account in the DeploymentConfig.
2222

@@ -45,13 +45,31 @@ You may also enable it in the Administrative console
4545

4646
## Configuration
4747

48-
This plugin will map OpenShift roles to Sonarqube roles. These values are set with the property (shown with the default value if property is not set)
48+
This plugin will map OpenShift groups to Sonarqube roles. These values are set with the property
4949

5050
```
51-
sonar.auth.openshift.sar.groups=admin=sonar-administrators,edit=sonar-users,view=sonar-users
51+
sonar.auth.openshift.sar.groups=ocp-admin=sonar-administrators,ocp-users=sonar-users
52+
```
53+
54+
This shows that Sonarqube will allow OpenShift users who are in the group ocp-admin users to be administrators with the role of sonar-administrators. Ordinary users will be added as sonar-users if they are OpenShift users in the group ocp-users. These OpenShift groups do not exist by default.
55+
56+
The default mapping value is:
57+
58+
```
59+
sonar.auth.openshift.sar.groups=sonar-administrators=sonar-administrators,sonar-users=sonar-users
60+
```
61+
To disable certificate validation (not recommended for production) configure the `ignore.certs` property
62+
63+
```
64+
ignore.certs=true
65+
```
66+
67+
The pod that sonarqube runs in should have a valid certificate to access the OpenShift/Kubernetes API. The Oauth server may have a different certificate. That certificate needs to be loaded into the keystore. To do so, place the certificate on the container's file system (via configmap, dockerfile, etc...). Then configure the sonar property to point the location on the file system
68+
69+
```
70+
oauth.cert=/opt/sonarqube/conf/oauth.crt
5271
```
5372

54-
The default shown will allow admin users of the project the role of sonar-administrators of Sonarqube. Edit and View role users will be added as sonar-users.
5573

5674
You may choose the background color of the log in button with the property
5775

example/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN cp -a /opt/sonarqube/data /opt/sonarqube/data-init && \
1010
chown root:root /opt/sonarqube && chmod -R gu+rwX /opt/sonarqube
1111
ADD plugins.sh /opt/sonarqube/bin/plugins.sh
1212
RUN /opt/sonarqube/bin/plugins.sh $sonar_plugins
13-
ADD sonar-auth-openshift-plugin-1.0.0.jar /opt/sonarqube/extensions-init/plugins/sonar-auth-openshift-plugin-1.0.0.jar
13+
ADD sonar-auth-openshift-plugin-1.1.0.jar /opt/sonarqube/extensions-init/plugins/sonar-auth-openshift-plugin-1.1.0.jar
1414
RUN chown root:root /opt/sonarqube -R; \
1515
chmod 6775 /opt/sonarqube -R
1616
USER 1001

example/README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Example Build and Deploy
22

3-
43
```
54
This example uses ansible. Windows users use a vm or apply each command manually
65
```
@@ -15,25 +14,33 @@ This section contains an example for how this plugin can be used with Sonarqube
1514
mvn clean package && cp target/sonar-auth-openshift-plugin-1.0.0.jar example/
1615
```
1716

18-
2. Create a project in OpenShift
19-
20-
```
21-
oc new-project sonarqube
22-
```
17+
2. Inspect the [all.yml](example/inventory/group_vars/all.yml) file. In the following step it will run the [OpenShift Applier](https://github.com/redhat-cop/openshift-applier) to create resources in OpenShift. Most importantly
18+
1. A project / namespace called `sonarqube` that the other resources will belong too.
19+
2. A deployment config to deploy sonarqube with the plugin.
20+
3. A build config to build the sonarqube-auth-openshift project.
21+
4. A route to navigate to the application.
22+
5. Two groups that will define the users and administrators of Sonarqube.
23+
1. Inspect the group allocation. Add/Remove appropriate users for your scenario. Users are listed in the two yaml files located in the files directory. Group creation and editing usually require elvated privileges. Group names are also defined here. If changed, the sonar.properties must also be changed to match.
2324

2425
3. From the example folder run the prerequisites
2526

2627
```
2728
ansible-galaxy install -r requirements.yml --roles-path=roles
2829
```
2930

30-
4. From the example folder run the ansible playbook which sets up the build and deploy for Sonarqube including a persistent volume and database
31+
1. From the example folder, run the ansible playbook which sets up the build and deploy for Sonarqube including a persistent volume and database.
3132

3233
```
3334
ansible-playbook -i inventory/ apply.yml
3435
```
36+
If the group are already setup and you do not want to add them with this playbook run this command instead
37+
38+
```
39+
ansible-playbook -i inventory/ apply.yml -e exclude_tags=users_and_groups
40+
```
41+
3542

36-
5. From the base folder build the Docker container on OpenShift
43+
1. From the base folder, build the Docker container on OpenShift. This will replace the original build with the build with local files.
3744

3845
```
3946
oc start-build sonarqube --from-dir=. -n sonarqube

example/files/project.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: project.openshift.io/v1
2+
kind: Project
3+
metadata:
4+
name: sonarqube
5+
spec:
6+
finalizers:
7+
- kubernetes
8+
status:
9+
phase: Active
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
apiVersion: user.openshift.io/v1
3+
kind: Group
4+
metadata:
5+
name: sonarqube_admin
6+
users:
7+
- developer
8+
- admin1
9+
- admin2
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
apiVersion: user.openshift.io/v1
3+
kind: Group
4+
metadata:
5+
name: sonarqube_user
6+
users:
7+
- developer
8+
- casual_user1
9+
- casual_user2

example/inventory/group_vars/all.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ sonarqube:
2121
POSTGRES_DATABASE_NAME: "sonar"
2222

2323
openshift_cluster_content:
24+
- object: project
25+
content:
26+
- name: sonar project
27+
file: "{{ playbook_dir}}/files/project.yml"
28+
tags:
29+
- project
30+
- object: user-groups
31+
content:
32+
- name: group-admin-members
33+
file: "{{ playbook_dir}}/files/sonarqube-admin-group.yml"
34+
namespace: "{{ ci_cd_namespace }}"
35+
tags:
36+
- users_and_groups
37+
- name: group-view-members
38+
file: "{{ playbook_dir}}/files/sonarqube-user-group.yml"
39+
namespace: "{{ ci_cd_namespace }}"
40+
tags:
41+
- users_and_groups
2442
- object: build
2543
content:
2644
- name: sonarqube

example/run.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
set -x
44
set -e
55

6+
rm -rf /opt/sonarqube/data/plugins/sonar-auth-openshift-plugin*.jar
7+
68
## If the mounted data volume is empty, populate it from the default data
79
cp -a /opt/sonarqube/data-init/* /opt/sonarqube/data/
810

@@ -25,4 +27,4 @@ fi
2527

2628
java -jar lib/sonar-application-$SONAR_VERSION.jar \
2729
-Dsonar.web.javaAdditionalOpts="${SONARQUBE_WEB_JVM_OPTS} -Djava.security.egd=file:/dev/./urandom" \
28-
"$@"
30+
"$@"

example/sonar.properties

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
sonar.log.console=true
2-
sonar.jdbc.username=${env:JDBC_USERNAME}
3-
sonar.jdbc.password=${env:JDBC_PASSWORD}
4-
sonar.jdbc.url=${env:JDBC_URL}
5-
sonar.forceAuthentication=${env:FORCE_AUTHENTICATION}
6-
sonar.authenticator.createUsers=${env:SONAR_AUTOCREATE_USERS}
7-
sonar.log.level=${env:SONAR_LOG_LEVEL}
8-
http.proxyHost=${env:PROXY_HOST}
9-
http.proxyPort=${env:PROXY_PORT}
10-
http.proxyUser=${env:PROXY_USER}
11-
http.proxyPassword=${env:PROXY_PASSWORD}
12-
kubernetes.service=https://${env:KUBERNETES_SERVICE_HOST}:${env:KUBERNETES_SERVICE_PORT}/
13-
sonar.auth.openshift.isEnabled=true
14-
sonar.auth.openshift.button.color=#000000
1+
sonar.log.console=true
2+
sonar.jdbc.username=${env:JDBC_USERNAME}
3+
sonar.jdbc.password=${env:JDBC_PASSWORD}
4+
sonar.jdbc.url=${env:JDBC_URL}
5+
sonar.forceAuthentication=${env:FORCE_AUTHENTICATION}
6+
sonar.authenticator.createUsers=${env:SONAR_AUTOCREATE_USERS}
7+
sonar.log.level=${env:SONAR_LOG_LEVEL}
8+
http.proxyHost=${env:PROXY_HOST}
9+
http.proxyPort=${env:PROXY_PORT}
10+
http.proxyUser=${env:PROXY_USER}
11+
http.proxyPassword=${env:PROXY_PASSWORD}
12+
kubernetes.service=https://${env:KUBERNETES_SERVICE_HOST}:${env:KUBERNETES_SERVICE_PORT}/
13+
sonar.auth.openshift.isEnabled=true
14+
sonar.auth.openshift.button.color=#000000
15+
sonar.auth.openshift.sar.groups=sonarqube_admin=sonar-administrators,sonarqube_user=sonar-users
16+
ignore.certs=false
17+
#oauth.cert=/opt/sonarqube/conf/oauth.crt
18+

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>org.sonarsource.auth.openshift</groupId>
88
<artifactId>sonar-auth-openshift-plugin</artifactId>
99
<packaging>sonar-plugin</packaging>
10-
<version>1.0.0</version>
10+
<version>1.1.0</version>
1111

1212
<name>OpenShift Authentication for SonarQube</name>
1313
<description><![CDATA[

0 commit comments

Comments
 (0)