Skip to content

Commit b4366a7

Browse files
committed
Add signing service inspection commands
[noissue]
1 parent 5e919f5 commit b4366a7

8 files changed

Lines changed: 138 additions & 4 deletions

File tree

.ci/run_container.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ curl -s http://localhost:8080/pulp/api/v3/status/ | jq ".versions"
4444
# shellcheck disable=SC2064
4545
trap "${CONTAINER_RUNTIME} stop pulp" EXIT
4646

47-
"${CONTAINER_RUNTIME}" exec -t pulp bash -c "pulpcore-manager reset-admin-password --password password"
47+
# Set admin password
48+
"${CONTAINER_RUNTIME}" exec pulp pulpcore-manager reset-admin-password --password password
49+
50+
# Setup a signing service
51+
"${CONTAINER_RUNTIME}" exec -i pulp bash -c "cat > /root/sign_deb_release.sh" < "${BASEPATH}/../tests/assets/sign_deb_release.sh"
52+
"${CONTAINER_RUNTIME}" exec -i pulp bash -c "cat > /tmp/setup_signing_service.py" < "${BASEPATH}/../tests/assets/setup_signing_service.py"
53+
curl -L https://github.com/pulp/pulp-fixtures/raw/master/common/GPG-KEY-pulp-qe | "${CONTAINER_RUNTIME}" exec -i pulp bash -c "cat > /tmp/GPG-KEY-pulp-qe"
54+
curl -L https://github.com/pulp/pulp-fixtures/raw/master/common/GPG-PRIVATE-KEY-pulp-qe | "${CONTAINER_RUNTIME}" exec -i pulp gpg --import
55+
echo "6EDF301256480B9B801EBA3D05A5E6DA269D9D98:6:" | "${CONTAINER_RUNTIME}" exec -i pulp gpg --import-ownertrust
56+
"${CONTAINER_RUNTIME}" exec pulp chmod a+x /root/sign_deb_release.sh /tmp/setup_signing_service.py
57+
"${CONTAINER_RUNTIME}" exec pulp /tmp/setup_signing_service.py /root/sign_deb_release.sh /tmp/GPG-KEY-pulp-qe
4858

4959
"$@"

CHANGES/189.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added signing-service list and show commands.

pulpcore/cli/core/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pulpcore.cli.core.orphans import orphans
1212
from pulpcore.cli.core.repository import repository
1313
from pulpcore.cli.core.show import show
14+
from pulpcore.cli.core.signing_service import signing_service
1415
from pulpcore.cli.core.status import status
1516
from pulpcore.cli.core.task import task
1617
from pulpcore.cli.core.user import user
@@ -29,6 +30,7 @@
2930
main.add_command(orphans)
3031
main.add_command(repository)
3132
main.add_command(show)
33+
main.add_command(signing_service)
3234
main.add_command(status)
3335
main.add_command(task)
3436
main.add_command(user)

pulpcore/cli/core/context.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def upload(self, file: IO[bytes], chunk_size: int = 1000000, check_exists: bool
8686

8787

8888
class PulpExporterContext(PulpEntityContext):
89-
ENTITY = "PulpExporter"
89+
ENTITY = "pulp exporter"
9090
HREF = "pulp_exporter_href"
9191
LIST_ID = "exporters_core_pulp_list"
9292
READ_ID = "exporters_core_pulp_read"
@@ -96,7 +96,7 @@ class PulpExporterContext(PulpEntityContext):
9696

9797

9898
class PulpExportContext(PulpEntityContext):
99-
ENTITY = "PulpExport"
99+
ENTITY = "pulp export"
100100
# This is replaced by a version aware property below
101101
# HREF = "pulp_pulp_export_href"
102102
LIST_ID = "exporters_core_pulp_exports_list"
@@ -267,7 +267,7 @@ def scope(self) -> Dict[str, Any]:
267267

268268

269269
class PulpImporterContext(PulpEntityContext):
270-
ENTITY = "PulpImporter"
270+
ENTITY = "pulp importer"
271271
HREF = "pulp_importer_href"
272272
CREATE_ID = "importers_core_pulp_create"
273273
READ_ID = "importers_core_pulp_read"
@@ -276,6 +276,14 @@ class PulpImporterContext(PulpEntityContext):
276276
LIST_ID = "importers_core_pulp_list"
277277

278278

279+
class PulpSigningServiceContext(PulpEntityContext):
280+
ENTITY = "signing service"
281+
ENTITIES = "signing services"
282+
HREF = "signing_service_href"
283+
LIST_ID = "signing_services_list"
284+
READ_ID = "signing_services_read"
285+
286+
279287
class PulpTaskContext(PulpEntityContext):
280288
ENTITY = "task"
281289
HREF = "task_href"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import gettext
2+
3+
import click
4+
5+
from pulpcore.cli.common.context import PulpContext, pass_pulp_context
6+
from pulpcore.cli.common.generic import href_option, list_command, name_option, show_command
7+
from pulpcore.cli.core.context import PulpSigningServiceContext
8+
9+
_ = gettext.gettext
10+
11+
12+
@click.group()
13+
@pass_pulp_context
14+
@click.pass_context
15+
def signing_service(ctx: click.Context, pulp_ctx: PulpContext) -> None:
16+
pulp_ctx.needs_plugin("core", min_version="3.10.dev")
17+
ctx.obj = PulpSigningServiceContext(pulp_ctx)
18+
19+
20+
lookup_options = [
21+
name_option,
22+
href_option,
23+
]
24+
25+
signing_service.add_command(list_command())
26+
signing_service.add_command(show_command(decorators=lookup_options))
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
6+
if __name__ == "__main__":
7+
8+
usage_string = "Usage: {} <path_to_signing_script> <path_to_public_key_file>".format(
9+
sys.argv[0]
10+
)
11+
12+
if len(sys.argv) != 3:
13+
print("ERROR: Not enough arguments!")
14+
print(usage_string)
15+
sys.exit(1)
16+
17+
script_path = os.path.realpath(sys.argv[1])
18+
public_key_file = os.path.realpath(sys.argv[2])
19+
20+
if not os.path.exists(script_path):
21+
print("ERROR: The signing script provided does not exist!")
22+
print(usage_string)
23+
sys.exit(1)
24+
25+
if not os.path.exists(public_key_file):
26+
print("ERROR: The public key file provided does not exist!")
27+
print(usage_string)
28+
sys.exit(1)
29+
30+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pulpcore.app.settings")
31+
32+
import django
33+
34+
django.setup()
35+
36+
from pulp_deb.app.models import AptReleaseSigningService
37+
38+
with open(public_key_file, "rb") as key:
39+
public_key = key.read()
40+
41+
AptReleaseSigningService.objects.create(
42+
name="sign_deb_release",
43+
script=script_path,
44+
public_key=public_key,
45+
pubkey_fingerprint="6EDF301256480B9B801EBA3D05A5E6DA269D9D98",
46+
)

tests/assets/sign_deb_release.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
RELEASE_FILE="$(/usr/bin/readlink -f "$1")"
6+
OUTPUT_DIR="$(/usr/bin/mktemp -d)"
7+
DETACHED_SIGNATURE_PATH="${OUTPUT_DIR}/Release.gpg"
8+
INLINE_SIGNATURE_PATH="${OUTPUT_DIR}/InRelease"
9+
GPG_KEY_ID="Pulp QE"
10+
11+
# Create a detached signature
12+
/usr/bin/gpg --batch --armor --digest-algo SHA256 \
13+
--detach-sign \
14+
--output "${DETACHED_SIGNATURE_PATH}" \
15+
--local-user "${GPG_KEY_ID}" \
16+
"${RELEASE_FILE}"
17+
18+
# Create an inline signature
19+
/usr/bin/gpg --batch --armor --digest-algo SHA256 \
20+
--clearsign \
21+
--output "${INLINE_SIGNATURE_PATH}" \
22+
--local-user "${GPG_KEY_ID}" \
23+
"${RELEASE_FILE}"
24+
25+
echo "{" \
26+
\"signatures\": "{" \
27+
\"inline\": \""${INLINE_SIGNATURE_PATH}"\", \
28+
\"detached\": \""${DETACHED_SIGNATURE_PATH}"\" \
29+
"}" \
30+
"}"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
# shellcheck source=tests/scripts/config.source
4+
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source
5+
6+
pulp debug has-plugin --name "core" --min-version 3.8 || exit 3
7+
pulp debug has-plugin --name "deb" || exit 3
8+
9+
expect_succ pulp signing-service list
10+
expect_succ test "$(echo "$OUTPUT" | jq -r length)" -ge "1"
11+
expect_succ pulp signing-service show --name "sign_deb_release"

0 commit comments

Comments
 (0)