Protected packages: Helm chart push protection
-
Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA. As a benefit of being a GitLab Community Contributor, you receive complimentary access to GitLab Duo.
What does this MR do and why?
- Add new package type
Helmto thePackageProtection::Rulemodel - Integrate push package protection for package format helm
- Allow creation of helm package protection rule in frontend
- This commit adds the feature flag
:packages_protected_packages_helm
Background context information
Helm packages (helm charts) are tar-compressed archives, e.g. deis-workflow-0.1.0.tgz. The helm chart includes the file Chart.yml which itself contains the specification (metadata), e.g. name, version, description.
This means, the helm chart archive needs to be decompressed (etc. untar) in order to retrieve the Helm chart specification. This metadata extraction happens in the background.
This is why the package protection is applied Packages::Helm::ProcessFileService as part of the Packages::Helm::ExtractionWorker background job.
Integrating the package protection in the helm-specific endpoint is not possible because the necessary metadata are not available, e.g. package name. See also comment: !189801 (comment 2487282950)
References
Screenshots or screen recordings
Before
When pushing a Helm chart to the GitLab package registry (via curl) the enpoint returns a success status code (201).
Click to expand console log from `curl` command
e45a21dcb18e:/charts# curl --fail-with-body --request POST --form 'chart=@other-deis-workflow-0.1.0.tgz' --user $PAT_PROJECT_DEVELOPER_USERNAME:$PAT_PROJECT_DEVELOPER_TOKEN http://gdk.test:3000/api/v4/projects/7/packages/helm/api/stable/charts
{"message":"201 Created"}
The background worker extracts the metadata and processed the helm chart withouth an error.
After
The changes in this MR do not affect the initial upload (push) of the Helm chart to the GitLab package registry (via curl). The endpoint still returns a success status code (201).
But with these MR changes, the background worker checks for existing package protection rules and stores the error and shows it to the user.
How to set up and validate locally
- In rails console, enable the feature flag
:packages_protected_packages_helmFeature.enable(:packages_protected_packages_helm) - Go to the package settings page of the seeded project "flightjs/Flight": http://gdk.test:3000/flightjs/Flight/-/settings/packages_and_registries
- Create a new package protection rule for the package type 'Helm':
-
Field "Package name pattern":
deis-workflow -
Field "Package type":
Helm -
Field "Minimum access level for push":
Administrator -
Field "Minimum access level for delete ":
Administrator
-
Field "Package name pattern":
- Download this Helm package
deis-workflow-0.1.0.tgzor create new helm chart as explained in the helm quickstart guide - Use
curlto publish the helm package to your local gdk instancecurl --fail-with-body --request POST --form 'chart=@deis-workflow-0.1.0.tgz' --user $PAT_PROJECT_DEVELOPER_USERNAME:$PAT_PROJECT_DEVELOPER_TOKEN http://gdk.test:3000/api/v4/projects/7/packages/helm/api/stable/charts - Pushing the helm chart should fail because the chart is protected, see console output above
💥 - Change the package protection rule to another package name pattern, e.g.
other-deis-workflowand push it again - Now, the helm chart should have been successfully pushed because it is not protected anymore
Click to expand the console output
root@e2622ca19fa4:~/AppLogger# dotnet helm push bin/Debug/flight-helm-protected-test.0.0.2.nupkg --source gdk_test --api-key ({personal_access_token_of_project_developer})
warn : You are running the 'push' operation with an 'HTTP' source, 'http://gdk.test:3000/api/v4/projects/7/packages/helm/index.json'. Non-HTTPS access will be removed in a future version. Consider migrating to an 'HTTPS' source.
Pushing flight-helm-protected-test.0.0.2.nupkg to 'http://gdk.test:3000/api/v4/projects/7/packages/helm'...
warn : You are running the 'push' operation with an 'HTTP' source, 'http://gdk.test:3000/api/v4/projects/7/packages/helm/'. Non-HTTPS access will be removed in a future version. Consider migrating to an 'HTTPS' source.
PUT http://gdk.test:3000/api/v4/projects/7/packages/helm/
Created http://gdk.test:3000/api/v4/projects/7/packages/helm/ 2189ms
Your package was pushed.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
MR Checklist (@gerardo-navarro)
-
Changelog entry added, if necessary -
Documentation created/updated via this MR -
Documentation reviewed by technical writer or follow-up review issue created -
Tests added for this feature/bug -
Tested in all supported browsers -
Conforms to the code review guidelines -
Conforms to the style guides -
Conforms to the javascript style guides -
Conforms to the database guides -
Conforms to the merge request performance guidelines
Related to #538372

