Skip to content

Instantly share code, notes, and snippets.

@peterjenkins1
Last active August 12, 2020 18:31
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save peterjenkins1/8f8bdbc82669314f7a2cc392f48be6a0 to your computer and use it in GitHub Desktop.
Save peterjenkins1/8f8bdbc82669314f7a2cc392f48be6a0 to your computer and use it in GitHub Desktop.
Harden Jenkins with groovy
// Harden Jenkins and remove all the nagging warnings in the web interface
import jenkins.model.Jenkins
import jenkins.security.s2m.*
Jenkins jenkins = Jenkins.getInstance()
// Disable remoting
jenkins.getDescriptor("jenkins.CLI").get().setEnabled(false)
// Enable Agent to master security subsystem
jenkins.injector.getInstance(AdminWhitelistRule.class).setMasterKillSwitch(false);
// Disable jnlp
jenkins.setSlaveAgentPort(-1);
// Disable old Non-Encrypted protocols
HashSet<String> newProtocols = new HashSet<>(jenkins.getAgentProtocols());
newProtocols.removeAll(Arrays.asList(
"JNLP3-connect", "JNLP2-connect", "JNLP-connect", "CLI-connect"
));
jenkins.setAgentProtocols(newProtocols);
jenkins.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment