4
4

More than 5 years have passed since last update.

Docker containerのJenkins2を最初からGoogle Login pluginが有効な状態で起動する

Posted at

tl;dr

dockerでjenkinsを立ち上げた時点でgoogle login pluginが有効になった状態にした
他の認証に関しては調べてないけど多分なんでもできる

概要

dockerで簡単にjenkinsが立ち上がるのはいいんだけど
ユーザとか初期設定がめんどくさいのでそれもDockerfileに含めちゃう。

  1. plugins.txt書いてDockerbuild時に必要なjenkins pluginを入れておく
  2. custom.groovyを書いておくと初回起動に実行してくれるのでそこに認証設定を書く

認証設定

custom.groovy

通常の認証

def instance = Jenkins.getInstance()

def hudsonRealm = new HudsonPrivateSecurityRealm(false)
hudsonRealm.createAccount("hoge","your_password")
instance.setSecurityRealm(hudsonRealm)
instance.save()

Google Login plugin

GCPでclientIDの作成とかcallback uriの設定とかは済んでる前提

def instance = Jenkins.getInstance()

// google login settings
def clientId = "YOUR_GOOGLE_APP_CLIENT_ID"
def clientSecret = "YOUR_GOOGLE_APP_SECRET"
def domain = "google.com"

def googleRealm = new GoogleOAuth2SecurityRealm(clientId, clientSecret, domain)
instance.setSecurityRealm(googleRealm)
instance.save()

権限設定

このままだとユーザーは存在するが何の権限もない何もできないユーザなので
permissionを設定する。

def strategy = new GlobalMatrixAuthorizationStrategy()
strategy.add(Jenkins.ADMINISTER, "sho20100@gmail.com")
instance.setAuthorizationStrategy(strategy)
instance.save()

参考資料

google login pluginの設定例
https://github.com/ridecharge/curbkins/blob/master/src/main/groovy/com/gocurb/curbkins/jobs/InstanceSecurity.groovy

LDAP認証とかPermissionを細く設定してる
https://github.com/hayderimran7/useful-jenkins-groovy-init-scripts/blob/master/init.groovy

4
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
4
4