|
| 1 | +/* |
| 2 | + * This file is part of Dependency-Track. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * SPDX-License-Identifier: Apache-2.0 |
| 17 | + * Copyright (c) OWASP Foundation. All Rights Reserved. |
| 18 | + */ |
| 19 | +package org.dependencytrack.v4migrator; |
| 20 | + |
| 21 | +import org.jdbi.v3.core.Jdbi; |
| 22 | + |
| 23 | +/** |
| 24 | + * Seeds the v5 {@code PERMISSION} catalog from the apiserver's |
| 25 | + * {@code org.dependencytrack.auth.Permissions} enum at Flyway head |
| 26 | + * {@code 202605111028}. Keep this in sync with the enum. |
| 27 | + * |
| 28 | + * <p>The migrator owns v5 PERMISSION seeding because downstream join-table loads |
| 29 | + * ({@code USERS_PERMISSIONS}, {@code TEAMS_PERMISSIONS}) need to FK-resolve v5 |
| 30 | + * permission IDs (including v5-only entries such as |
| 31 | + * {@code PORTFOLIO_ACCESS_CONTROL_BYPASS}) before the apiserver runs its own |
| 32 | + * seeding step on first post-migration boot. |
| 33 | + * |
| 34 | + * <p>Seeding runs in {@code bootstrap} rather than {@code transform} so that a |
| 35 | + * documented "drop v5 schema, re-bootstrap, re-run load" recovery (see ADR-023 |
| 36 | + * §Resumability and the user-facing migration guide) leaves PERMISSION populated |
| 37 | + * without re-running {@code transform}. The INSERT uses |
| 38 | + * {@code ON CONFLICT ("NAME") DO NOTHING} and is safe to invoke repeatedly. |
| 39 | + */ |
| 40 | +public final class PermissionCatalog { |
| 41 | + |
| 42 | + private static final String SEED_SQL = """ |
| 43 | + INSERT INTO "PERMISSION" ("NAME", "DESCRIPTION") VALUES |
| 44 | + ('BOM_UPLOAD', 'Allows the ability to upload CycloneDX Software Bill of Materials (SBOM)'), |
| 45 | + ('VIEW_PORTFOLIO', 'Provides the ability to view the portfolio of projects, components, and licenses'), |
| 46 | + ('PORTFOLIO_ACCESS_CONTROL_BYPASS', 'Provides the ability to bypass portfolio access control, granting access to all projects'), |
| 47 | + ('PORTFOLIO_MANAGEMENT', 'Allows the creation, modification, and deletion of data in the portfolio'), |
| 48 | + ('PORTFOLIO_MANAGEMENT_CREATE', 'Allows the creation of data in the portfolio'), |
| 49 | + ('PORTFOLIO_MANAGEMENT_READ', 'Allows the reading of data in the portfolio'), |
| 50 | + ('PORTFOLIO_MANAGEMENT_UPDATE', 'Allows the updating of data in the portfolio'), |
| 51 | + ('PORTFOLIO_MANAGEMENT_DELETE', 'Allows the deletion of data in the portfolio'), |
| 52 | + ('VIEW_VULNERABILITY', 'Provides the ability to view the vulnerabilities projects are affected by'), |
| 53 | + ('VULNERABILITY_ANALYSIS', 'Provides all abilities to make analysis decisions on vulnerabilities'), |
| 54 | + ('VULNERABILITY_ANALYSIS_CREATE', 'Provides the ability to upload supported VEX documents to a project'), |
| 55 | + ('VULNERABILITY_ANALYSIS_READ', 'Provides the ability read the VEX document for a project'), |
| 56 | + ('VULNERABILITY_ANALYSIS_UPDATE', 'Provides the ability to make analysis decisions on vulnerabilities and upload supported VEX documents for a project'), |
| 57 | + ('VIEW_POLICY_VIOLATION', 'Provides the ability to view policy violations'), |
| 58 | + ('VULNERABILITY_MANAGEMENT', 'Allows all management permissions of internally-defined vulnerabilities'), |
| 59 | + ('VULNERABILITY_MANAGEMENT_CREATE', 'Allows creation of internally-defined vulnerabilities'), |
| 60 | + ('VULNERABILITY_MANAGEMENT_READ', 'Allows reading internally-defined vulnerabilities'), |
| 61 | + ('VULNERABILITY_MANAGEMENT_UPDATE', 'Allows updating internally-defined vulnerabilities and vulnerability tags'), |
| 62 | + ('VULNERABILITY_MANAGEMENT_DELETE', 'Allows management of internally-defined vulnerabilities'), |
| 63 | + ('POLICY_VIOLATION_ANALYSIS', 'Provides the ability to make analysis decisions on policy violations'), |
| 64 | + ('ACCESS_MANAGEMENT', 'Allows the management of users, teams, and API keys'), |
| 65 | + ('ACCESS_MANAGEMENT_CREATE', 'Allows create permissions of users, teams, and API keys'), |
| 66 | + ('ACCESS_MANAGEMENT_READ', 'Allows read permissions of users, teams, and API keys'), |
| 67 | + ('ACCESS_MANAGEMENT_UPDATE', 'Allows update permissions of users, teams, and API keys'), |
| 68 | + ('ACCESS_MANAGEMENT_DELETE', 'Allows delete permissions of users, teams, and API keys'), |
| 69 | + ('SECRET_MANAGEMENT', 'Grants full secret management access'), |
| 70 | + ('SECRET_MANAGEMENT_CREATE', 'Grants the ability to create secrets'), |
| 71 | + ('SECRET_MANAGEMENT_UPDATE', 'Grants the ability to update secrets'), |
| 72 | + ('SECRET_MANAGEMENT_DELETE', 'Grants the ability to delete secrets'), |
| 73 | + ('SYSTEM_CONFIGURATION', 'Allows all access to configuration of the system including notifications, repositories, and email settings'), |
| 74 | + ('SYSTEM_CONFIGURATION_CREATE', 'Allows creating configuration of the system including notifications, repositories, and email settings'), |
| 75 | + ('SYSTEM_CONFIGURATION_READ', 'Allows reading the configuration of the system including notifications, repositories, and email settings'), |
| 76 | + ('SYSTEM_CONFIGURATION_UPDATE', 'Allows updating the configuration of the system including notifications, repositories, and email settings'), |
| 77 | + ('SYSTEM_CONFIGURATION_DELETE', 'Allows deleting the configuration of the system including notifications, repositories, and email settings'), |
| 78 | + ('PROJECT_CREATION_UPLOAD', 'Provides the ability to optionally create project (if non-existent) on BOM or scan upload'), |
| 79 | + ('POLICY_MANAGEMENT', 'Allows the creation, modification, and deletion of policy'), |
| 80 | + ('POLICY_MANAGEMENT_CREATE', 'Allows the creation of a policy'), |
| 81 | + ('POLICY_MANAGEMENT_READ', 'Allows reading of policies'), |
| 82 | + ('POLICY_MANAGEMENT_UPDATE', 'Allows the modification of a policy'), |
| 83 | + ('POLICY_MANAGEMENT_DELETE', 'Allows the deletion of a policy'), |
| 84 | + ('TAG_MANAGEMENT', 'Allows the modification and deletion of tags'), |
| 85 | + ('TAG_MANAGEMENT_DELETE', 'Allows the deletion of a tag') |
| 86 | + ON CONFLICT ("NAME") DO NOTHING |
| 87 | + """; |
| 88 | + |
| 89 | + private PermissionCatalog() { |
| 90 | + } |
| 91 | + |
| 92 | + public static int seed(final Jdbi target) { |
| 93 | + return target.withHandle(h -> h.execute(SEED_SQL)); |
| 94 | + } |
| 95 | +} |
0 commit comments