Page MenuHomePhabricator

JENKINS-2111 path sanitization ineffective when using legacy Workspace Root Directory
Closed, ResolvedPublic

Description

Spotted in the Jenkins logs:

Jan 16 19:29:24 contint1001 jenkins[30762]: WARNING: [jenkins.branch.WorkspaceLocatorImpl getWorkspaceRoot]
JENKINS-2111 path sanitization ineffective when using legacy Workspace Root Directory
‘/srv/jenkins/workspace/${ITEM_FULL_NAME}’; switch to ${JENKINS_HOME}/workspace/${ITEM_FULLNAME} as in JENKINS-8446 / JENKINS-21942

Upstream tasks:

Event Timeline

https://integration.wikimedia.org/ci/configure has:

Home directory/var/lib/jenkins

The error comes from the branch api plugin: https://github.com/jenkinsci/branch-api-plugin

src/main/java/jenkins/branch/WorkspaceLocatorImpl.java
public class WorkspaceLocatorImpl extends WorkspaceLocator {

...

    private static final Pattern GOOD_RAW_WORKSPACE_DIR = Pattern.compile("(.+)[/\\\\][$][{]ITEM_FULL_?NAME[}][/\\\\]?");
    static @CheckForNull FilePath getWorkspaceRoot(Node node) {
        if (node instanceof Jenkins) {
            Matcher m = GOOD_RAW_WORKSPACE_DIR.matcher(((Jenkins) node).getRawWorkspaceDir());
            if (m.matches()) {
                return new FilePath(new File(m.group(1).replace("${JENKINS_HOME}", ((Jenkins) node).getRootDir().getAbsolutePath())));
            } else {
                LOGGER.log(Level.WARNING, "JENKINS-2111 path sanitization ineffective when using legacy Workspace Root Directory ‘{0}’; switch to ‘$'{'JENKINS_HOME'}'/workspace/$'{'ITEM_FULL_NAME'}'’ as in JENKINS-8446 / JENKINS-21942", ((Jenkins) node).getRawWorkspaceDir());
                return null;
            }
        } else if (node instanceof Slave) {
            return ((Slave) node).getWorkspaceRoot();
        } else {
            LOGGER.log(Level.WARNING, "Unrecognized node {0} of {1}", new Object[] {node, node.getClass()});
            return null;
        }
    }

So apparently we have /srv/jenkins/workspace/${ITEM_FULL_NAME} not being matched by (.+)[/\\\\][$][{]ITEM_FULL_?NAME[}][/\\\\]?.

The directory comes from a java system parameter used to start Jenkins:

-Djenkins.model.Jenkins.workspacesDir=/srv/jenkins/workspace/${ITEM_FULL_NAME}

Which I guess is used by the master node. And indeed the parameter has been added in 2018 by 2a7444c67b1d961878d9b6f8462ed1f4728547fa for T200953:

jenkins: add workspacesDir system property

This option was removed from the UI and needs to be set for a select few jobs that must run on contint1001.

hieradata/role/common/ci/master.yaml
profile::ci::jenkins::workspaces_dir: '/srv/jenkins/workspace/${ITEM_FULL_NAME}'
modules/jenkins/manifests/init.pp
"-Djenkins.model.Jenkins.workspacesDir=${workspaces_dir_for_systemd}"
hashar claimed this task.

7e08181a3ef48886d01b7019b98a29391f0790d9

[JENKINS-54654] WorkspaceLocatorImpl.getWorkspaceRoot did not handle paths using ${ITEM_FULL_NAME} but not ${JENKINS_HOME}

https://issues.jenkins-ci.org/browse/JENKINS-54654

Released with branch api plugin 2.1.2 and we have 2.5.2

I have looked at the logs on contint1001 and the message no more show up.