Store the certificate chain in archives without private keys

未关闭
#381 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
58/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
django, python
领域
database

调研方向

Read morango/sync/archive.py and the related Certificate code in morango/models/certificates.py, especially save_certificate_chain. Then inspect tests/testapp/tests/sync/test_archive.py and the tree-field formula in spec §3.5. Done means Archive.write_certificates writes the chain to the archive alias with explicit tree fields, no private keys or default-DB queries, while preserving source objects and values; this is blocked by #378.

由索引模型根据 Issue 内容生成。

描述

DEV: backend DEV: distributions P0 - critical TAG: new feature

Overview

An archive stores the exporter certificate chain and the archive certificate, with no private keys. This issue is part of milestone M5 (archive).

Background & Motivation

A network server that receives a push holds the certificate chain of the client. The parity rule in the design requires the archive to hold the same state. A future import (Phase 2) also uses the chain to validate the scope of the archive data.

A normal save of a certificate into the archive alias sends queries to the default database, for two reasons (#362). Morango's Certificate.save takes its MPTT lock on the default database. The Certificate model also uses django-mptt, which selects its database through the router and its default manager, and ignores save(using=...).

Certificate.scope_definition is a foreign key. The archive must hold the ScopeDefinition rows of the chain before the certificates are inserted, or the insert fails with IntegrityError.

Design: spec. Plan: implementation plan, Task 20.

Description & Expected Outcomes

The archive writes a certificate chain, ordered from root to leaf, into its own database. Every stored certificate has no private key, even when the source certificate has one. The stored rows keep the same serialized and signature values as the source.

The chain is a single path of certificates. The tree fields for each row follow the formula in spec §3.5. A walk of parent_id from the leaf in the archive reaches the root. The certificate objects of the caller do not change.

Deliverables & Contracts

The feature delivers these capabilities:

  • Archive.write_certificates(chain) writes the chain into the archive alias.
  • Every stored row has private_key set to NULL.
  • The archive holds the ScopeDefinition of every certificate in the chain.
  • The write path does not use MPTT save or tree-mutation methods.
Acceptance Criteria
  • A chain of three certificates with private keys is stored with private_key NULL on every row.
  • The tree fields of each row equal the formula in spec §3.5.
  • A walk of parent_id from the leaf in the archive alias reaches the root.
  • The stored serialized and signature values equal the source values.
  • The source certificate objects are unchanged after the call.
  • A chain whose ScopeDefinition is not in the archive is written without an IntegrityError.
  • The test passes inside assert_no_default_db_queries().

Technical Pointers & Architecture

  • Target Components / Context: morango/sync/archive.py (Archive).
  • Related Patterns: Certificate (morango/models/certificates.py:36) and Certificate.save_certificate_chain (morango/models/certificates.py:192).
  • Data Model & Schema Considerations: No schema change.
  • Resilience & Failure Modes: If the write fails, the error propagates, and the caller discards the archive.

Notes & Tradeoffs

  • Dependencies: Blocked by: #378 (Archive.create, discard, and ArchiveDatabase). Blocks: #383.
  • Testing Requirements: Unit tests in tests/testapp/tests/sync/test_archive.py under the Default-DB guard.
  • Tradeoffs & Alternatives Considered: #362 (spike) tests the MPTT routing behavior. A direct bulk insert with explicit tree fields is simple because the chain has no branches.
  • Security: An archive never contains private keys. This rule is a hard requirement of the design.

Metadata

  • Complexity: Low
  • Target Branch: release-v0.9.x

AI Usage

Drafted with Claude (Claude Code) from the approved design spec and implementation plan. The author reviewed the requirements, and the code references were checked against the release-v0.9.x codebase.

主要语言
Python
星标
15
派生
27
平均合并
6 天 44 分钟
30 天内合并 PR
13

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

learningequality/morango 的其他 Issue

查看 learningequality/morango 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。