Skip to content

Commit 6387320

Browse files
author
GitLab Bot
committed
Add latest changes from gitlab-org/gitlab@master
1 parent 35ca7dd commit 6387320

File tree

12 files changed

+350
-10
lines changed

12 files changed

+350
-10
lines changed

GITALY_SERVER_VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
af0566ee3ca5075025da8442a44ba7e411caa530
1+
3f12b41f93ded89c6ee7843526bf5529982250af

app/assets/javascripts/pages/projects/shared/permissions/components/settings_panel.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ export default {
9494
),
9595
pipelineExecutionPoliciesLabel: s__('ProjectSettings|Pipeline execution policies'),
9696
sppRepositoryPipelineAccessLabel: s__(
97-
'ProjectSettings|Grant access to this repository for projects linked to it as the security policy project source for security policies.',
97+
'ProjectSettings|Grant access to the CI/CD configurations for projects linked to this security policy project as the source for security policies.',
9898
),
9999
sppRepositoryPipelineAccessHelpText: s__(
100-
'ProjectSettings|Allow users and tokens read-only access to fetch security policy configurations within this project to enforce policies. %{linkStart}Learn more%{linkEnd}.',
100+
'ProjectSettings|Allow users and tokens read-only access to fetch security policy configurations in this project to enforce policies. %{linkStart}Learn more%{linkEnd}.',
101101
),
102102
},
103103
VISIBILITY_LEVEL_PRIVATE_INTEGER,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
migration_job_name: BackfillIdentifierNamesOfVulnerabilityReads
3+
description: Backfills identifier_names column for vulnerability_reads table.
4+
feature_category: vulnerability_management
5+
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/163088
6+
milestone: '17.5'
7+
queued_migration_version: 20241007115637
8+
finalize_after: '2024-10-20'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
class QueueBackfillIdentifierNamesOfVulnerabilityReads < Gitlab::Database::Migration[2.2]
4+
milestone '17.5'
5+
6+
restrict_gitlab_migration gitlab_schema: :gitlab_sec
7+
8+
MIGRATION = "BackfillIdentifierNamesOfVulnerabilityReads"
9+
DELAY_INTERVAL = 160.seconds
10+
BATCH_SIZE = 12000
11+
SUB_BATCH_SIZE = 40 # Total number of sub-batches: 375
12+
13+
def up
14+
queue_batched_background_migration(
15+
MIGRATION,
16+
:vulnerability_reads,
17+
:id,
18+
job_interval: DELAY_INTERVAL,
19+
batch_size: BATCH_SIZE,
20+
sub_batch_size: SUB_BATCH_SIZE
21+
)
22+
end
23+
24+
def down
25+
delete_batched_background_migration(MIGRATION, :vulnerability_reads, :id, [])
26+
end
27+
end

db/schema_migrations/20241007115637

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
edcd4fe555d70c81956eabc52e6207e8a81f81620e64869cdfdd72e55113be4c

doc/administration/packages/container_registry_metadata_database.md

+44-2
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ you must restore to a backup of the desired version in order to downgrade.
506506

507507
## Troubleshooting
508508

509-
### `there are pending database migrations` error
509+
### Error: `there are pending database migrations`
510510

511511
If the registry has been updated and there are pending schema migrations,
512512
the registry fails to start with the following error message:
@@ -517,7 +517,7 @@ FATA[0000] configuring application: there are pending database migrations, use t
517517

518518
To fix this issue, follow the steps to [apply schema migrations](#apply-schema-migrations).
519519

520-
### `offline garbage collection is no longer possible` error
520+
### Error: `offline garbage collection is no longer possible`
521521

522522
If the registry uses the metadata database and you try to run
523523
[offline garbage collection](container_registry.md#container-registry-garbage-collection),
@@ -626,3 +626,45 @@ You must truncate the table manually on your PostgreSQL instance:
626626
```
627627
628628
1. After truncating the `tags` table, try running the migration process again.
629+
630+
### Error: `database-in-use lockfile exists`
631+
632+
If you try to [migrate existing registries](#existing-registries) and encounter the following error:
633+
634+
```shell
635+
| [0s] step two: import tags failed to import metadata: importing all repositories: 1 error occurred:
636+
* could not restore lockfiles: database-in-use lockfile exists
637+
```
638+
639+
This error means that you have previously imported the registry and completed importing all
640+
repository data (step two) and the `database-in-use` exists in the registry file system.
641+
You should not run the importer again if you encounter this issue.
642+
643+
If you must proceed, you must delete the `database-in-use` lock file manually from the file system.
644+
The file is located at `/path/to/rootdirectory/docker/registry/lockfiles/database-in-use`.
645+
646+
### Registry fails to start due to metadata management issues
647+
648+
The registry could fail to start with of the following errors:
649+
650+
#### Error: `registry filesystem metadata in use, please import data before enabling the database`
651+
652+
This error happens when the database is enabled in your configuration `registry['database'] = { 'enabled' => true}`
653+
but you have not [migrated existing data](#existing-registries) to the metadata database yet.
654+
655+
#### Error: `registry metadata database in use, please enable the database`
656+
657+
This error happens when you have completed [migrating existing data](#existing-registries) to the metadata database,
658+
but you have not enabled the database in your configuration.
659+
660+
#### Problems checking or creating the lock files
661+
662+
If you encounter any of the following errors:
663+
664+
- `could not check if filesystem metadata is locked`
665+
- `could not check if database metadata is locked`
666+
- `failed to mark filesystem for database only usage`
667+
- `failed to mark filesystem only usage`
668+
669+
The registry cannot access the configured `rootdirectory`. This error is unlikely to happen if you
670+
had a working registry previously. Review the error logs for any misconfiguration issues.

doc/user/application_security/policies/pipeline_execution_policies.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,21 @@ These stages are always available, regardless of any project's CI/CD configurati
128128
| `file` | `string` | true | A full file path relative to the root directory (/). The YAML files must have the `.yml` or `.yaml` extension. |
129129
| `ref` | `string` | false | The ref to retrieve the file from. Defaults to the HEAD of the project when not specified. |
130130

131-
To run pipelines with injected CI/CD configuration, users must have access to the project with the CI/CD configuration.
131+
Use the `content` type in a policy to reference a CI/CD configuration stored in another repository.
132+
This allows you to reuse the same CI/CD configuration across multiple policies, reducing the
133+
overhead of maintaining these configurations. For example, if you have a custom secret detection
134+
CI/CD configuration you want to enforce in policy A and policy B, you can create a single YAML configuration file and reference the configuration in both policies.
132135

133-
Starting in GitLab 17.4, users can store the CI/CD configuration in a security policy project repository and grant pipeline execution access to the repository. Projects linked to the security policy project then have access to the repository as a source for security policies.
134-
You can configure this in the project's general settings for security policy projects.
136+
Prerequisites:
137+
138+
- Users triggering pipelines run in those projects on which a policy containing the `content` type
139+
is enforced must have at minimum read-only access to the project containing the CI/CD
140+
- In projects that enforce pipeline execution policies, users must have at least read-only access to the project that contains the CI/CD configuration to trigger the pipeline.
141+
142+
In GitLab 17.4 and later, you can grant the required read-only access for the CI/CD configuration file
143+
specified in a security policy project using the `content` type. To do so, enable the setting **Pipeline execution policies** in the general settings of the security policy project.
144+
Enabling this setting grants the user who triggered the pipeline access to
145+
read the CI/CD configuration file enforced by the pipeline execution policy. This setting does not grant the user access to any other parts of the project where the configuration file is stored.
135146

136147
### `policy_scope` scope type
137148

doc/user/project/repository/repository_size.md

+2
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ For example, to get a list of files at a given commit or branch sorted by size:
323323
324324
The third column in the output is the object ID of the blob.
325325
326+
Alternatively, you can get these IDs using the [Repositories API list repository tree](../../../api/repositories.md#list-repository-tree) endpoint.
327+
326328
## Storage limits
327329
328330
Repository size limits:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
3+
module Gitlab
4+
module BackgroundMigration
5+
class BackfillIdentifierNamesOfVulnerabilityReads < BatchedMigrationJob
6+
operation_name :backfill_identifier_names
7+
feature_category :vulnerability_management
8+
9+
UPDATE_SQL = <<~SQL
10+
UPDATE vulnerability_reads AS vr
11+
SET identifier_names = selected_ids.names
12+
FROM (?) AS selected_ids
13+
WHERE vr.id = selected_ids.id
14+
SQL
15+
16+
class VulnerabilitiesRead < ::Gitlab::Database::SecApplicationRecord
17+
self.table_name = 'vulnerability_reads'
18+
end
19+
20+
def perform
21+
each_sub_batch do |sub_batch|
22+
cte = Gitlab::SQL::CTE.new(:batched_relation, sub_batch.limit(40))
23+
24+
filtered_results = cte
25+
.apply_to(VulnerabilitiesRead.all)
26+
.joins(
27+
'INNER JOIN vulnerability_occurrences vo ' \
28+
'ON vulnerability_reads.vulnerability_id = vo.vulnerability_id'
29+
)
30+
.joins('INNER JOIN vulnerability_occurrence_identifiers voi ON vo.id = voi.occurrence_id')
31+
.joins('INNER JOIN vulnerability_identifiers vi ON voi.identifier_id = vi.id')
32+
.group("vulnerability_reads.id")
33+
.select(
34+
'vulnerability_reads.id AS id',
35+
'ARRAY_AGG(vi.name ORDER BY vi.name) AS names'
36+
)
37+
38+
update_query = VulnerabilitiesRead.sanitize_sql([UPDATE_SQL, filtered_results])
39+
40+
connection.execute(update_query)
41+
end
42+
end
43+
end
44+
end
45+
end

locale/gitlab.pot

+2-2
Original file line numberDiff line numberDiff line change
@@ -43101,7 +43101,7 @@ msgstr ""
4310143101
msgid "ProjectSettings|Allow skipping the merge train"
4310243102
msgstr ""
4310343103

43104-
msgid "ProjectSettings|Allow users and tokens read-only access to fetch security policy configurations within this project to enforce policies. %{linkStart}Learn more%{linkEnd}."
43104+
msgid "ProjectSettings|Allow users and tokens read-only access to fetch security policy configurations in this project to enforce policies. %{linkStart}Learn more%{linkEnd}."
4310543105
msgstr ""
4310643106

4310743107
msgid "ProjectSettings|Always show thumbs-up and thumbs-down emoji buttons on issues, merge requests, and snippets."
@@ -43266,7 +43266,7 @@ msgstr ""
4326643266
msgid "ProjectSettings|Global"
4326743267
msgstr ""
4326843268

43269-
msgid "ProjectSettings|Grant access to this repository for projects linked to it as the security policy project source for security policies."
43269+
msgid "ProjectSettings|Grant access to the CI/CD configurations for projects linked to this security policy project as the source for security policies."
4327043270
msgstr ""
4327143271

4327243272
msgid "ProjectSettings|Highlight the usage of hidden unicode characters. These have innocent uses for right-to-left languages, but can also be used in potential exploits."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe Gitlab::BackgroundMigration::BackfillIdentifierNamesOfVulnerabilityReads, feature_category: :vulnerability_management do
6+
let(:namespaces) { table(:namespaces) }
7+
let(:projects) { table(:projects) }
8+
let(:users) { table(:users) }
9+
let(:scanners) { table(:vulnerability_scanners) }
10+
let(:vulnerabilities) { table(:vulnerabilities) }
11+
let(:vulnerability_reads) { table(:vulnerability_reads) }
12+
let(:vulnerability_findings) { table(:vulnerability_occurrences) }
13+
let(:vulnerability_occurrence_identifiers) { table(:vulnerability_occurrence_identifiers) }
14+
let(:vulnerability_identifiers) { table(:vulnerability_identifiers) }
15+
16+
let(:namespace) { namespaces.create!(name: 'user', path: 'user') }
17+
let(:project) { projects.create!(namespace_id: namespace.id, project_namespace_id: namespace.id) }
18+
let(:user) { users.create!(username: 'john_doe', email: '[email protected]', projects_limit: 10) }
19+
let(:scanner) { scanners.create!(project_id: project.id, external_id: 'external_id', name: 'Test Scanner') }
20+
21+
shared_context 'with vulnerability data' do
22+
let(:identifier_1) do
23+
create_identifier(external_id: 'A03:2021', external_type: 'owasp', name: 'A03:2021 - Injection')
24+
end
25+
26+
let(:identifier_2) { create_identifier(external_id: 'CVE-2021-1234', external_type: 'cve', name: 'CVE-2021-1234') }
27+
let(:identifier_3) { create_identifier(external_id: '79', external_type: 'cwe', name: 'CWE-79') }
28+
29+
let(:finding_1) { create_finding(primary_identifier_id: identifier_1.id) }
30+
let(:finding_2) { create_finding(primary_identifier_id: identifier_2.id) }
31+
let(:finding_3) { create_finding(primary_identifier_id: identifier_3.id) }
32+
33+
let(:vulnerability_1) { create_vulnerability(title: 'vulnerability 1', finding_id: finding_1.id) }
34+
let(:vulnerability_2) { create_vulnerability(title: 'vulnerability 2', finding_id: finding_2.id) }
35+
let(:vulnerability_3) { create_vulnerability(title: 'vulnerability 3', finding_id: finding_3.id) }
36+
37+
let!(:vulnerability_read_1) { create_vulnerability_read(vulnerability_id: vulnerability_1.id) }
38+
let!(:vulnerability_read_2) { create_vulnerability_read(vulnerability_id: vulnerability_2.id) }
39+
let!(:vulnerability_read_3) { create_vulnerability_read(vulnerability_id: vulnerability_3.id) }
40+
41+
before do
42+
create_vulnerability_occurrence_identifier(occurrence_id: finding_1.id, identifier_id: identifier_1.id)
43+
create_vulnerability_occurrence_identifier(occurrence_id: finding_2.id, identifier_id: identifier_2.id)
44+
create_vulnerability_occurrence_identifier(occurrence_id: finding_3.id, identifier_id: identifier_3.id)
45+
46+
finding_1.update!(vulnerability_id: vulnerability_1.id)
47+
finding_2.update!(vulnerability_id: vulnerability_2.id)
48+
finding_3.update!(vulnerability_id: vulnerability_3.id)
49+
end
50+
end
51+
52+
describe '#perform' do
53+
subject(:perform_migration) do
54+
described_class.new(
55+
start_id: vulnerability_reads.first.id,
56+
end_id: vulnerability_reads.last.id,
57+
batch_table: :vulnerability_reads,
58+
batch_column: :id,
59+
sub_batch_size: vulnerability_reads.count,
60+
pause_ms: 0,
61+
connection: ActiveRecord::Base.connection
62+
).perform
63+
end
64+
65+
context 'with vulnerability data' do
66+
include_context 'with vulnerability data'
67+
68+
it 'updates identifier_names for vulnerability_reads' do
69+
expect { perform_migration }
70+
.to change { vulnerability_read_1.reload.identifier_names }
71+
.from([]).to(array_including(identifier_1.name))
72+
.and change { vulnerability_read_2.reload.identifier_names }
73+
.from([]).to(array_including(identifier_2.name))
74+
.and change { vulnerability_read_3.reload.identifier_names }
75+
.from([]).to(array_including(identifier_3.name))
76+
end
77+
78+
it 'updates identifier_names with correct aggregation' do
79+
create_vulnerability_occurrence_identifier(occurrence_id: finding_1.id, identifier_id: identifier_2.id)
80+
create_vulnerability_occurrence_identifier(occurrence_id: finding_2.id, identifier_id: identifier_3.id)
81+
82+
perform_migration
83+
84+
expect(vulnerability_read_1.reload.identifier_names).to contain_exactly(identifier_1.name,
85+
identifier_2.name)
86+
expect(vulnerability_read_2.reload.identifier_names).to contain_exactly(identifier_2.name,
87+
identifier_3.name)
88+
expect(vulnerability_read_3.reload.identifier_names).to contain_exactly(identifier_3.name)
89+
end
90+
91+
it 'sorts identifier_names' do
92+
create_vulnerability_occurrence_identifier(occurrence_id: finding_1.id, identifier_id: identifier_3.id)
93+
create_vulnerability_occurrence_identifier(occurrence_id: finding_1.id, identifier_id: identifier_2.id)
94+
95+
perform_migration
96+
97+
expect(vulnerability_read_1.reload.identifier_names).to eq([identifier_1.name,
98+
identifier_2.name, identifier_3.name])
99+
end
100+
end
101+
102+
context 'with no matching identifiers' do
103+
include_context 'with vulnerability data' do
104+
before do
105+
vulnerability_occurrence_identifiers.delete_all
106+
end
107+
end
108+
109+
it 'does not update identifier_names' do
110+
perform_migration
111+
112+
expect(vulnerability_reads.where.not(identifier_names: []).count).to eq(0)
113+
end
114+
end
115+
end
116+
117+
private
118+
119+
def create_vulnerability(overrides = {})
120+
vulnerabilities.create!({
121+
project_id: project.id,
122+
author_id: user.id,
123+
title: 'test',
124+
severity: 1,
125+
confidence: 1,
126+
report_type: 1
127+
}.merge(overrides))
128+
end
129+
130+
def create_vulnerability_read(overrides = {})
131+
vulnerability_reads.create!({
132+
project_id: project.id,
133+
vulnerability_id: 1,
134+
scanner_id: scanner.id,
135+
severity: 1,
136+
report_type: 1,
137+
state: 1,
138+
uuid: SecureRandom.uuid
139+
}.merge(overrides))
140+
end
141+
142+
def create_finding(overrides = {})
143+
vulnerability_findings.create!({
144+
project_id: project.id,
145+
scanner_id: scanner.id,
146+
severity: 5, # medium
147+
confidence: 2, # unknown,
148+
report_type: 99, # generic
149+
primary_identifier_id: create_identifier.id,
150+
project_fingerprint: SecureRandom.hex(20),
151+
location_fingerprint: SecureRandom.hex(20),
152+
uuid: SecureRandom.uuid,
153+
name: "CVE-2018-1234",
154+
raw_metadata: "{}",
155+
metadata_version: "test:1.0"
156+
}.merge(overrides))
157+
end
158+
159+
def create_identifier(overrides = {})
160+
vulnerability_identifiers.create!({
161+
project_id: project.id,
162+
external_id: "CVE-2018-1234",
163+
external_type: "CVE",
164+
name: "CVE-2018-1234",
165+
fingerprint: SecureRandom.hex(20)
166+
}.merge(overrides))
167+
end
168+
169+
def create_vulnerability_occurrence_identifier(overrides = {})
170+
vulnerability_occurrence_identifiers.create!({
171+
created_at: Time.now.utc,
172+
updated_at: Time.now.utc,
173+
occurrence_id: nil,
174+
identifier_id: nil
175+
}.merge(overrides))
176+
end
177+
end

0 commit comments

Comments
 (0)