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

Add support for Rpm Package signing #3425

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pedro-psb
Copy link
Member

@pedro-psb pedro-psb commented Feb 5, 2024

This is a draft for implementing Rpm Package support in pulp_rpm.

My plan is (not necessarily in this order):

  • write test for service registration and validation with sample script (using rpm --addsign)
  • implement the RpmPackageSigningService model
  • write unit test for RpmTool
  • write functional tests with sample script (using rpm --addsign)
  • implement the API options and add new model fields
  • implement the signing call logic (I need to find the right spots to call it)
  • add documentation

other:

  • Fix tests: rpm-tool requires permission to access to /var/lib/rpm.
    Currently, my workaround is to change the permission of this folder, but I believe that's not an ideal approach.
  • Ship empty RPM package (for signing service validation).
  • Investigate why the functional test fails on on azure and s3.
  • Don't build an empty rpm on each validate call.
  • Decouple key used for signing from a specific signing service, so the same signing service can use different keys.

closes #2986

@github-actions github-actions bot added the multi-commit Added when a PR consists of more than one commit label Feb 6, 2024
@ipanova
Copy link
Member

ipanova commented Feb 7, 2024

#closes is wrong ;)

@pedro-psb
Copy link
Member Author

Ops

@pedro-psb pedro-psb force-pushed the add-rpm-sign-support branch 5 times, most recently from 5807490 to d3f921c Compare March 4, 2024 16:14
@pedro-psb pedro-psb force-pushed the add-rpm-sign-support branch 4 times, most recently from 9cdd600 to 9299ed4 Compare March 14, 2024 20:34
}
upload_task_href = rpm_package_api.create(**upload_attrs).task
package_href = monitor_task(upload_task_href).created_resources[2]
package_loc_href = rpm_package_api.read(package_href).location_href
Copy link
Member Author

Choose a reason for hiding this comment

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

@dralley I'm using rpm_package_api.create direcly here, and it seems to be "leaking" throughout runs (I can see the number of artifacts increasing at each run).

I'm not sure what is the recommended way to keep runs as isolated as possible. Is it using gen_object_with_cleanup? I've tried that but then I receive an empty package.

I could use feedback about the general use of fixtures here as well.

Copy link
Contributor

@dralley dralley Mar 19, 2024

Choose a reason for hiding this comment

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

gen_object_with_cleanup is generally used with deletable resources like remotes, repositories, etc. Content isn't considered deletable, it goes through the orphan cleanup process which is indirect. Generally a test that needs completely fresh state (that is, deleting any previous content / artifacts and then re-creating them) will call orphan cleanup first and otherwise we'll just let it be.

It's perfectly OK to let the content / artifacts accumulate unless you need the test to create a new content / artifact during the test run which cannot pre-exist. Running orphan cleanup all the time unnecessarily would slow down the tests quite a bit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Running orphan cleanup all the time unnecessarily would slow down the tests quite a bit.

Yeah, true. Thanks for the clarification

@bersace
Copy link

bersace commented Apr 12, 2024

Just a question. Why do you need a new rpm package signing service ? Why core signing service can't do the job ?

@pedro-psb
Copy link
Member Author

pedro-psb commented Apr 12, 2024

Just a question. Why do you need a new rpm package signing service ? Why core signing service can't do the job ?

Our signing service models relies on the implementation of a validation method, which assures a registered signing script can really perform a specific type of signing on a file. Currently, the only pulpcore signing service implementation is for detached signatures, so we need another that knows how to validate an rpm package signature, which is "attached" and requires using the rpm cli tool.

https://github.com/pulp/pulpcore/blob/9192c2bf0ccb0e0a2df595fd3efdd0980c80ff34/pulpcore/app/models/content.py#L884

@bersace
Copy link

bersace commented Apr 12, 2024

@pedro-psb ok, got it. It's like pulp_deb:AptReleaseSigningService, you use it with --class ?

@pedro-psb
Copy link
Member Author

Yes, in the pulpcore-manager command you can specify what type of signing service you are registering through the --class option. If ommited, it will use the detached one I've linked.

@pedro-psb pedro-psb force-pushed the add-rpm-sign-support branch 6 times, most recently from ef49b8b to d833e55 Compare April 25, 2024 20:04
package_signing_service = RpmPackageSigningService.objects.get(pk=signing_service_pk)
uploaded_package = PulpTemporaryFile.objects.get(pk=temporary_file_pk)
with NamedTemporaryFile(mode="wb", dir=".", delete=False) as final_package:
print("*" * 100)
Copy link
Contributor

Choose a reason for hiding this comment

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

debug prints

item
for item in (serializer.validated_data.get(key) for key in ("upload", "repository"))
if item
]
Copy link
Contributor

Choose a reason for hiding this comment

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

[serializer.validated_data.get("upload"), serializer.validated_data.get("repository")] might be simpler

sign_package=True,
)
package_a_href = monitor_task(upload_response.task)
# import epdb;epdb.serve(port=12345)
Copy link
Contributor

Choose a reason for hiding this comment

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

leftovers

return file


def test_get_empty_rpm_is_valid(tmp_path, monkeypatch):
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably not necessary - either the empty rpm is there or it's not

@dralley
Copy link
Contributor

dralley commented May 16, 2024

We should document the limitations and give the feature a tech preview label

@github-actions github-actions bot removed the multi-commit Added when a PR consists of more than one commit label May 22, 2024
@pedro-psb pedro-psb force-pushed the add-rpm-sign-support branch 3 times, most recently from a1b4c25 to af6855c Compare May 22, 2024 21:46
@pedro-psb pedro-psb marked this pull request as ready for review May 22, 2024 21:47
@@ -0,0 +1 @@
Added supported for signing RPM Packages on upload.
Copy link
Member

Choose a reason for hiding this comment

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

Consider adding a sentence that this is in tech preview

@@ -0,0 +1,72 @@
import tempfile
Copy link
Member

Choose a reason for hiding this comment

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

hmm, maybe having this in modes/repository.py or models/signing_service.py will be better?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've followed pulpcore, which defines the base SigningService under content. But I agree, models/signing_service.py feels better (and its what pulp_deb does also).


1. Create a signing script capable of signing an RPM Package.
- The script receives a file path as its first argument.
- The script should return a json-formatted. No signature is required, since its embedded.
Copy link
Member

Choose a reason for hiding this comment

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

...a json-formatted output.

1. Register it with `pulpcore-manager add-signing-service`.
- The `--class` should be `rpm:RpmPackageSigningService`.
- The key provided here serves only for validating the script.
The signing fingerprint are provided dynamically, as [on upload signing](site:pulp_rpm/docs/user/guides/06-sign-packages/#on-upload).
Copy link
Member

Choose a reason for hiding this comment

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

s/are/is

### Example

```bash
# Create a Repository w/ required porams
Copy link
Member

Choose a reason for hiding this comment

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

s/porams/params

pulp rpm content upload \
--repository ${REPOSITORY} \
--file ${FILE} \
--sign-package True
Copy link
Member

Choose a reason for hiding this comment

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

Do I read this correctly that one need to specify on upload per package whether to sign it or not? Meaning that in repo there could be mixture of signed/unsigned content?
Have we considered to automatically sign on upload if the package signing service was defined on the repo?In the similar fashion as we do with metadata signing service?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, you understand correctly.
I remember we have discussed the possibility of doing something similar to this, I'm not sure why I didn't commit to this design.

I'll do like that, really looks more consistent with the usecase we want to support.

@github-actions github-actions bot added the multi-commit Added when a PR consists of more than one commit label May 28, 2024
What this does:
- Create RpmPackageSigningService
- Create RpmTool utility
- Add fields to Repository model
- Add branch on Package upload to sign the package with the associated
  SigningService and fingerprint.
- Add docs

Closes pulp#2986
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
multi-commit Added when a PR consists of more than one commit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Native obs-signd support for signing PULP hosted content
4 participants