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

Cache GroovySourceFileAllowlist responses and remove entries from the default allowlist that are unrelated to WithScriptDescriptor.WithScriptAllowlist #829

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

Conversation

dwnusbaum
Copy link
Member

See #538 (comment).

GroovySourceFileAllowlist can be consulted many times, but the allowed files are effectively static and just depend on which plugins are installed. Once a file has been allowed once, we don't need to check all of the allowlists again.

Testing done

Submitter checklist

Edit tasklist title
Beta Give feedback Tasklist Submitter checklist, more options

Delete tasklist

Delete tasklist block?
Are you sure? All relationships in this tasklist will be removed.
  1. Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
    Options
  2. Ensure that the pull request title represents the desired changelog entry
    Options
  3. Please describe what you did
    Options
  4. Link to relevant issues in GitHub or Jira
    Options
  5. Link to relevant pull requests, esp. upstream and downstream changes
    Options
  6. Ensure you have provided tests - that demonstrates feature works or fixes the issue
    Options

GroovySourceFileAllowlist can be consulted many times, but the allowed files
are effectively static and just depend on which plugins are installed. Once a
file has been allowed once, we don't need to check all of the allowlists again.
@@ -152,6 +148,22 @@ private static boolean endsWithIgnoreCase(String value, String suffix) {
}
}

@Extension
public static class AllowedGroovyResourcesCache {
private final Map<String, Boolean> cache = new ConcurrentHashMap<>();
Copy link
Member Author

Choose a reason for hiding this comment

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

At most there would be around 50 entries in the map if you used every single plugin that has Groovy source files, so I don't think we need anything fancy.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually IDK if that's right, let me see if we get here with Groovy's speculative class loading as well.

Copy link
Member Author

@dwnusbaum dwnusbaum Jan 9, 2024

Choose a reason for hiding this comment

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

Never mind, we do really only get here for the weird Groovy DSL script files in Jenkins plugins or other attempts to directly load Groovy source files on the classpath. I guess that is obvious in hindsight, otherwise we would see a ton of log spam for otherwise non-existent classes.

(SandboxResolvingClassLoader in script-security on the other hand does see a bunch of class loading attempts for random non-existent classes, but I guess that has to do with overriding loadClass, which we do not do here.)

/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/AnyScript.groovy
/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/LabelScript.groovy
/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/NoneScript.groovy
/org/jenkinsci/plugins/pipeline/modeldefinition/when/impl/AbstractChangelogConditionalScript.groovy
Copy link
Member Author

Choose a reason for hiding this comment

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

Comment on lines -21 to -22
# pipeline-model-extensions
/org/jenkinsci/plugins/pipeline/modeldefinition/agent/CheckoutScript.groovy
Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -1,10 +1,8 @@
# This list is ordered from most popular to least popular plugin to minimize performance impact.
# pipeline-model-definition
/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy
Copy link
Member Author

Choose a reason for hiding this comment

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

# docker-workflow
/org/jenkinsci/plugins/docker/workflow/Docker.groovy
/org/jenkinsci/plugins/docker/workflow/declarative/AbstractDockerPipelineScript.groovy
Copy link
Member Author

Choose a reason for hiding this comment

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

# docker-workflow
/org/jenkinsci/plugins/docker/workflow/Docker.groovy
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

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

Seems safe enough IIUC.

@@ -152,6 +148,27 @@ private static boolean endsWithIgnoreCase(String value, String suffix) {
}
}

@Extension
@SuppressFBWarnings(value = "NP_BOOLEAN_RETURN_NULL", justification = "intentionally not caching negative results")
Copy link
Member Author

@dwnusbaum dwnusbaum Jan 17, 2024

Choose a reason for hiding this comment

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

Not sure why, but this annotation actually does have to be on the class. If it's on the isAllowed method, SpotBugs still complains.

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