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

Fixes the permission issue with import-all. #379

Merged
merged 1 commit into from
Jun 26, 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
1 change: 1 addition & 0 deletions CHANGES/373.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an issue when trying to use import-all as a non-admin user.
3 changes: 1 addition & 2 deletions pulp_ostree/app/tasks/importing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def import_all_refs_and_commits(artifact_pk, repository_pk, repository_name):
repository_name (str): The name of an OSTree repository (e.g., "repo").
Raises:
ValueError: If an OSTree repository could not be properly parsed or the specified ref
does not exist.
ValueError: If an OSTree repository could not be properly parsed.
"""
tarball_artifact = Artifact.objects.get(pk=artifact_pk)
repository = Repository.objects.get(pk=repository_pk)
Expand Down
2 changes: 1 addition & 1 deletion pulp_ostree/app/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class OstreeRepositoryViewSet(core.RepositoryViewSet, ModifyRepositoryActionMixi
"principal": "authenticated",
"effect": "allow",
"condition": [
"has_model_or_domain_or_obj_perms:ostree.import_commits_ostreerepository"
"has_model_or_domain_or_obj_perms:ostree.import_commits_ostreerepository",
"has_model_or_domain_or_obj_perms:ostree.view_ostreerepository",
],
},
Expand Down
47 changes: 47 additions & 0 deletions pulp_ostree/tests/functional/api/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,50 @@ def test_import_commits_same_ref(
assert added_content["ostree.commit"]["count"] == 1
assert added_content["ostree.content"]["count"] == 2
assert added_content["ostree.summary"]["count"] == 1


@pytest.mark.parallel
def test_import_all_as_ostree_repo_admin(
pulpcore_bindings,
gen_user,
role_factory,
gen_object_with_cleanup,
monitor_task,
ostree_repository_factory,
ostree_repositories_api_client,
ostree_repositories_versions_api_client,
tmp_path,
):
"""Create a role for ostree admin, then import a repository with import-all."""

os.chdir(tmp_path)
repo_name = "repo"
sample_dir = tmp_path / str(uuid.uuid4())
sample_file1 = sample_dir / str(uuid.uuid4())
branch_name = "foo"

# 1. create a first file
sample_dir.mkdir()
sample_file1.touch()

# 2. initialize a local OSTree repository and commit the created file
subprocess.run(["ostree", f"--repo={repo_name}", "init", "--mode=archive"])
subprocess.run(
["ostree", f"--repo={repo_name}", "commit", f"--branch={branch_name}", f"{sample_dir}/"]
)
subprocess.run(["tar", "-cvf", f"{repo_name}.tar", f"{repo_name}/"])

user = gen_user(model_roles=["ostree.ostreerepository_creator"])

with user:
artifact = gen_object_with_cleanup(pulpcore_bindings.ArtifactsApi, f"{repo_name}.tar")
repo = ostree_repository_factory(name=repo_name)
commit_data = OstreeImportAll(artifact.pulp_href, repo_name)
response = ostree_repositories_api_client.import_all(repo.pulp_href, commit_data)

repo_version = monitor_task(response.task).created_resources[0]

repository_version = ostree_repositories_versions_api_client.read(repo_version)
added_content = repository_version.content_summary.added
assert added_content["ostree.refs"]["count"] == 1
assert added_content["ostree.commit"]["count"] == 1
Loading