Is it possible to get Jenkins password in build job - jenkins

I am not sure if this was already asked/ discussed before.
In my Jenkins, I have setup LDAP authentication and that password is required in one of my jobs to remotely login to a different server using that password and execute some tasks there
Assume the remote task is executed via sshexec in ant task which requires username password. I dont want the user to enter the password again in the form of a build paramater, is there a way to get the password used for Jenkins authentication inside the build job ???

[I]s there a way to get the password used for Jenkins authentication inside the build job?
Not as such. Jenkins does not retain the password after you log in, it simply passes it to the LDAP server long enough to verify that you should be authenticated.
So what you need is to define Credentials persisted in Jenkins that can be used during a build. You can use the Credentials Binding plugin to set up a fixed username/password which the job will have access to.
If your requirement is for the credentials to not be available for any build of the job, but instead that a user manually initiating the build should have to supply them (meaning that scheduled or otherwise triggered builds are impossible), I think this is also supported as of version 1.1. Define a parameter of credentials type for the job, to be used via variable expansion in the binding. Then have the user define these credentials in their user configuration page (/me/configure). Then when selecting Build with Parameters they should see their own personal credentials and be able to select them. The user needs the Credentials/UseOwn permission on the job.
Another option for the future would be a subtype of username/password credentials which does not store the password at all (maybe just a “salted” hash, using jBCrypt), and somehow prompts for you to enter the password before the credentials are considered valid, probably expiring after a few minutes. This mode has not been implemented but would be useful for sites with stricter security requirements.
(Regular credentials are stored encrypted, but the default secure storage mechanism keeps the master encryption key in $JENKINS_HOME—so secure so long as you do not allow shell access to your server to anyone who is not already a Jenkins administrator, and of course so long as you configure the master computer to have zero executors so people cannot run builds on it, only on slaves. Another RFE would be an alternate storage mechanism that allows the master key to be injected by some other means.)

The best possible way to do is to allow permission to jenkins user in the remote server.

Related

Jenkins miniOrange SAML 2.0 failed login

I have installed and configured miniorange plugin following exactly this setup: https://plugins.miniorange.com/saml-single-sign-on-sso-into-jenkins-using-google-apps-g-suite-as-idp#1549619168146-1d45d518-daa7. Google Apps are redirecting me to my instance, but when I try to log in, it says:
More than one user found with this email address.
Any ideas why this is happening?
Error itself stating the solution. Same user can be somewhere else in your Jenkins configuration. To be specific, check your "People" and "Jenkins owned database Users", You will get same user in both pools but possibly with different name. So remove one of them or specifically user that you or admin created in Jenkins Own Database and try.
In "People" pool you will get users those are participating or contributing in triggering Jobs(either by Github commit or other mode) and Jenkins captures the UserID. So keep this UserID as your desired user name and set your authorization or permission in "Matrix based authorization".

jenkins api authentication failure

I am using oauth authentication for jenkins. I can successfully make api calls if i use my_user_name:api_token when my user name is explicitly configure in global security. It fails when my user name does not exist but a group which contains the user name and has all permissions.
Any idea about this phenomenon ?
thanks in advance
The Jenkins api-token is obtained for a specific user http://<jenkins-server>/user/<username>/configure and can be used for that same user only.

Issue with jenkins security

I installed a fresh copy of jenkins 1.609 and configured one job (I had multiple instances of previous jenkins versions earlier). I wanted to protect this instance, in particular protect the jobs and everything, since it runs on the internet.
When I activate security, and check jenkins-own user database checkbox as well as logged-in users can do everything checkbox and save it, it seems to have no effect, as anonymous user is still able to access the job and the workspace of the job.
When I active use-matrix-based security and give my user admin (actually all) rights, the job isn't visible anymore, but I lose all privileges and I see
<username> is missing the Overall/Administer permission
immediately. After that I have no access to administration overview anymore.
So question from my side, what should I choose if I want the anonymous user to see a blank page, and logged in user to do everything.
The solution is choose the "Matrix-based security" option with the configuration below:
Then, you just have to set the relevant permissions to authenticated users.
Anonymous users will not be able to access your Jenkins server :)

How to setup credentials for every project in Jenkins?

I have some 10 projects in my Jenkins , each for 10 different clients . So i need to create credentials for all my projects , so that each client can access only their project .
Is there any plugin to achieve my requirement .??
Please Help !!!
Select "Project-based Matrix Authorization Strategy" under Global Security
Define general users, without access to projects at this level.
Then on per-project select "Enable project-based security", and here you can give individual users addition permissions, such as ability to view and execute the job
Edit:
In Configure Global Security, under Project-based Matrix Authorization:
Make sure Anonymous and Authenticated don't have any other permissions.
Give Anonymous:
Job Discover (this will redirect non-logged in users to login page).
Give Authenticated:
Overall Read (without this permission, nothing else will work).
View Read, optional (without this, they won't see custom views, just the 'all view').
Save configuration
In Job Configuration, under Enable project-based security:
Give client1:
Job Read (this will allow to view this particular job, and nothing else).
Give additional permissions as required (build, workspace, promote, etc).
Save configuration

Adding "bot" credentials to jenkins when using Unix user/group database

We're using Jenkins server (v. 1.571) with the following authorization configuration:
Security Realm: Unix user/group database.
Authorization: Matrix-based security
up until now, each member of our team used its private credentials to login and perform operations on this server.
We want to enable bot scripts to login to the server with "global" credentials and perform some of these operations, without changing the current credentials of the users (and hopefully, don't touch the current authorization guidelines).
How can this be achieved?
thanks!
You can check Mask Passwords Plugin. It provides you the option to define user and password in Manage Hudson > Configure System section. To add to it, as the name suggests, the password will be masked in the console output. Even in the Configure section where you create user and password, the password will remain in masked state.

Resources