-
Notifications
You must be signed in to change notification settings - Fork 27
Add dependency proxy configs #1882
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
Open
refoo0
wants to merge
20
commits into
main
Choose a base branch
from
add-dependency-proxy-configs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e7b8588
add functions to safely retrieve organization, project, and asset fro…
refoo0 d4f3843
add dependency proxy secrets model and migration scripts
refoo0 bafe189
add dependency proxy secret repository and service implementations
refoo0 abf3a7c
add dependency proxy repository and service to providers
refoo0 e3e03e8
add CheckNotAllowedPackage function and tests
refoo0 6edcd37
add dependency proxy controller to asset, org, and project routers
refoo0 8a3df65
add ShareDependencyProxyRouter and integrate into dependency proxy co…
refoo0 3f79556
rename ProvideDependencyProxyConfig to ProvideDependencyProxyCache
refoo0 6ed9da6
add dependency proxy base URL to environment configuration
refoo0 fa2a8dc
Merge remote-tracking branch 'origin/main' into add-dependency-proxy-…
refoo0 ac0a79c
update dependency proxy secret handling and improve error reporting
refoo0 c6af48f
fix lint
refoo0 8e8b7e9
add validation for disallowed package patterns in PyPI proxy and upda…
refoo0 0775e61
Update IsMalicious method to return an error for valid versions
refoo0 59ccc10
Enhance dependency proxy handling by improving path decoding and vali…
refoo0 fdd6491
Refactor Go proxy cache handling
refoo0 0cc01cc
Refactor package pattern matching logic and improve URL joining for N…
refoo0 09333d5
Merge remote-tracking branch 'origin/main' into add-dependency-proxy-…
refoo0 11b5eb2
Update dependency proxy configurations and enhance error handling
refoo0 c862c6d
Add mock for DependencyProxySecretService and update MaliciousPackage…
refoo0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
database/migrations/20260410163018_add_dependency_proxy_secret.down.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| -- Copyright (C) 2026 l3montree GmbH | ||
| -- | ||
| -- This program is free software: you can redistribute it and/or modify | ||
| -- it under the terms of the GNU Affero General Public License as | ||
| -- published by the Free Software Foundation, either version 3 of the | ||
| -- License, or (at your option) any later version. | ||
| -- | ||
| -- This program is distributed in the hope that it will be useful, | ||
| -- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| -- GNU Affero General Public License for more details. | ||
| -- | ||
| -- You should have received a copy of the GNU Affero General Public License | ||
| -- along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| DROP TABLE IF EXISTS public.dependency_proxy_secrets; |
33 changes: 33 additions & 0 deletions
33
database/migrations/20260410163018_add_dependency_proxy_secret.up.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| -- Copyright (C) 2026 l3montree GmbH | ||
| -- | ||
| -- This program is free software: you can redistribute it and/or modify | ||
| -- it under the terms of the GNU Affero General Public License as | ||
| -- published by the Free Software Foundation, either version 3 of the | ||
| -- License, or (at your option) any later version. | ||
| -- | ||
| -- This program is distributed in the hope that it will be useful, | ||
| -- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| -- GNU Affero General Public License for more details. | ||
| -- | ||
| -- You should have received a copy of the GNU Affero General Public License | ||
| -- along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| CREATE TABLE IF NOT EXISTS public.dependency_proxy_secrets ( | ||
| secret uuid DEFAULT gen_random_uuid() PRIMARY KEY, | ||
| asset_id uuid, | ||
| project_id uuid, | ||
| org_id uuid, | ||
| CONSTRAINT dependency_proxy_secrets_exactly_one_scope CHECK ( | ||
| ((asset_id IS NOT NULL)::int + (project_id IS NOT NULL)::int + (org_id IS NOT NULL)::int) = 1 | ||
| ) | ||
| ); | ||
| CREATE UNIQUE INDEX IF NOT EXISTS dependency_proxy_secrets_unique_asset_id | ||
| ON public.dependency_proxy_secrets (asset_id) | ||
| WHERE asset_id IS NOT NULL; | ||
| CREATE UNIQUE INDEX IF NOT EXISTS dependency_proxy_secrets_unique_project_id | ||
| ON public.dependency_proxy_secrets (project_id) | ||
| WHERE project_id IS NOT NULL; | ||
| CREATE UNIQUE INDEX IF NOT EXISTS dependency_proxy_secrets_unique_org_id | ||
| ON public.dependency_proxy_secrets (org_id) | ||
| WHERE org_id IS NOT NULL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright (C) 2026 l3montree GmbH | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as | ||
| // published by the Free Software Foundation, either version 3 of the | ||
| // License, or (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| package models | ||
|
|
||
| import ( | ||
| "github.com/google/uuid" | ||
| ) | ||
|
|
||
| type DependencyProxySecret struct { | ||
| Secret uuid.UUID `gorm:"type:uuid;primaryKey; default:gen_random_uuid()"` | ||
| AssetID *uuid.UUID `gorm:"type:uuid;"` | ||
| ProjectID *uuid.UUID `gorm:"type:uuid;"` | ||
| OrgID *uuid.UUID `gorm:"type:uuid;"` | ||
| } | ||
|
|
||
| func (DependencyProxySecret) TableName() string { | ||
| return "dependency_proxy_secrets" | ||
| } |
123 changes: 123 additions & 0 deletions
123
database/repositories/dependency_proxy_secret_repository.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| // Copyright (C) 2026 l3montree GmbH | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as | ||
| // published by the Free Software Foundation, either version 3 of the | ||
| // License, or (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| package repositories | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/google/uuid" | ||
| "github.com/l3montree-dev/devguard/database/models" | ||
| "github.com/l3montree-dev/devguard/utils" | ||
| "gorm.io/gorm" | ||
| ) | ||
|
|
||
| type dependencyProxySecretRepository struct { | ||
| db *gorm.DB | ||
| utils.Repository[uuid.UUID, models.DependencyProxySecret, *gorm.DB] | ||
| } | ||
|
|
||
| func NewDependencyProxyRepository(db *gorm.DB) *dependencyProxySecretRepository { | ||
| return &dependencyProxySecretRepository{db: db, Repository: newGormRepository[uuid.UUID, models.DependencyProxySecret](db)} | ||
| } | ||
|
|
||
| func (r *dependencyProxySecretRepository) GetOrCreateByOrgID(ctx context.Context, tx *gorm.DB, orgID uuid.UUID) (models.DependencyProxySecret, error) { | ||
| var proxy models.DependencyProxySecret | ||
| err := r.db.WithContext(ctx).Where("org_id = ?", orgID).First(&proxy).Error | ||
| //check if not exists, then create a new one | ||
| if err != nil { | ||
| if err == gorm.ErrRecordNotFound { | ||
| newProxy := models.DependencyProxySecret{ | ||
| OrgID: &orgID, | ||
| } | ||
|
|
||
| err = r.Create(ctx, r.db, &newProxy) | ||
| return newProxy, err | ||
|
refoo0 marked this conversation as resolved.
|
||
| } | ||
| return proxy, err | ||
| } | ||
| return proxy, err | ||
| } | ||
|
|
||
| func (r *dependencyProxySecretRepository) GetOrCreateByProjectID(ctx context.Context, tx *gorm.DB, projectID uuid.UUID) (models.DependencyProxySecret, error) { | ||
| var proxy models.DependencyProxySecret | ||
| err := r.db.WithContext(ctx).Where("project_id = ?", projectID).First(&proxy).Error | ||
| //check if not exists, then create a new one | ||
| if err != nil { | ||
| if err == gorm.ErrRecordNotFound { | ||
| newProxy := models.DependencyProxySecret{ | ||
| ProjectID: &projectID, | ||
| } | ||
| err = r.Create(ctx, r.db, &newProxy) | ||
| return newProxy, err | ||
| } | ||
| return proxy, err | ||
| } | ||
| return proxy, err | ||
| } | ||
|
|
||
| func (r *dependencyProxySecretRepository) GetOrCreateByAssetID(ctx context.Context, tx *gorm.DB, assetID uuid.UUID) (models.DependencyProxySecret, error) { | ||
| var proxy models.DependencyProxySecret | ||
| err := r.db.WithContext(ctx).Where("asset_id = ?", assetID).First(&proxy).Error | ||
| //check if not exists, then create a new one | ||
| if err != nil { | ||
| if err == gorm.ErrRecordNotFound { | ||
| newProxy := models.DependencyProxySecret{ | ||
| AssetID: &assetID, | ||
| } | ||
| err = r.Create(ctx, r.db, &newProxy) | ||
| return newProxy, err | ||
| } | ||
| return proxy, err | ||
| } | ||
| return proxy, err | ||
| } | ||
|
|
||
| func (r *dependencyProxySecretRepository) UpdateSecret(ctx context.Context, tx *gorm.DB, proxy models.DependencyProxySecret) (models.DependencyProxySecret, error) { | ||
| exec := func(db *gorm.DB) error { | ||
| newSecret := uuid.New() | ||
| if err := db.Delete(&models.DependencyProxySecret{}, "secret = ?", proxy.Secret).Error; err != nil { | ||
| return err | ||
| } | ||
| proxy.Secret = newSecret | ||
| if err := db.Create(&proxy).Error; err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
| var err error | ||
| if tx != nil { | ||
| err = exec(tx.WithContext(ctx)) | ||
| } else { | ||
| err = r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { | ||
| return exec(tx) | ||
| }) | ||
| } | ||
| if err != nil { | ||
| return proxy, err | ||
| } | ||
|
|
||
| return proxy, nil | ||
| } | ||
|
|
||
| func (r *dependencyProxySecretRepository) GetBySecret(ctx context.Context, tx *gorm.DB, secret uuid.UUID) (models.DependencyProxySecret, error) { | ||
|
|
||
| var proxy models.DependencyProxySecret | ||
|
|
||
| if err := r.db.WithContext(ctx).Where("secret = ?", secret).First(&proxy).Error; err != nil { | ||
| return proxy, err | ||
| } | ||
|
|
||
| return proxy, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.