{
  "id": "CB-UBU-PKG-001",
  "standard": "ubuntu",
  "version": "0.1.0",
  "url": "https://baselines.cirsec.org/b/ubuntu/v0.1.0/CB-UBU-PKG-001",
  "json": "https://baselines.cirsec.org/b/ubuntu/v0.1.0/CB-UBU-PKG-001.json",
  "yaml": "https://baselines.cirsec.org/b/ubuntu/v0.1.0/CB-UBU-PKG-001.yml",
  "profiles_effective": [
    "core",
    "server",
    "server-hardened",
    "desktop",
    "desktop-hardened"
  ],
  "license": "Text CC BY 4.0, code Apache-2.0",
  "attribution": "CIRSEC Baselines, https://baselines.cirsec.org",
  "control": {
    "id": "CB-UBU-PKG-001",
    "title": "Bind every APT repository to its signing key",
    "finding": {
      "title": "APT repositories are not bound to a signing key or bypass signature checks",
      "description": "A repository without its own key is trusted with every key known to APT, and options such as trusted=yes disable signature checks entirely."
    },
    "status": "active",
    "profiles": [
      "core"
    ],
    "risk": {
      "severity": "high"
    },
    "assessment": "automated",
    "tags": [
      "apt",
      "repositories",
      "signatures",
      "supply-chain"
    ],
    "description": "APT checks the signature of the `Release` file of each repository. The `Signed-By` option\n(`[signed-by=...]` in the one-line format, `Signed-By:` field in the deb822 `.sources` format)\nnames the keyring allowed to sign that repository. Without it, any key in\n`/etc/apt/trusted.gpg.d/` is accepted for every repository.\n\nPer-source options can also weaken or disable the checks: `trusted=yes`, `allow-insecure=yes`,\n`allow-weak=yes`, `allow-downgrade-to-insecure=yes`, `check-valid-until=no` and `check-date=no`.\n",
    "rationale": "Binding each repository to its own key limits a compromised or malicious third-party key to the\nrepository it was added for: it cannot sign packages that replace Ubuntu ones. Sources that\nbypass the signature checks let anyone on the network path, or controlling the mirror, install\narbitrary packages as root.\n",
    "impact": "None for the Ubuntu archive. A third-party repository (PPA, vendor repository) needs its key\nstored as a separate file (usually under `/etc/apt/keyrings/`) and referenced from its source\nentry. Keys left in `/etc/apt/trusted.gpg.d/` keep working for entries without `Signed-By`.\n",
    "notes": "Ubuntu 24.04 and 26.04 use the deb822 file `/etc/apt/sources.list.d/ubuntu.sources` with\n`Signed-By`: they pass. Ubuntu 20.04 and 22.04 use one-line entries in `/etc/apt/sources.list`\nwithout it, the Ubuntu keys being in `/etc/apt/trusted.gpg.d/`: they fail until fixed. The\nautomated fix adds the Ubuntu archive keyring to entries of `archive.ubuntu.com`,\n`<country>.archive.ubuntu.com`, `security.ubuntu.com` and `ports.ubuntu.com`. Other\nrepositories, internal mirrors and the bypass options are left to a human. The repositories\nwritten by the Ubuntu Pro client (`esm.ubuntu.com`) carry their own `Signed-By`.\n",
    "setting": {
      "location": "/etc/apt/sources.list, /etc/apt/sources.list.d/*.list, /etc/apt/sources.list.d/*.sources",
      "default_value": "Signed-By set on 24.04 and later (ubuntu.sources), missing on 20.04 and 22.04 (sources.list)",
      "recommended_value": "Signed-By on every entry, no option that disables or weakens signature checks"
    },
    "audit": {
      "manual": "Read every enabled entry in `/etc/apt/sources.list`, `/etc/apt/sources.list.d/*.list` and\n`/etc/apt/sources.list.d/*.sources`:\n1. each one-line entry has `[signed-by=<keyring>]`, each deb822 stanza a `Signed-By:` field;\n2. no entry sets `trusted=yes`, `allow-insecure=yes`, `allow-weak=yes`,\n   `allow-downgrade-to-insecure=yes`, `check-valid-until=no` or `check-date=no` (or the\n   matching deb822 fields).\n",
      "checks": [
        {
          "id": "sources",
          "engine": "shell",
          "description": "Signed-By and signature options of every enabled APT source entry.",
          "spec": {
            "script": "files=\nfor f in /etc/apt/sources.list /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources; do\n  [ -f \"$f\" ] && files=\"$files $f\"\ndone\n[ -n \"$files\" ] || { echo \"no APT source file\"; exit 2; }\n# One line per entry: file:line, types, URIs, suites, ;option=value list (lowercase).\n# shellcheck disable=SC2086\nawk '\n  function flush() { if (st && en != \"no\") print src \"\\t\" ty \"\\t\" ur \"\\t\" su \"\\t\" op; st = 0; ty = ur = su = op = en = \"\" }\n  FNR == 1 { flush(); d = FILENAME ~ /\\.sources$/ }\n  !d {\n    sub(/#.*/, \"\"); if ($1 !~ /^deb(-src)?$/) next\n    l = $0; o = \"\"; i = index(l, \"[\"); j = index(l, \"]\")\n    if (i && j > i) { o = substr(l, i + 1, j - i - 1); l = substr(l, 1, i - 1) \" \" substr(l, j + 1) }\n    split(l, w, \" \"); gsub(/[ \\t]+/, \";\", o)\n    print FILENAME \":\" FNR \"\\t\" w[1] \"\\t\" w[2] \"\\t\" w[3] \"\\t;\" tolower(o); next\n  }\n  /^#/ { next }\n  /^[ \\t]*$/ { flush(); next }\n  /^[ \\t]/ { next }\n  {\n    if (!st) { st = 1; src = FILENAME \":\" FNR }\n    k = $0; sub(/:.*/, \"\", k); k = tolower(k); v = $0; sub(/^[^:]*:[ \\t]*/, \"\", v)\n    if (k == \"types\") ty = v; else if (k == \"uris\") ur = v; else if (k == \"suites\") su = v\n    else if (k == \"enabled\") en = tolower(v)\n    else op = op \";\" k \"=\" tolower(v == \"\" ? \"inline\" : v)\n  }\n  END { flush() }' $files | awk -F '\\t' '\n  {\n    bad = \"\"\n    if ($5 !~ /;signed-by=/) bad = bad \" no-signed-by\"\n    n = split(\"trusted=yes allow-insecure=yes allow-weak=yes allow-downgrade-to-insecure=yes check-valid-until=no check-date=no\", o, \" \")\n    for (i = 1; i <= n; i++) if (index($5, \";\" o[i])) bad = bad \" \" o[i]\n    if (bad != \"\") { print $1 \" \" $3 \":\" bad; rc = 1 } else ok++\n  }\n  END { print ok + 0 \" entries bound to a key\"; exit rc }'\n"
          }
        }
      ]
    },
    "remediation": {
      "manual": "1. For each repository, store its public key in its own file, for example\n   `/etc/apt/keyrings/<vendor>.asc` (Ubuntu keys are in `/usr/share/keyrings/`).\n2. Reference it from the entry: `deb [signed-by=/etc/apt/keyrings/<vendor>.asc] https://...`\n   in the one-line format, or `Signed-By: /etc/apt/keyrings/<vendor>.asc` in a `.sources`\n   stanza. On 26.04, `apt modernize-sources` converts old entries to deb822.\n3. Remove `trusted=yes` and the other options that weaken the checks. A repository that only\n   works with them must be fixed by its owner (signed) or removed.\n4. Run `apt-get update` and check that it prints no signature warning.\n\nThe automated fix only adds `/usr/share/keyrings/ubuntu-archive-keyring.gpg` to entries of the\nUbuntu archive.\n",
      "effects": {
        "restart": "none",
        "disruption": "none",
        "lockout_risk": false
      },
      "rollback": "Restore the source files from the backup directory printed by `remediate.sh`.\n",
      "scripts": [
        {
          "id": "signed-by-ubuntu",
          "engine": "shell",
          "file": "fix.sh"
        }
      ]
    },
    "references": [
      {
        "title": "sources.list(5), Ubuntu manual pages",
        "url": "https://manpages.ubuntu.com/manpages/noble/man5/sources.list.5.html",
        "publisher": "Canonical",
        "kind": "vendor-doc",
        "accessed": "2026-10-19"
      },
      {
        "title": "apt-secure(8), Ubuntu manual pages",
        "url": "https://manpages.ubuntu.com/manpages/noble/man8/apt-secure.8.html",
        "publisher": "Canonical",
        "kind": "vendor-doc",
        "accessed": "2026-10-19"
      },
      {
        "title": "Ubuntu Server documentation - Third-party repository usage",
        "url": "https://documentation.ubuntu.com/server/explanation/software/third-party-repository-usage/",
        "publisher": "Canonical",
        "kind": "vendor-doc",
        "accessed": "2026-10-19"
      },
      {
        "title": "ANSSI-BP-028 v2.0 - Recommandations de configuration d'un système GNU/Linux (R59)",
        "url": "https://messervices.cyber.gouv.fr/documents-guides/fr_np_linux_configuration-v2.0.pdf",
        "publisher": "ANSSI",
        "kind": "guide",
        "accessed": "2026-10-19"
      }
    ],
    "mappings": [
      {
        "framework": "anssi-linux",
        "framework_version": "2.0",
        "id": "R59",
        "relation": "partial",
        "note": "R59 asks for trusted repositories only; this control enforces that each one is authenticated with its own key."
      },
      {
        "framework": "nist-800-53r5",
        "framework_version": "5.1.1",
        "id": "CM-14",
        "relation": "related"
      },
      {
        "framework": "nist-800-53r5",
        "framework_version": "5.1.1",
        "id": "SI-7",
        "relation": "related"
      }
    ],
    "threats": [
      {
        "framework": "mitre-attack",
        "id": "T1195.002"
      },
      {
        "framework": "cwe",
        "id": "CWE-494"
      }
    ],
    "related_controls": [
      {
        "id": "CB-UBU-PKG-003",
        "type": "related"
      }
    ],
    "authors": [
      {
        "name": "Alice",
        "github": "Sn0wAlice"
      }
    ],
    "verified": [
      {
        "date": "2026-10-19",
        "by": "Sn0wAlice",
        "versions": [
          "20.04"
        ],
        "environment": "Proxmox VM, Ubuntu 20.04 cloud image, kernel 5.4.0-216-generic",
        "notes": "Fails on stock (one-line sources.list without Signed-By); fix adds the Ubuntu archive keyring, apt-get update over https works; trusted=yes and deb822 stanza without Signed-By detected, disabled stanza skipped; idempotent, kept after reboot."
      },
      {
        "date": "2026-10-19",
        "by": "Sn0wAlice",
        "versions": [
          "22.04"
        ],
        "environment": "Proxmox VM, Ubuntu 22.04 cloud image, kernel 5.15.0-198-generic",
        "notes": "Fails on stock (one-line sources.list without Signed-By); fix adds the Ubuntu archive keyring, apt-get update over https works; trusted=yes and deb822 stanza without Signed-By detected, disabled stanza skipped; idempotent, kept after reboot."
      },
      {
        "date": "2026-10-19",
        "by": "Sn0wAlice",
        "versions": [
          "24.04"
        ],
        "environment": "Proxmox VM, Ubuntu 24.04 cloud image, kernel 6.8.0-147-generic",
        "notes": "Passes on stock (ubuntu.sources with Signed-By); one-line entry with trusted=yes and deb822 stanza without Signed-By detected, disabled stanza skipped; fix adds the keyring to the Ubuntu stanza only, apt-get update works; idempotent, kept after reboot."
      },
      {
        "date": "2026-10-19",
        "by": "Sn0wAlice",
        "versions": [
          "26.04"
        ],
        "environment": "Proxmox VM, Ubuntu 26.04 cloud image, kernel 7.0.0-38-generic",
        "notes": "Passes on stock (ubuntu.sources with Signed-By); one-line entry with trusted=yes and deb822 stanza without Signed-By detected, disabled stanza skipped; fix adds the keyring to the Ubuntu stanza only, apt-get update works; idempotent, kept after reboot."
      }
    ],
    "introduced_in": "0.1.0",
    "created": "2026-10-19",
    "updated": "2026-10-19"
  }
}