diff --git a/README.md b/README.md index 951dcee..ea9a9bb 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,7 @@ Both release callers pin the reviewed shared workflow at `7b046ce67239bf889ab68e This repository has one POM project, no ordinary JUnit suites, and no producer or SDK. The explicit POM-only policy runs the normal `release` profile with `clean verify` and captures the effective model in the same invocation. The publication file is `.flattened-pom.xml`, the actual POM selected by that lifecycle. Source/Javadoc goals remain enabled; POM packaging produces no attached JARs. This exemption cannot qualify service reactors or their original producer/SDK gates. -The policy records the current source version `26.10.6`, which is already published. It does not authorize republishing it. A future release requires a separately reconciled and reserved numeric monthly patch, coordinated POM/policy updates, an immutable tag at the reviewed source, and fresh cold validation. No version is allocated here. Central and `both` remain blocked because the policy deliberately has no unreviewed signing fingerprint; add the independently reviewed complete fingerprint before qualifying those destinations. GitHub-only validation is the default route. +The policy records the current source version `26.10.6`, which is already published. It does not authorize republishing it. A future release requires a separately reconciled and reserved numeric monthly patch, coordinated POM/policy updates, an immutable tag at the reviewed source, and fresh cold validation. No version is allocated here. The policy explicitly selects the independently verified prior publisher fingerprint; current hosted private-key access and publication rights still require their own gates. GitHub-only validation is the default route. Offline caller controls require Python 3.11+, Ruby with its standard YAML/JSON libraries, and a clean checkout of the exact shared workflow implementation. No helper implementation is copied into this repository: diff --git a/docs/central-release-prerequisites.md b/docs/central-release-prerequisites.md index ceee59b..a6b3072 100644 --- a/docs/central-release-prerequisites.md +++ b/docs/central-release-prerequisites.md @@ -35,6 +35,14 @@ An authenticated empty listing is distinct from a404 or incomplete listing. Account-visible two-sweep stability is not an atomic or global Portal snapshot. The workflow does not upload, publish, allocate a version, sign, or run Maven. +An unsupported component with a missing, empty or non-string PURL still makes the +inventory incomplete. Its failure report includes only a bounded structural +description: fixed known-field type labels, field counts, and at most eight +SHA-256 hashes of unknown field names. Component values, raw bodies, names, paths, +errors and credentials are excluded. This diagnostic does not supply coordinates +or permit version allocation; the actual schema must be established and separately +validated before the component can be accepted. + Parent6 and Jafly20 remain pinned. A future Jafly23 adoption requires actual Central publication proof first. Parent21 and BOM7 remain unreserved by this source change. Any later allocation must reconcile published versions and actual diff --git a/scripts/sonatype_deployments.py b/scripts/sonatype_deployments.py index bf4c102..6a120dd 100644 --- a/scripts/sonatype_deployments.py +++ b/scripts/sonatype_deployments.py @@ -3,6 +3,8 @@ import argparse import base64 from datetime import datetime +import hashlib +from itertools import islice import json import os from pathlib import Path @@ -23,13 +25,18 @@ PURL = re.compile(r'pkg:maven/io\.fireflysoftware/([A-Za-z0-9][A-Za-z0-9_.-]{0,199})@([A-Za-z0-9][A-Za-z0-9_.+-]{0,127})') QUALIFIER_VALUE = re.compile(r'[A-Za-z0-9][A-Za-z0-9_.+-]{0,127}') IDENTIFIER = re.compile(r'[A-Za-z0-9][A-Za-z0-9_-]{0,127}') +COMPONENT_FIELDS = ('purl', 'packageUrl', 'packageURL', 'packageType', 'type', 'name', + 'namespace', 'groupId', 'artifactId', 'version', 'classifier', 'packaging', + 'extension', 'filename', 'fileName', 'path', 'errors', 'warnings', + 'coordinates', 'componentName', 'componentId', 'id', 'gav') class InventoryError(ValueError): """Only fixed, credential-free diagnostics may cross this boundary.""" - def __init__(self, message, reason_code=None): + def __init__(self, message, reason_code=None, component_schema=None): super().__init__(message) self.reason_code = reason_code + self.component_schema = component_schema class NoRedirect(urllib.request.HTTPRedirectHandler): @@ -101,8 +108,23 @@ def timestamp(value): -def coordinate_error(code): - raise InventoryError('Portal component Maven coordinates are unsupported.', code) from None +def component_schema(component): + types = {type(None): 'null', bool: 'boolean', int: 'number', float: 'number', + str: 'string', list: 'array', dict: 'object'} + known = {key: types.get(type(component[key]), 'unsupported') + for key in COMPONENT_FIELDS if key in component} + unknown_count = len(component) - len(known) + unknown = islice((key for key in component if key not in COMPONENT_FIELDS), 8) + hashes = sorted(hashlib.sha256(key.encode('utf-8', 'surrogatepass')).hexdigest() + for key in unknown) + return {'schema': 1, 'componentKind': 'object', 'fieldCount': len(component), + 'knownFieldTypes': known, 'unknownFieldCount': unknown_count, + 'unknownFieldNamesSha256': hashes, 'unknownFieldsTruncated': unknown_count > len(hashes)} + + +def coordinate_error(code, component=None): + diagnostic = component_schema(component) if component is not None else None + raise InventoryError('Portal component Maven coordinates are unsupported.', code, diagnostic) from None def decode_coordinate(value): @@ -122,7 +144,7 @@ def maven_coordinate(component): coordinate_error('PURL_COMPONENT') purl = component.get('purl') if not isinstance(purl, str) or not purl: - coordinate_error('PURL_MISSING') + coordinate_error('PURL_MISSING', component) if len(purl) > 2048: coordinate_error('PURL_BOUNDS') scheme, colon, rest = purl.partition(':') @@ -260,9 +282,10 @@ def write_report(output, report): stream.write('\n') -def incomplete(reason='Portal reconciliation did not complete.', reason_code=None): +def incomplete(reason='Portal reconciliation did not complete.', reason_code=None, component_schema=None): return {'schema': 1, 'status': 'INCOMPLETE', 'namespace': NAMESPACE, 'reason': reason, **({'reasonCode': reason_code} if reason_code is not None else {}), + **({'componentSchema': component_schema} if component_schema is not None else {}), 'versionAllocated': False, 'releasePublished': False} @@ -273,7 +296,7 @@ def worker(output): write_report(output, report) return 0 except InventoryError as error: - write_report(output, incomplete(str(error), error.reason_code)) + write_report(output, incomplete(str(error), error.reason_code, error.component_schema)) return 1 except Exception: # Third-party exceptions can include URLs, headers or response bodies. diff --git a/tests/test_sonatype_deployments.py b/tests/test_sonatype_deployments.py index ead5464..7dd9e63 100644 --- a/tests/test_sonatype_deployments.py +++ b/tests/test_sonatype_deployments.py @@ -364,5 +364,68 @@ def test_worker_report_contains_only_fixed_failure_code_not_the_purl(self): self.assertFalse(report['versionAllocated']) +class ComponentDiagnosticTests(unittest.TestCase): + def report(self, component): + row = deployment(); row['deploymentComponents'] = [component] + api = Api([page([row])]) + with tempfile.TemporaryDirectory() as directory: + out = Path(directory) / 'report.json' + with patch.dict(os.environ, {'SONATYPE_USERNAME': 'synthetic', 'SONATYPE_PASSWORD': 'synthetic'}, clear=True), \ + patch.object(m.urllib.request, 'build_opener', return_value=api): + self.assertEqual(1, m.worker(out)) + report = json.loads(out.read_text()) + self.assertEqual('INCOMPLETE', report['status']) + self.assertFalse(report['versionAllocated']) + self.assertNotIn('PRIVATE-', out.read_text()) + self.assertNotIn('TOKEN-SENTINEL', out.read_text()) + self.assertEqual(0o600, out.stat().st_mode & 0o777) + return report + + def test_missing_purl_reports_known_field_types_without_values(self): + report = self.report({'packageUrl': 'PRIVATE-URL', 'name': 'PRIVATE-NAME', + 'errors': ['PRIVATE-ERROR'], 'PRIVATE-FIELD-NAME': 'TOKEN-SENTINEL'}) + self.assertEqual('PURL_MISSING', report['reasonCode']) + self.assertIn('componentSchema', report) + self.assertEqual({'schema': 1, 'componentKind': 'object', 'fieldCount': 4, + 'knownFieldTypes': {'packageUrl': 'string', 'name': 'string', 'errors': 'array'}, + 'unknownFieldCount': 1, 'unknownFieldNamesSha256': ['7640b675f865ebb3b23d429d8802477416c8ce644eaed5f3c65049c5ee66a32d'], + 'unknownFieldsTruncated': False}, report['componentSchema']) + + def test_missing_and_null_or_non_string_purl_remain_distinct_refusals(self): + for component, expected in [({}, {}), ({'purl': None}, {'purl': 'null'}), + ({'purl': False}, {'purl': 'boolean'}), + ({'purl': 1}, {'purl': 'number'}), + ({'purl': []}, {'purl': 'array'}), + ({'purl': ''}, {'purl': 'string'})]: + with self.subTest(expected=expected): + report = self.report(component) + self.assertIn('componentSchema', report) + self.assertEqual(expected, report['componentSchema']['knownFieldTypes']) + + def test_unknown_field_report_is_bounded_and_contains_no_field_names(self): + report = self.report({f'PRIVATE-FIELD-{index}': 'PRIVATE-VALUE' for index in range(128)}) + self.assertIn('componentSchema', report) + diagnostic = report['componentSchema'] + self.assertEqual(128, diagnostic['fieldCount']) + self.assertEqual(128, diagnostic['unknownFieldCount']) + self.assertEqual({}, diagnostic['knownFieldTypes']) + self.assertEqual(8, len(diagnostic['unknownFieldNamesSha256'])) + self.assertTrue(diagnostic['unknownFieldsTruncated']) + self.assertLess(len(json.dumps(report)), 1500) + for value in diagnostic['unknownFieldNamesSha256']: + self.assertRegex(value, r'^[0-9a-f]{64}$') + + def test_nested_values_never_enter_the_structural_report(self): + report = self.report({'purl': {'PRIVATE-NESTED-KEY': 'TOKEN-SENTINEL'}, + 'coordinates': {'PRIVATE-SECRET': ['PRIVATE-ERROR']}}) + self.assertIn('componentSchema', report) + self.assertEqual({'purl': 'object', 'coordinates': 'object'}, report['componentSchema']['knownFieldTypes']) + + def test_other_coordinate_refusals_do_not_gain_arbitrary_diagnostics(self): + report = self.report({'purl': 'pkg:maven/io.fireflysoftware/a@1#PRIVATE-SUBPATH'}) + self.assertEqual('PURL_SUBPATH', report['reasonCode']) + self.assertNotIn('componentSchema', report) + + if __name__ == '__main__': unittest.main()