@umacloud/knowledge 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/00-governance/governance-capabilities.md +557 -0
- package/00-governance/knowledge-map.md +39 -0
- package/00-governance/maintenance-policy.md +76 -0
- package/00-governance/review-checklist.md +81 -0
- package/README.md +13 -0
- package/ai/01-standards/agent-development-complete.md +691 -0
- package/ai/01-standards/llm-application-complete.md +488 -0
- package/ai/01-standards/mlops-complete.md +798 -0
- package/ai/01-standards/prompt-engineering-complete.md +646 -0
- package/ai/01-standards/rag-architecture-complete.md +649 -0
- package/ai/02-playbooks/llm-evaluation-playbook.md +847 -0
- package/ai/03-checklists/ai-project-checklist.md +215 -0
- package/ai/04-antipatterns/ai-antipatterns.md +661 -0
- package/ai/05-cases/case-rag-production.md +147 -0
- package/ai/06-glossary/ai-glossary.md +162 -0
- package/ai/agent-evaluation-benchmark.md +53 -0
- package/ai/ai-agent-memory-context-management.md +41 -0
- package/ai/ai-cost-capacity-optimization-playbook.md +42 -0
- package/ai/ai-data-security-and-compliance-playbook.md +37 -0
- package/ai/ai-domain-index-and-checklist.md +40 -0
- package/ai/ai-governance-maturity-model.md +50 -0
- package/ai/ai-model-selection-and-routing-strategy.md +47 -0
- package/ai/ai-observability-and-oncall-runbook.md +52 -0
- package/ai/ai-rag-engineering-playbook.md +42 -0
- package/ai/ai-red-team-and-safety-evaluation.md +42 -0
- package/ai/ai-release-readiness-and-rollback-gate.md +42 -0
- package/ai/llm-agent-engineering-deep-dive.md +57 -0
- package/ai/prompt-and-tool-guardrails.md +52 -0
- package/api/01-standards/enterprise-api-standards.md +198 -0
- package/api/01-standards/rest-api-design-guide.md +63 -0
- package/api/02-playbooks/api-pagination-playbook.md +93 -0
- package/api/02-playbooks/graphql-production-playbook.md +176 -0
- package/api/03-checklists/api-review-checklist.md +55 -0
- package/api/04-antipatterns/api-antipatterns.md +112 -0
- package/architecture/01-standards/api-gateway-patterns.md +496 -0
- package/architecture/01-standards/cloud-native-patterns.md +644 -0
- package/architecture/01-standards/distributed-systems-patterns.md +591 -0
- package/architecture/01-standards/event-driven-architecture.md +595 -0
- package/architecture/01-standards/microservices-patterns-complete.md +968 -0
- package/architecture/01-standards/microservices-patterns.md +495 -0
- package/architecture/01-standards/system-design-interview.md +664 -0
- package/architecture/02-playbooks/microservices-patterns-playbook.md +137 -0
- package/architecture/02-playbooks/migration-playbook.md +780 -0
- package/architecture/02-playbooks/system-design-playbook.md +779 -0
- package/architecture/03-checklists/architecture-decision-checklist.md +297 -0
- package/architecture/04-antipatterns/architecture-antipatterns.md +417 -0
- package/architecture/05-cases/case-netflix-microservices.md +413 -0
- package/architecture/06-glossary/architecture-glossary.md +164 -0
- package/architecture/adr-template-and-examples.md +38 -0
- package/architecture/api-gateway-deep-dive.md +1291 -0
- package/architecture/configuration-management.md +1162 -0
- package/architecture/distributed-transactions.md +1220 -0
- package/architecture/microservices-complete.md +735 -0
- package/architecture/resilience-and-disaster-patterns.md +37 -0
- package/architecture/service-governance.md +1198 -0
- package/architecture/system-architecture-deep-dive.md +37 -0
- package/backend/01-standards/analytics-and-growth.md +65 -0
- package/backend/01-standards/api-and-error-conventions.md +120 -0
- package/backend/01-standards/application-layering-and-packaging.md +160 -0
- package/backend/01-standards/auth-implementation.md +104 -0
- package/backend/01-standards/backend-framework-idioms.md +74 -0
- package/backend/01-standards/background-jobs-and-async.md +66 -0
- package/backend/01-standards/caching-strategies-complete.md +390 -0
- package/backend/01-standards/config-and-observability.md +77 -0
- package/backend/01-standards/data-modeling-and-persistence.md +94 -0
- package/backend/01-standards/django-complete.md +1765 -0
- package/backend/01-standards/email-and-notifications.md +64 -0
- package/backend/01-standards/fastapi-complete.md +925 -0
- package/backend/01-standards/file-upload-and-storage.md +66 -0
- package/backend/01-standards/graphql-api-complete.md +416 -0
- package/backend/01-standards/llm-application-standard.md +78 -0
- package/backend/01-standards/message-queue-patterns.md +379 -0
- package/backend/01-standards/microservices-and-distributed.md +78 -0
- package/backend/01-standards/nestjs-complete.md +2167 -0
- package/backend/01-standards/payment-integration.md +80 -0
- package/backend/01-standards/rate-limiting-complete.md +451 -0
- package/backend/01-standards/realtime-and-websocket.md +65 -0
- package/backend/01-standards/search-and-filtering.md +64 -0
- package/backend/01-standards/spring-boot-complete.md +445 -0
- package/backend/02-playbooks/api-design-playbook.md +718 -0
- package/backend/02-playbooks/email-send-playbook.md +130 -0
- package/backend/02-playbooks/file-upload-s3-playbook.md +153 -0
- package/backend/02-playbooks/typescript-enterprise-playbook.md +133 -0
- package/backend/02-playbooks/websocket-realtime-playbook.md +154 -0
- package/backend/03-checklists/api-launch-checklist.md +189 -0
- package/backend/04-antipatterns/backend-antipatterns.md +1051 -0
- package/blockchain/01-standards/blockchain-basics.md +557 -0
- package/blockchain/01-standards/smart-contract-development.md +1315 -0
- package/cicd/01-standards/deployment-and-delivery-standard.md +96 -0
- package/cicd/01-standards/github-actions-complete.md +473 -0
- package/cicd/01-standards/release-and-store-submission.md +75 -0
- package/cicd/02-playbooks/cicd-pipeline-playbook.md +144 -0
- package/cicd/02-playbooks/release-management-playbook.md +605 -0
- package/cicd/03-checklists/pipeline-security-checklist.md +168 -0
- package/cicd/04-antipatterns/cicd-antipatterns.md +589 -0
- package/cicd/05-cases/case-deployment-automation.md +221 -0
- package/cicd/05-cases/case-gitops-transformation.md +212 -0
- package/cicd/06-glossary/cicd-glossary.md +114 -0
- package/cicd/cicd-blueprint-deep-dive.md +38 -0
- package/cicd/release-readiness-gate.md +37 -0
- package/cloud-native/01-standards/container-security.md +741 -0
- package/cloud-native/01-standards/kubernetes-complete.md +812 -0
- package/cloud-native/02-playbooks/api-gateway-playbook.md +155 -0
- package/cloud-native/02-playbooks/gitops-with-argocd.md +760 -0
- package/cloud-native/02-playbooks/k8s-troubleshooting-playbook.md +1942 -0
- package/cloud-native/02-playbooks/message-queue-playbook.md +129 -0
- package/cloud-native/02-playbooks/multicloud-governance.md +726 -0
- package/cloud-native/02-playbooks/serverless-patterns.md +788 -0
- package/cloud-native/02-playbooks/service-mesh-playbook.md +612 -0
- package/cloud-native/02-playbooks/terraform-iac-playbook.md +143 -0
- package/cloud-native/03-checklists/container-security-checklist.md +431 -0
- package/cloud-native/03-checklists/k8s-production-readiness-checklist.md +460 -0
- package/cloud-native/04-antipatterns/container-antipatterns.md +660 -0
- package/cloud-native/04-antipatterns/k8s-antipatterns.md +743 -0
- package/cloud-native/05-cases/case-k8s-migration.md +478 -0
- package/cloud-native/05-cases/case-k8s-scaling.md +642 -0
- package/cloud-native/05-cases/case-k8s-security-incident.md +397 -0
- package/cloud-native/06-glossary/cloud-native-glossary.md +337 -0
- package/cross-platform/01-standards/cross-platform-frameworks.md +83 -0
- package/cross-platform/01-standards/platform-selection-and-architecture.md +77 -0
- package/data/01-standards/elasticsearch-complete.md +2098 -0
- package/data/01-standards/postgresql-complete.md +1613 -0
- package/data/01-standards/redis-complete.md +1527 -0
- package/data/02-playbooks/database-optimization-playbook.md +403 -0
- package/data/02-playbooks/elasticsearch-production-playbook.md +132 -0
- package/data/03-checklists/database-launch-checklist.md +187 -0
- package/data/04-antipatterns/database-antipatterns.md +873 -0
- package/data/05-cases/case-database-migration.md +310 -0
- package/data/06-glossary/database-glossary.md +440 -0
- package/data/data-governance-and-modeling-deep-dive.md +39 -0
- package/data-engineering/01-standards/airflow-complete.md +523 -0
- package/data-engineering/01-standards/kafka-complete.md +1521 -0
- package/data-engineering/02-playbooks/spark-etl-playbook.md +496 -0
- package/data-engineering/03-checklists/pipeline-launch-checklist.md +194 -0
- package/data-engineering/04-antipatterns/data-pipeline-antipatterns.md +684 -0
- package/data-engineering/05-cases/case-real-time-pipeline.md +355 -0
- package/data-engineering/06-glossary/data-engineering-glossary.md +429 -0
- package/database/01-standards/database-schema-standards.md +147 -0
- package/database/02-playbooks/postgresql-optimization-quick.md +52 -0
- package/database/02-playbooks/postgresql-performance-optimization.md +58 -0
- package/database/02-playbooks/postgresql-production-playbook.md +146 -0
- package/database/02-playbooks/redis-caching-playbook.md +117 -0
- package/database/03-checklists/database-review-checklist.md +50 -0
- package/database/04-antipatterns/database-antipatterns.md +112 -0
- package/design/01-standards/ui-design-system-complete.md +423 -0
- package/design/02-playbooks/design-handoff-playbook.md +254 -0
- package/design/02-playbooks/design-review-playbook.md +388 -0
- package/design/03-checklists/design-review-checklist.md +246 -0
- package/design/04-antipatterns/design-antipatterns.md +378 -0
- package/design/05-cases/case-design-system-adoption.md +328 -0
- package/design/06-glossary/design-glossary.md +329 -0
- package/design/ui-full-lifecycle-cross-platform-playbook.md +571 -0
- package/design/ux-system-deep-dive.md +38 -0
- package/design-systems/00-craft-rules.md +71 -0
- package/design-systems/aesthetic-families.md +43 -0
- package/design-systems/anti-ai-slop.md +162 -0
- package/design-systems/bold-geometric.md +120 -0
- package/design-systems/brutalist-bold.md +103 -0
- package/design-systems/editorial-clean.md +109 -0
- package/design-systems/glass-aurora.md +108 -0
- package/design-systems/modern-minimal.md +145 -0
- package/design-systems/premium-luxury.md +106 -0
- package/design-systems/product-type-design-map.md +48 -0
- package/design-systems/soft-warm.md +123 -0
- package/design-systems/tech-utility.md +113 -0
- package/desktop/01-standards/desktop-app-standard.md +72 -0
- package/desktop/01-standards/desktop-design.md +71 -0
- package/development/00-governance/document-template.md +41 -0
- package/development/01-standards/api-versioning-strategies.md +432 -0
- package/development/01-standards/authentication-patterns-complete.md +479 -0
- package/development/01-standards/css-architecture-complete.md +550 -0
- package/development/01-standards/database-migration-strategies.md +484 -0
- package/development/01-standards/elasticsearch-complete.md +347 -0
- package/development/01-standards/git-complete.md +371 -0
- package/development/01-standards/golang-complete.md +1565 -0
- package/development/01-standards/graphql-complete.md +298 -0
- package/development/01-standards/javascript-bundlers-complete.md +469 -0
- package/development/01-standards/javascript-typescript-complete.md +528 -0
- package/development/01-standards/jest-complete.md +275 -0
- package/development/01-standards/linux-complete.md +234 -0
- package/development/01-standards/logging-observability-complete.md +526 -0
- package/development/01-standards/microservices-communication.md +502 -0
- package/development/01-standards/mongodb-complete.md +406 -0
- package/development/01-standards/oauth2-complete.md +285 -0
- package/development/01-standards/performance-optimization-complete.md +289 -0
- package/development/01-standards/playwright-complete.md +247 -0
- package/development/01-standards/postgresql-complete.md +456 -0
- package/development/01-standards/pytest-complete.md +340 -0
- package/development/01-standards/python-async-programming.md +902 -0
- package/development/01-standards/python-complete.md +956 -0
- package/development/01-standards/python-decorators-complete.md +799 -0
- package/development/01-standards/python-design-patterns.md +2854 -0
- package/development/01-standards/python-packaging-distribution.md +420 -0
- package/development/01-standards/python-testing-strategies.md +607 -0
- package/development/01-standards/python-web-frameworks-comparison.md +471 -0
- package/development/01-standards/redis-complete.md +317 -0
- package/development/01-standards/rest-api-complete.md +316 -0
- package/development/01-standards/rust-complete.md +578 -0
- package/development/01-standards/typescript-advanced-types.md +1513 -0
- package/development/01-standards/web-security-complete.md +292 -0
- package/development/02-playbooks/api-design-playbook.md +810 -0
- package/development/02-playbooks/database-migration-playbook.md +580 -0
- package/development/02-playbooks/debugging-playbook.md +692 -0
- package/development/02-playbooks/feature-delivery-playbook.md +430 -0
- package/development/02-playbooks/incident-hotfix-playbook.md +387 -0
- package/development/02-playbooks/performance-optimization-playbook.md +531 -0
- package/development/02-playbooks/performance-tuning-playbook.md +652 -0
- package/development/02-playbooks/refactor-playbook.md +403 -0
- package/development/02-playbooks/release-playbook.md +469 -0
- package/development/03-checklists/architecture-review-checklist.md +168 -0
- package/development/03-checklists/data-migration-checklist.md +157 -0
- package/development/03-checklists/oncall-handover-checklist.md +173 -0
- package/development/03-checklists/pr-checklist.md +158 -0
- package/development/03-checklists/production-readiness-checklist.md +190 -0
- package/development/03-checklists/release-readiness-checklist.md +154 -0
- package/development/03-checklists/security-review-checklist.md +182 -0
- package/development/04-antipatterns/api-antipatterns.md +657 -0
- package/development/04-antipatterns/architecture-antipatterns.md +686 -0
- package/development/04-antipatterns/backend-antipatterns.md +648 -0
- package/development/04-antipatterns/cicd-antipatterns.md +540 -0
- package/development/04-antipatterns/code-smell-antipatterns.md +571 -0
- package/development/04-antipatterns/data-antipatterns.md +658 -0
- package/development/04-antipatterns/database-antipatterns.md +578 -0
- package/development/04-antipatterns/frontend-antipatterns.md +635 -0
- package/development/04-antipatterns/reliability-antipatterns.md +700 -0
- package/development/04-antipatterns/security-antipatterns.md +747 -0
- package/development/05-cases/case-api-version-migration.md +428 -0
- package/development/05-cases/case-authorization-hardening.md +383 -0
- package/development/05-cases/case-bluegreen-rollback.md +466 -0
- package/development/05-cases/case-cache-snowball-protection.md +485 -0
- package/development/05-cases/case-ci-cd-pipeline.md +544 -0
- package/development/05-cases/case-database-scaling.md +500 -0
- package/development/05-cases/case-db-hotspot-optimization.md +487 -0
- package/development/05-cases/case-incident-mttr-reduction.md +563 -0
- package/development/05-cases/case-microservice-migration.md +375 -0
- package/development/05-cases/case-performance-optimization.md +406 -0
- package/development/05-cases/case-security-incident-response.md +345 -0
- package/development/06-glossary/full-stack-glossary.md +166 -0
- package/development/09-maturity/quarterly-audit-template.md +35 -0
- package/development/11-ui-excellence/ui-aesthetic-system.md +41 -0
- package/development/11-ui-excellence/ui-engineering-excellence.md +435 -0
- package/development/12-scenarios/development-scenarios-guide.md +565 -0
- package/development/13-implementation-assets/implementation-toolkit.md +282 -0
- package/development/13-implementation-assets/knowledge-gates-execution.md +43 -0
- package/development/14-full-lifecycle/software-lifecycle-gates.md +511 -0
- package/development/15-lifecycle-templates/project-templates-collection.md +791 -0
- package/development/api-contract-and-versioning-guide.md +36 -0
- package/development/api-governance-complete.md +43 -0
- package/development/backend-engineering-complete.md +43 -0
- package/development/code-review-quality-complete.md +43 -0
- package/development/concurrency-reliability-complete.md +43 -0
- package/development/database-engineering-complete.md +43 -0
- package/development/engineering-effectiveness-complete.md +43 -0
- package/development/engineering-standards-deep-dive.md +38 -0
- package/development/frontend-engineering-complete.md +43 -0
- package/development/performance-capacity-complete.md +43 -0
- package/development/refactor-migration-complete.md +42 -0
- package/development/refactoring-and-techdebt-playbook.md +37 -0
- package/development/security-in-development-complete.md +43 -0
- package/devops/01-standards/cicd-pipeline-complete.md +262 -0
- package/devops/01-standards/docker-complete.md +1490 -0
- package/devops/01-standards/github-actions-complete.md +337 -0
- package/devops/01-standards/kubernetes-complete.md +638 -0
- package/devops/01-standards/terraform-complete.md +2117 -0
- package/devops/02-playbooks/docker-compose-playbook.md +233 -0
- package/devops/02-playbooks/docker-k8s-production-playbook.md +186 -0
- package/devops/02-playbooks/docker-production-playbook.md +952 -0
- package/edge-iot/01-standards/edge-iot-complete.md +473 -0
- package/experts/architect/api-design.md +178 -0
- package/experts/architect/methodology.md +124 -0
- package/experts/architect/security.md +75 -0
- package/experts/backend-lead/methodology.md +216 -0
- package/experts/devops/methodology.md +160 -0
- package/experts/frontend-lead/methodology.md +178 -0
- package/experts/product-manager/industry/ecommerce.md +43 -0
- package/experts/product-manager/industry/saas.md +40 -0
- package/experts/product-manager/methodology.md +97 -0
- package/experts/qa-lead/methodology.md +123 -0
- package/experts/qa-lead/test-strategy.md +128 -0
- package/experts/uiux-designer/methodology.md +125 -0
- package/frontend/01-standards/accessibility-complete.md +532 -0
- package/frontend/01-standards/accessibility-standard.md +74 -0
- package/frontend/01-standards/admin-dashboard-and-crud.md +72 -0
- package/frontend/01-standards/design-tokens-complete.md +444 -0
- package/frontend/01-standards/forms-and-validation.md +77 -0
- package/frontend/01-standards/frontend-architecture-and-layering.md +119 -0
- package/frontend/01-standards/i18n-and-localization.md +65 -0
- package/frontend/01-standards/nextjs-complete.md +451 -0
- package/frontend/01-standards/react-complete.md +713 -0
- package/frontend/01-standards/react-hooks-complete-guide.md +1100 -0
- package/frontend/01-standards/react-hooks-complete.md +1171 -0
- package/frontend/01-standards/seo-and-web-vitals.md +77 -0
- package/frontend/01-standards/state-management-complete.md +444 -0
- package/frontend/01-standards/vue-complete.md +499 -0
- package/frontend/01-standards/vue3-complete.md +2002 -0
- package/frontend/01-standards/web-framework-best-practices.md +64 -0
- package/frontend/01-standards/web-performance-complete.md +495 -0
- package/frontend/02-playbooks/accessibility-a11y-playbook.md +161 -0
- package/frontend/02-playbooks/frontend-performance-playbook.md +707 -0
- package/frontend/02-playbooks/i18n-internationalization-playbook.md +120 -0
- package/frontend/02-playbooks/performance-optimization-playbook.md +163 -0
- package/frontend/02-playbooks/react-nextjs-production-playbook.md +167 -0
- package/frontend/02-playbooks/react-state-management-playbook.md +173 -0
- package/frontend/03-checklists/component-quality-checklist.md +166 -0
- package/frontend/03-checklists/frontend-launch-checklist.md +299 -0
- package/frontend/04-antipatterns/frontend-antipatterns.md +886 -0
- package/frontend/05-cases/case-performance-optimization.md +274 -0
- package/harmony/01-standards/harmonyos-arkts-standard.md +75 -0
- package/harmony/01-standards/harmonyos-design.md +65 -0
- package/high-quality-engineering-playbook.md +54 -0
- package/incident/01-standards/incident-response-complete.md +303 -0
- package/incident/02-playbooks/chaos-engineering-playbook.md +883 -0
- package/incident/02-playbooks/postmortem-playbook.md +398 -0
- package/incident/03-checklists/incident-readiness-checklist.md +181 -0
- package/incident/04-antipatterns/incident-antipatterns.md +490 -0
- package/incident/05-cases/case-cascade-failure.md +176 -0
- package/incident/06-glossary/incident-glossary.md +114 -0
- package/incident/postmortem-and-response-deep-dive.md +39 -0
- package/industries/ecommerce/ecommerce-complete.md +631 -0
- package/industries/education/education-complete.md +555 -0
- package/industries/fintech/fintech-complete.md +501 -0
- package/industries/gaming/gaming-complete.md +587 -0
- package/industries/healthcare/healthcare-complete.md +452 -0
- package/low-code/01-standards/low-code-complete.md +944 -0
- package/miniprogram/01-standards/ai-common-mistakes.md +61 -0
- package/miniprogram/01-standards/miniprogram-custom-navbar-capsule.md +77 -0
- package/miniprogram/01-standards/miniprogram-design.md +61 -0
- package/miniprogram/01-standards/miniprogram-standard.md +81 -0
- package/mobile/01-standards/android-material-design.md +70 -0
- package/mobile/01-standards/flutter-complete.md +384 -0
- package/mobile/01-standards/ios-design-hig.md +78 -0
- package/mobile/01-standards/mobile-app-standard.md +85 -0
- package/mobile/01-standards/react-native-complete.md +352 -0
- package/mobile/02-playbooks/mobile-cross-platform-playbook.md +175 -0
- package/mobile/02-playbooks/mobile-performance.md +473 -0
- package/mobile/03-checklists/mobile-release-checklist.md +234 -0
- package/mobile/04-antipatterns/mobile-antipatterns.md +798 -0
- package/mobile/05-cases/case-app-performance.md +500 -0
- package/mobile/05-cases/case-app-startup-optimization.md +218 -0
- package/mobile/06-glossary/mobile-glossary.md +484 -0
- package/observability/01-standards/observability-standards.md +103 -0
- package/observability/02-playbooks/prometheus-grafana-playbook.md +135 -0
- package/observability/02-playbooks/structured-logging-playbook.md +73 -0
- package/observability/03-checklists/observability-checklist.md +54 -0
- package/observability/04-antipatterns/observability-antipatterns.md +106 -0
- package/operations/01-standards/prometheus-monitoring-complete.md +1578 -0
- package/operations/02-playbooks/capacity-planning-playbook.md +620 -0
- package/operations/03-checklists/production-launch-checklist.md +365 -0
- package/operations/04-antipatterns/operations-antipatterns.md +664 -0
- package/operations/05-cases/case-sre-practices.md +581 -0
- package/operations/06-glossary/operations-glossary.md +120 -0
- package/operations/aiops-anomaly-detection.md +758 -0
- package/operations/capacity-planning.md +1061 -0
- package/operations/chaos-engineering.md +659 -0
- package/operations/incident-command-system.md +38 -0
- package/operations/observability-complete.md +442 -0
- package/operations/slo-sli-playbook.md +517 -0
- package/operations/sre-operations-deep-dive.md +39 -0
- package/package.json +8 -0
- package/performance/01-standards/performance-and-scalability.md +80 -0
- package/performance/01-standards/performance-standards.md +156 -0
- package/performance/02-playbooks/query-optimization-playbook.md +103 -0
- package/performance/03-checklists/performance-checklist.md +56 -0
- package/performance/04-antipatterns/performance-antipatterns.md +146 -0
- package/product/01-standards/product-management-complete.md +285 -0
- package/product/02-playbooks/feature-launch-playbook.md +207 -0
- package/product/02-playbooks/user-research-playbook.md +532 -0
- package/product/03-checklists/feature-launch-checklist.md +275 -0
- package/product/04-antipatterns/product-antipatterns.md +355 -0
- package/product/05-cases/case-mvp-to-scale.md +384 -0
- package/product/06-glossary/product-glossary.md +462 -0
- package/product/feature-prioritization-framework.md +40 -0
- package/product/kpi-and-metric-tree.md +37 -0
- package/product/product-discovery-and-prd-deep-dive.md +41 -0
- package/quantum/01-standards/quantum-complete.md +1186 -0
- package/security/01-standards/api-security-complete.md +511 -0
- package/security/01-standards/container-runtime-security.md +574 -0
- package/security/01-standards/data-protection-gdpr.md +543 -0
- package/security/01-standards/owasp-top10-complete.md +1890 -0
- package/security/01-standards/secure-coding-baseline.md +90 -0
- package/security/01-standards/supply-chain-security.md +441 -0
- package/security/01-standards/web-security-checklist.md +108 -0
- package/security/01-standards/zero-trust-architecture.md +521 -0
- package/security/02-playbooks/auth-sso-playbook.md +166 -0
- package/security/02-playbooks/incident-response-security-playbook.md +588 -0
- package/security/02-playbooks/owasp-api-security-playbook.md +129 -0
- package/security/02-playbooks/payment-integration-playbook.md +119 -0
- package/security/02-playbooks/penetration-testing-playbook.md +517 -0
- package/security/03-checklists/security-audit-checklist.md +356 -0
- package/security/04-antipatterns/security-coding-antipatterns.md +580 -0
- package/security/05-cases/case-log4shell-incident.md +537 -0
- package/security/05-cases/case-major-breaches.md +468 -0
- package/security/06-glossary/security-glossary.md +212 -0
- package/security/compliance-automation.md +993 -0
- package/security/container-security.md +680 -0
- package/security/devsecops-complete.md +426 -0
- package/security/sast-dast-sca.md +775 -0
- package/security/secrets-management.md +594 -0
- package/security/security-architecture-deep-dive.md +37 -0
- package/security/threat-modeling-stride-playbook.md +40 -0
- package/seed-templates/auth-system.md +59 -0
- package/seed-templates/blog-content.md +94 -0
- package/seed-templates/dashboard.md +89 -0
- package/seed-templates/docs-site.md +73 -0
- package/seed-templates/e-commerce.md +50 -0
- package/seed-templates/saas-landing.md +92 -0
- package/seed-templates/settings-page.md +51 -0
- package/testing/01-standards/test-strategy-and-layering.md +83 -0
- package/testing/01-standards/testing-strategy-complete.md +422 -0
- package/testing/01-standards/unit-testing-best-practices.md +118 -0
- package/testing/02-playbooks/e2e-testing-playbook.md +988 -0
- package/testing/02-playbooks/testing-strategy-playbook.md +126 -0
- package/testing/03-checklists/test-strategy-checklist.md +208 -0
- package/testing/04-antipatterns/testing-antipatterns.md +718 -0
- package/testing/05-cases/case-testing-transformation.md +300 -0
- package/testing/06-glossary/testing-glossary.md +110 -0
- package/testing/risk-based-test-matrix.md +36 -0
- package/testing/testing-strategy-deep-dive.md +37 -0
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: data-protection-gdpr
|
|
3
|
+
title: 数据保护与GDPR合规
|
|
4
|
+
domain: security
|
|
5
|
+
category: 01-standards
|
|
6
|
+
difficulty: intermediate
|
|
7
|
+
tags: [agent, checklist, data, gdpr, protection, security, 实战代码示例, 常见陷阱]
|
|
8
|
+
quality_score: 70
|
|
9
|
+
last_updated: 2026-06-15
|
|
10
|
+
---
|
|
11
|
+
# 数据保护与GDPR合规
|
|
12
|
+
|
|
13
|
+
## 概述
|
|
14
|
+
数据保护是现代软件系统的法律和道德义务。本指南覆盖GDPR(通用数据保护条例)核心要求、数据分类、加密、脱敏、审计日志和DPIA(数据保护影响评估),帮助团队构建合规的数据处理系统。
|
|
15
|
+
|
|
16
|
+
## 核心概念
|
|
17
|
+
|
|
18
|
+
### 1. GDPR核心原则
|
|
19
|
+
- **合法性、公正性、透明性**: 有合法依据处理数据,对用户透明
|
|
20
|
+
- **目的限制**: 只为明确声明的目的收集数据
|
|
21
|
+
- **数据最小化**: 只收集必要的最少数据
|
|
22
|
+
- **准确性**: 保持数据准确并及时更新
|
|
23
|
+
- **存储限制**: 不超过必要期限保留数据
|
|
24
|
+
- **完整性与保密性**: 适当的安全措施保护数据
|
|
25
|
+
- **问责制**: 能证明合规
|
|
26
|
+
|
|
27
|
+
### 2. 数据分类
|
|
28
|
+
|
|
29
|
+
| 分类 | 示例 | 保护级别 | 处理要求 |
|
|
30
|
+
|------|------|----------|----------|
|
|
31
|
+
| 公开数据 | 公司名称、产品描述 | 基础 | 无特殊要求 |
|
|
32
|
+
| 内部数据 | 内部文档、配置 | 标准 | 访问控制 |
|
|
33
|
+
| 机密数据 | 客户信息、财务数据 | 高 | 加密+访问控制+审计 |
|
|
34
|
+
| 敏感个人数据 | 健康/种族/宗教/性取向 | 最高 | 明确同意+加密+DPIA |
|
|
35
|
+
| PII(个人身份信息) | 姓名/邮箱/手机/身份证 | 高 | 加密+最小化+删除权 |
|
|
36
|
+
|
|
37
|
+
### 3. 用户权利(GDPR)
|
|
38
|
+
- **访问权**: 用户可以获取其数据副本
|
|
39
|
+
- **更正权**: 用户可以修正不准确的数据
|
|
40
|
+
- **删除权(被遗忘权)**: 用户可以要求删除其数据
|
|
41
|
+
- **可携带权**: 用户可以获取结构化机器可读格式的数据
|
|
42
|
+
- **限制处理权**: 用户可以限制数据的处理方式
|
|
43
|
+
- **反对权**: 用户可以反对某些类型的处理
|
|
44
|
+
- **不受自动化决策约束的权利**: 拒绝纯自动化决策
|
|
45
|
+
|
|
46
|
+
### 4. 合规框架对比
|
|
47
|
+
| 法规 | 地区 | 罚款 | 关键差异 |
|
|
48
|
+
|------|------|------|----------|
|
|
49
|
+
| GDPR | 欧盟/EEA | 最高2000万欧元或4%全球营收 | 最严格,域外适用 |
|
|
50
|
+
| CCPA/CPRA | 加州 | 每项违规$7,500 | 侧重消费者权利 |
|
|
51
|
+
| PIPL | 中国 | 最高5000万元或5%营收 | 数据本地化要求 |
|
|
52
|
+
| LGPD | 巴西 | 最高营收2% | 类似GDPR |
|
|
53
|
+
|
|
54
|
+
## 实战代码示例
|
|
55
|
+
|
|
56
|
+
### 数据加密
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
# 字段级加密
|
|
60
|
+
from cryptography.fernet import Fernet
|
|
61
|
+
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
|
62
|
+
from cryptography.hazmat.primitives import hashes
|
|
63
|
+
import base64
|
|
64
|
+
import os
|
|
65
|
+
|
|
66
|
+
class FieldEncryptor:
|
|
67
|
+
"""字段级加密器"""
|
|
68
|
+
|
|
69
|
+
def __init__(self, master_key: str):
|
|
70
|
+
# 从主密钥派生加密密钥
|
|
71
|
+
kdf = PBKDF2HMAC(
|
|
72
|
+
algorithm=hashes.SHA256(),
|
|
73
|
+
length=32,
|
|
74
|
+
salt=b"field-encryption-salt", # 实际应用中使用随机盐并存储
|
|
75
|
+
iterations=480000,
|
|
76
|
+
)
|
|
77
|
+
key = base64.urlsafe_b64encode(kdf.derive(master_key.encode()))
|
|
78
|
+
self.cipher = Fernet(key)
|
|
79
|
+
|
|
80
|
+
def encrypt(self, plaintext: str) -> str:
|
|
81
|
+
"""加密字段值"""
|
|
82
|
+
return self.cipher.encrypt(plaintext.encode()).decode()
|
|
83
|
+
|
|
84
|
+
def decrypt(self, ciphertext: str) -> str:
|
|
85
|
+
"""解密字段值"""
|
|
86
|
+
return self.cipher.decrypt(ciphertext.encode()).decode()
|
|
87
|
+
|
|
88
|
+
# SQLAlchemy加密列
|
|
89
|
+
from sqlalchemy import TypeDecorator, String
|
|
90
|
+
|
|
91
|
+
class EncryptedString(TypeDecorator):
|
|
92
|
+
"""透明加密的字符串列"""
|
|
93
|
+
impl = String
|
|
94
|
+
cache_ok = True
|
|
95
|
+
|
|
96
|
+
def __init__(self, encryptor: FieldEncryptor, *args, **kwargs):
|
|
97
|
+
self.encryptor = encryptor
|
|
98
|
+
super().__init__(*args, **kwargs)
|
|
99
|
+
|
|
100
|
+
def process_bind_param(self, value, dialect):
|
|
101
|
+
if value is not None:
|
|
102
|
+
return self.encryptor.encrypt(value)
|
|
103
|
+
return value
|
|
104
|
+
|
|
105
|
+
def process_result_value(self, value, dialect):
|
|
106
|
+
if value is not None:
|
|
107
|
+
return self.encryptor.decrypt(value)
|
|
108
|
+
return value
|
|
109
|
+
|
|
110
|
+
# 使用
|
|
111
|
+
encryptor = FieldEncryptor(os.environ["ENCRYPTION_KEY"])
|
|
112
|
+
|
|
113
|
+
class User(Base):
|
|
114
|
+
__tablename__ = "users"
|
|
115
|
+
id = Column(Integer, primary_key=True)
|
|
116
|
+
name = Column(String(100)) # 非敏感,不加密
|
|
117
|
+
email = Column(EncryptedString(encryptor, length=500)) # PII,加密
|
|
118
|
+
phone = Column(EncryptedString(encryptor, length=500)) # PII,加密
|
|
119
|
+
email_hash = Column(String(64), index=True) # 用于查询的哈希
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### 数据脱敏
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
# 数据脱敏工具
|
|
126
|
+
import re
|
|
127
|
+
import hashlib
|
|
128
|
+
|
|
129
|
+
class DataMasker:
|
|
130
|
+
"""数据脱敏工具"""
|
|
131
|
+
|
|
132
|
+
@staticmethod
|
|
133
|
+
def mask_email(email: str) -> str:
|
|
134
|
+
"""邮箱脱敏: user@example.com → u***@example.com"""
|
|
135
|
+
if not email or "@" not in email:
|
|
136
|
+
return "***"
|
|
137
|
+
local, domain = email.split("@", 1)
|
|
138
|
+
if len(local) <= 1:
|
|
139
|
+
return f"*@{domain}"
|
|
140
|
+
return f"{local[0]}{'*' * (len(local) - 1)}@{domain}"
|
|
141
|
+
|
|
142
|
+
@staticmethod
|
|
143
|
+
def mask_phone(phone: str) -> str:
|
|
144
|
+
"""手机号脱敏: 13812345678 → 138****5678"""
|
|
145
|
+
digits = re.sub(r'\D', '', phone)
|
|
146
|
+
if len(digits) >= 7:
|
|
147
|
+
return digits[:3] + "****" + digits[-4:]
|
|
148
|
+
return "****"
|
|
149
|
+
|
|
150
|
+
@staticmethod
|
|
151
|
+
def mask_id_card(id_card: str) -> str:
|
|
152
|
+
"""身份证脱敏: 110101199001011234 → 110101****1234"""
|
|
153
|
+
if len(id_card) >= 8:
|
|
154
|
+
return id_card[:6] + "****" + id_card[-4:]
|
|
155
|
+
return "****"
|
|
156
|
+
|
|
157
|
+
@staticmethod
|
|
158
|
+
def mask_name(name: str) -> str:
|
|
159
|
+
"""姓名脱敏: 张三 → 张* / Alice Bob → A*** Bob"""
|
|
160
|
+
if not name:
|
|
161
|
+
return "***"
|
|
162
|
+
parts = name.split()
|
|
163
|
+
if len(parts) == 1:
|
|
164
|
+
return name[0] + "*" * (len(name) - 1)
|
|
165
|
+
return parts[0][0] + "***" + " " + parts[-1]
|
|
166
|
+
|
|
167
|
+
@staticmethod
|
|
168
|
+
def pseudonymize(value: str, pepper: str) -> str:
|
|
169
|
+
"""假名化: 可逆映射(需要pepper)"""
|
|
170
|
+
return hashlib.sha256(f"{pepper}:{value}".encode()).hexdigest()[:16]
|
|
171
|
+
|
|
172
|
+
# API响应自动脱敏
|
|
173
|
+
from pydantic import BaseModel, field_serializer
|
|
174
|
+
|
|
175
|
+
class UserPublicResponse(BaseModel):
|
|
176
|
+
"""面向公众的用户响应(脱敏)"""
|
|
177
|
+
id: int
|
|
178
|
+
name: str
|
|
179
|
+
email: str
|
|
180
|
+
phone: str | None = None
|
|
181
|
+
|
|
182
|
+
@field_serializer("email")
|
|
183
|
+
def mask_email_field(self, v: str) -> str:
|
|
184
|
+
return DataMasker.mask_email(v)
|
|
185
|
+
|
|
186
|
+
@field_serializer("phone")
|
|
187
|
+
def mask_phone_field(self, v: str | None) -> str | None:
|
|
188
|
+
if v:
|
|
189
|
+
return DataMasker.mask_phone(v)
|
|
190
|
+
return None
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### 审计日志
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
# GDPR审计日志系统
|
|
197
|
+
from datetime import datetime
|
|
198
|
+
from enum import Enum
|
|
199
|
+
from pydantic import BaseModel
|
|
200
|
+
import json
|
|
201
|
+
|
|
202
|
+
class AuditAction(str, Enum):
|
|
203
|
+
CREATE = "create"
|
|
204
|
+
READ = "read"
|
|
205
|
+
UPDATE = "update"
|
|
206
|
+
DELETE = "delete"
|
|
207
|
+
EXPORT = "export"
|
|
208
|
+
CONSENT_GRANTED = "consent_granted"
|
|
209
|
+
CONSENT_WITHDRAWN = "consent_withdrawn"
|
|
210
|
+
DATA_ACCESS_REQUEST = "data_access_request"
|
|
211
|
+
DATA_DELETION_REQUEST = "data_deletion_request"
|
|
212
|
+
|
|
213
|
+
class AuditLog(BaseModel):
|
|
214
|
+
timestamp: datetime
|
|
215
|
+
action: AuditAction
|
|
216
|
+
actor_id: str
|
|
217
|
+
actor_type: str # "user" | "system" | "admin"
|
|
218
|
+
resource_type: str
|
|
219
|
+
resource_id: str
|
|
220
|
+
data_categories: list[str]
|
|
221
|
+
legal_basis: str
|
|
222
|
+
ip_address: str
|
|
223
|
+
user_agent: str | None = None
|
|
224
|
+
details: dict = {}
|
|
225
|
+
|
|
226
|
+
class GDPRAuditLogger:
|
|
227
|
+
"""GDPR合规审计日志记录器"""
|
|
228
|
+
|
|
229
|
+
def __init__(self, storage):
|
|
230
|
+
self.storage = storage
|
|
231
|
+
|
|
232
|
+
async def log(self, audit: AuditLog):
|
|
233
|
+
"""记录审计日志(不可修改)"""
|
|
234
|
+
record = audit.model_dump()
|
|
235
|
+
record["timestamp"] = record["timestamp"].isoformat()
|
|
236
|
+
# 追加写入,不可修改
|
|
237
|
+
await self.storage.append(record)
|
|
238
|
+
# 同时发送到SIEM
|
|
239
|
+
await self.siem.send(record)
|
|
240
|
+
|
|
241
|
+
async def log_data_access(
|
|
242
|
+
self,
|
|
243
|
+
actor_id: str,
|
|
244
|
+
resource_type: str,
|
|
245
|
+
resource_id: str,
|
|
246
|
+
data_fields: list[str],
|
|
247
|
+
purpose: str,
|
|
248
|
+
request: Request,
|
|
249
|
+
):
|
|
250
|
+
await self.log(AuditLog(
|
|
251
|
+
timestamp=datetime.utcnow(),
|
|
252
|
+
action=AuditAction.READ,
|
|
253
|
+
actor_id=actor_id,
|
|
254
|
+
actor_type="user",
|
|
255
|
+
resource_type=resource_type,
|
|
256
|
+
resource_id=resource_id,
|
|
257
|
+
data_categories=classify_fields(data_fields),
|
|
258
|
+
legal_basis=purpose,
|
|
259
|
+
ip_address=request.client.host,
|
|
260
|
+
user_agent=request.headers.get("user-agent"),
|
|
261
|
+
details={"fields_accessed": data_fields},
|
|
262
|
+
))
|
|
263
|
+
|
|
264
|
+
# FastAPI审计中间件
|
|
265
|
+
audit_logger = GDPRAuditLogger(storage)
|
|
266
|
+
|
|
267
|
+
@app.get("/api/users/{user_id}")
|
|
268
|
+
async def get_user(user_id: int, auth = Depends(authenticate), request: Request):
|
|
269
|
+
user = await user_repo.get(user_id)
|
|
270
|
+
|
|
271
|
+
await audit_logger.log_data_access(
|
|
272
|
+
actor_id=str(auth.user_id),
|
|
273
|
+
resource_type="user",
|
|
274
|
+
resource_id=str(user_id),
|
|
275
|
+
data_fields=["name", "email", "phone"],
|
|
276
|
+
purpose="user_profile_view",
|
|
277
|
+
request=request,
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
return user
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### 用户权利实现
|
|
284
|
+
|
|
285
|
+
```python
|
|
286
|
+
# GDPR用户权利API
|
|
287
|
+
class GDPRService:
|
|
288
|
+
"""GDPR权利服务"""
|
|
289
|
+
|
|
290
|
+
async def handle_access_request(self, user_id: int) -> dict:
|
|
291
|
+
"""处理数据访问请求(SAR)"""
|
|
292
|
+
# 收集用户所有数据
|
|
293
|
+
data = {
|
|
294
|
+
"personal_info": await user_repo.get(user_id),
|
|
295
|
+
"orders": await order_repo.get_by_user(user_id),
|
|
296
|
+
"activity_logs": await activity_repo.get_by_user(user_id),
|
|
297
|
+
"preferences": await preference_repo.get(user_id),
|
|
298
|
+
"consent_records": await consent_repo.get_by_user(user_id),
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
# 审计日志
|
|
302
|
+
await audit_logger.log(AuditLog(
|
|
303
|
+
action=AuditAction.DATA_ACCESS_REQUEST,
|
|
304
|
+
actor_id=str(user_id),
|
|
305
|
+
resource_type="user_data",
|
|
306
|
+
resource_id=str(user_id),
|
|
307
|
+
data_categories=["all"],
|
|
308
|
+
legal_basis="gdpr_article_15",
|
|
309
|
+
))
|
|
310
|
+
|
|
311
|
+
return data
|
|
312
|
+
|
|
313
|
+
async def handle_deletion_request(self, user_id: int) -> dict:
|
|
314
|
+
"""处理删除请求(被遗忘权)"""
|
|
315
|
+
results = {"deleted": [], "retained": [], "errors": []}
|
|
316
|
+
|
|
317
|
+
# 1. 删除非必须保留的数据
|
|
318
|
+
deletable_data = [
|
|
319
|
+
("user_profile", user_repo.delete_profile),
|
|
320
|
+
("preferences", preference_repo.delete),
|
|
321
|
+
("activity_logs", activity_repo.delete_by_user),
|
|
322
|
+
("sessions", session_repo.delete_by_user),
|
|
323
|
+
]
|
|
324
|
+
|
|
325
|
+
for name, delete_fn in deletable_data:
|
|
326
|
+
try:
|
|
327
|
+
await delete_fn(user_id)
|
|
328
|
+
results["deleted"].append(name)
|
|
329
|
+
except Exception as e:
|
|
330
|
+
results["errors"].append({"data": name, "error": str(e)})
|
|
331
|
+
|
|
332
|
+
# 2. 标记必须保留的数据(法律义务)
|
|
333
|
+
retained = [
|
|
334
|
+
("financial_records", "Tax law requires 7-year retention"),
|
|
335
|
+
("audit_logs", "Regulatory compliance"),
|
|
336
|
+
]
|
|
337
|
+
results["retained"] = [
|
|
338
|
+
{"data": name, "reason": reason, "retention_until": calculate_retention_end(name)}
|
|
339
|
+
for name, reason in retained
|
|
340
|
+
]
|
|
341
|
+
|
|
342
|
+
# 3. 匿名化而非删除(保留统计价值)
|
|
343
|
+
await user_repo.anonymize(user_id)
|
|
344
|
+
|
|
345
|
+
# 审计日志
|
|
346
|
+
await audit_logger.log(AuditLog(
|
|
347
|
+
action=AuditAction.DATA_DELETION_REQUEST,
|
|
348
|
+
actor_id=str(user_id),
|
|
349
|
+
resource_type="user_data",
|
|
350
|
+
resource_id=str(user_id),
|
|
351
|
+
data_categories=["all"],
|
|
352
|
+
legal_basis="gdpr_article_17",
|
|
353
|
+
details=results,
|
|
354
|
+
))
|
|
355
|
+
|
|
356
|
+
return results
|
|
357
|
+
|
|
358
|
+
async def handle_portability_request(self, user_id: int) -> bytes:
|
|
359
|
+
"""处理数据可携带请求"""
|
|
360
|
+
data = await self.handle_access_request(user_id)
|
|
361
|
+
# 返回结构化JSON格式
|
|
362
|
+
return json.dumps(data, indent=2, default=str, ensure_ascii=False).encode()
|
|
363
|
+
|
|
364
|
+
# API端点
|
|
365
|
+
@app.post("/api/gdpr/access-request")
|
|
366
|
+
async def request_data_access(auth = Depends(authenticate)):
|
|
367
|
+
"""提交数据访问请求(SAR)"""
|
|
368
|
+
data = await gdpr_service.handle_access_request(auth.user_id)
|
|
369
|
+
return data
|
|
370
|
+
|
|
371
|
+
@app.post("/api/gdpr/deletion-request")
|
|
372
|
+
async def request_data_deletion(auth = Depends(authenticate)):
|
|
373
|
+
"""提交数据删除请求"""
|
|
374
|
+
result = await gdpr_service.handle_deletion_request(auth.user_id)
|
|
375
|
+
return result
|
|
376
|
+
|
|
377
|
+
@app.get("/api/gdpr/export")
|
|
378
|
+
async def export_data(auth = Depends(authenticate)):
|
|
379
|
+
"""导出个人数据(可携带权)"""
|
|
380
|
+
data = await gdpr_service.handle_portability_request(auth.user_id)
|
|
381
|
+
return Response(
|
|
382
|
+
content=data,
|
|
383
|
+
media_type="application/json",
|
|
384
|
+
headers={"Content-Disposition": "attachment; filename=my_data.json"},
|
|
385
|
+
)
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### 同意管理
|
|
389
|
+
|
|
390
|
+
```python
|
|
391
|
+
# 同意管理系统
|
|
392
|
+
class ConsentPurpose(str, Enum):
|
|
393
|
+
ESSENTIAL = "essential" # 必要功能
|
|
394
|
+
ANALYTICS = "analytics" # 数据分析
|
|
395
|
+
MARKETING = "marketing" # 营销推广
|
|
396
|
+
PERSONALIZATION = "personalization" # 个性化
|
|
397
|
+
THIRD_PARTY = "third_party" # 第三方共享
|
|
398
|
+
|
|
399
|
+
class ConsentRecord(BaseModel):
|
|
400
|
+
user_id: int
|
|
401
|
+
purpose: ConsentPurpose
|
|
402
|
+
granted: bool
|
|
403
|
+
granted_at: datetime | None
|
|
404
|
+
withdrawn_at: datetime | None
|
|
405
|
+
version: str # 隐私政策版本
|
|
406
|
+
method: str # "web_form" | "api" | "email"
|
|
407
|
+
ip_address: str
|
|
408
|
+
|
|
409
|
+
class ConsentManager:
|
|
410
|
+
async def grant_consent(self, user_id: int, purpose: ConsentPurpose, request: Request):
|
|
411
|
+
record = ConsentRecord(
|
|
412
|
+
user_id=user_id,
|
|
413
|
+
purpose=purpose,
|
|
414
|
+
granted=True,
|
|
415
|
+
granted_at=datetime.utcnow(),
|
|
416
|
+
withdrawn_at=None,
|
|
417
|
+
version=CURRENT_PRIVACY_POLICY_VERSION,
|
|
418
|
+
method="web_form",
|
|
419
|
+
ip_address=request.client.host,
|
|
420
|
+
)
|
|
421
|
+
await consent_repo.save(record)
|
|
422
|
+
await audit_logger.log(AuditLog(
|
|
423
|
+
action=AuditAction.CONSENT_GRANTED,
|
|
424
|
+
actor_id=str(user_id),
|
|
425
|
+
resource_type="consent",
|
|
426
|
+
resource_id=purpose,
|
|
427
|
+
legal_basis="gdpr_article_6_1_a",
|
|
428
|
+
))
|
|
429
|
+
|
|
430
|
+
async def check_consent(self, user_id: int, purpose: ConsentPurpose) -> bool:
|
|
431
|
+
"""检查用户是否同意特定目的"""
|
|
432
|
+
if purpose == ConsentPurpose.ESSENTIAL:
|
|
433
|
+
return True # 必要处理不需要同意
|
|
434
|
+
record = await consent_repo.get_latest(user_id, purpose)
|
|
435
|
+
return record is not None and record.granted
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
## 最佳实践
|
|
439
|
+
|
|
440
|
+
### 1. 数据最小化
|
|
441
|
+
- 只收集业务必需的数据
|
|
442
|
+
- 注册时不要求不必要的字段
|
|
443
|
+
- 定期审查数据收集范围
|
|
444
|
+
- 日志中不包含PII(或脱敏)
|
|
445
|
+
|
|
446
|
+
### 2. 加密策略
|
|
447
|
+
- 传输加密: TLS 1.2+全覆盖
|
|
448
|
+
- 存储加密: 敏感字段加密(AES-256)
|
|
449
|
+
- 数据库加密: 透明数据加密(TDE)
|
|
450
|
+
- 密钥管理: 使用KMS(AWS KMS/Vault)
|
|
451
|
+
|
|
452
|
+
### 3. 数据保留
|
|
453
|
+
- 定义每类数据的保留期限
|
|
454
|
+
- 自动清理过期数据
|
|
455
|
+
- 法律要求的数据标记保留原因
|
|
456
|
+
- 保留策略文档化并定期审查
|
|
457
|
+
|
|
458
|
+
### 4. 隐私设计(Privacy by Design)
|
|
459
|
+
- 默认设置最高隐私保护
|
|
460
|
+
- 隐私考虑融入开发流程
|
|
461
|
+
- DPIA在处理高风险数据前执行
|
|
462
|
+
- 第三方数据处理需签署DPA
|
|
463
|
+
|
|
464
|
+
### 5. 事件响应
|
|
465
|
+
- 72小时内向监管机构通报数据泄露
|
|
466
|
+
- 高风险泄露需通知受影响用户
|
|
467
|
+
- 准备数据泄露应急响应流程
|
|
468
|
+
- 定期演练数据泄露场景
|
|
469
|
+
|
|
470
|
+
## 常见陷阱
|
|
471
|
+
|
|
472
|
+
### 陷阱1: 日志中泄露PII
|
|
473
|
+
```python
|
|
474
|
+
# 错误
|
|
475
|
+
logger.info(f"User login: {user.email}, IP: {ip}")
|
|
476
|
+
logger.error(f"Payment failed for card {card_number}")
|
|
477
|
+
|
|
478
|
+
# 正确
|
|
479
|
+
logger.info("User login", user_id=user.id, ip=mask_ip(ip))
|
|
480
|
+
logger.error("Payment failed", user_id=user.id, card_last4=card[-4:])
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
### 陷阱2: 删除数据不彻底
|
|
484
|
+
```python
|
|
485
|
+
# 错误: 只删除主表,备份和缓存中还有数据
|
|
486
|
+
await user_repo.delete(user_id)
|
|
487
|
+
|
|
488
|
+
# 正确: 删除所有存储位置
|
|
489
|
+
await user_repo.delete(user_id)
|
|
490
|
+
await cache.delete(f"user:{user_id}")
|
|
491
|
+
await search_index.delete(f"user_{user_id}")
|
|
492
|
+
await cdn.purge(f"/avatars/{user_id}/*")
|
|
493
|
+
# 备份中的数据:标记为待清理,下次备份时排除
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
### 陷阱3: 同意管理不完善
|
|
497
|
+
```python
|
|
498
|
+
# 错误: 使用预勾选的同意框
|
|
499
|
+
# 错误: 一次性同意所有用途
|
|
500
|
+
# 错误: 不提供撤回同意的途径
|
|
501
|
+
|
|
502
|
+
# 正确:
|
|
503
|
+
# - 每个目的单独同意
|
|
504
|
+
# - 默认不勾选
|
|
505
|
+
# - 撤回同意与授予同意一样容易
|
|
506
|
+
# - 记录同意的版本、时间、方式
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
### 陷阱4: 跨境数据传输不合规
|
|
510
|
+
```python
|
|
511
|
+
# 错误: 直接将EU用户数据存储到美国服务器
|
|
512
|
+
# 正确:
|
|
513
|
+
# - 使用标准合同条款(SCCs)
|
|
514
|
+
# - 评估目标国数据保护水平
|
|
515
|
+
# - 考虑数据本地化方案
|
|
516
|
+
# - 使用EU区域的云服务
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
## Agent Checklist
|
|
520
|
+
|
|
521
|
+
### 数据分类与保护
|
|
522
|
+
- [ ] 所有数据字段已分类(公开/内部/机密/敏感)
|
|
523
|
+
- [ ] PII字段已识别并标注
|
|
524
|
+
- [ ] 敏感数据字段级加密已实现
|
|
525
|
+
- [ ] 数据脱敏在日志/测试/非生产环境中应用
|
|
526
|
+
|
|
527
|
+
### 用户权利
|
|
528
|
+
- [ ] 数据访问请求(SAR)接口已实现
|
|
529
|
+
- [ ] 数据删除/匿名化接口已实现
|
|
530
|
+
- [ ] 数据导出(可携带权)接口已实现
|
|
531
|
+
- [ ] 同意管理系统已实现
|
|
532
|
+
|
|
533
|
+
### 合规管理
|
|
534
|
+
- [ ] 隐私政策已发布并可访问
|
|
535
|
+
- [ ] 审计日志覆盖所有数据操作
|
|
536
|
+
- [ ] 数据保留策略已定义并自动执行
|
|
537
|
+
- [ ] 数据泄露应急响应流程已建立
|
|
538
|
+
|
|
539
|
+
### 技术措施
|
|
540
|
+
- [ ] 全链路TLS加密
|
|
541
|
+
- [ ] 密钥管理使用KMS
|
|
542
|
+
- [ ] 第三方数据处理有DPA协议
|
|
543
|
+
- [ ] DPIA已对高风险处理执行
|