<!-- Copyright (c) 2026 defconxt. All rights reserved. -->
<!-- Licensed under AGPL-3.0 — see LICENSE file for details. -->
---
name: implementing-secure-package-publishing
description: >-
  Implement secure package publishing workflows with provenance attestation,
  signing, reproducible builds, and trusted publishing via OIDC to prevent
  unauthorized package releases and supply chain tampering.
domain: cybersecurity
subdomain: supply-chain-security
tags:
  - package-publishing
  - provenance
  - signing
  - reproducible-builds
  - oidc-publishing
  - artifact-integrity
version: "1.0"
author: defconxt
license: AGPL-3.0
metadata:
  mitre-attack: ["T1195.002"]
---

# Implementing Secure Package Publishing

## Overview

Secure package publishing protects the final mile of the software supply chain
— from build to registry. This skill covers provenance attestation (SLSA),
package signing with Sigstore, reproducible build verification, trusted
publishing via OIDC (eliminating stored API tokens), and publication workflow
hardening to prevent unauthorized or tampered releases.

Mode: `[MODE: ARCHITECT]` — Design and implement secure package publishing pipelines.

## Prerequisites

| Requirement | Details |
|---|---|
| cosign for signing (`brew install cosign`) | Required |
| slsa-verifier (`go install github.com/slsa-framework/slsa-verifier/v2/cli/slsa-verifier@latest`) | Required |
| npm/PyPI CLI for publishing | Required |
| GitHub Actions for CI/CD | Required |
| Python 3.10+ with `requests`, `sigstore` | Required |

## Key Concepts

### Provenance Attestation

```bash
# Generate SLSA provenance for npm package
npm publish --provenance

# Verify npm package provenance
npm audit signatures

# Generate SLSA provenance with GitHub Actions
# (in workflow YAML)
# - uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.9.0

# Verify SLSA provenance
slsa-verifier verify-artifact artifact.tar.gz \
  --provenance-path provenance.intoto.jsonl \
  --source-uri github.com/owner/repo
```

### Package Signing with Sigstore

```bash
# Sign artifact with cosign (keyless)
cosign sign-blob --bundle artifact.bundle artifact.tar.gz

# Verify signed artifact
cosign verify-blob --bundle artifact.bundle artifact.tar.gz \
  --certificate-identity workflow@github.com \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com

# Sign container image
cosign sign --yes ghcr.io/owner/image:tag
```

### Trusted Publishing (OIDC)

```bash
# PyPI trusted publishing — no stored tokens needed
# Configure in pyproject.toml:
# [tool.setuptools]
# ...

# GitHub Actions workflow for trusted publishing
# - uses: pypa/gh-action-pypi-publish@release/v1
#   with:
#     attestations: true

# npm trusted publishing with provenance
npm publish --provenance --access public
```

## Workflow

### Step 1: Verify package provenance and signatures

```bash
node scripts/agent.js --action verify --target /tmp/target --output /tmp/verify-result.json
```

### Step 2: Check publishing configuration for security

```bash
node scripts/agent.js --action configure --target /tmp/target --output /tmp/configure-result.json
```

### Step 3: Generate publishing security assessment

```bash
node scripts/agent.js --action report --target /tmp/target --output /tmp/report-result.json
```

## Detection

```yaml
title: Secure Package Publishing Detection
id: e3103d6e-e0df-44ac-bb8c-dd0a93518bff
status: experimental
description: Detects suspicious activity related to implementing secure package publishing techniques in supply chain security context
logsource:
  category: process_creation
  product: linux
detection:
  selection:
    CommandLine: "*implementing*secure*"
  condition: selection
level: medium
tags:
  - attack.t1195.002
  - attack.initial_access
falsepositives:
  - Package manager performing routine dependency resolution
```


**Detection Opportunities**

| Indicator | Source | Detection Logic |
|---|---|---|
| Secure Package Publishing Detection | linux/process_creation | Sigma rule (medium) |
| ATT&CK Coverage | MITRE ATT&CK | T1195.002 |

## Verification

- [ ] All published packages include SLSA provenance attestation
- [ ] Package signatures verified against expected identity
- [ ] Trusted publishing configured (no stored API tokens)
- [ ] Build process is reproducible and documented
- [ ] Publication requires multi-party approval workflow

## References

- [SLSA Framework](https://slsa.dev/)
- [Sigstore Documentation](https://docs.sigstore.dev/)
- [PyPI Trusted Publishing](https://docs.pypi.org/trusted-publishers/)
- [npm Provenance](https://docs.npmjs.com/generating-provenance-statements)
