-
New Feature
-
Resolution: Unresolved
-
Minor
-
None
We are attempting to block access to pipeline steps that we consider a security risk (e.g. the Kubernetes plugin steps) from user provided Jenkinsfiles, but allowing access to all the steps from global pipeline libraries. Ideally we would only allow access to steps within our global pipeline library.
The only way we have come up with is to create StepListener extension. The extension uses reflection on the StepContext to check whether the step was executed via the Jenkinsfile or a global pipeline library.
As I understand it, this is not considered good practice and may break in future.
Is there some existing functionality to achieve what we need here or the possibility of extending the StepListener API to provide it?
[JENKINS-69606] Ability to whitelist steps in Jenkinsfiles while allowing all steps in global pipeline libraries
Component/s | New: script-security-plugin [ 18520 ] |
Assignee | New: Sam Gleske [ sag47 ] |
This would be a useful open source plugin. Adding on, I would also like to not even necessarily allow all Vars or shared library steps. In some cases, I develop a global step meant only for private use in the global shared pipeline library. Not meant for use by users.
Detecting a global var
Here's some code which allows a dynamic var look up to see if a step is a core Jenkins step or a shared pipeline var.
https://github.com/samrocketman/jervis/blob/64d21aff1d08ae58cc310cae5e868a4923b4bcab/vars/hasGlobalVar.groovy#L33
It would be great if the whitelist could also apply to global vars or have an option around global vars.
Other necessary considerations
I've found doing a basic AST review of a Jenkinsfile is not enough because a user can pull in a user shared library via the library step. I think user shared libraries should be supported so allowing steps in a user shared library is useful to be automatically white listed without having to explicitly state allowed steps.
This also means it is necessary for limitations around allowed steps also be applied to the contents of user shared libraries.