Skip to content
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

ensure all credentials are masked in output logs #212

Closed
clemensutschig opened this issue Mar 31, 2020 · 12 comments · Fixed by #341
Closed

ensure all credentials are masked in output logs #212

clemensutschig opened this issue Mar 31, 2020 · 12 comments · Fixed by #341
Assignees
Labels
bug Something isn't working

Comments

@clemensutschig
Copy link
Member

there is still cases where credentials may not be masked (e.g. thru the ods-context).

@clemensutschig clemensutschig added the bug Something isn't working label Mar 31, 2020
@clemensutschig clemensutschig added this to To Do in OpenDevStack 3.0 via automation Mar 31, 2020
@renedupont
Copy link
Member

so far I only found the snyk auth token in the console output, what other credentials did you see?

@michaelsauter
Copy link
Member

I think also the Nexus credentials can be exposed as they are not read via withCredentials :(

@renedupont
Copy link
Member

renedupont commented Apr 3, 2020

@clemensutschig @michaelsauter
After looking a bit into it the only quick fix I found so far without any changes on the user side would be to use 'set +x' in the shell cmd, e.g:

script.sh(
  script: """
            set +x
            snyk auth ${authCode} | tee -a ${reportFile}
          """,
  returnStatus: true,
  label: "Authenticate with Snyk server"
)

...that way it is not displayed in the output. It looks then like this:

[Pipeline] sh (Authenticate with Snyk server)
set +x

Your account has been authenticated. Snyk is now ready to be used.

btw. I found in Jenkins that if you open a build and click on the right side 'Pipeline Steps' (instead of 'Console Output') that all credentials are visible there in clear text... even the ones that are used within withCredentials.
Any thought on this if this is critical or not?

@michaelsauter
Copy link
Member

I think the most important thing is to avoid accidental credentials leakage. Therefore I'm ok with them being visible outside the build logs.

Regarding Snyk, it makes sense to do set +x, however we could also do the automatic transformation to a secret ... maybe we do set +x now because it is easy, and then do the secret in a next step.

@renedupont
Copy link
Member

Yes I was thinking the same regarding the next steps...

but I just discovered that if you use Jenkins in the blue ocean view, it is all there in clear text :(
even when withCredentials was used.

@michaelsauter
Copy link
Member

@renedupont wow. is that a known bug with the credentials plugin and/or blue ocean? that sounds like something the Jenkins community would try to fix, no?

@renedupont
Copy link
Member

I don't know yet, this needs further investigation, but it looks like as if the blue ocean view is basically what you can see in the classic view if you click on 'Pipeline Steps'

@renedupont
Copy link
Member

another idea that @stitakis told me about is to write the command into a file and execute it from there.
For example I tried this

    script.writeFile file: 'snykauth.sh', text: 'snyk auth ' + authCode + ' | tee -a ${reportFile}'
    script.sh(
        script: """
          ls -l snykauth.sh
          chmod +x snykauth.sh
          ./snykauth.sh
        """,
      returnStatus: true,
      label: "Authenticate with Snyk server"
    )

and it results in the log as:

[Pipeline] writeFile
[Pipeline] sh (Authenticate with Snyk server)
+ ls -l snykauth.sh
-rw-r--r--. 1 default 1009280000 69 Apr  6 19:46 snykauth.sh
+ chmod +x snykauth.sh
+ ./snykauth.sh

Your account has been authenticated. Snyk is now ready to be used.

I could not see it either in the ocean blue view. We could write a groovy method in /vars folder that encapsulates this, but for me this still looks like a workaround.

I am considering to take a look at https://jenkins.io/doc/pipeline/steps/mask-passwords/ soon. If this works maybe we could integrate this into the jenkins image.

@renedupont
Copy link
Member

@michaelsauter I think I found out why the credentials are not masked when we use withCredentials... we use triple-double-quotation marks instead of triple-single-quotation marks in the sh call.
Unfortunately, when using the single marks ('''), variables are not interpolated and something like USERPASS.replace(...) does not work that way when using '''. I tried out a lot of variants to still get it right that way but no luck yet.

@michaelsauter
Copy link
Member

@renedupont Why is triple-double-quotes an issue? Do you have a reference?

@renedupont
Copy link
Member

I tried it out because of the examples given here: https://jenkins.io/doc/pipeline/steps/credentials-binding/

@clemensutschig
Copy link
Member Author

partially fixed by #329

OpenDevStack 3.0 automation moved this from To Do to Done May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants