-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace EOL Google Oauth library #409
Conversation
src/main/java/org/jenkinsci/plugins/oic/OicServerWellKnownConfiguration.java
Outdated
Show resolved
Hide resolved
src/main/java/org/jenkinsci/plugins/oic/OicServerWellKnownConfiguration.java
Outdated
Show resolved
Hide resolved
import jenkins.security.FIPS140; | ||
|
||
@SuppressFBWarnings(value = "WEAK_TRUST_MANAGER", justification = "Opt in by user") | ||
final class AnythingGoesTrustManager implements X509TrustManager { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are enough of these in all plugins this should really be in Jenkins core.
* {@link HostnameVerifier} that accepts any presented hostanme including incorrect ones. | ||
*/ | ||
@Restricted(NoExternalUse.class) | ||
public final class IgnoringHostNameVerifier implements HostnameVerifier { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, enough plugins use something like this that it should be offered from Jenkins core.
+ "\"token_endpoint\":\"http://localhost:%1$d/token\"," | ||
+ "\"userinfo_endpoint\":\"http://localhost:%1$d/user\"," | ||
+ "\"jwks_uri\":\"http://localhost:%1$d/jwks\"," | ||
+ "\"scopes_supported\": null," |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the OpenID spec says if something is empty is it ommitted completely and does not contain "null"
may as well say we support the default.
} | ||
|
||
flow.createAndStoreCredential(response, null); | ||
public void doCommenceLogin(@QueryParameter String from, @Header("Referer") final String referer) |
Check warning
Code scanning / Jenkins Security Scan
Stapler: Missing POST/RequirePOST annotation Warning
src/main/java/org/jenkinsci/plugins/oic/ProxyAwareResourceRetriever.java
Dismissed
Show resolved
Hide resolved
@@ -1,6 +1,11 @@ | |||
<?jelly escape-by-default='true'?> | |||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> | |||
|
|||
|
|||
<f:entry title="${%Issuer}" field="issuer"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved up as it is now mandatory to make it more prominent vs the other fields.
pom.xml
Outdated
<jenkins.version>2.426.3</jenkins.version> | ||
<spotless.check.skip>false</spotless.check.skip> | ||
<spotbugs.effort>Max</spotbugs.effort> | ||
<configuration-as-code.version>1836.vccda_4a_122a_a_e</configuration-as-code.version> | ||
<hpi.compatibleSinceVersion>4.347</hpi.compatibleSinceVersion> | ||
<hpi.compatibleSinceVersion>4.356</hpi.compatibleSinceVersion> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be checked and updated before final merge.
src/main/java/org/jenkinsci/plugins/oic/OicServerWellKnownConfiguration.java
Outdated
Show resolved
Hide resolved
a8f5665
to
3fec21b
Compare
src/main/java/org/jenkinsci/plugins/oic/OicSecurityRealm.java
Dismissed
Show dismissed
Hide dismissed
src/main/java/org/jenkinsci/plugins/oic/OicSecurityRealm.java
Dismissed
Show dismissed
Hide dismissed
} | ||
|
||
private OidcConfiguration buildOidcConfiguration() { | ||
// TODO cache this and use the well known if available. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for a future PR. We can cache the client and invalidate it every 1 hour if using the well-known (as the well known refresh is now hard coded to 1hr).
// TODO what do we prefer? | ||
// conf.setPreferredJwsAlgorithm(JWSAlgorithm.HS256); | ||
// set many more as needed... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not intending for this to happen in this PR but a follow-up that exposes some more advanced options.
e.g. #408
This changes the Google OAuth library which is in maintainance mode with a supported library (nimbusds via pac4j) The library requires that the Issuer is set to enforce security and there is no option to disable this requirement as it is mandated in the specificiation. As such users must first update to 4.355.v3a_fb_fca_b_96d4 to set the Issuer before updating to this version. fixes: jenkinsci#313
The option is not removed here, so that it can staty in the config. This will at least allow users to downgrade as the option would be retained.
fixing the NPE, shows there is another more serious issue here, the token validator is used to cehck the id token when refreshing (actually creating a new!) Profile.
This appears to be a bug with pac4j. We ae not using the latest version as that requires java17 which is not required for Jenkins prior to |
Pac4j setups the token validators, which during the refresh lifecycle will attempt to check an ID tokens nonce. However a provider should not set the nonce in the idtoken during a refresh, and in this case the validator fails because the nonce is missing from the token! we disable the nonce check for the refresh call. it can be optionally re-enabled by setting the system property org.jenkinsci.plugins.oic.OicSecurityRealm.checkNonceInRefreshFlow to true. this is not exposed as a config option in the UI as 1) providers should not be sending the nonce anyway 2) this should be a short lived workaround whilst the issue with the library is filed and fixed.
workaround added in fb4ce0c @fcojfernandez is attempting to reproduce this with pac4j v6 to either upgrade or file a report upstream |
For extra security disable the "none" algorithm if the server claims to support it. Whilst we are using code flow, it is not needed, but providers MUST support RS256 so there would always be a more secure option we can use.
} | ||
|
||
setWellKnownExpires(response.getHeaders()); | ||
// do not allow the "none" singing algorithm for security |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whilst we are using code flow, it is not needed, but providers MUST support RS256 so there would always be a more secure option we can use.
src/main/java/org/jenkinsci/plugins/oic/OicServerManualConfiguration.java
Show resolved
Hide resolved
src/main/java/org/jenkinsci/plugins/oic/OicServerManualConfiguration.java
Outdated
Show resolved
Hide resolved
public OIDCProviderMetadata toProviderMetadata() { | ||
// we perform this download manually rather than letting pac4j perform it | ||
// so that we can cache and expire the result. | ||
// pac4j will cache the result yet never expire it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I do not think you should hesitate to switch the plugin baseline to 2.479, especially for a major change like this one. |
CustomOidcConfiguration(boolean disableTLS) { | ||
this.disableTLS = disableTLS; | ||
if (FIPS140.useCompliantAlgorithms() && disableTLS) { | ||
throw new IllegalStateException("Cannot disable TLS validation in FIPS-140 mode"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my own learning.
IllegalState instead of IllegalArgument because this is only used during login, so it means configuration was already wrong (and should have been raised when creating the realm once jtnord#1 is merged) isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and should have been raised when creating the realm once jtnord#1 is merged
correct
src/main/java/org/jenkinsci/plugins/oic/OicServerManualConfiguration.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Pere <[email protected]>
@jglick I'm doing it as part of #409 (comment) |
@michael-doubez would you like to take a look at this before I merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I played around with this locally using a keycloak
idp that i already had configured and did not encounter any issues. This change did help me uncover a misconfiguration in my security realm (disable token validation
was not checked, but no JWKS url was specified - the old code cleverly hid this from you for some reason 🥲 )
This changes the Google OAuth library which is in maintenance mode with a supported library (nimbusds via pac4j)
The change no longer determines how often to refresh the
well-known
settings (if used), they are now refreshed every hour.fixes: #313
Testing done
mvn hpi:run
(java11) against a local AD FS server (login, logout) (disable TLS verification) (well known config)mvn hpi:run
(java11) against a local AD FS server (login, logout) (trusted TLS cert) (well known config)java -jar jenkins-2.479.war --httpListenAddress=127.0.0.1 --prefix=/jenkins
(java17) against a local AD FS server (login, logout) (disable TLS verification) (well known config)JENKINS_VERSION=2.462.3 LOCAL_JARS=/path/to/oic-auth-plugin/target/oic-auth.hpi mvn -Dtest=OicAuthPluginTest
JENKINS_VERSION=2.479 LOCAL_JARS=/path/to/oic-auth-plugin/target/oic-auth.hpi mvn test -Dtest=OicAuthPluginTest
mvn hpi:run
(java11) against an AWS Cognito server (login, logout) (well known config)mvn hpi:run
(java11) against an AWS Cognito server (login, logout) (manual config)Submitter checklist