Skip to content
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

Fix restrict-access to not restrict within same package #11014

Merged
merged 5 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20241119-162338.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Fix restrict-access to not apply within a package
time: 2024-11-19T16:23:38.144589-05:00
custom:
Author: gshank
Issue: "10134"
4 changes: 3 additions & 1 deletion core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1505,8 +1505,10 @@ def is_invalid_private_ref(
return is_private_ref and (
not hasattr(node, "group")
or not node.group
# Invalid reference because group does not match
or node.group != target_model.group
or restrict_package_access
# Or, invalid because these are different namespaces (project/package) and restrict-access is enforced
or (node.package_name != target_model.package_name and restrict_package_access)
)

def is_invalid_protected_ref(
Expand Down
45 changes: 45 additions & 0 deletions tests/functional/access/test_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,3 +470,48 @@ def test_dbt_project_access_config(self, project):
assert model_two.access == AccessType.Private
assert model_three.group == "marts"
assert model_three.access == AccessType.Public


models_yml = """
models:
- name: accounts
description: >
All accounts with whom we have done business. This is a very sensitive asset.
access: private
group: sales

columns:
- name: name
description: Name of the account.
tests:
- not_null
- unique

groups:
- name: sales
owner:
name: sales_owner
"""

accounts_sql = """
select 'Jane' as name
"""


class TestGenericTestRestrictAccess:
@pytest.fixture(scope="class")
def models(self):
return {
"models.yml": models_yml,
"accounts.sql": accounts_sql,
}

@pytest.fixture(scope="class")
def project_config_update(self):
return {
"restrict-access": True,
}

def test_generic_tests(self, project):
run_dbt(["run"])
run_dbt(["test"])