SHARE
TWEET

Untitled

a guest Jan 25th, 2019 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!groovy
  2.  
  3. import jenkins.model.*
  4. import hudson.security.*
  5. import jenkins.security.s2m.AdminWhitelistRule
  6. import hudson.security.csrf.DefaultCrumbIssuer
  7. import jenkins.security.s2m.AdminWhitelistRule
  8.  
  9. def instance = Jenkins.getInstance()
  10.  
  11.  
  12. //
  13. // Automate Admin Setup & Plugin Installs
  14.  
  15. def user = new File("/tmp/user").text.trim()
  16. def pass = new File("/tmp/pass").text.trim()
  17.  
  18. // Create Admin User
  19. def hudsonRealm = new HudsonPrivateSecurityRealm(false)
  20. hudsonRealm.createAccount(user, pass)
  21. instance.setSecurityRealm(hudsonRealm)
  22.  
  23. // Set Auth to Full Control Once Logged In
  24. def strategy = new FullControlOnceLoggedInAuthorizationStrategy()
  25. instance.setAuthorizationStrategy(strategy)
  26.  
  27.  
  28. //
  29. // Lock Down Jenkins Security
  30.  
  31. instance.getInjector().getInstance(AdminWhitelistRule.class).setMasterKillSwitch(false)
  32.  
  33. // Disable remoting
  34. instance.getDescriptor("jenkins.CLI").get().setEnabled(false)
  35.  
  36. // Enable Agent to master security subsystem
  37. instance.injector.getInstance(AdminWhitelistRule.class).setMasterKillSwitch(false);
  38.  
  39. // Disable jnlp
  40. instance.setSlaveAgentPort(-1);
  41.  
  42. //  CSRF Protection
  43. instance.setCrumbIssuer(new DefaultCrumbIssuer(true))
  44.  
  45. // Disable old Non-Encrypted protocols
  46. HashSet<String> newProtocols = new HashSet<>(instance.getAgentProtocols());
  47. newProtocols.removeAll(Arrays.asList(
  48.         "JNLP3-connect", "JNLP2-connect", "JNLP-connect", "CLI-connect"
  49. ));
  50. instance.setAgentProtocols(newProtocols);
  51.  
  52. instance.save()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top