How to hide passwords on Jenkins console output? - jenkins

I have a job to be triggered by developers where they have to put their AD's before triggering build. But thoes passwords are displayed on console output. I have tried mask passwords plugin. But the problem is I cannot store all developers AD's in job configuration.
Please suggest me any solution.

Please find below my findings with solution [without using Mask Passwords plugin]:
Brief Description about my jenkins job:
I wrote a job which downloads the artifacts from Nexus based on the parameters given at run-time and then makes a Database SQL connection and deploy the SQL scripts using maven flyway plugin. My job takes - Environment, Database Schema, Artifact version number, Flyway command, Database User and it's password as input parameters.
Brief Background about problem:
While passing the PASSWORD as MAVEN GOAL (Parameter), it was coming in Jenkins Console as a plain text.
Although I was using "Password Parameter" to pass the password at run-time but then also it was coming as plain text in console.
I tried to use the "secret text" to encrypt the password but then my job started failing because the encrypted password was getting passed to Maven Goals, which was not able to connect to DB.
Solution:
I used "Inject passwords to the build as environment variables" from Build Environment and defined its value as my "password parameter" (my password parameter name was db_password) which I am passing as parameter at run-time (eg.: I defined my inject password value as : ${db_password} ).
And this is working as expected. The password which I am passing while running my job is coming as [*******]
[console log:
Executing Maven: -B -f /work/jenkins_data/workspace/S2/database-deployment-via-flyway-EDOS/pom.xml clean compile -Ddb=UAT_cms_core -DdatabaseSchema=cms-core -Dmode=info -DdeploymentVersion=1.2.9 -Ddb_user=DB_USER -Ddb_password=[*******]
]
Regards,
Rohit Rajpoot

Here's an answer I just came across in the Jenkins documentation:
Normally you will start your script with
set +x
so that commands you run are not echoed to the log, in case you
mention the values of secrets in those commands.

Related

How to inject dynamic secret parameters from Jenkins job execute shell script

I am working on jenkins, which has dropdownlist/select list load with set MQ broker details. Each broker have different passwords stored in AWS secrets manger. I have written shell script to fetch password AWS secrets manager, i can able to get the password in execute shell build step.
I tried using mask passwords plugin-> mask passwords and regex, i am using same variable(BR_PASSWORD) defined in mask password option, even in shell script also.
What i provided default value with variables defined in global or password parameter , for default value.
All these options masking defined in default password in console output. But values which are coming trough shell script dynamically is not masking in console out put.
please add an example of your code.
And use groove string 'command ' for mask passwords
sh '$password'

JMeter did not execute the properly the # of users using Jenkins parameterization

I set up a Jenkins to integrate the JMeter script. Using the Freestyle project in Jenkins, I enabled "This project is parameterized" to set a String parameters for the Threads, Loop_Count and Think Time.
In .jmx file, I used the Function Parameters function to define those
variables, as shown below image:
User Defined Variable
In Jenkins, I configured the parameterization as shown below:
Set Parameterization
Command Line
However, when running the test for 40 users using the Build parameter in Jenkins, it looks like the # of threads/users are not correct that is being executed, the Samples that are being generated only 3 for most of the pages. Only the Homepage (which is the first page on the test) is only getting the correct # of Samples, but the rest of the URLS/pages are not correct. Below the actual output.
Output
Can you please help what might the causing this issue, I already checked the Jmeter script and jenkins config and appears to be correct but still I'm getting the issue. Thanks for the help.
Setting parameters in Jenkins itself is not sufficient to pass them to JMeter, you need to pass this parameterized value to JMeter startup script via -J command-line argument
-Jusers=%users%
End-to-end demo:
More information: Apache JMeter Properties Customization Guide

How to find the job which is printing credentials on console logs in jenkins

I am working on a security project where I need to Prevent output of sensitive data.We have more than 100 jobs running in Jenkins machine and its very difficult to check the jobs one by one .Is there any way to check the jobs which are printing credential in console output?Can someone suggest.Thanks.
As Subhadeep mentioned - mask passwords plugin is a right tool to mask credentials in jobs' output. It will help you in the future.
If you want to check which jobs with which build numbers showed credentials in plain text - it's better to use grep or analogues.
For example:
grep -e psw -o -r /var/lib/jenkins/jobs/*
Instead of looking into jenkins console output for password/credentials, you can look to implement jenkins mask password plugin and hide your password printing in plain text in console output.
There are some tools available which you can use to scan jenkins console log.
One of the tool is Veracode Jenkins Plugin.
Till you can find out any way, you can limit the access who can see the console.
You may use matrix base security for this and only admin people can see console log.
Thanks,
Subhadeep

Accessing a Username with Password Credential Parameter from a Jenkins Execute Groovy build step using Groovy command?

Software levels:
Jenkins 2.121.2
Credentials Plugin 2.1.18
Credentials Binding Plugin 1.16
Plain Credentials Plugin 1.4
I am working with a Freestyle project (not a pipeline) and want to use a Groovy command build step for the job's main processing.
I am trying to obtain the userid and password from a user credential so the groovy script can use them for various CLI manipulations. I spent a lot of time searching for answers, but none of the ones I've found worked. Most were not clear, many were geared toward pipelines.
I would greatly appreciate a little guidance at this point.
Here are the gory details.
I created a new parameterized Freestyle project in which I added a Credentials Parameter for a "Username and password" credential. It defaults to one of the credentials that I defined to Jenkins via the Credentials Plugin. I'm not sure this is necessary if the binding selects the credential to use explicitly.
I checked "Use secret text(s) or file(s)" in the Build Environment section, although I'm not certain that is essential for a Username/password style binding.
I added a "Username and password (separated)" binding and set USERID and PASSWORD as the respective variables.
My groovy command window has this sole line:
println("${USERID} ${PASSWORD}")
When I build the job, I get this error:
The both ways will inject the credential into Environment Variable, thus you can access them from Environment Variable in Groovy Script as following for both ways.
def env = System.getenv()
println env['auth']
println env['USERNAME']
println env['PASSSWORD']
But the injected value of the both ways are different.
1) Adding a Credential job parameter for user to choose when run job
In this way, the credentialId is injected, so you not get the username and password.
credentialId example: 1dd4755a-9396-4819-9327-86f25650c7d7
2) Using Credential Bindings
In this way, the username and password are injected, I think this is what you wanted.
def env = System.getenv()
def username = env['USERNAME']
def password = env['PASSSWORD']
def cmd = "curl -u $username:$password ...."
Add a Jenkins Build Step supply by plugin Execute Groovy script
To summarize, the techniques identified by #yong's post will only work with System Groovy Script build steps. The latest plugin and Jenkins levels will obfuscate the credential parameters, so println cannot be used to verify their content by visual inspection.

Jenkins Workflow Shell Step and Passwords

Is there a way with the Jenkins Workflow 'sh' step to hide or mask whats being executed from the builds console output?
I'm currently using it to execute a command that contains a password and this is being exposed in plain text in the build output.
Install the Credentials Binding plugin and use the withCredentials step to obtain your password from a secure source. It will be automatically suppressed from any build output within that block.
You should take a look at this plugin
This will allow you to mask the password variable in the job & its output.

Resources