LoginSignup
0
4

More than 5 years have passed since last update.

SonarQubeコンテナの認証をAD連携させる

Posted at

SonarQubeコンテナの認証をActiveDirectory連携させる方法です。
ADに関する各種設定値は、sonar.propertiesを変更するのではなく、コンテナ起動時の環境変数に設定することで実現させました。

動作環境

以下の環境下で動作確認しています。

  • Docker
    • 17.12.0-ce
  • Docker Compose
    • 1.18.0
  • SonarQube
    • 7.0 / 6.6
  • SonarQube LDAP Plugin
    • 2.2.0.608

事前準備

LDAPプラグインはバンドルされていないので、事前にダウンロードしてDockerサーバに配置しておきます。

LDAPプラグインダウンロード

イメージビルド

  • Dockerファイルを作ります。
Dockerfile
FROM sonarqube:7.0

# plugin install
COPY sonar-ldap-plugin-2.2.0.608.jar /opt/sonarqube/extensions/plugins
  • ビルドします。
cp -p /xxx/sonar-ldap-plugin*.jar ./
docker build -f ./Dockerfile -t sonarqube:7.0-1.0 .

コンテナ起動

  • 以下のようなcomposeファイルを作ります。データ永続化はしてないので必要に応じて修正を加えてください。
docker-compose.yml
version: '3'

services:

  test_sonarqube:
    image: sonarqube:7.0-1.0
    ports:
      - 9000:9000
    depends_on:
      - test_sq_mysql
    environment:
      - SONARQUBE_JDBC_USERNAME=sonar
      - SONARQUBE_JDBC_PASSWORD=sonar
      - SONARQUBE_JDBC_URL=jdbc:mysql://test_sq_mysql:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
      - LDAP_HOST=ldap://[YOUR LDAP HOSTNAME]:[YOUR LDAP PORT]
      - LDAP_USER_BASE_DN=CN=[YOUR AD CN],DC=[YOUR AD DC],DC=[YOUR AD DC],DC=[YOUR AD DC]
      - LDAP_USER_REQUEST=(&(objectClass=user)(sAMAccountName={login}))
      - LDAP_BIND_DN=[YOUR LDAP USERNAME]
      - LDAP_BIND_PASSWORD=[YOUR LDAP PASSWORD]
    command: bash -c "./bin/run.sh -Dsonar.security.realm=LDAP -Dldap.url=$$LDAP_HOST -Dldap.bindDn=$$LDAP_BIND_DN -Dldap.bindPassword=$$LDAP_BIND_PASSWORD -Dldap.user.baseDn=$$LDAP_USER_BASE_DN -Dldap.user.request=$$LDAP_USER_REQUEST -Dldap.user.realNameAttribute=displayname -Dldap.user.emailAttribute=mail"

  test_sq_mysql:
    image: mysql:5.7.21
    command:
      mysqld
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_unicode_ci
      --max_allowed_packet=64MB
    environment:
      - MYSQL_DATABASE=sonar
      - MYSQL_USER=sonar
      - MYSQL_ROOT_PASSWORD=sonar
      - MYSQL_PASSWORD=sonar

動作確認

  • http://[YOUR DOCKER HOST]:9000 にアクセスし、ADユーザでログインしてください
  • SonarQubeコンテナ起動直後からADユーザでログイン可能になっているはずです
0
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
4