Skip to content
This repository has been archived by the owner on Feb 8, 2021. It is now read-only.

Commit

Permalink
modify
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowwalkersb committed Aug 3, 2019
1 parent 74297e4 commit 7b88206
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions jenkins/security.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@

import jenkins.model.*
import hudson.security.*
import jenkins.security.s2m.AdminWhitelistRule
import jenkins.install.InstallState

def instance = Jenkins.getInstance()

def user = new File("/run/secrets/jenkins-user").text.trim()
def pass = new File("/run/secrets/jenkins-pass").text.trim()

def hudsonRealm = new HudsonPrivateSecurityRealm(false)
hudsonRealm.createAccount(user, pass)
instance.setSecurityRealm(hudsonRealm)
println "--> creating local user 'admin'"
// Create user with custom pass
def user = instance.getSecurityRealm().createAccount(user, pass)
user.save()

def strategy = new FullControlOnceLoggedInAuthorizationStrategy()
strategy.setAllowAnonymousRead(false)
instance.setAuthorizationStrategy(strategy)
instance.save()

Jenkins.instance.getInjector().getInstance(AdminWhitelistRule.class).setMasterKillSwitch(false)
if (!instance.installState.isSetupComplete()) {
println '--> Neutering SetupWizard'
InstallState.INITIAL_SETUP_COMPLETED.initializeState()
}

instance.save()

0 comments on commit 7b88206

Please sign in to comment.