Skip to content

Commit

Permalink
Merge pull request #418 from olamy/fips-escapehatch
Browse files Browse the repository at this point in the history
[JEP-237] disable escapeHatch when Jenkins is in FIPS mode
  • Loading branch information
jtnord authored Oct 11, 2024
2 parents 5b97484 + ab4ab83 commit 2679db6
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 17 deletions.
18 changes: 17 additions & 1 deletion src/main/java/org/jenkinsci/plugins/oic/OicSecurityRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,14 @@ protected Object readResolve() throws ObjectStreamException {
this.setTokenFieldToCheckKey(this.tokenFieldToCheckKey);
// ensure escapeHatchSecret is encrypted
this.setEscapeHatchSecret(this.escapeHatchSecret);

// validate this option in FIPS env or not
try {
this.setEscapeHatchEnabled(this.escapeHatchEnabled);
} catch (FormException e) {
throw new IllegalArgumentException(e.getFormField() + ": " + e.getMessage());

Check warning on line 360 in src/main/java/org/jenkinsci/plugins/oic/OicSecurityRealm.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 359-360 are not covered by tests
}

try {
if (automanualconfigure != null) {
if ("auto".equals(automanualconfigure)) {
Expand Down Expand Up @@ -607,7 +615,10 @@ public void setPostLogoutRedirectUrl(String postLogoutRedirectUrl) {
}

@DataBoundSetter
public void setEscapeHatchEnabled(boolean escapeHatchEnabled) {
public void setEscapeHatchEnabled(boolean escapeHatchEnabled) throws FormException {
if (FIPS140.useCompliantAlgorithms() && escapeHatchEnabled) {
throw new FormException("Escape Hatch cannot be enabled in FIPS environment", "escapeHatchEnabled");
}
this.escapeHatchEnabled = escapeHatchEnabled;
}

Expand Down Expand Up @@ -1422,5 +1433,10 @@ private FormValidation doCheckFieldName(String fieldName, FormValidation validIf
public Descriptor<OicServerConfiguration> getDefaultServerConfigurationType() {
return Jenkins.get().getDescriptor(OicServerWellKnownConfiguration.class);
}

@Restricted(NoExternalUse.class) // used by jelly only
public boolean isFipsEnabled() {
return FIPS140.useCompliantAlgorithms();

Check warning on line 1439 in src/main/java/org/jenkinsci/plugins/oic/OicSecurityRealm.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 1439 is not covered by tests
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,23 @@
<f:checkbox/>
</f:entry>
</f:advanced>

<f:block>
<table>
<f:optionalBlock inline="true" title="${%ConfigureEscapeHatch}" field="escapeHatchEnabled">
<f:entry title="${%Username}" field="escapeHatchUsername">
<f:textbox/>
</f:entry>
<f:entry title="${%Secret}" field="escapeHatchSecret">
<f:password/>
</f:entry>
<f:entry title="${%Group}" field="escapeHatchGroup">
<f:textbox/>
</f:entry>
</f:optionalBlock>
</table>
</f:block>
<j:if test="${!descriptor.isFipsEnabled()}">
<f:block>
<table>
<f:optionalBlock inline="true" title="${%ConfigureEscapeHatch}" field="escapeHatchEnabled">
<f:entry title="${%Username}" field="escapeHatchUsername">
<f:textbox/>
</f:entry>
<f:entry title="${%Secret}" field="escapeHatchSecret">
<f:password/>
</f:entry>
<f:entry title="${%Group}" field="escapeHatchGroup">
<f:textbox/>
</f:entry>
</f:optionalBlock>
</table>
</f:block>
</j:if>

</f:section>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.jenkinsci.plugins.oic;

Check warning on line 1 in src/test/java/org/jenkinsci/plugins/oic/SecurityRealmConfigurationFIPSTest.java

View check run for this annotation

ci.jenkins.io / Java Compiler

checkstyle:check

ERROR: (misc) NewlineAtEndOfFile: Expected line ending for file is LF(\n), but CRLF(\r\n) is detected.

import hudson.model.Descriptor;
import org.junit.ClassRule;
import org.junit.Test;
import org.jvnet.hudson.test.FlagRule;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

public class SecurityRealmConfigurationFIPSTest {

@ClassRule
public static FlagRule<String> FIPS_RULE = FlagRule.systemProperty("jenkins.security.FIPS140.COMPLIANCE", "true");

@Test(expected = Descriptor.FormException.class)
public void escapeHatchThrowsException() throws Exception {
new OicSecurityRealm("clientId", null, null, null).setEscapeHatchEnabled(true);
}

@Test
public void escapeHatchToFalse() throws Exception {
OicSecurityRealm oicSecurityRealm = new OicSecurityRealm("clientId", null, null, null);
oicSecurityRealm.setEscapeHatchEnabled(false);
assertThat(oicSecurityRealm.isEscapeHatchEnabled(), is(false));
}

@Test
public void readresolve() throws Exception {
OicSecurityRealm oicSecurityRealm = new OicSecurityRealm("clientId", null, null, null);
oicSecurityRealm.setEscapeHatchEnabled(false);
assertThat(oicSecurityRealm.isEscapeHatchEnabled(), is(false));
oicSecurityRealm.readResolve();
}
}

0 comments on commit 2679db6

Please sign in to comment.