forked from cloudbees/jenkins-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setCjocSecurity.groovy
36 lines (30 loc) · 1.89 KB
/
setCjocSecurity.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import jenkins.model.GlobalConfiguration
import com.cloudbees.opscenter.server.security.SecurityEnforcer
import com.cloudbees.opscenter.server.sso.SecurityEnforcerImpl
import com.cloudbees.opscenter.server.security.RestrictedEquivalentRAMF
/*
Author: Philip Cheong
This script will set the Security Setting Enforcement to Single Sign-On (security realm and authorization strategy)
The authentication mapping can be changed from RestrictedEquivalentRAMF to either TrustedEquivalentRAMF
or UntrustedEquivalentRAMF
It will also enforce all the security policies such as preventing XSS
javadoc to help understand this code:
https://repo.cloudbees.com/content/repositories/dev-connect/com/cloudbees/operations-center/server/operations-center-sso/2.222.0.2/operations-center-sso-2.222.0.2-javadoc.jar
https://repo.cloudbees.com/content/repositories/dev-connect/com/cloudbees/operations-center/server/operations-center-server/2.222.0.2/operations-center-server-2.222.0.2-javadoc.jar
*/
// get the current global security config
SecurityEnforcer.GlobalConfigurationImpl secEnfImpl = GlobalConfiguration.all().get(SecurityEnforcer.GlobalConfigurationImpl.class)
// There appear to be 3 different options that we can set using the SSO plugin.
secEnfImpl.setGlobal(new SecurityEnforcerImpl(
false, // Allow client masters to opt-out
false, // Allow per-master configuration of authentication mapping
new RestrictedEquivalentRAMF())) // or TrustedEquivalentRAMF or UntrustedEquivalentRAMF
SecurityEnforcer secEnf = SecurityEnforcer.getCurrent()
// Enforce Cross Site Request Forgery exploits prevention settings
secEnf.setCrumbIssuer(true)
// Enforce markup formatter settings
secEnf.setMarkupFormatter(true)
// Enforce slave → master security settings
secEnf.setMasterKillSwitch(true)
// Enforce remember me settings
secEnf.setRememberMe(true)