Skip to content

Commit ff0f64e

Browse files
committed
Merge remote-tracking branch 'origin/main' into 1720-add-config-option-to-disable-organisation-creation-for-an-devguard-instance
2 parents 0588a22 + 45842e2 commit ff0f64e

168 files changed

Lines changed: 4277 additions & 4527 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/devguard-scanner.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
substituters = https://cache.nixos.org https://nix.garage.l3montree.cloud
4747
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nix.garage.l3montree.cloud:MGlzfPQKA91/zxw91CN+GP7NpjAAwmKvWXlDYgeeI8k=
4848
- name: Run unittests
49-
run: nix develop . --command bash -c "go test \$(go list ./... | grep -v '/mocks') -coverprofile=coverage.out && go tool cover -func=coverage.out"
49+
run: nix develop . --command bash -c "go test -timeout 20m \$(go list ./... | grep -v '/mocks') -coverprofile=coverage.out && go tool cover -func=coverage.out"
5050
- name: Archive code coverage results
5151
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 - https://github.com/actions/upload-artifact/releases/tag/v4.6.2
5252
with:
@@ -121,7 +121,7 @@ jobs:
121121
devguard-token: ${{ secrets.DEVGUARD_TOKEN }}
122122

123123
postgresql-pipeline:
124-
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main'
124+
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/')
125125
uses: l3montree-dev/devguard-action/.github/workflows/full-nix.yml@nix
126126
permissions:
127127
contents: read

.github/workflows/vulndb.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ jobs:
2222
FRONTEND_URL: "doesntmatter"
2323
services:
2424
postgres:
25-
image: ghcr.io/l3montree-dev/devguard-postgresql:v0.5.3@sha256:a06c9e7c8ee334790cc66d52e89ff5ef05352ab264841d3d9f3659c046732251
25+
image: ghcr.io/l3montree-dev/devguard/postgresql:v1.3.1
2626
env:
2727
POSTGRES_DB: ${{env.POSTGRES_DB}}
2828
POSTGRES_USER: ${{env.POSTGRES_USER}}
2929
POSTGRES_PASSWORD: ${{env.POSTGRES_PASSWORD}}
3030
ports:
3131
- 5432:5432
32-
options: '--health-cmd="pg_isready -U devguard" --health-interval=10s --health-timeout=5s --health-retries=5 '
32+
options: '--health-cmd="pg_isready -U devguard" --health-interval=10s --health-timeout=5s --health-retries=5 --tmpfs /docker-entrypoint-initdb.d --tmpfs /run/postgresql'
3333
steps:
3434
- name: Install postgresql client
3535
run: |

accesscontrol/members.go

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -14,72 +14,3 @@
1414
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1515

1616
package accesscontrol
17-
18-
import (
19-
"maps"
20-
21-
"github.com/l3montree-dev/devguard/dtos"
22-
"github.com/l3montree-dev/devguard/shared"
23-
"github.com/l3montree-dev/devguard/utils"
24-
"github.com/ory/client-go"
25-
)
26-
27-
// FetchMembersOfOrganization retrieves all members of an organization including their roles
28-
// from both the RBAC system and third-party integrations
29-
func FetchMembersOfOrganization(ctx shared.Context) ([]dtos.UserDTO, error) {
30-
// get all members from the organization
31-
organization := shared.GetOrg(ctx)
32-
accessControl := shared.GetRBAC(ctx)
33-
34-
members, err := accessControl.GetAllMembersOfOrganization()
35-
36-
if err != nil {
37-
return nil, err
38-
}
39-
40-
users := make([]dtos.UserDTO, 0, len(members))
41-
if len(members) > 0 {
42-
// get the auth admin client from the context
43-
authAdminClient := shared.GetAuthAdminClient(ctx)
44-
// fetch the users from the auth service
45-
m, err := authAdminClient.ListUser(client.IdentityAPIListIdentitiesRequest{}.Ids(members))
46-
if err != nil {
47-
return nil, err
48-
}
49-
50-
// get the roles for the members
51-
errGroup := utils.ErrGroup[map[string]shared.Role](10)
52-
for _, member := range m {
53-
errGroup.Go(func() (map[string]shared.Role, error) {
54-
role, err := accessControl.GetDomainRole(member.Id)
55-
if err != nil {
56-
return map[string]shared.Role{member.Id: shared.RoleUnknown}, nil
57-
}
58-
return map[string]shared.Role{member.Id: role}, nil
59-
})
60-
}
61-
62-
roles, err := errGroup.WaitAndCollect()
63-
if err != nil {
64-
return nil, err
65-
}
66-
67-
roleMap := utils.Reduce(roles, func(acc map[string]shared.Role, r map[string]shared.Role) map[string]shared.Role {
68-
maps.Copy(acc, r)
69-
return acc
70-
}, make(map[string]shared.Role))
71-
72-
for _, member := range m {
73-
users = append(users, dtos.UserDTO{
74-
ID: member.Id,
75-
Name: shared.IdentityName(member.Traits),
76-
Role: string(roleMap[member.Id]),
77-
})
78-
}
79-
}
80-
81-
// fetch all members from third party integrations
82-
thirdPartyIntegrations := shared.GetThirdPartyIntegration(ctx)
83-
users = append(users, thirdPartyIntegrations.GetUsers(organization)...)
84-
return users, nil
85-
}

cmd/devguard-cli/commands/vulndb_import.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,24 @@ import (
1414
)
1515

1616
func newImportCommand() *cobra.Command {
17+
var full bool
18+
var batchSize int
19+
var bulk bool
20+
var limitedToTables []string
21+
1722
importCmd := &cobra.Command{
1823
Use: "import",
1924
Short: "Import the latest state of the vulnerability database",
2025
Long: "Pulls the pre-built vulndb artifact from the OCI registry and applies all changes to the local database",
2126
RunE: func(cmd *cobra.Command, args []string) error {
2227
shared.LoadConfig() // nolint
2328
migrateDB()
29+
opts := shared.ImportOptions{
30+
Full: full,
31+
BatchSize: batchSize,
32+
Bulk: bulk,
33+
LimitedToTables: limitedToTables,
34+
}
2435
app := fx.New(
2536
fx.NopLogger,
2637
database.Module,
@@ -29,7 +40,7 @@ func newImportCommand() *cobra.Command {
2940
services.ServiceModule,
3041
vulndb.Module,
3142
fx.Invoke(func(svc shared.VulnDBService) error {
32-
return svc.ImportRC(context.Background())
43+
return svc.ImportRC(context.Background(), opts)
3344
}),
3445
)
3546

@@ -46,6 +57,11 @@ func newImportCommand() *cobra.Command {
4657
},
4758
}
4859

60+
importCmd.Flags().BoolVar(&full, "full", false, "Force a full import, ignoring the last-import watermark")
61+
importCmd.Flags().IntVar(&batchSize, "batchSize", 5000, "Number of OSV entries per batch (default 5000)")
62+
importCmd.Flags().BoolVar(&bulk, "bulk", false, "Load all gob data into RAM before writing (faster but uses ~2-3 GB memory)")
63+
importCmd.Flags().StringSliceVar(&limitedToTables, "limitedToTables", []string{}, "Comma-separated list of tables to limit the import to (e.g. --limitedToTables=cves,exploits,malicious_packages)")
64+
4965
return importCmd
5066
}
5167

cmd/devguard-cli/hashmigrations/hash_migration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func RunHashMigrationsIfNeeded(pool *pgxpool.Pool, daemonRunner shared.DaemonRun
9191
slog.Warn("could not clear vulndb.lastRCImport config", "err", err)
9292
}
9393
slog.Info("triggering full vulndb import after hash migration")
94-
if err := vulndbService.ImportRC(ctx); err != nil {
94+
if err := vulndbService.ImportRC(ctx, shared.ImportOptions{}); err != nil {
9595
return fmt.Errorf("full vulndb import after hash migration failed: %w", err)
9696
}
9797
}

cmd/devguard-scanner/commands/clean.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package commands
22

33
import (
4-
"context"
54
"log/slog"
65

76
"github.com/google/go-containerregistry/pkg/authn"
@@ -12,10 +11,6 @@ import (
1211
"github.com/spf13/cobra"
1312
)
1413

15-
func cleanImage(ctx context.Context, regOpts cosignoptions.RegistryOptions, cleanType cosignoptions.CleanType, imageRef string) error {
16-
return cosignclean.CleanCmd(ctx, regOpts, cleanType, imageRef, true)
17-
}
18-
1914
// NewCleanCommand returns a command that removes attestations/signatures from an OCI image.
2015
func NewCleanCommand() *cobra.Command {
2116
cmd := &cobra.Command{

cmd/devguard-scanner/commands/clean_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/google/go-containerregistry/pkg/registry"
2626
"github.com/google/go-containerregistry/pkg/v1/random"
2727
"github.com/google/go-containerregistry/pkg/v1/remote"
28+
cosignclean "github.com/sigstore/cosign/v2/cmd/cosign/cli"
2829
cosignoptions "github.com/sigstore/cosign/v2/cmd/cosign/cli/options"
2930
ociremote "github.com/sigstore/cosign/v2/pkg/oci/remote"
3031
)
@@ -100,7 +101,7 @@ func TestCleanImageCleanTypeAllRemovesAllTags(t *testing.T) {
100101
t.Fatal("signature tag should exist before clean")
101102
}
102103

103-
if err := cleanImage(context.Background(), regOpts, cosignoptions.CleanTypeAll, imageRef); err != nil {
104+
if err := cosignclean.CleanCmd(context.Background(), regOpts, cosignoptions.CleanTypeAll, imageRef, true); err != nil {
104105
t.Fatalf("cleanImage: %v", err)
105106
}
106107

@@ -130,7 +131,7 @@ func TestCleanImageCleanTypeAttestationLeavesSignatureTag(t *testing.T) {
130131
pushDummyImage(t, attTag, remoteOpts)
131132
pushDummyImage(t, sigTag, remoteOpts)
132133

133-
if err := cleanImage(context.Background(), regOpts, cosignoptions.CleanTypeAttestation, imageRef); err != nil {
134+
if err := cosignclean.CleanCmd(context.Background(), regOpts, cosignoptions.CleanTypeAttestation, imageRef, true); err != nil {
134135
t.Fatalf("cleanImage: %v", err)
135136
}
136137

@@ -160,7 +161,7 @@ func TestCleanImageCleanTypeSignatureLeavesAttestationTag(t *testing.T) {
160161
pushDummyImage(t, attTag, remoteOpts)
161162
pushDummyImage(t, sigTag, remoteOpts)
162163

163-
if err := cleanImage(context.Background(), regOpts, cosignoptions.CleanTypeSignature, imageRef); err != nil {
164+
if err := cosignclean.CleanCmd(context.Background(), regOpts, cosignoptions.CleanTypeSignature, imageRef, true); err != nil {
164165
t.Fatalf("cleanImage: %v", err)
165166
}
166167

@@ -179,7 +180,7 @@ func TestCleanImageNoTagsDoesNotError(t *testing.T) {
179180
pushBaseImage(t, imageRef, remoteOpts)
180181

181182
// no attestation/signature tags present — clean should still succeed
182-
if err := cleanImage(context.Background(), regOpts, cosignoptions.CleanTypeAll, imageRef); err != nil {
183+
if err := cosignclean.CleanCmd(context.Background(), regOpts, cosignoptions.CleanTypeAll, imageRef, true); err != nil {
183184
t.Fatalf("cleanImage on image with no sig/att tags failed: %v", err)
184185
}
185186
}

cmd/devguard-scanner/commands/intoto/intoto_record.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,14 @@ import (
2020
"fmt"
2121
"log/slog"
2222
"os"
23-
"strings"
2423

2524
toto "github.com/in-toto/in-toto-golang/in_toto"
2625
"github.com/l3montree-dev/devguard/cmd/devguard-scanner/config"
2726
"github.com/l3montree-dev/devguard/cmd/devguard-scanner/scanner"
28-
"github.com/l3montree-dev/devguard/utils"
2927
"github.com/pkg/errors"
3028
"github.com/spf13/cobra"
3129
)
3230

33-
func parseGitIgnore(path string) ([]string, error) {
34-
// read .gitignore if exists
35-
content, err := os.ReadFile(path)
36-
if err == nil {
37-
ignorePaths := strings.Split(string(content), "\n")
38-
39-
// make sure to remove new lines and empty strings
40-
ignorePaths = utils.Filter(
41-
utils.Map(utils.Map(ignorePaths, strings.TrimSpace), func(e string) string {
42-
// nextjs products a gitignore which contains /node_modules but we need to ignore /node_modules/
43-
if e == "/node_modules" {
44-
return e + "/"
45-
}
46-
return e
47-
}),
48-
func(e string) bool {
49-
return e != "" && e != "\n" && !strings.HasPrefix(strings.TrimSpace(e), "#")
50-
})
51-
52-
return ignorePaths, nil
53-
}
54-
55-
return nil, err
56-
}
57-
5831
func stopInTotoRecording(cmd *cobra.Command, args []string) error {
5932
if config.RuntimeInTotoConfig.Disabled {
6033
return nil
Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1 @@
11
package intotocmd
2-
3-
import (
4-
"os"
5-
"path"
6-
"testing"
7-
8-
"github.com/stretchr/testify/assert"
9-
)
10-
11-
func TestParseGitIgnore(t *testing.T) {
12-
t.Run("parseGitIgnore with empty strings", func(t *testing.T) {
13-
// create temp dir for testing
14-
dir, err := os.MkdirTemp("", "test")
15-
assert.NoError(t, err, "failed to create temporary directory")
16-
17-
defer os.RemoveAll(dir)
18-
19-
// Create a temporary .gitignore file for testing
20-
gitignoreContent := "\n.DS_Store\n\t\t\t\n"
21-
22-
filepath := path.Join(dir, ".gitignore")
23-
24-
err = os.WriteFile(filepath, []byte(gitignoreContent), 0600)
25-
assert.NoError(t, err, "failed to create temporary .gitignore file")
26-
27-
ignorePaths, err := parseGitIgnore(filepath)
28-
assert.NoError(t, err, "expected no error when reading .gitignore")
29-
assert.Equal(t, []string{".DS_Store"}, ignorePaths, "unexpected ignore paths")
30-
31-
})
32-
}

controllers/artifact_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ func (c *ArtifactController) BuildVulnerabilityReportPDF(ctx shared.Context) err
672672
SourceName: escapeLatex(v.Source.Name),
673673
SourceURL: escapeLatex(v.Source.URL),
674674
AffectedComponent: escapeLatex(dv.ComponentPurl),
675-
CveDescription: escapeLatex(dv.CVE.Description),
675+
CveDescription: escapeLatex(dv.GetCVE().Description),
676676
AnalysisState: escapeLatex(string(v.Analysis.State)),
677677
AnalysisResponse: escapeLatex(response),
678678
AnalysisDetail: escapeLatex(v.Analysis.Detail),

0 commit comments

Comments
 (0)