Add support for disabling SSL verification in GitLab client by BB-steel · Pull Request #1364 · python-semantic-release/python-semantic-release
Purpose
This pull request fixes a bug where python-semantic-release fails to create releases on self-hosted GitLab instances that use self-signed or internally-issued SSL certificates.
When the insecure = true flag is set in pyproject.toml, the release process currently fails with an SSLCertVerificationError, preventing users from publishing releases in their private GitLab environments. This PR ensures that the insecure flag is correctly honored.
Solves: requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed when running semantic-release publish against a self-hosted GitLab instance.
Rationale
The root cause of the issue is that the allow_insecure parameter in the semantic_release.hvcs.gitlab.Gitlab class was not being passed down to the underlying python-gitlab client.
The gitlab.Gitlab constructor accepts an ssl_verify parameter, which defaults to True. The python-semantic-release wrapper did not utilize the allow_insecure flag to modify this behavior. As a result, the python-gitlab client always attempted to verify SSL certificates, regardless of the user's configuration in pyproject.toml.
The solution is to explicitly pass ssl_verify=not allow_insecure during the initialization of the gitlab.Gitlab client within semantic_release/hvcs/gitlab.py. This directly connects the configuration option to the client's behavior, making the insecure flag work as intended.
Workarounds like setting REQUESTS_CA_BUNDLE or GITLAB_SSL_VERIFY environment variables were considered but are less ideal as they require extra configuration in the user's CI/CD environment rather than fixing the bug at its source.
How did you test?
This change was validated through manual end-to-end testing in a CI/CD environment that replicates the original issue.
Methodology:
- Forked the Repository: Created a fork of
python-semantic-releaseand applied the code change on a new branch. - CI Pipeline Setup: Configured a GitLab CI pipeline to run against a self-hosted GitLab instance using a self-signed certificate.
- Configuration: The
pyproject.tomlfile was configured with the following remote settings:[tool.semantic_release.remote] type = "gitlab" insecure = true gitlab_url = "https://your.self-hosted.gitlab"
- Installation: The CI job was modified to install
python-semantic-releasedirectly from the forked Git repository and branch.- uv pip install "git+https://github.com/your-username/python-semantic-release.git@fix/gitlab-ssl-verify" - Execution: Ran the
semantic-release publishcommand. - Validation:
- Before Fix: The pipeline failed with the
SSLCertVerificationError. - After Fix: The pipeline successfully executed the
publishstep, creating a new release in the self-hosted GitLab project.
- Before Fix: The pipeline failed with the
No edge cases were identified, as this change simply wires a boolean flag to its intended destination. Existing unit tests continue to pass.
How to Verify
A reviewer can verify this fix by following these steps:
- Check out this PR branch locally.
- Set up a test environment pointing to a self-hosted GitLab instance that uses a self-signed or non-publicly trusted SSL certificate.
- In a test project, configure
pyproject.tomlas follows:[tool.semantic_release] # ... other settings [tool.semantic_release.remote] type = "gitlab" gitlab_url = "https://your.gitlab.instance" token = { env = "GITLAB_TOKEN" } insecure = true
- Install this patched version of
python-semantic-release. - Run
semantic-release publish. - Expected Result: The command should complete successfully, creating a release on the GitLab instance without any SSL errors. To confirm the failure, run the same command on the
mainbranch, which should fail with theSSLCertVerificationError.
PR Completion Checklist
- Reviewed & followed the Contributor Guidelines
- Changes Implemented & Validation pipeline succeeds
- Commits follow the Conventional Commits standard and are separated into the proper commit type and scope (recommended order: test, build, feat/fix, docs)
- Appropriate Unit tests added/updated
- Appropriate End-to-End tests added/updated
- Appropriate Documentation added/updated and syntax validated for sphinx build (see Contributor Guidelines)