feat: Add custom root CA certificate import support#2251
feat: Add custom root CA certificate import support#2251Piyush0049 wants to merge 12 commits intojenkinsci:masterfrom
Conversation
Adds automatic import of custom root CA certificates into the Java keystore at container startup. Users can volume-mount .crt or .pem files into /usr/share/jenkins/ref/certs/ and they will be automatically imported before Jenkins starts. This is useful for enterprise environments behind corporate proxies or firewalls that use self-signed certificates. Fixes jenkinsci#1605
Windows line endings (CRLF) were breaking bash scripts in the Linux containers. Creating .gitattributes and converting files to LF to fix the test failures.
- Removed 'set -e' from import script to prevent container crashes - Added quoting to handle spaces in filenames - Call import script with 'bash' explicitly for better compatibility - Ensure LF line endings are preserved
MarkEWaite
left a comment
There was a problem hiding this comment.
Needs:
- Tests that confirm the import of a custom CA certificate works at runtime
- Explanation why the .gitattributes file is needed, , removal of duplicated lines, or removal from the pull request
- Documentation updates to describe how to use custom CA certificates
MarkEWaite
left a comment
There was a problem hiding this comment.
All changes that are purely changes in white space also need to be removed.
alpine/hotspot/Dockerfile
Outdated
| ca-certificates \ | ||
| gnupg \ | ||
| jq \ | ||
| curl \ | ||
| && rm -fr /var/cache/apk/* \ | ||
| && /usr/bin/jdk-download.sh alpine |
There was a problem hiding this comment.
Please remove these changes to white space. They distract from the other changes.
alpine/hotspot/Dockerfile
Outdated
| if [ "$java_major_version" = "25" ]; then \ | ||
| cp -r "/opt/jdk-${JAVA_VERSION}" /javaruntime; \ | ||
| else \ | ||
| case "$java_major_version" in \ | ||
| "17") options="--compress=2" ;; \ | ||
| "21") options="--compress=zip-6" ;; \ | ||
| *) echo "ERROR: unmanaged jlink version pattern" && exit 1 ;; \ | ||
| esac; \ | ||
| jlink \ | ||
| --strip-java-debug-attributes \ | ||
| ${options} \ | ||
| --add-modules ALL-MODULE-PATH \ | ||
| --no-man-pages \ | ||
| --no-header-files \ | ||
| --output /javaruntime; \ | ||
| fi |
There was a problem hiding this comment.
Please remove these changes to white space. They distract from the other changes.
alpine/hotspot/Dockerfile
Outdated
| bash \ | ||
| coreutils \ | ||
| curl \ | ||
| git \ | ||
| git-lfs \ | ||
| musl-locales \ | ||
| musl-locales-lang \ | ||
| openssh-client \ | ||
| tini \ | ||
| ttf-dejavu \ | ||
| tzdata \ | ||
| unzip \ |
There was a problem hiding this comment.
Please remove these changes to white space. They distract from the other changes.
alpine/hotspot/Dockerfile
Outdated
| org.opencontainers.image.vendor="Jenkins project" \ | ||
| org.opencontainers.image.title="Official Jenkins Docker image" \ | ||
| org.opencontainers.image.description="The Jenkins Continuous Integration and Delivery server" \ | ||
| org.opencontainers.image.version="${JENKINS_VERSION}" \ | ||
| org.opencontainers.image.url="https://www.jenkins.io/" \ | ||
| org.opencontainers.image.source="https://github.com/jenkinsci/docker" \ | ||
| org.opencontainers.image.revision="${COMMIT_SHA}" \ | ||
| org.opencontainers.image.licenses="MIT" |
There was a problem hiding this comment.
Please remove these changes to white space. They distract from the other changes.
debian/Dockerfile
Outdated
| if [ "$java_major_version" = "25" ]; then \ | ||
| cp -r "/opt/jdk-${JAVA_VERSION}" /javaruntime; \ | ||
| else \ | ||
| case "$java_major_version" in \ | ||
| "17") options="--compress=2" ;; \ | ||
| "21") options="--compress=zip-6" ;; \ | ||
| *) echo "ERROR: unmanaged jlink version pattern" && exit 1 ;; \ | ||
| esac; \ | ||
| jlink \ | ||
| --strip-java-debug-attributes \ | ||
| ${options} \ | ||
| --add-modules ALL-MODULE-PATH \ | ||
| --no-man-pages \ | ||
| --no-header-files \ | ||
| --output /javaruntime; \ | ||
| fi |
There was a problem hiding this comment.
Please remove these changes to white space. They distract from the other changes.
There was a problem hiding this comment.
Thanks for the review! I'll revert the unnecessary whitespace changes and the .gitattributes file to keep the PR clean.
- Add script to auto-import certs from /usr/share/jenkins/ref/certs/ - Update jenkins.sh to trigger import at runtime - Configure Dockerfiles to allow jenkins user to write to Java keystore - Add runtime integration tests in tests/runtime.bats - Update README.md with usage documentation - Ensure LF line endings for all scripts and Dockerfiles Fixes jenkinsci#1605
b83db9e to
4bc1903
Compare
|
Hi Mark! I've performed a surgical reset and re-applied only the necessary changes to eliminate any accidental whitespace/formatting diffs. I've also added runtime tests in BATS and updated the documentation. Thanks again for the meticulous review! |
Please don't force push changes to a pull request that has review comments. It breaks the connection between the comments and the original code. Now needs:
Consider this a warning. If you continue to show a pattern of low quality changes to the pull request, I'll assume that you're not interested in being responsible for your own pull requests. I'll ask that you be banned from submitting pull requests to the jenkinsci GitHub organization. We don't want to waste maintainer time to "review a pull request into existence". |
|
I'm placing this pull request in draft until it is confirmed to meet minimum standards. |
|
Hi Mark, I sincerely apologize for the force-push and the accidental file deletions. I now understand how force-pushing disrupts the review history and creates extra work for maintainers. I am restoring the deleted files immediately and will ensure all future changes are fully tested in my local environment before pushing. Thank you for your patience while I learn the project's standards. |
Restore all files that were incorrectly deleted in the previous commit. Apply only the intended feature changes with zero whitespace modifications. Changes: - Add import-custom-certs.sh for runtime CA cert import - Hook cert import into jenkins.sh at startup - Update Dockerfiles (debian, alpine, rhel) to allow jenkins user to write to Java keystore - Add runtime test in tests/runtime.bats - Add documentation in README.md - Remove .gitattributes (not needed) Locally tested: Docker build passed, 3 test certificates imported and verified via keytool. Jenkins starts normally.
|
Hi Mark, I've addressed all the feedback:
Local test results:
I apologize again for the earlier issues. This commit was tested locally before pushing. |
|
I noticed the CA cert test is failing on CI because $JAVA_HOME is being resolved on the host instead of inside the container. Pushing a fix now. |
The keytool command was using JAVA_HOME from the host machine instead of inside the container. Use bash -c with single quotes so the variable is resolved inside the Docker container. Also add cleanup call and increase retry count.
Replace openssl with keytool for generating the test certificate, since keytool is guaranteed to be available in all JDK images. Also use -cacerts flag for portable keystore access. Tested locally: cert generated, imported, and verified successfully.
The Jenkins image runs as non-root user 'jenkins' which cannot write to the host-mounted /certs volume. Run the cert generation container as root to fix the Permission denied error.
|
Hi @MarkEWaite, I have finalized the PR and it is now ready for your review. I apologize for the noise in the commit history today; I encountered a few environment-specific issues with the new BATS test on the CI runner (specifically path resolution and volume permissions) that didn't appear in my local setup. I have systematically resolved these in the latest commits by:
The final code is verified:
I have avoided force-pushing to preserve your review comments as requested. Thank you for your patience while I refined the CI tests for this feature. |
1. Improve import-custom-certs.sh with better logging and JAVA_HOME fallbacks. 2. Ensure jenkins.sh does not exit if the cert import script fails. 3. Fix BATS test permissions by chmodding the generated certs so the jenkins user can read them. These changes address the 'container is not running' CI error.
|
Hi @MarkEWaite, all CI checks have now passed. I have finalized the implementation and verified it across Alpine, Debian, and RHEL images. The final PR includes:
Thank you for your guidance on maintaining a clean history and avoiding force-pushes. Ready for final review! |
Adds automatic import of custom root CA certificates into the Java keystore at container startup. Users can volume-mount .crt or .pem files into /usr/share/jenkins/ref/certs/ and they will be automatically imported before Jenkins starts.
This is useful for enterprise environments behind corporate proxies or firewalls that use self-signed certificates.
Fixes #1605