Created
March 2, 2016 06:23
-
-
Save rj-reilly/8b7068ad097c15cf51fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jenkins.model.* | |
import hudson.security.* | |
import com.cloudbees.plugins.credentials.* | |
import hudson.plugins.active_directory.* | |
def instance = Jenkins.getInstance() | |
def hudsonRealm = new ActiveDirectorySecurityRealm("domain", "site", "bindName", "bindPassword", "server", GroupLookupStrategy.CHAIN) | |
//def hudsonRealm = new HudsonPrivateSecurityRealm(false) | |
instance.setSecurityRealm(hudsonRealm) | |
def strategy = new GlobalMatrixAuthorizationStrategy() | |
// Roles based on https://wiki.jenkins-ci.org/display/JENKINS/Matrix-based+security | |
//Overall - http://javadoc.jenkins-ci.org/jenkins/model/Jenkins.html | |
strategy.add(Jenkins.ADMINISTER, "my-user") | |
strategy.add(Jenkins.READ, "my-user") | |
strategy.add(Jenkins.RUN_SCRIPTS, "my-user") | |
// Slave - http://javadoc.jenkins-ci.org/jenkins/model/Jenkins.MasterComputer.html | |
strategy.add(Jenkins.MasterComputer.BUILD, "my-user") | |
strategy.add(Jenkins.MasterComputer.CONFIGURE, "my-user") | |
strategy.add(Jenkins.MasterComputer.CONNECT, "my-user") | |
strategy.add(Jenkins.MasterComputer.CREATE, "my-user") | |
strategy.add(Jenkins.MasterComputer.DELETE, "my-user") | |
strategy.add(Jenkins.MasterComputer.DISCONNECT, "my-user") | |
// Job - http://javadoc.jenkins-ci.org/hudson/model/Item.html | |
strategy.add(Item.BUILD, "my-user") | |
strategy.add(Item.CANCEL, "my-user") | |
strategy.add(Item.CONFIGURE, "my-user") | |
strategy.add(Item.CREATE, "my-user") | |
strategy.add(Item.DELETE, "my-user") | |
strategy.add(Item.DISCOVER, "my-user") | |
strategy.add(Item.EXTENDED_READ, "my-user") | |
strategy.add(Item.READ, "my-user") | |
strategy.add(Item.WIPEOUT, "my-user") | |
strategy.add(Item.WORKSPACE, "my-user") | |
// View - http://javadoc.jenkins-ci.org/hudson/model/View.html | |
strategy.add(View.CONFIGURE, "my-user") | |
strategy.add(View.CREATE, "my-user") | |
strategy.add(View.DELETE, "my-user") | |
strategy.add(View.READ, "my-user") | |
// Run - http://javadoc.jenkins-ci.org/hudson/model/Run.html | |
strategy.add(Run.ARTIFACTS, "my-user") | |
strategy.add(Run.DELETE, "my-user") | |
strategy.add(Run.UPDATE, "my-user") | |
// Credentials - https://github.com/jenkinsci/credentials-plugin/blob/master/src/main/java/com/cloudbees/plugins/credentials/CredentialsProvider.java | |
strategy.add(CredentialsProvider.CREATE, "my-user") | |
strategy.add(CredentialsProvider.UPDATE, "my-user") | |
strategy.add(CredentialsProvider.VIEW, "my-user") | |
strategy.add(CredentialsProvider.DELETE, "my-user") | |
strategy.add(CredentialsProvider.MANAGE_DOMAINS, "my-user") | |
// Plugin Manager http://javadoc.jenkins-ci.org/hudson/PluginManager.html | |
strategy.add(PluginManager.UPLOAD_PLUGINS, "my-user") | |
strategy.add(PluginManager.CONFIGURE_UPDATECENTER, "my-user") | |
instance.setAuthorizationStrategy(strategy) | |
instance.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment