configuration-as-code-groovy-plugin icon indicating copy to clipboard operation
configuration-as-code-groovy-plugin copied to clipboard

Add secret variables expansion from CNode value

Open ziouf opened this issue 5 years ago • 14 comments

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 avatar Nov 13 '19 14:11 ziouf

could you review my pull request please ?

ziouf avatar Dec 04 '19 10:12 ziouf

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

szandala avatar Jan 24 '20 11:01 szandala

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

ziouf avatar Jan 30 '20 13:01 ziouf

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

danielraq avatar Oct 12 '20 09:10 danielraq

OK, I will try today's evening. Honestly I am looking for a co-maintainer, because I heavily lack time

pon., 12 paź 2020 o 11:30 danielraq [email protected] napisał(a):

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jenkinsci/configuration-as-code-groovy-plugin/pull/3#issuecomment-707002547, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC7SR3DBPZ4G4FAXLPOFMWDSKLEEJANCNFSM4JM4IHLQ .

szandala avatar Oct 12 '20 09:10 szandala

THX

danielraq avatar Oct 12 '20 09:10 danielraq

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

jetersen avatar Oct 19 '20 08:10 jetersen

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 avatar Oct 19 '20 22:10 jetersen

@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 😓

jetersen avatar Oct 21 '20 13:10 jetersen

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.

per-bohlin avatar Feb 15 '21 10:02 per-bohlin

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.

jetersen avatar Feb 15 '21 11:02 jetersen

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 secretSource = new PropertiesSecretSource()
secretSource.init()

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

kylegibson avatar Jan 07 '22 19:01 kylegibson

@kylegibson , where does secret come from in your code snipped?

Btw. this functionality would still be nice, five years later. Appreciated if you could make time for it.

bn-jbischko avatar Sep 30 '24 14:09 bn-jbischko

@kylegibson , where does secret come from in your code snipped?

Btw. this functionality would still be nice, five years later. Appreciated if you could make time for it.

@bn-jbischko I corrected the code snippet to address your question. Hopefully it makes sense now.

kylegibson avatar Sep 30 '24 20:09 kylegibson