Git Product home page Git Product logo

jenkins-cas-plugin's Introduction

Jenkins Plugin Jenkins Plugin installs Build Status

Jenkins CAS Plugin

This is a Jenkins plugin providing authentication with CAS, with Single Sign-On (SSO) and Single Logout (SLO) support.

Installation

The latest version is available for download from the Update Center and from the Download Site.

Upgrade notice

  • Jenkins 2.266 and higher require CAS plugin version 1.5.0 or higher.
  • Jenkins 2.265 and lower require CAS plugin version 1.4.3 (1.5.0 is NOT compatible).
  • Jenkins 2.160 or 2.150.2 LTS and higher require CAS plugin version 1.4.3.

In these cases, you will need to upgrade Jenkins and CAS plugin together to avoid issues. This means manually downloading and updating the cas-plugin.hpi file in your Jenkins plugins directory (rename to cas-plugin.jpi as needed).

Building from source

  1. Checkout or download the source code from the current master or latest tag on GitHub.
  2. Execute mvn clean verify from your local source code folder (install Maven if not already done).
  3. Find the cas-plugin.hpi file in the target subfolder.
  4. Upload it to Jenkins from the Advanced tab of the Manage Plugins page.

Setup

Basic Setup

  1. Install the plugin from Manage Jenkins > Manage Plugins > Available > CAS Plugin.
  2. Go to Manage Jenkins > Configure Global Security, check Enable Security and select CAS (Central Authentication Service) as the Security Realm.
  3. Next to CAS Server URL, enter the base URL to your CAS server, e.g. https://cas.example.com/cas
  4. Next to CAS Protocol, select the protocol to use to communicate with CAS, e.g. SAML 1.1 if you are using Apereo CAS Server 3.x or higher, or CAS 3.0 if you are using Apereo CAS Server 4.x or higher.
  5. If there are no warnings, click the Save button at the bottom and attempt logging in.

Advanced Setup

Additional configuration options are available under the Security Realm section:

  • Force authentication renewal: when checked, Single Sign-On (SSO) is disabled: even if a CAS session is already open, the user will have to provide credentials again to confirm his/her identity.
  • Use CAS REST API for external/scripted clients: when checked, the CAS REST API will be used to authenticate Jenkins API requests (in addition to Jenkins API keys) using a username/password.
  • Process Single Logout (SLO) requests from CAS: when checked, Single Logout is enabled: whenever the user logs out of CAS (e.g. when logging out of another CAS-enabled application), the corresponding Jenkins session will be destroyed and the local user logged out as well. Note that for this to work, the CAS server must be able to communicate with Jenkins using the service URL that was passed to it during login.
  • Logout from CAS when logging out of Jenkins: when checked, Jenkins will redirect to CAS after logging out the local user, in order to destroy the SSO session.

Several protocols implemented by CAS are available in the CAS Protocol dropdown (click the Advanced... button to reveal more options):

  • CAS 1.0: a text-based legacy protocol. Custom extensions may provide support for roles, which can be parsed with a Groovy script specified in Roles Validation Script.
  • CAS 2.0: a XML-based protocol. It supports Proxy Tickets, allowing external applications already secured with CAS to authenticate in Jenkins without requiring user input or password. Custom extensions may provide support for attributes.
  • CAS 3.0: a XML or JSON-based protocol. It supports Proxy Tickets, allowing external applications already secured with CAS to authenticate in Jenkins without requiring user input or password. It fully supports attributes out-of-the-box, without requiring custom extensions. This is a recommended protocol for Apereo CAS Server 4.x and higher.
  • SAML 1.1: a XML-based protocol. It fully supports attributes out-of-the-box, without requiring custom extensions. This is a recommended protocol for Apereo CAS Server 3.x and higher.

Attributes are an easy (and recommended) way to add full name and email address information to an authenticated user, as well as roles/groups membership. CAS 1.0 response parsing with a custom Groovy script is made available as a legacy option for backward compatibility with the CAS1 Plugin.

Usage

Access from external/scripted clients

By default, when using the CAS plugin for authentication, you cannot use a regular username/password for remote authentication into Jenkins. This is by design, as the CAS protocol does not allow "direct" authentication and works with secure redirections, which are not compatible with remote calls such as SVN or GitHub hooks.

You have two options:

  • Use the user's API token as the password; you can find it by going to the Configuration page of the Jenkins user you intend to use for external access. This API token does not expire and you may regenerate it as you need.
  • Enable the REST API option in the plugin configuration, to use the CAS REST API to process the real username/password. The CAS REST protocol must be enabled server-side for this option to work.

See the following page for more information: Authenticating scripted clients

Jenkins URL when used behind a reverse proxy

When using Jenkins behind a reverse proxy, depending on configuration the URL users get redirected to after authentication may be wrong. If this is the case:

  1. Go to Manage Jenkins > Configure System.
  2. Under Jenkins Location, make sure the Jenkins URL is valid and can be reached by users. It will be used by CAS to redirect back to Jenkins after authentication.

Troubleshooting

SSL certificate issues

Please see the Troubleshooting Guide from the CAS Project.

Issue validating SAML 1.1 tickets

If Jenkins systematically fails to validate SAML 1.1 tickets, make sure to check whether the system clock of your Jenkins and CAS servers are synchronized. Indeed, the timestamp at which SAML 1.1 tickets were generated is checked when validating them, with a configurable tolerance (see "Time Tolerance" plugin option). Out-of-sync clocks may log errors such as "skipping assertion that's not yet valid" in Jenkins.

Failure to authenticate external/scripted clients

By default, using normal username/password is not possible from external/scripted clients when using CAS. You may use an API token instead and/or enable the REST API support. See "Usage" section above for more details.

Missing group memberships when logging with external/scripted clients

This issue (JENKINS-20064) is fixed in Jenkins 1.556 and higher, provided that the user logged in through the web interface at least once. This limitation does not apply when the REST API option is enabled along with the real username/password.

Invalid Jenkins URL after logging in through CAS

If Jenkins is behind a reverse proxy, it may not be able to detect its own URL by itself. In this case, you need to manually configure the Jenkins URL. See "Usage" section above for a solution.

Documentation

jenkins-cas-plugin's People

Contributors

daniel-beck avatar daniel-beck-bot avatar dodok1 avatar fcrespel avatar jdbeutel avatar jglick avatar mabes avatar sdorra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jenkins-cas-plugin's Issues

Invalid property 'casServerUrlPrefix' of bean class [org.jasig.cas.client.session.SingleSignOutHandler]

In accordance with the use of plug-in configuration, the results reported the following error, what should I do

/root/.jenkins/config.xml
<securityRealm class="org.jenkinsci.plugins.cas.CasSecurityRealm" plugin="[email protected]"> <casServerUrl>https://cas.***.net/cas/</casServerUrl> <casProtocol class="org.jenkinsci.plugins.cas.protocols.Cas20Protocol"> <authoritiesAttribute>groups,roles</authoritiesAttribute> <fullNameAttribute>cn</fullNameAttribute> <emailAttribute>mail</emailAttribute> <proxyEnabled>false</proxyEnabled> <proxyAllowAny>false</proxyAllowAny> <proxyAllowList></proxyAllowList> </casProtocol> <forceRenewal>false</forceRenewal> <enableSingleSignOut>false</enableSingleSignOut> <enableRestApi>false</enableRestApi> </securityRealm>

hudson.util.HudsonFailedToLoad: org.jvnet.hudson.reactor.ReactorException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'casFilter': Cannot create inner bean '(inner bean)' of type [org.jenkinsci.plugins.cas.spring.security.CasSingleSignOutFilter] while setting bean property 'filters' with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1': Cannot create inner bean '(inner bean)' of type [org.jasig.cas.client.session.SingleSignOutHandler] while setting bean property 'singleSignOutHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'casServerUrlPrefix' of bean class [org.jasig.cas.client.session.SingleSignOutHandler]: Bean property 'casServerUrlPrefix' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at hudson.WebAppMain$3.run(WebAppMain.java:248)
Caused by: org.jvnet.hudson.reactor.ReactorException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'casFilter': Cannot create inner bean '(inner bean)' of type [org.jenkinsci.plugins.cas.spring.security.CasSingleSignOutFilter] while setting bean property 'filters' with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1': Cannot create inner bean '(inner bean)' of type [org.jasig.cas.client.session.SingleSignOutHandler] while setting bean property 'singleSignOutHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'casServerUrlPrefix' of bean class [org.jasig.cas.client.session.SingleSignOutHandler]: Bean property 'casServerUrlPrefix' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.jvnet.hudson.reactor.Reactor.execute(Reactor.java:269)
at jenkins.InitReactorRunner.run(InitReactorRunner.java:47)
at jenkins.model.Jenkins.executeReactor(Jenkins.java:1109)
at jenkins.model.Jenkins.(Jenkins.java:925)
at hudson.model.Hudson.(Hudson.java:85)
at hudson.model.Hudson.(Hudson.java:81)
at hudson.WebAppMain$3.run(WebAppMain.java:231)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'casFilter': Cannot create inner bean '(inner bean)' of type [org.jenkinsci.plugins.cas.spring.security.CasSingleSignOutFilter] while setting bean property 'filters' with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1': Cannot create inner bean '(inner bean)' of type [org.jasig.cas.client.session.SingleSignOutHandler] while setting bean property 'singleSignOutHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'casServerUrlPrefix' of bean class [org.jasig.cas.client.session.SingleSignOutHandler]: Bean property 'casServerUrlPrefix' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:230)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:122)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:287)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:126)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at hudson.util.spring.DefaultRuntimeSpringConfiguration.getApplicationContext(DefaultRuntimeSpringConfiguration.java:94)
at hudson.util.spring.BeanBuilder.createApplicationContext(BeanBuilder.java:391)
at org.jenkinsci.plugins.cas.CasSecurityRealm.getApplicationContext(CasSecurityRealm.java:151)
at org.jenkinsci.plugins.cas.CasSecurityRealm.createFilter(CasSecurityRealm.java:230)
at hudson.security.HudsonFilter.reset(HudsonFilter.java:144)
at jenkins.model.Jenkins.setSecurityRealm(Jenkins.java:2514)
at jenkins.model.Jenkins$19.run(Jenkins.java:3109)
at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:169)
at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:282)
at jenkins.model.Jenkins$7.runTask(Jenkins.java:1085)
at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:210)
at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1': Cannot create inner bean '(inner bean)' of type [org.jasig.cas.client.session.SingleSignOutHandler] while setting bean property 'singleSignOutHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'casServerUrlPrefix' of bean class [org.jasig.cas.client.session.SingleSignOutHandler]: Bean property 'casServerUrlPrefix' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:230)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:122)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:219)
... 32 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'casServerUrlPrefix' of bean class [org.jasig.cas.client.session.SingleSignOutHandler]: Bean property 'casServerUrlPrefix' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1279)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:219)
... 40 more
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'casServerUrlPrefix' of bean class [org.jasig.cas.client.session.SingleSignOutHandler]: Bean property 'casServerUrlPrefix' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:801)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:651)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1276)
... 46 more

Upgrading to Jenkins 2.160 breaks CAS logins

Upgrading to Jenkins 2.160 (from 2.159) causes CAS logins to fail with an infinite loop, as Jenkins does not respect the result of the authorization flow. To reproduce:

  • Start with a working Jenkins 2.159 and CAS Plugin
  • Upgrade to Jenkins 2.160
  • Try logging back in and observe that you're thrown into an infinite loop

Note:

  • I'm running Jenkins behind nginx.
  • This update procedure has never previously failed.
  • Jenkins 2.160 introduces an obvious related change.
  • The problem persists even after clearing cookies.
  • Downgrading from 2.160 to 2.159 fixes the problem.

Recent cas upgrade break the connexion

Hi,

Thanks for your plugin, we've been using it without any issue for a long time. Recently we've upgraded CAS to the 6.6.7 release.
It's placed behind an apache RP and is using ldap as a athentication source.
The attribute cn is exposed and also configured in jenkins 2.405 and I'm experiencing something that looks like #9 (comment)

here is the log I have in jenkins :

2023-05-25 19:21:19.974+0000 [id=35604]        SEVERE        o.j.cas.client.util.CommonUtils#getResponseFromServer: Error getting response from host: [cas.....] with path: [/cas/p3/serviceValidate] and protocol: [https] Error Message: Server returned HTTP response code: 403 for URL: https://cas...../cas/p3/serviceValidate?ticket=ST-33-????????-sso&service=https%3A%2F%2Fjenkins.tld%2FsecurityRealm%2FfinishLogin
mai 25 19:21:19 jenkins jenkins[647557]: java.io.IOException: Server returned HTTP response code: 403 for URL: https://cas..../cas/p3/serviceValidate?ticket=ST-33-????????-sso&service=https%3A%2F%2Fjenkins.tld%2FsecurityRealm%2FfinishLogin
mai 25 19:21:19 jenkins jenkins[647557]:         at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1924)

could you tell me how to help you to identify what's going on ?
Regards

how to set the ignorePattern parameter?

CAS official client provides the parameter ignorePattern but our plug-in does not provide

ignorePattern | Defines the url pattern to ignore, when intercepting authentication requests.

API token failure authentication using some jenkins ruby library

Hi,

when authenticating against the jenkins users db using an api token everything works as it should. But when we enable the jenkins-cas plugin https://wiki.jenkins-ci.org/display/JENKINS/CAS+Plugin and we try to use the https://github.com/arangamani/jenkins_api_client it spaws some error:

ERROR -- : JenkinsApi::Exceptions::Forbidden: Access denied. Please ensure that Jenkins is set up to allow access to this operation.

Any ideas what I'm doing wrong?

Compilation fails with latest version of jenkins

I'm using the latest git version.

If I change the parent version in the pom:

<parent>
    <groupId>org.jenkins-ci.plugins</groupId>
    <artifactId>plugin</artifactId>
    <version>1.640</version>
</parent>

I get:

[ERROR] /private/tmp/cas-plugin/src/main/java/org/jenkinsci/plugins/cas/spring/CasEventListener.java:[3,19] error: cannot find symbol

with a mvn clean package

If I add:

    <dependency>
        <groupId>org.jvnet.hudson.main</groupId>
        <artifactId>hudson-core</artifactId>
        <scope>provided</scope>
        <version>2.2.1</version>
    </dependency>

I'm getting

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] error: javax.annotation.processing.FilerException: Attempt to reopen a file for path /private/tmp/cas-plugin/target/classes/org/jenkinsci/plugins/cas/protocols/Cas20Protocol.stapler
[INFO] 1 error
[INFO] -------------------------------------------------------------

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.