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

Add secret variables expansion from CNode value #3

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ziouf
Copy link

@ziouf ziouf commented Nov 13, 2019

I faced jCasC secrets variables expansion issue with jCasC-Groovy plugin.

So I made this PR to implement usage of jCasC secrets feature.

As an example, this allows to setup secret token in URL to authenticate remote server.

Before, the following example wasn't working.

groovy:
  - url: http://login:${SECRET_TOKEN}@my.web.site/path/to/groovy/script.groovy

Regards

@ziouf ziouf force-pushed the feature/add-secrets-expansion-in-yaml branch 2 times, most recently from 2ba7033 to f47a3d7 Compare November 14, 2019 20:54
@ziouf ziouf force-pushed the feature/add-secrets-expansion-in-yaml branch from f47a3d7 to 8dc7868 Compare November 14, 2019 21:07
@ziouf
Copy link
Author

ziouf commented Dec 4, 2019

could you review my pull request please ?

@szandala
Copy link
Contributor

Could You add an example to the demos directory, please?

@ziouf
Copy link
Author

ziouf commented Jan 30, 2020

I added demo file, as requested.
Usage is very simple , as you can see

@danielraq
Copy link

When will you merge this and release a new version of the plugin? I really need this

@szandala
Copy link
Contributor

szandala commented Oct 12, 2020 via email

@danielraq
Copy link

THX

@jetersen
Copy link
Member

@szandala I'll happily help get this over the line 👍

@jetersen jetersen closed this Oct 19, 2020
@jetersen jetersen reopened this Oct 19, 2020
Copy link
Member

@jetersen jetersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two minor nitpicks

pom.xml Outdated
@@ -58,7 +58,7 @@
<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
<version>1.0</version>
<version>1.32</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest bumping to 1.42 as ordinal was fixed in 1.41 and secret resolver was improved in 1.42

Suggested change
<version>1.32</version>
<version>1.42</version>

Parent pom should be bumped as well

@jetersen jetersen force-pushed the feature/add-secrets-expansion-in-yaml branch from f5b73e4 to 316f5bf Compare October 19, 2020 21:29
@jetersen
Copy link
Member

Tried adding a simple test.

The test only seem to work from script console.

groovy:
    - script: |
        import jenkins.model.Jenkins;

        def systemMessage = "Hello World";
        def jenkins = Jenkins.get();
        jenkins.setSystemMessage(systemMessage);
        jenkins.save();

@jetersen jetersen force-pushed the feature/add-secrets-expansion-in-yaml branch from 623e29c to 9fee9aa Compare October 19, 2020 22:27
@jetersen
Copy link
Member

jetersen commented Oct 21, 2020

@szandala @ziouf @danielraq perhaps one of you would be willing to test the HPI: https://ci.jenkins.io/blue/organizations/jenkins/Plugins%2Fconfiguration-as-code-groovy-plugin/detail/PR-3/15/artifacts

I would love to have test that actually works 😓

@per-bohlin
Copy link

per-bohlin commented Feb 15, 2021

I was in dire need of this functionality, so I tried to use this implementation, but sadly it is severely broken. It causes the entire CASC plugin to fail to load other configuration. I have not been able to determine the root cause yet, but I'm guessing it is the rewrite of the groovy code processing that causes it. So for now, I'll have to revert to the published version and use some other mechanisms to inject secrets. I will try to get more time to keep looking into what is causing the failure.

The scary thing is that it doesn't fail in a clear and obvious way. Instead jenkins starts, its just that some configuration will simply not have been loaded. Looking in the logs, I can see that the CASC plugin doesn't know how to dispatch the configuration that fails to load. Reverting back to the published version and everything works again.

@jetersen
Copy link
Member

Ya, would be nice to add tests to see if this actually works. I tried adding tests but I think I ran into the same problem your describing.

@kylegibson
Copy link

kylegibson commented Jan 7, 2022

Is there any work around for the lack of this functionality?

Update/edit

I'm using this as a work around:

import io.jenkins.plugins.casc.impl.secrets.PropertiesSecretSource
def pss = new PropertiesSecretSource()
secret.init()

def foo = secret.reveal('secret_var').get()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants