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

Fix handling of -cert parameter in inbound agent #925

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ ADD --chown="${user}":"${group}" "https://repo.jenkins-ci.org/public/org/jenkins
RUN chmod 0644 /usr/share/jenkins/agent.jar \
&& ln -sf /usr/share/jenkins/agent.jar /usr/share/jenkins/slave.jar

# Copy the certificate file to the container
COPY ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

ENV JAVA_HOME=/opt/java/openjdk
COPY --from=jre-build /javaruntime "$JAVA_HOME"
Expand Down Expand Up @@ -133,4 +135,4 @@ LABEL \
org.opencontainers.image.source="https://github.com/jenkinsci/docker-agent" \
org.opencontainers.image.licenses="MIT"

ENTRYPOINT ["/usr/local/bin/jenkins-agent"]
ENTRYPOINT ["/usr/local/bin/jenkins-agent", "-cert", "@/etc/ssl/certs/ca-certificates.crt"]
5 changes: 4 additions & 1 deletion debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ RUN chmod +x /usr/local/bin/jenkins-agent &&\
ln -s /usr/local/bin/jenkins-agent /usr/local/bin/jenkins-slave
USER ${user}

# Copy the certificate file to the container
COPY ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

LABEL \
org.opencontainers.image.vendor="Jenkins project" \
org.opencontainers.image.title="Official Jenkins Inbound Agent Base Docker image" \
Expand All @@ -144,4 +147,4 @@ LABEL \
org.opencontainers.image.source="https://github.com/jenkinsci/docker-agent" \
org.opencontainers.image.licenses="MIT"

ENTRYPOINT ["/usr/local/bin/jenkins-agent"]
ENTRYPOINT ["/usr/local/bin/jenkins-agent", "-cert", "@/etc/ssl/certs/ca-certificates.crt"]
14 changes: 13 additions & 1 deletion jenkins-agent
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,21 @@ else
esac
fi

# Handle the -cert parameter
CERT=""
for arg in "$@"; do
if [ "$arg" = "-cert" ]; then
CERT_FILE=true
elif [ "$CERT_FILE" = true ]; then
CERT_CONTENT=$(cat "$arg")
CERT="-cert $CERT_CONTENT"
CERT_FILE=false
fi
done

#TODO: Handle the case when the command-line and Environment variable contain different values.
#It is fine it blows up for now since it should lead to an error anyway.

exec $JAVA_BIN $JAVA_OPTIONS -jar $AGENT_FILE $SECRET $AGENT_NAME $TUNNEL $URL $WORKDIR $WEB_SOCKET $DIRECT $PROTOCOLS $INSTANCE_IDENTITY $REMOTING_OPTS "$@"
exec $JAVA_BIN $JAVA_OPTIONS -jar $AGENT_FILE $SECRET $AGENT_NAME $TUNNEL $URL $WORKDIR $WEB_SOCKET $DIRECT $PROTOCOLS $INSTANCE_IDENTITY $CERT $REMOTING_OPTS "$@"

fi
9 changes: 8 additions & 1 deletion jenkins-agent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Param(
$JenkinsJavaBin = '',
$JavaHome = $env:JAVA_HOME,
$JenkinsJavaOpts = '',
$RemotingOpts = ''
$RemotingOpts = '',
$Cert = '' # P7458
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the meaning of this comment exactly?

)

# Usage jenkins-agent.ps1 [options] -Url http://jenkins -Secret [SECRET] -Name [AGENT_NAME]
Expand Down Expand Up @@ -75,6 +76,7 @@ if(![System.String]::IsNullOrWhiteSpace($Cmd)) {
'InstanceIdentity' = 'JENKINS_INSTANCE_IDENTITY';
'Protocols' = 'JENKINS_PROTOCOLS';
'RemotingOpts' = 'REMOTING_OPTS';
'Cert' = 'JENKINS_CERT' # P7458
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the meaning of this comment exactly?

}

# this does some trickery to update the variable from the CmdletBinding
Expand Down Expand Up @@ -147,6 +149,11 @@ if(![System.String]::IsNullOrWhiteSpace($Cmd)) {
$AgentArguments += @('-protocols', $Protocols)
}

if(![System.String]::IsNullOrWhiteSpace($Cert)) {
$CertContent = Get-Content -Path $Cert -Raw
$AgentArguments += @('-cert', $CertContent)
}

if(![System.String]::IsNullOrWhiteSpace($JenkinsJavaBin)) {
$JAVA_BIN = $JenkinsJavaBin
} else {
Expand Down
Loading