Skip to content

ROX-18202: Fix language layer error due to unique constraint #1223

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

Merged
merged 3 commits into from
Aug 9, 2023

Conversation

connorgorman
Copy link
Contributor

@connorgorman connorgorman commented Jul 22, 2023

The issue was laid out in the doc by David. Basically what's happening is that the sample images have layers that are identical so they have the same "layer_name" which is the digest, but the lineage is different. This means that if you have identical layers with vulns that have different lineages (or parent layers) then the second insertion is due to the conflict on the layer_name (insert does on conflict do nothing). This change makes it so that table is keyed on layer_name and lineage, effectively only deduping layers with the exact same parents (which is good because we don't need to reinsert the layers). The unit test should test this case

Note: for some reason, this does not work on scratch, but I find that less pressing because it seems to be when the language vuln is simply in the base layer

This is fixed by always evaluating language vulns even if there are no db features

@connorgorman connorgorman requested review from RTann and dcaravel July 22, 2023 04:23
@connorgorman connorgorman changed the title Fix language layer error due to unique constraint ROX-18202: Fix language layer error due to unique constraint Jul 22, 2023
@ghost
Copy link

ghost commented Jul 22, 2023

Images are ready for the commit at 7186419.

To use the images, use the tag 2.30.x-30-g7186419737.

@connorgorman
Copy link
Contributor Author

I'll look into the failure

@connorgorman
Copy link
Contributor Author

/retest

1 similar comment
@RTann
Copy link
Collaborator

RTann commented Jul 26, 2023

/retest

RegisterMigration(migrate.Migration{
ID: 20,
Up: migrate.Queries([]string{
`ALTER TABLE LanguageLayer DROP CONSTRAINT IF EXISTS languagelayer_pkey`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a generic, default constraint? I don't see it in my deployment:

postgres=# \d languagelayer
                         Table "public.languagelayer"
       Column       |          Type          | Collation | Nullable | Default 
--------------------+------------------------+-----------+----------+---------
 layer_id           | integer                |           | not null | 
 layer_name         | character varying(128) |           | not null | 
 component_data     | bytea                  |           | not null | 
 removed_components | text[]                 |           |          | 
 lineage            | character varying      |           |          | 
Indexes:
    "languagelayer_layer_name_key" UNIQUE CONSTRAINT, btree (layer_name)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

languagelayer_pkey is the name of the constraint after ALTER TABLE LanguageLayer ADD PRIMARY KEY (layer_name, lineage) is applied, the default name of a primary key looks to be <table name>_pkey

Possibly added to the migration so that it would not cause errors if re-ran.

ID: 20,
Up: migrate.Queries([]string{
`ALTER TABLE LanguageLayer DROP CONSTRAINT IF EXISTS languagelayer_pkey`,
`ALTER TABLE LanguageLayer DROP CONSTRAINT IF EXISTS languagelayer_layer_name_key`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so dropping this constraint removes the UNIQUE part of layer_name VARCHAR(128) NOT NULL UNIQUE?

api/v1/models.go Outdated
for _, dbFeatureVersion := range dbLayer.Features {
feature := featureFromDatabaseModel(dbFeatureVersion, opts.GetUncertifiedRHEL(), depMap)
if withFeatures || withVulnerabilities {
if dbLayer.Features != nil || namespaces.IsRHELNamespace(layer.NamespaceName) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would need to see if our scanning notes accounts for us still finding language vulns without OS-level vulns. Don't think we considered this possibility before

Copy link
Contributor

@dcaravel dcaravel Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the GetComponents flow used via GRPC looks like the OS-level comps vs. language comps are not dependent - FWIW

@connorgorman
Copy link
Contributor Author

/retest

@connorgorman connorgorman force-pushed the cgorman-fix-scanner-language-layer-error branch from b53279b to 8b4408a Compare July 27, 2023 18:54
Connor Gorman added 2 commits July 27, 2023 11:55
@connorgorman
Copy link
Contributor Author

/retest

dcaravel
dcaravel previously approved these changes Aug 2, 2023
Copy link
Contributor

@dcaravel dcaravel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Cloned and retested per the original findings and this indeed fixes the issue. Thanks @connorgorman !

@dcaravel dcaravel dismissed their stale review August 2, 2023 21:20

Dismissing - need to retest - force push'd changes were not brought into my tests.

Copy link
Contributor

@dcaravel dcaravel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retesting, GRPC looks good, HTTP is better except for if scratch is the base image detection fails. The changes to api/v1/models.go seemed to fix that, were those reverted due to other failing tests?

@connorgorman
Copy link
Contributor Author

Yeah i separated them because it was causing other issues and is a larger change

@connorgorman connorgorman merged commit dab8406 into master Aug 9, 2023
@connorgorman connorgorman deleted the cgorman-fix-scanner-language-layer-error branch August 9, 2023 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants