Skip to content

Conversation

@pascal-hofmann
Copy link
Contributor

@pascal-hofmann pascal-hofmann commented Apr 14, 2023

Since the upgrade to SnakeYAML 1.32 it is not possible to read YAML files greater than 3MB. This PR adds the new, optional attribute codePointLimit to readYaml. This makes it possible to work around this limitation.

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@pascal-hofmann pascal-hofmann force-pushed the feature/add-codepointlimit branch from 56082ff to c49f637 Compare April 14, 2023 16:50
@MarkEWaite
Copy link
Contributor

Thanks for the pull request. Also reported as JENKINS-71077. I've invited the person that reported the issue to test drive this pull request and report their results.

@MarkEWaite
Copy link
Contributor

@pascal-hofmann it would be nice if the pull request title were updated to include [JENKINS-71077] as the start the the title so that the changelog generated by release drafter will include a link to the Jira issue.

@pascal-hofmann pascal-hofmann force-pushed the feature/add-codepointlimit branch from c49f637 to 15f3717 Compare April 17, 2023 01:47
@pascal-hofmann pascal-hofmann changed the title Allow overriding codePointLimit to allow reading larger yaml files [JENKINS-71077] Allow overriding codePointLimit to allow reading larger yaml files Apr 17, 2023
@pascal-hofmann
Copy link
Contributor Author

Hi @MarkEWaite,
I've updated the commit message.

Thanks for looking at this PR so quickly. ❤️

Cheers,
Pascal

@sbollap1
Copy link

I was able to verify that pipeline-utility-steps:2.15.2-rc651.15f371774808 version of the plugin worked for me after making the necessary changes to my readYaml call, thanks a lot for the help
ex: Data = readYaml file: "mylargeyamlfile.yaml", maxAliasesForCollections: 999, codePointLimit: 104857600

@MarkEWaite
Copy link
Contributor

I was able to verify that pipeline-utility-steps:2.15.2-rc651.15f371774808 version of the plugin worked for me

Thanks very much. Could you also check that the Pipeline syntax snippet generator is well behaved when generating sample syntax for the improved readYaml step?

@sbollap1
Copy link

sbollap1 commented Apr 17, 2023

I was able to verify that pipeline-utility-steps:2.15.2-rc651.15f371774808 version of the plugin worked for me

Thanks very much. Could you also check that the Pipeline syntax snippet generator is well behaved when generating sample syntax for the improved readYaml step?
I am not seeing the parameters or anything useful being generated, for other sample step, I am seeing the file option at the least, however, on the other versions of jenkins(s) and plugin version also I am seeing same behavior, so its fine.
image

@MarkEWaite
Copy link
Contributor

Thanks for checking. I didn't realize that was a special step that does not have full support in the Pipeline syntax snippet generator. Could you confirm that the online help displayed when the '?' is clicked is reasonable.

@sbollap1
Copy link

Thanks for checking. I didn't realize that was a special step that does not have full support in the Pipeline syntax snippet generator. Could you confirm that the online help displayed when the '?' is clicked is reasonable.

yes, that looks accurate and matches with the version I have
image

@MarkEWaite
Copy link
Contributor

That's great. Thanks. I think this has been well tested. Now it is left to the maintainers to review, merge, and release.

@pascal-hofmann pascal-hofmann force-pushed the feature/add-codepointlimit branch from 15f3717 to 1542eae Compare April 17, 2023 20:51
@pascal-hofmann
Copy link
Contributor Author

FYI: I just added a missing space to the help text. (Limit for incoming data in bytes.Default…)

*/
public class ReadYamlStep extends AbstractFileOrTextStep {

private int codePointLimit = -1;

Choose a reason for hiding this comment

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

would it be possible to add a static field/method to set the default value for this setting as its done for the MAX_ALIASES_FOR_COLLECTIONS? then old pipelines can keep using old step signature and stay backward compatible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I‘ll add this tomorrow. 👍

Choose a reason for hiding this comment

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

thank you so much!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just added this. Is it ok like this?

Choose a reason for hiding this comment

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

Looks good to me, thanks!
I tested this on local jenkins instance with couple of nodes - works fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added MAX_CODE_POINT_LIMIT. With this, the setters/getters also make sense, because they are required for validation / the help page / tests.

@pascal-hofmann pascal-hofmann force-pushed the feature/add-codepointlimit branch from 1542eae to 9db10ea Compare April 18, 2023 08:57
@pascal-hofmann
Copy link
Contributor Author

Is there an issue with the CI job or is the long runtime OK?

@sbollap1
Copy link

sbollap1 commented Apr 20, 2023

I can see the build is successfull but there are some junut checks that failed. https://ci.jenkins.io/job/Plugins/job/pipeline-utility-steps-plugin/view/change-requests/job/PR-206/5/console however, not sure if this is what's blocking it from moving forward.

Comment on lines 87 to 111
public static int setDefaultCodePointLimit(int defaultCodePointLimit) {
DEFAULT_CODE_POINT_LIMIT = defaultCodePointLimit;
return DEFAULT_CODE_POINT_LIMIT;
}
public static int getDefaultCodePointLimit() {
return DEFAULT_CODE_POINT_LIMIT;
}
Copy link
Member

Choose a reason for hiding this comment

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

This is very redundant. No need for a setter/getter for a pseudo constant.

Suggested change
public static int setDefaultCodePointLimit(int defaultCodePointLimit) {
DEFAULT_CODE_POINT_LIMIT = defaultCodePointLimit;
return DEFAULT_CODE_POINT_LIMIT;
}
public static int getDefaultCodePointLimit() {
return DEFAULT_CODE_POINT_LIMIT;
}

public static final String DEFAULT_CODE_POINT_LIMIT_PROPERTY = ReadYamlStep.class.getName() + ".DEFAULT_CODE_POINT_LIMIT";

@SuppressFBWarnings(value={"MS_SHOULD_BE_FINAL"}, justification="Non final so that an admin can adjust the value through the groovy script console without restarting the instance.")
private static /*almost final*/ int DEFAULT_CODE_POINT_LIMIT = setDefaultCodePointLimit(Integer.getInteger(DEFAULT_CODE_POINT_LIMIT_PROPERTY, -1));
Copy link
Member

Choose a reason for hiding this comment

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

This is very redundant. No need for a setter/getter for a pseudo constant.

Suggested change
private static /*almost final*/ int DEFAULT_CODE_POINT_LIMIT = setDefaultCodePointLimit(Integer.getInteger(DEFAULT_CODE_POINT_LIMIT_PROPERTY, -1));
private static /*almost final*/ int DEFAULT_CODE_POINT_LIMIT = Integer.getInteger(DEFAULT_CODE_POINT_LIMIT_PROPERTY, -1);


@DataBoundSetter
public void setCodePointLimit(final int codePointLimit) {
this.codePointLimit = codePointLimit;
Copy link
Member

Choose a reason for hiding this comment

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

This is very similar to masAliasForCollection. So you need to add similar protections as in setMaxAliasesForCollections(...) or a potential nefarious user could sink a Jenkins controller by reading in a couple of GB of data until the instance runs our of memory.

Copy link
Contributor Author

@pascal-hofmann pascal-hofmann Apr 21, 2023

Choose a reason for hiding this comment

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

Whoever sets this limit can also just execute random groovy/shell code and sink the instance this way.

Copy link
Member

Choose a reason for hiding this comment

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

No because the pipeline is running in the sandbox.
https://www.jenkins.io/doc/developer/security/misc/#groovy-scripting

Copy link
Member

Choose a reason for hiding this comment

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

Besides, it is needed for users to not shoot themselves in the foot. They don't know how much memory the Jenkins controller has available, but the administrator should.

jenkins-attcomdev pushed a commit to att-comdev/charts that referenced this pull request Apr 27, 2023
There is known limitation in pipeline-utility-steps plugin which is
blocking us from running deployment pipelines. which is being fixed
by jenkinsci/pipeline-utility-steps-plugin#206
until this pull request is merged, this PS is using specific
version of the plugin from this pull request.

quay.io plugin removed as this is not being used and has a vulnerability warning displayed

Change-Id: If9f14b6d65504eea25dc44456a54e2dfa1c4deb5
@pascal-hofmann pascal-hofmann force-pushed the feature/add-codepointlimit branch from 9db10ea to 898ca71 Compare May 19, 2023 11:49
@icep87
Copy link

icep87 commented May 29, 2023

Will this manage to make it into the next release?

@pascal-hofmann
Copy link
Contributor Author

Hi Piotr,
I did not have time to update my PR according to the review comments yet. I try to squeeze this in this week.

Cheers,
Pascal

@pascal-hofmann pascal-hofmann force-pushed the feature/add-codepointlimit branch 2 times, most recently from 09cafb6 to 5773678 Compare June 12, 2023 19:04
@pascal-hofmann
Copy link
Contributor Author

pascal-hofmann commented Jun 12, 2023

Hey everyone,
I finally managed to work on this again. Could you do another review?

Thanks for your patience.

Cheers,
Pascal

Edit: I just realized there were some conflicts, so I rebased on latest master.

@pascal-hofmann pascal-hofmann force-pushed the feature/add-codepointlimit branch from 5773678 to 78e3fac Compare June 12, 2023 19:12
@pascal-hofmann pascal-hofmann requested a review from rsandell June 14, 2023 12:38
@pascal-hofmann
Copy link
Contributor Author

@rsandell Can you have another look at this PR?

@rsandell rsandell merged commit b750cd9 into jenkinsci:master Jun 19, 2023
@pascal-hofmann pascal-hofmann deleted the feature/add-codepointlimit branch June 20, 2023 08:56
@vgrutsenko
Copy link

Thanks @rsandell for merging this. How soon can we expect a new version of the plugin?

@rsandell
Copy link
Member

rsandell commented Jul 6, 2023

Oh, sorry!
I merged this while I was on vacation and forgot to make the release when I came back. Doing the release now.

@vgrutsenko
Copy link

Perfect, thanks!

@Kanav14
Copy link

Kanav14 commented Jul 14, 2023

I was able to verify that pipeline-utility-steps:2.15.2-rc651.15f371774808 version of the plugin worked for me after making the necessary changes to my readYaml call, thanks a lot for the help ex: Data = readYaml file: "mylargeyamlfile.yaml", maxAliasesForCollections: 999, codePointLimit: 104857600

This did not work for me when reading yaml as a variable like below:

readYaml text: newVar, codePointLimit: 52428800

@Kanav14
Copy link

Kanav14 commented Jul 14, 2023

, codePointLimit=52428800} for org.jenkinsci.plugins.pipeline.utility.steps.conf.ReadYamlStep: java.lang.reflect.InvocationTargetException

error message

@rsandell
Copy link
Member

Don't use = for named parameter values, use name: value i.e. , codePointLimit: 52428800}

@sblatnick
Copy link

We're using 2.16.0 and this is failing from within a shared library class:

def yaml = script.readYaml file: results, codePointLimit: 134217728

With:

16:08:12  java.lang.IllegalArgumentException: Could not instantiate {file=scanner-results.yaml, codePointLimit=134217728} for org.jenkinsci.plugins.pipeline.utility.steps.conf.ReadYamlStep: java.lang.reflect.InvocationTargetException

Any ideas what might be wrong?

@rsandell
Copy link
Member

Can you get the stacktrace of the InvocationTargetException? It's probably in the system log.

@sblatnick
Copy link

This is the same issue as JENKINS-72556

Unfortunately, I don't have access to the jenkins system logs, and we found a work-around by using python and only extracting what we need from the yaml.

I don't understand why this wasn't working for us, but unless someone else is seeing this issue, feel free to close it.

@cpotter302
Copy link

We're using 2.16.0 and this is failing from within a shared library class:

def yaml = script.readYaml file: results, codePointLimit: 134217728

With:

16:08:12  java.lang.IllegalArgumentException: Could not instantiate {file=scanner-results.yaml, codePointLimit=134217728} for org.jenkinsci.plugins.pipeline.utility.steps.conf.ReadYamlStep: java.lang.reflect.InvocationTargetException

Any ideas what might be wrong?

Having the same issues here. System log is empty unfortunately

@rsandell
Copy link
Member

Without knowing the exception that caused the InvocationTargetException it will be hard.
Maybe the codePointLimit: 134217728 is too large i.e. larger than what MAX_CODE_POINT_LIMIT is set to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants