tl;dr
dockerでjenkinsを立ち上げた時点でgoogle login pluginが有効になった状態にした
他の認証に関しては調べてないけど多分なんでもできる
概要
dockerで簡単にjenkinsが立ち上がるのはいいんだけど
ユーザとか初期設定がめんどくさいのでそれもDockerfileに含めちゃう。
- plugins.txt書いてDockerbuild時に必要なjenkins pluginを入れておく
- 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