* feat(addon): Store addon registry tokens in Secrets
Previously, addon registry tokens were stored in plaintext within the 'vela-addon-registry' ConfigMap. This is not a secure practice for sensitive data.
This commit refactors the addon registry functionality to store tokens in Kubernetes Secrets. The ConfigMap now only contains a reference to the secret name, while the token itself is stored securely.
This change includes:
- Creating/updating secrets when a registry is added/updated.
- Loading tokens from secrets when a registry is listed/retrieved.
- Deleting secrets when a registry is deleted.
Signed-off-by: Ashvin Bambhaniya <ashvin.bambhaniya@improwised.com>
* test(addon): Add tests for registry token secret storage
This commit introduces a comprehensive test suite for the addon registry feature.
It includes:
- Isolated unit tests for each CRUD operation (Add, Update, List, Get, Delete) to ensure each function works correctly in isolation.
- A stateful integration test to validate the complete lifecycle of an addon registry from creation to deletion.
The tests verify that tokens are handled correctly via Kubernetes Secrets, confirming the implementation of the secure token storage feature.
Signed-off-by: Ashvin Bambhaniya <ashvin.bambhaniya@improwised.com>
* feat(addon): improve addon registry robustness and fix bugs
This commit introduces several improvements to the addon registry to make it more robust and fixes several bugs.
- When updating a secret, the existing secret is now fetched and updated to avoid potential conflicts.
- Deleting a non-existent registry now returns no error, making the operation idempotent.
- Getting a non-existent registry now returns a structured not-found error.
- Loading a token from a non-existent secret is now handled gracefully.
- When setting a token directly on a git-based addon source, the token secret reference is now cleared.
- The token secret reference is now correctly copied in `SafeCopy`.
Signed-off-by: Ashvin Bambhaniya <ashvin.bambhaniya@improwised.com>
* Refactor(addon): Fix secret deletion and improve registry logic
This commit refactors the addon registry data store to fix a critical bug where deleting an addon registry would not delete its associated token secret.
The root cause was that the `GetRegistry` function, which was used by `DeleteRegistry`, would load the token from the secret and then clear the `TokenSecretRef` field on the in-memory object. This meant that when `DeleteRegistry` tried to find the secret to delete, the reference was already gone.
This has been fixed by:
1. Introducing a central `getRegistries` helper function to read the raw registry data from the ConfigMap.
2. Refactoring all data store methods (`List`, `Get`, `Add`, `Update`, `Delete`) to use this central helper, removing duplicate code.
3. Ensuring `DeleteRegistry` uses the raw, unmodified registry data so that the `TokenSecretRef` is always available for deletion.
Additionally, comprehensive unit tests for the new helper functions (`getRegistries`, `loadTokenFromSecret`, `createOrUpdateTokenSecret`) have been added to verify the fix and improve overall code quality and stability.
Signed-off-by: Ashvin Bambhaniya <ashvin.bambhaniya@improwised.com>
* feat(addon): improve addon registry token security and logging
This commit enhances the security and observability of addon registry token handling.
- Adds a warning message to users when an insecure inline token is detected in an addon registry configuration, prompting them to migrate to a more secure secret-based storage.
- Implements info-level logging to create an audit trail for token migrations, providing administrators with visibility into security-related events.
- Refactors the token migration logic into a new `migrateInlineTokenToSecret` function, improving code clarity and maintainability.
- Introduces unit tests for the `TokenSource` interface methods and the `GetTokenSource` function to ensure correctness and prevent regressions.
Signed-off-by: Ashvin Bambhaniya <ashvin.bambhaniya@improwised.com>
* Chore: remove comments to triger ci
Signed-off-by: Ashvin Bambhaniya <ashvin.bambhaniya@improwised.com>
---------
Signed-off-by: Ashvin Bambhaniya <ashvin.bambhaniya@improwised.com>
* Feat(#5861): Support addon dependencies version ranges
This change enables addon maintainers to define version ranges for
dependencies in an addon's metadata.yaml file.
This behavior is similar to the version range allowed in the `system`
section of the metadata file. The version range expression for
`dependencies` follows the same format as for `system`.
Example:
```yaml
dependencies:
- name: addon1
version: ">= 2.3.3, < 3.0.0"
- name: addon2
version: ">= 0.1.0, < 1.0.0"
```
When installing an addon, the behavior varies depending on whether the
dependency is already installed.
If a dependency is already installed, the installed version will be
validated against the version range, and installation will fail with an
error if there's a mismatch.
If a dependency is not installed, the version range will be used to
select the addon version to be installed. If no addon version matching
the range exists, the installation will fail with an error.
Fixes#5861
Signed-off-by: Michael Russo <merusso@gmail.com>
* fix(lint): remove unused ctx parameter
Signed-off-by: Michael Russo <merusso@gmail.com>
* fix(lint): Add comment for IsLocalRegistry
Signed-off-by: Michael Russo <merusso@gmail.com>
* fix(lint): unexport AddonInfoMap
Signed-off-by: Michael Russo <merusso@gmail.com>
* fix(lint): unexport addonInfo
Signed-off-by: Michael Russo <merusso@gmail.com>
* chore: replace map[string]addonInfo with addonInfoMap for consistency
Signed-off-by: Michael Russo <merusso@gmail.com>
* fix: add short circuit when dependency version is not specified
Signed-off-by: Michael Russo <merusso@gmail.com>
* feat: Add test for multiple validation errors
Signed-off-by: Michael Russo <merusso@gmail.com>
* fix: Run go mod tidy
Signed-off-by: Michael Russo <merusso@gmail.com>
* feat: add tests for ToVersionedRegistry
Signed-off-by: Michael Russo <merusso@gmail.com>
* fix: simplify listInstalledAddons loop
Signed-off-by: Michael Russo <merusso@gmail.com>
* feat: listAvailableAddons returns addons from multiple sources
Changes:
* implement ListAddonInfo in Registry
* add interface to aid testing of listAvailableAddons
* add tests for listAvailableAddons
Signed-off-by: Michael Russo <merusso@gmail.com>
* refactor: simplify validateAddonDependencies
move logic from validateAddonDependencies to
calculateDependencyVersionToInstall.
Signed-off-by: Michael Russo <merusso@gmail.com>
* fix(lint): Implicit memory aliasing in for loop.
Signed-off-by: Michael Russo <merusso@gmail.com>
* fix(lint): non-wrapping format verb for fmt.Errorf
Signed-off-by: Michael Russo <merusso@gmail.com>
* fix(lint): indent-error-flow: (revive)
Signed-off-by: Michael Russo <merusso@gmail.com>
* fix(lint): unexported-return
Signed-off-by: Michael Russo <merusso@gmail.com>
* fix(lint): exported type comment format (revive)
Signed-off-by: Michael Russo <merusso@gmail.com>
* fix(lint): refactor AddonInfo to ItemInfo, avoid "stutter" (revive)
Signed-off-by: Michael Russo <merusso@gmail.com>
* fix(lint): add comment to exported method Registry.ListAddonInfo
Signed-off-by: Michael Russo <merusso@gmail.com>
* fix(lint): fix stutter, rename AddonInfoLister to ItemInfoLister
Signed-off-by: Michael Russo <merusso@gmail.com>
* chore: Add suite tests for Registry.ListAddonInfo()
Signed-off-by: Michael Russo <merusso@gmail.com>
* Test: add test cases for addon.sortVersionsDescending
Signed-off-by: Michael Russo <merusso@gmail.com>
---------
Signed-off-by: Michael Russo <merusso@gmail.com>
* Fix: read oss addon prefix bug
This bug is about list OSS bucket by prefix which will cause confusion between `terraform` and `terraform-alibaba`
Signed-off-by: qiaozp <chivalry.pp@gmail.com>
* add test
Signed-off-by: qiaozp <chivalry.pp@gmail.com>
* fix data race
Signed-off-by: qiaozp <chivalry.pp@gmail.com>
* fix channel block
add test
Signed-off-by: qiaozp <chivalry.pp@gmail.com>
* reviewable
Signed-off-by: qiaozp <chivalry.pp@gmail.com>