Aller au contenu

Plan d'Implémentation — PD-44

Story : PD-44 — Implémenter validation Object Lock WORM Date : 2026-02-16 Auteur : Claude (Orchestrateur)

1. Architecture cible

Vue d'ensemble

┌─────────────────────────────────────────────────────────────────────────┐
│                    ProbatioVault WORM Validation                        │
├─────────────────────────────────────────────────────────────────────────┤
│                                                                         │
│  ┌──────────────┐    ┌──────────────┐    ┌──────────────┐              │
│  │  EventBridge │───►│   Lambda     │───►│  S3 Audit    │              │
│  │  (Schedule)  │    │  Validator   │    │  (Preuves)   │              │
│  └──────────────┘    └──────┬───────┘    └──────────────┘              │
│                             │                                           │
│       ┌─────────────────────┼─────────────────────┐                    │
│       │                     │                     │                    │
│       ▼                     ▼                     ▼                    │
│  ┌──────────┐         ┌──────────┐         ┌──────────┐               │
│  │ AWS S3   │         │ OVH S3   │         │ AWS      │               │
│  │ Paris    │         │ (GRA)    │         │ Frankfurt│               │
│  │ WORM     │         │ WORM     │         │ Réplica  │               │
│  └──────────┘         └──────────┘         └──────────┘               │
│       │                     │                     │                    │
│       └─────────────────────┴─────────────────────┘                    │
│                             │                                           │
│                             ▼                                           │
│                    ┌──────────────┐                                    │
│                    │  CloudWatch  │                                    │
│                    │  + SNS Alert │                                    │
│                    └──────────────┘                                    │
│                                                                         │
└─────────────────────────────────────────────────────────────────────────┘

Composants

Composant Type Description
worm-validator-lambda Lambda Python Vérifie Object Lock sur tous les buckets
worm-proof-bucket S3 Bucket Stockage des preuves de validation
worm-validation-schedule EventBridge Déclencheur périodique (1h)
worm-alerts-topic SNS Topic Alertes en cas d'écart
worm-dashboard CloudWatch Dashboard de monitoring

2. Réponses aux réserves Gate 3

R-44-01 : Intervalle de contrôle

Décision : Intervalle = 1 heure, Tolérance = 15 minutes

Criticité Intervalle Tolérance Justification
Probatoire strict 1h 15min Détection rapide, coût Lambda acceptable
Standard 4h 1h Équilibre coût/réactivité

R-44-02 : Couverture objet

Décision : Échantillonnage statistique + exhaustif pour nouveaux objets

Type Couverture Méthode
Buckets 100% Exhaustif
Objets récents (24h) 100% Tous les objets uploadés
Objets existants 5% Échantillon aléatoire par cycle

R-44-03 : Classification "probatoire strict"

Référentiel : Buckets taggés Compliance: NF-Z42-013 = probatoire strict

Tag Compliance Classification Mode requis
NF-Z42-013 ou ISO-14641 ou eIDAS Probatoire strict COMPLIANCE
Autre Standard GOVERNANCE accepté

R-44-04 : Contraintes Deep Archive

Règle : Validation différée pour objets en Deep Archive

Storage Class Délai validation objet Règle
STANDARD, IA, GLACIER_IR Immédiat Validation directe
DEEP_ARCHIVE Ignoré Validation bucket seulement

R-44-05 : Delete-marker réplication

Règle : Delete-marker replication = DISABLED (learning PD-6)

Contrôle : Vérifier que delete_marker_replication.status = Disabled sur toutes les règles CRR.

R-44-06 : Format preuve

Schéma canonique :

proof:
  version: "1.0"
  type: "WORM_VALIDATION"
  cycle_id: "uuid-v7"
  timestamp_iso: "2026-02-16T14:30:00Z"
  timestamp_epoch: 1771163400

  scope:
    buckets_total: 5
    buckets_checked: 5
    objects_sampled: 1250

  results:
    status: "COMPLIANT|NON_COMPLIANT|PARTIAL"
    buckets:
      - name: "probatiovault-documents-cold-prod"
        provider: "aws"
        region: "eu-west-3"
        object_lock_enabled: true
        mode_observed: "COMPLIANCE"
        mode_required: "COMPLIANCE"
        retention_years_config: 10
        retention_years_required: 10
        verdict: "COMPLIANT"
    objects_non_compliant: []
    gaps: []

  integrity:
    hash_algorithm: "SHA3-256"
    hash_value: "abc123..."

  correlation:
    previous_cycle_id: "uuid-previous"
    chain_sequence: 1234

3. Décomposition en tâches

Phase 1 : Infrastructure Lambda

# Tâche Agent Fichiers
T01 Créer module Terraform worm_validator agent-sre terraform/modules/worm_validator/
T02 Lambda Python de validation agent-developer lambda/worm-validator/
T03 EventBridge schedule agent-sre terraform/modules/worm_validator/schedule.tf

Phase 2 : Logique de validation

# Tâche Agent Fichiers
T04 Collecte état Object Lock bucket agent-developer lambda/worm-validator/collectors/bucket.py
T05 Collecte mode/rétention agent-developer lambda/worm-validator/collectors/retention.py
T06 Échantillonnage objets agent-developer lambda/worm-validator/collectors/objects.py
T07 Comparaison attendu/observé agent-developer lambda/worm-validator/validators/policy.py

Phase 3 : Preuves et audit

# Tâche Agent Fichiers
T08 Génération preuve JSON agent-developer lambda/worm-validator/proof/generator.py
T09 Calcul hash intégrité agent-developer lambda/worm-validator/proof/integrity.py
T10 Stockage preuve S3 agent-developer lambda/worm-validator/storage/proof_store.py

Phase 4 : Alerting et monitoring

# Tâche Agent Fichiers
T11 SNS Topic + alertes agent-sre terraform/modules/worm_validator/alerts.tf
T12 CloudWatch Dashboard agent-sre terraform/modules/worm_validator/dashboard.tf
T13 Métriques custom agent-developer lambda/worm-validator/metrics/cloudwatch.py

Phase 5 : Multi-cloud OVH

# Tâche Agent Fichiers
T14 Collector OVH S3 agent-developer lambda/worm-validator/collectors/ovh.py
T15 Normalisation multi-cloud agent-developer lambda/worm-validator/normalizers/

Phase 6 : Tests

# Tâche Agent Fichiers
T16 Tests unitaires Lambda agent-qa-unit-integration lambda/worm-validator/tests/
T17 Tests intégration LocalStack agent-qa-unit-integration lambda/worm-validator/tests/integration/

4. Dépendances

T01 ──► T02 ──► T04 ──► T07 ──► T08 ──► T10
                │                │
                ├──► T05 ───────►│
                │                │
                └──► T06 ───────►└──► T09
T03 ──► T02                           │
T11 ◄───────────────────────────── T13
      T12

T14 ──► T15 ──► T07 (normalisation)

T16 ◄── T04..T10
T17 ◄── T01..T13

5. Estimations

Phase Tâches Estimation
Infrastructure T01-T03 2h
Logique validation T04-T07 4h
Preuves et audit T08-T10 3h
Alerting T11-T13 2h
Multi-cloud OVH T14-T15 2h
Tests T16-T17 3h
Total 17 tâches 16h

6. Risques et mitigations

Risque Impact Mitigation
Quota Lambda dépassé Moyen Batch processing, 1000 objets/invocation max
OVH API différente Moyen Abstraction via normalizers
Deep Archive latence Faible Exclusion explicite (validation bucket only)
Coût CloudWatch Faible Métriques agrégées, pas par objet

7. Critères de succès

  • Tous les buckets probatoires sont validés chaque heure
  • Preuves générées avec hash SHA3-256
  • Alertes émises < 5 minutes après détection écart
  • Dashboard opérationnel
  • Tests coverage >= 80%

8. Résilience et gestion d'erreurs (ex-R-44-P-01)

8.1 Stratégie de retry

Erreur Retry Délai Max tentatives
ThrottlingException Oui Exponential backoff (1s, 2s, 4s) 3
ServiceUnavailable Oui Exponential backoff 3
AccessDenied Non - 0 (alerte immédiate)
NoSuchBucket Non - 0 (alerte immédiate)
Timeout réseau Oui Linéaire (5s) 2

8.2 Dead Letter Queue (DLQ)

┌─────────────┐     Échec après retry     ┌─────────────┐
│   Lambda    │ ─────────────────────────► │  SQS DLQ   │
│  Validator  │                            │  worm-dlq  │
└─────────────┘                            └──────┬──────┘
                                           ┌─────────────┐
                                           │ Lambda DLQ  │
                                           │  Processor  │
                                           └──────┬──────┘
                                    ┌─────────────┴─────────────┐
                                    ▼                           ▼
                              ┌──────────┐               ┌──────────┐
                              │   SNS    │               │ CloudWatch│
                              │  Alert   │               │   Logs   │
                              └──────────┘               └──────────┘

Configuration DLQ : - Rétention : 14 jours - Visibilité timeout : 300s - Max receive count avant DLQ : 3

8.3 Idempotence

Mécanisme Description
cycle_id UUID v7 (timestamp-based) généré au début du cycle
Deduplication Clé S3 preuve = {date}/{cycle_id}.yaml → écrasement si rejeu
Condition write If-None-Match: * pour éviter double-écriture
Métriques Counter validation_cycles avec label cycle_id

8.4 Circuit breaker

Seuil Action
5 erreurs consécutives sur même bucket Skip bucket + alerte
10 erreurs globales par cycle Abort cycle + alerte CRITICAL
3 cycles échoués consécutifs Alerte ESCALADE + PagerDuty

9. Diagrammes Mermaid

9.1 Graphe de dépendances des tâches

graph TD
    T01[T01 — Module Terraform<br>worm_validator] --> T02[T02 — Lambda Python<br>de validation]
    T03[T03 — EventBridge<br>schedule] --> T02

    T02 --> T04[T04 — Collecte état<br>Object Lock bucket]
    T02 --> T05[T05 — Collecte<br>mode/rétention]
    T02 --> T06[T06 — Échantillonnage<br>objets]

    T04 --> T07[T07 — Comparaison<br>attendu/observé]
    T05 --> T07
    T06 --> T07

    T07 --> T08[T08 — Génération<br>preuve JSON]
    T08 --> T09[T09 — Calcul hash<br>intégrité SHA3-256]
    T08 --> T10[T10 — Stockage<br>preuve S3]
    T09 --> T10

    T10 --> T13[T13 — Métriques<br>custom CloudWatch]
    T13 --> T11[T11 — SNS Topic<br>+ alertes]
    T11 --> T12[T12 — CloudWatch<br>Dashboard]

    T14[T14 — Collector<br>OVH S3] --> T15[T15 — Normalisation<br>multi-cloud]
    T15 --> T07

    T04 --> T16[T16 — Tests unitaires]
    T05 --> T16
    T06 --> T16
    T07 --> T16
    T08 --> T16
    T09 --> T16
    T10 --> T16

    T01 --> T17[T17 — Tests intégration<br>LocalStack]
    T11 --> T17
    T12 --> T17
    T13 --> T17

    style T01 fill:#4a90d9,color:#fff
    style T03 fill:#4a90d9,color:#fff
    style T11 fill:#4a90d9,color:#fff
    style T12 fill:#4a90d9,color:#fff
    style T16 fill:#e67e22,color:#fff
    style T17 fill:#e67e22,color:#fff
    style T14 fill:#27ae60,color:#fff
    style T15 fill:#27ae60,color:#fff

Légende : agent-sre | agent-developer | agent-qa-unit-integration | multi-cloud OVH

9.2 Séquence de validation multi-service (cycle horaire)

sequenceDiagram
    participant EB as EventBridge<br>(Schedule 1h)
    participant LV as Lambda<br>worm-validator
    participant S3_AWS as AWS S3<br>(Paris + Frankfurt)
    participant S3_OVH as OVH S3<br>(GRA)
    participant Proof as S3 Audit<br>(Preuves)
    participant CW as CloudWatch<br>(Métriques)
    participant SNS as SNS<br>(Alertes)
    participant DLQ as SQS DLQ

    EB->>LV: Trigger cycle (cycle_id UUID v7)

    rect rgb(230, 245, 255)
        Note over LV,S3_AWS: Phase 1 — Collecte AWS
        LV->>S3_AWS: ListBuckets + GetObjectLockConfiguration
        S3_AWS-->>LV: État Object Lock, mode, rétention
        LV->>S3_AWS: ListObjectsV2 (récents 24h = 100%)
        S3_AWS-->>LV: Objets + ObjectRetention
        LV->>S3_AWS: Échantillonnage 5% objets existants
        S3_AWS-->>LV: Objets échantillonnés
        LV->>S3_AWS: GetReplicationConfiguration (CRR)
        S3_AWS-->>LV: DeleteMarkerReplication = Disabled ✓
    end

    rect rgb(230, 255, 230)
        Note over LV,S3_OVH: Phase 2 — Collecte OVH
        LV->>S3_OVH: ListBuckets + GetObjectLockConfiguration
        S3_OVH-->>LV: État Object Lock (immutable)
        LV->>S3_OVH: ListObjectsV2 + ObjectRetention
        S3_OVH-->>LV: Objets + rétention
    end

    rect rgb(255, 245, 230)
        Note over LV,Proof: Phase 3 — Validation + Preuve
        LV->>LV: Normalisation multi-cloud (T15)
        LV->>LV: Comparaison attendu/observé (T07)
        LV->>LV: Génération preuve YAML (T08)
        LV->>LV: Calcul SHA3-256 (T09)
        LV->>Proof: PutObject (If-None-Match: *)<br>{date}/{cycle_id}.yaml
        Proof-->>LV: 200 OK
    end

    rect rgb(245, 230, 255)
        Note over LV,SNS: Phase 4 — Métriques + Alertes
        LV->>CW: PutMetricData (buckets_checked, objects_sampled, verdict)
        alt NON_COMPLIANT détecté
            LV->>SNS: Publish alerte (< 5 min)
            SNS-->>SNS: Notification email/PagerDuty
        end
    end

    alt Erreur après 3 retries
        LV->>DLQ: SendMessage (bucket + erreur)
        DLQ->>SNS: Lambda DLQ → alerte CRITICAL
    end

9.3 Séquence de résilience (circuit breaker + DLQ)

sequenceDiagram
    participant LV as Lambda<br>worm-validator
    participant S3 as S3 Bucket
    participant CB as Circuit Breaker<br>(in-memory)
    participant DLQ as SQS DLQ
    participant DLP as Lambda DLQ<br>Processor
    participant SNS as SNS Alertes
    participant CW as CloudWatch Logs

    LV->>S3: GetObjectLockConfiguration
    S3-->>LV: ThrottlingException

    loop Retry exponential backoff (1s, 2s, 4s)
        LV->>S3: GetObjectLockConfiguration (retry)
        S3-->>LV: ThrottlingException
    end

    LV->>CB: Incrémenter compteur erreurs (bucket X)

    alt 5 erreurs consécutives même bucket
        CB-->>LV: SKIP bucket + alerte
        LV->>SNS: Alerte WARNING (bucket skipped)
    end

    alt 10 erreurs globales par cycle
        CB-->>LV: ABORT cycle
        LV->>SNS: Alerte CRITICAL (cycle avorté)
    end

    alt 3 cycles échoués consécutifs
        CB-->>LV: ESCALADE
        LV->>SNS: Alerte ESCALADE + PagerDuty
    end

    LV->>DLQ: Message (bucket, erreur, cycle_id)
    DLQ->>DLP: Trigger Lambda DLQ Processor
    DLP->>SNS: Alerte enrichie
    DLP->>CW: Log détaillé (rétention 14j)

10. Matrice de traçabilité (ex-R-44-P-02)

10.1 CA → Code Contract → Tests

CA Description CC TC
CA-44-01 Object Lock activé sur tous les buckets CC-44-01, CC-44-02 TC-NOM-01, TC-NOM-02
CA-44-02 Mode COMPLIANCE sur buckets probatoires CC-44-02 TC-NOM-03, TC-NOM-04
CA-44-03 Rétention conforme aux exigences légales CC-44-02 TC-NOM-05, TC-NOM-06
CA-44-04 Preuves horodatées et hashées CC-44-04 TC-NOM-07, TC-NOM-08
CA-44-05 Alertes < 5 min après détection écart CC-44-05 TC-NOM-09, TC-ERR-01
CA-44-06 Couverture 100% buckets + 5% objets CC-44-01, CC-44-03 TC-NOM-10, TC-NOM-11
CA-44-07 Validation delete-marker réplication CC-44-06 TC-NOM-12
CA-44-08 Multi-cloud AWS + OVH CC-44-01, CC-44-06 TC-NOM-13
CA-44-09 Dashboard temps réel CC-44-07 TC-NR-01
CA-44-10 Cycle validation < 60 min CC-44-03 TC-NR-02, TC-NR-03
CA-44-11 Résilience aux erreurs API CC-44-05 TC-ERR-02 à TC-ERR-11
CA-44-12 Preuves immuables (Object Lock) CC-44-04 TC-NEG-01 à TC-NEG-07

10.2 INV → Code Contract

INV Description CC principal CC secondaire
INV-44-01 Tous buckets Compliance listés CC-44-01 -
INV-44-02 Object Lock activé CC-44-02 -
INV-44-03 Mode COMPLIANCE uniquement CC-44-02 -
INV-44-04 Rétention >= minimum légal CC-44-02 -
INV-44-05 Échantillonnage objets CC-44-03 -
INV-44-06 Non-conformité → alerte < 5min CC-44-05 -
INV-44-07 Deep Archive = bucket only CC-44-02 CC-44-03
INV-44-08 Alertes vers SNS CC-44-05 -
INV-44-09 Preuves avec SHA3-256 CC-44-04 -
INV-44-10 Couverture 100% récents CC-44-03 -
INV-44-11 Classification via tag CC-44-01 -
INV-44-12 Validation réplication CRR CC-44-06 -

10.3 Couverture tests

Phase Tâches Tests unitaires Tests intégration
Infrastructure T01-T03 N/A (Terraform) TC-NR-04, TC-NR-05
Validation T04-T07 TC-NOM-01 à TC-NOM-08 TC-NOM-13
Preuves T08-T10 TC-NOM-07, TC-NOM-08 TC-NEG-01 à TC-NEG-07
Alerting T11-T13 TC-NOM-09 TC-ERR-01
Multi-cloud T14-T15 TC-NOM-12, TC-NOM-13 TC-NOM-13

Couverture cible : 80% (lignes) / 75% (branches)

11. Stratégie de phasage (ex-R-44-P-03)

11.1 Lot 1 : AWS (Prioritaire)

Durée estimée : 12h Périmètre : Buckets AWS Paris (eu-west-3) + Frankfurt (eu-central-1)

Phase Tâches Livrables
1 T01-T03 Module Terraform, Lambda, EventBridge
2 T04-T07 Collecteurs AWS, Validators
3 T08-T10 Générateur preuves, Stockage S3
4 T11-T13 SNS, CloudWatch, Métriques
6 T16-T17 (AWS) Tests unitaires + intégration LocalStack

Critères de passage Lot 2 : - [ ] Validation OK sur buckets AWS Paris - [ ] Preuves générées avec intégrité SHA3-256 - [ ] Alertes fonctionnelles (test manuel) - [ ] Tests coverage >= 80% sur code AWS - [ ] Pipeline CI vert

11.2 Lot 2 : OVH (Extension)

Durée estimée : 4h Périmètre : Buckets OVH GRA (Gravelines) Prérequis : Credentials OVH S3 configurés (cf. storage-ovh.tf)

Phase Tâches Livrables
5 T14-T15 Collecteur OVH, Normalizers multi-cloud
6 T16-T17 (OVH) Extension tests pour OVH

Adaptations OVH : | Différence | AWS | OVH | Adaptation | |------------|-----|-----|------------| | API endpoint | s3.eu-west-3.amazonaws.com | s3.gra.cloud.ovh.net | Config provider | | Object Lock | Natif | Émulation via immutable | Validator spécifique | | Authentification | IAM | EC2 credentials | Dual auth |

11.3 Lot 3 : Frankfurt CRR (Validation)

Durée estimée : Inclus dans Lot 1 Périmètre : Validation réplication Cross-Region

Validation Description
CRR status Vérifier ReplicationStatus = COMPLETED
Delete-marker Vérifier DeleteMarkerReplication = Disabled
Object Lock replica Vérifier mode COMPLIANCE préservé

11.4 Timeline

Semaine 1                          Semaine 2
├─────────────────────────────────┼─────────────────────────────────┤
│ Lot 1 - AWS (12h)               │ Lot 2 - OVH (4h)               │
│ ├── Phase 1: Infra (2h)         │ ├── T14: Collector OVH (1.5h)  │
│ ├── Phase 2: Validation (4h)    │ ├── T15: Normalizers (1.5h)    │
│ ├── Phase 3: Preuves (3h)       │ └── Tests OVH (1h)             │
│ ├── Phase 4: Alerting (2h)      │                                 │
│ └── Tests AWS (1h)              │                                 │
├─────────────────────────────────┼─────────────────────────────────┤
│         Gate 8 intermédiaire    │         Gate 8 finale          │
│         (AWS only)              │         (AWS + OVH)            │
└─────────────────────────────────┴─────────────────────────────────┘

11.5 Critères GO pour chaque lot

Lot Critères GO
Lot 1 Tests AWS verts, preuves générées, alertes OK
Lot 2 Collector OVH OK, normalizers fonctionnels
Lot 3 Validation CRR Paris→Frankfurt OK
Global Coverage >= 80%, tous invariants validés