@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,521 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: zero-trust-architecture
|
|
3
|
+
title: 零信任架构指南
|
|
4
|
+
domain: security
|
|
5
|
+
category: 01-standards
|
|
6
|
+
difficulty: intermediate
|
|
7
|
+
tags: [agent, architecture, checklist, security, trust, zero, 实战代码示例, 常见陷阱]
|
|
8
|
+
quality_score: 70
|
|
9
|
+
last_updated: 2026-06-15
|
|
10
|
+
---
|
|
11
|
+
# 零信任架构指南
|
|
12
|
+
|
|
13
|
+
## 概述
|
|
14
|
+
零信任(Zero Trust)是一种安全模型,核心原则是"永不信任,始终验证"。传统边界安全模型假设内网可信,而零信任消除了隐式信任,对每次访问都进行身份验证、授权和加密。本指南覆盖零信任原则、实现路径、mTLS、身份验证和微分段。
|
|
15
|
+
|
|
16
|
+
## 核心概念
|
|
17
|
+
|
|
18
|
+
### 1. 零信任核心原则
|
|
19
|
+
- **永不信任,始终验证**: 无论请求来自内网还是外网,一视同仁
|
|
20
|
+
- **最小权限**: 仅授予完成工作所需的最低权限
|
|
21
|
+
- **假设已被入侵**: 设计系统时假定攻击者已在内部
|
|
22
|
+
- **显式验证**: 基于所有可用数据点(身份/位置/设备/行为)验证
|
|
23
|
+
- **微分段**: 将网络划分为小的隔离区域,限制横向移动
|
|
24
|
+
|
|
25
|
+
### 2. 零信任架构组件
|
|
26
|
+
| 组件 | 功能 | 实现技术 |
|
|
27
|
+
|------|------|----------|
|
|
28
|
+
| 身份提供者(IdP) | 集中身份管理和认证 | Okta/Auth0/Keycloak/Azure AD |
|
|
29
|
+
| 策略引擎 | 访问决策 | OPA/Cedar/Zanzibar |
|
|
30
|
+
| 策略执行点(PEP) | 拦截和执行策略 | API Gateway/Service Mesh Sidecar |
|
|
31
|
+
| 设备信任评估 | 验证设备安全状态 | MDM/EDR/设备证书 |
|
|
32
|
+
| 网络微分段 | 隔离网络区域 | Kubernetes NetworkPolicy/Calico |
|
|
33
|
+
| 加密通信 | 端到端加密 | mTLS/WireGuard |
|
|
34
|
+
|
|
35
|
+
### 3. 零信任成熟度模型
|
|
36
|
+
- **Level 1**: 基础 — 强身份认证(MFA)、基础网络分段
|
|
37
|
+
- **Level 2**: 进阶 — 设备信任评估、基于策略的访问控制
|
|
38
|
+
- **Level 3**: 优化 — 持续验证、行为分析、自动化响应
|
|
39
|
+
- **Level 4**: 全面 — 完整的微分段、端到端加密、AI驱动的风险评估
|
|
40
|
+
|
|
41
|
+
## 实战代码示例
|
|
42
|
+
|
|
43
|
+
### mTLS服务间认证
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
# FastAPI mTLS服务端配置
|
|
47
|
+
import ssl
|
|
48
|
+
import uvicorn
|
|
49
|
+
|
|
50
|
+
def create_ssl_context():
|
|
51
|
+
"""创建mTLS SSL上下文"""
|
|
52
|
+
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
|
53
|
+
ssl_context.load_cert_chain(
|
|
54
|
+
certfile="/certs/server.crt",
|
|
55
|
+
keyfile="/certs/server.key",
|
|
56
|
+
)
|
|
57
|
+
# 要求客户端证书
|
|
58
|
+
ssl_context.verify_mode = ssl.CERT_REQUIRED
|
|
59
|
+
ssl_context.load_verify_locations("/certs/ca.crt")
|
|
60
|
+
return ssl_context
|
|
61
|
+
|
|
62
|
+
if __name__ == "__main__":
|
|
63
|
+
uvicorn.run(
|
|
64
|
+
"app:app",
|
|
65
|
+
host="0.0.0.0",
|
|
66
|
+
port=8443,
|
|
67
|
+
ssl_certfile="/certs/server.crt",
|
|
68
|
+
ssl_keyfile="/certs/server.key",
|
|
69
|
+
ssl_ca_certs="/certs/ca.crt",
|
|
70
|
+
ssl_cert_reqs=ssl.CERT_REQUIRED,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
# 从客户端证书提取身份
|
|
74
|
+
from fastapi import Request
|
|
75
|
+
|
|
76
|
+
async def get_client_identity(request: Request) -> dict:
|
|
77
|
+
"""从mTLS证书提取客户端身份"""
|
|
78
|
+
cert = request.scope.get("tls_client_cert")
|
|
79
|
+
if not cert:
|
|
80
|
+
raise HTTPException(401, "Client certificate required")
|
|
81
|
+
|
|
82
|
+
subject = dict(x[0] for x in cert.get("subject", []))
|
|
83
|
+
return {
|
|
84
|
+
"service_name": subject.get("commonName"),
|
|
85
|
+
"organization": subject.get("organizationName"),
|
|
86
|
+
"serial_number": cert.get("serialNumber"),
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
# mTLS客户端调用
|
|
92
|
+
import httpx
|
|
93
|
+
|
|
94
|
+
class SecureServiceClient:
|
|
95
|
+
"""带mTLS的服务客户端"""
|
|
96
|
+
|
|
97
|
+
def __init__(self, service_url: str):
|
|
98
|
+
self.client = httpx.AsyncClient(
|
|
99
|
+
base_url=service_url,
|
|
100
|
+
cert=("/certs/client.crt", "/certs/client.key"),
|
|
101
|
+
verify="/certs/ca.crt",
|
|
102
|
+
timeout=10.0,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
async def call(self, path: str, method: str = "GET", **kwargs):
|
|
106
|
+
response = await self.client.request(method, path, **kwargs)
|
|
107
|
+
response.raise_for_status()
|
|
108
|
+
return response.json()
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 基于OPA的策略引擎
|
|
112
|
+
|
|
113
|
+
```rego
|
|
114
|
+
# policy.rego — Open Policy Agent策略定义
|
|
115
|
+
|
|
116
|
+
package authz
|
|
117
|
+
|
|
118
|
+
import future.keywords.if
|
|
119
|
+
import future.keywords.in
|
|
120
|
+
|
|
121
|
+
# 默认拒绝
|
|
122
|
+
default allow := false
|
|
123
|
+
|
|
124
|
+
# 管理员允许所有操作
|
|
125
|
+
allow if {
|
|
126
|
+
input.user.roles[_] == "admin"
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
# 用户只能访问自己的资源
|
|
130
|
+
allow if {
|
|
131
|
+
input.method == "GET"
|
|
132
|
+
input.path = ["api", "users", user_id]
|
|
133
|
+
input.user.id == user_id
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
# 编辑者可以创建和更新
|
|
137
|
+
allow if {
|
|
138
|
+
input.method in ["POST", "PUT", "PATCH"]
|
|
139
|
+
input.user.roles[_] == "editor"
|
|
140
|
+
not is_admin_path(input.path)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
# 服务间调用需要正确的服务身份
|
|
144
|
+
allow if {
|
|
145
|
+
input.source_service == "order-service"
|
|
146
|
+
input.target_service == "inventory-service"
|
|
147
|
+
input.method in ["GET", "POST"]
|
|
148
|
+
startswith(input.path_string, "/api/inventory")
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
# 工作时间限制(敏感操作)
|
|
152
|
+
allow if {
|
|
153
|
+
input.action == "export_data"
|
|
154
|
+
is_business_hours(input.timestamp)
|
|
155
|
+
input.user.roles[_] == "data_analyst"
|
|
156
|
+
input.user.device_trust_score >= 80
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
is_admin_path(path) if {
|
|
160
|
+
path[0] == "api"
|
|
161
|
+
path[1] == "admin"
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
is_business_hours(ts) if {
|
|
165
|
+
hour := time.clock(time.parse_rfc3339_ns(ts))[0]
|
|
166
|
+
hour >= 9
|
|
167
|
+
hour < 18
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
# FastAPI OPA集成
|
|
173
|
+
import httpx
|
|
174
|
+
|
|
175
|
+
class OPAClient:
|
|
176
|
+
def __init__(self, opa_url: str = "http://opa:8181"):
|
|
177
|
+
self.url = opa_url
|
|
178
|
+
self.client = httpx.AsyncClient()
|
|
179
|
+
|
|
180
|
+
async def check_access(self, input_data: dict) -> bool:
|
|
181
|
+
response = await self.client.post(
|
|
182
|
+
f"{self.url}/v1/data/authz/allow",
|
|
183
|
+
json={"input": input_data},
|
|
184
|
+
)
|
|
185
|
+
result = response.json()
|
|
186
|
+
return result.get("result", False)
|
|
187
|
+
|
|
188
|
+
opa = OPAClient()
|
|
189
|
+
|
|
190
|
+
class ZeroTrustMiddleware(BaseHTTPMiddleware):
|
|
191
|
+
async def dispatch(self, request, call_next):
|
|
192
|
+
auth = await authenticate(request)
|
|
193
|
+
|
|
194
|
+
# 构建OPA策略输入
|
|
195
|
+
policy_input = {
|
|
196
|
+
"user": {
|
|
197
|
+
"id": auth.user_id,
|
|
198
|
+
"roles": auth.roles,
|
|
199
|
+
"device_trust_score": auth.device_score,
|
|
200
|
+
},
|
|
201
|
+
"method": request.method,
|
|
202
|
+
"path": request.url.path.strip("/").split("/"),
|
|
203
|
+
"path_string": request.url.path,
|
|
204
|
+
"source_ip": request.client.host,
|
|
205
|
+
"timestamp": datetime.utcnow().isoformat(),
|
|
206
|
+
"source_service": request.headers.get("X-Source-Service"),
|
|
207
|
+
"target_service": "current-service",
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
allowed = await opa.check_access(policy_input)
|
|
211
|
+
if not allowed:
|
|
212
|
+
logger.warning("Access denied by policy", extra=policy_input)
|
|
213
|
+
raise HTTPException(403, "Access denied by policy")
|
|
214
|
+
|
|
215
|
+
return await call_next(request)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Kubernetes网络策略(微分段)
|
|
219
|
+
|
|
220
|
+
```yaml
|
|
221
|
+
# 默认拒绝所有入站流量
|
|
222
|
+
apiVersion: networking.k8s.io/v1
|
|
223
|
+
kind: NetworkPolicy
|
|
224
|
+
metadata:
|
|
225
|
+
name: default-deny-ingress
|
|
226
|
+
namespace: production
|
|
227
|
+
spec:
|
|
228
|
+
podSelector: {}
|
|
229
|
+
policyTypes:
|
|
230
|
+
- Ingress
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
# 只允许API Gateway访问后端服务
|
|
234
|
+
apiVersion: networking.k8s.io/v1
|
|
235
|
+
kind: NetworkPolicy
|
|
236
|
+
metadata:
|
|
237
|
+
name: allow-api-gateway
|
|
238
|
+
namespace: production
|
|
239
|
+
spec:
|
|
240
|
+
podSelector:
|
|
241
|
+
matchLabels:
|
|
242
|
+
app: backend-api
|
|
243
|
+
policyTypes:
|
|
244
|
+
- Ingress
|
|
245
|
+
ingress:
|
|
246
|
+
- from:
|
|
247
|
+
- podSelector:
|
|
248
|
+
matchLabels:
|
|
249
|
+
app: api-gateway
|
|
250
|
+
ports:
|
|
251
|
+
- port: 8080
|
|
252
|
+
protocol: TCP
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
# 只允许后端服务访问数据库
|
|
256
|
+
apiVersion: networking.k8s.io/v1
|
|
257
|
+
kind: NetworkPolicy
|
|
258
|
+
metadata:
|
|
259
|
+
name: allow-backend-to-db
|
|
260
|
+
namespace: production
|
|
261
|
+
spec:
|
|
262
|
+
podSelector:
|
|
263
|
+
matchLabels:
|
|
264
|
+
app: postgresql
|
|
265
|
+
policyTypes:
|
|
266
|
+
- Ingress
|
|
267
|
+
ingress:
|
|
268
|
+
- from:
|
|
269
|
+
- podSelector:
|
|
270
|
+
matchLabels:
|
|
271
|
+
tier: backend
|
|
272
|
+
ports:
|
|
273
|
+
- port: 5432
|
|
274
|
+
protocol: TCP
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
# 限制出站流量(只允许访问必要服务)
|
|
278
|
+
apiVersion: networking.k8s.io/v1
|
|
279
|
+
kind: NetworkPolicy
|
|
280
|
+
metadata:
|
|
281
|
+
name: restrict-egress
|
|
282
|
+
namespace: production
|
|
283
|
+
spec:
|
|
284
|
+
podSelector:
|
|
285
|
+
matchLabels:
|
|
286
|
+
app: backend-api
|
|
287
|
+
policyTypes:
|
|
288
|
+
- Egress
|
|
289
|
+
egress:
|
|
290
|
+
- to:
|
|
291
|
+
- podSelector:
|
|
292
|
+
matchLabels:
|
|
293
|
+
app: postgresql
|
|
294
|
+
ports:
|
|
295
|
+
- port: 5432
|
|
296
|
+
- to:
|
|
297
|
+
- podSelector:
|
|
298
|
+
matchLabels:
|
|
299
|
+
app: redis
|
|
300
|
+
ports:
|
|
301
|
+
- port: 6379
|
|
302
|
+
- to:
|
|
303
|
+
- namespaceSelector: {}
|
|
304
|
+
podSelector:
|
|
305
|
+
matchLabels:
|
|
306
|
+
k8s-app: kube-dns
|
|
307
|
+
ports:
|
|
308
|
+
- port: 53
|
|
309
|
+
protocol: UDP
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### 持续验证与行为分析
|
|
313
|
+
|
|
314
|
+
```python
|
|
315
|
+
# 持续风险评估
|
|
316
|
+
from dataclasses import dataclass
|
|
317
|
+
from enum import Enum
|
|
318
|
+
|
|
319
|
+
class RiskLevel(str, Enum):
|
|
320
|
+
LOW = "low"
|
|
321
|
+
MEDIUM = "medium"
|
|
322
|
+
HIGH = "high"
|
|
323
|
+
CRITICAL = "critical"
|
|
324
|
+
|
|
325
|
+
@dataclass
|
|
326
|
+
class RiskSignals:
|
|
327
|
+
"""访问风险信号"""
|
|
328
|
+
ip_reputation_score: float # 0-100
|
|
329
|
+
device_trust_score: float # 0-100
|
|
330
|
+
user_behavior_score: float # 0-100
|
|
331
|
+
geo_anomaly: bool # 地理位置异常
|
|
332
|
+
time_anomaly: bool # 时间异常
|
|
333
|
+
impossible_travel: bool # 不可能的旅行
|
|
334
|
+
failed_attempts_1h: int # 1小时内失败次数
|
|
335
|
+
|
|
336
|
+
class RiskEngine:
|
|
337
|
+
"""零信任风险评估引擎"""
|
|
338
|
+
|
|
339
|
+
def evaluate(self, signals: RiskSignals) -> tuple[RiskLevel, float]:
|
|
340
|
+
"""评估访问风险"""
|
|
341
|
+
score = 100.0
|
|
342
|
+
|
|
343
|
+
# IP声誉
|
|
344
|
+
score -= max(0, (100 - signals.ip_reputation_score)) * 0.2
|
|
345
|
+
|
|
346
|
+
# 设备信任
|
|
347
|
+
score -= max(0, (100 - signals.device_trust_score)) * 0.3
|
|
348
|
+
|
|
349
|
+
# 行为评分
|
|
350
|
+
score -= max(0, (100 - signals.user_behavior_score)) * 0.2
|
|
351
|
+
|
|
352
|
+
# 异常标志
|
|
353
|
+
if signals.geo_anomaly:
|
|
354
|
+
score -= 15
|
|
355
|
+
if signals.time_anomaly:
|
|
356
|
+
score -= 10
|
|
357
|
+
if signals.impossible_travel:
|
|
358
|
+
score -= 30
|
|
359
|
+
|
|
360
|
+
# 失败尝试
|
|
361
|
+
score -= min(30, signals.failed_attempts_1h * 5)
|
|
362
|
+
|
|
363
|
+
score = max(0, score)
|
|
364
|
+
|
|
365
|
+
if score >= 80:
|
|
366
|
+
return RiskLevel.LOW, score
|
|
367
|
+
elif score >= 60:
|
|
368
|
+
return RiskLevel.MEDIUM, score
|
|
369
|
+
elif score >= 40:
|
|
370
|
+
return RiskLevel.HIGH, score
|
|
371
|
+
else:
|
|
372
|
+
return RiskLevel.CRITICAL, score
|
|
373
|
+
|
|
374
|
+
def get_required_actions(self, risk_level: RiskLevel) -> list[str]:
|
|
375
|
+
"""根据风险等级确定需要的额外验证"""
|
|
376
|
+
actions = {
|
|
377
|
+
RiskLevel.LOW: [],
|
|
378
|
+
RiskLevel.MEDIUM: ["step_up_mfa"],
|
|
379
|
+
RiskLevel.HIGH: ["step_up_mfa", "manager_approval"],
|
|
380
|
+
RiskLevel.CRITICAL: ["block_access", "alert_security_team"],
|
|
381
|
+
}
|
|
382
|
+
return actions[risk_level]
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### Service Mesh mTLS(Istio)
|
|
386
|
+
|
|
387
|
+
```yaml
|
|
388
|
+
# Istio PeerAuthentication — 强制mTLS
|
|
389
|
+
apiVersion: security.istio.io/v1beta1
|
|
390
|
+
kind: PeerAuthentication
|
|
391
|
+
metadata:
|
|
392
|
+
name: default
|
|
393
|
+
namespace: production
|
|
394
|
+
spec:
|
|
395
|
+
mtls:
|
|
396
|
+
mode: STRICT # 所有服务间通信必须mTLS
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
# Istio AuthorizationPolicy — 服务间授权
|
|
400
|
+
apiVersion: security.istio.io/v1beta1
|
|
401
|
+
kind: AuthorizationPolicy
|
|
402
|
+
metadata:
|
|
403
|
+
name: order-service-policy
|
|
404
|
+
namespace: production
|
|
405
|
+
spec:
|
|
406
|
+
selector:
|
|
407
|
+
matchLabels:
|
|
408
|
+
app: order-service
|
|
409
|
+
rules:
|
|
410
|
+
- from:
|
|
411
|
+
- source:
|
|
412
|
+
principals: ["cluster.local/ns/production/sa/api-gateway"]
|
|
413
|
+
to:
|
|
414
|
+
- operation:
|
|
415
|
+
methods: ["GET", "POST"]
|
|
416
|
+
paths: ["/api/orders/*"]
|
|
417
|
+
- from:
|
|
418
|
+
- source:
|
|
419
|
+
principals: ["cluster.local/ns/production/sa/payment-service"]
|
|
420
|
+
to:
|
|
421
|
+
- operation:
|
|
422
|
+
methods: ["GET"]
|
|
423
|
+
paths: ["/api/orders/*/status"]
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
## 最佳实践
|
|
427
|
+
|
|
428
|
+
### 1. 身份管理
|
|
429
|
+
- 集中身份管理(使用IdP)
|
|
430
|
+
- 所有用户和服务都有唯一身份
|
|
431
|
+
- 强制MFA(至少TOTP,推荐Passkey)
|
|
432
|
+
- 服务间使用SPIFFE/mTLS身份
|
|
433
|
+
- 定期审计和轮换凭证
|
|
434
|
+
|
|
435
|
+
### 2. 网络安全
|
|
436
|
+
- 默认拒绝所有流量(Network Policy)
|
|
437
|
+
- 微分段隔离不同服务和环境
|
|
438
|
+
- 服务间通信全部加密(mTLS)
|
|
439
|
+
- 使用Service Mesh简化mTLS管理
|
|
440
|
+
- 出站流量也要控制(防数据外泄)
|
|
441
|
+
|
|
442
|
+
### 3. 访问控制
|
|
443
|
+
- 基于策略的访问控制(OPA/Cedar)
|
|
444
|
+
- 最小权限原则(Just-In-Time/Just-Enough)
|
|
445
|
+
- 持续验证(不仅在登录时)
|
|
446
|
+
- 上下文感知(设备/位置/时间/行为)
|
|
447
|
+
|
|
448
|
+
### 4. 监控与响应
|
|
449
|
+
- 记录所有访问决策(允许和拒绝)
|
|
450
|
+
- 实时行为分析(检测异常模式)
|
|
451
|
+
- 自动化响应(风险升高→要求额外验证)
|
|
452
|
+
- 定期红队演练(测试横向移动能力)
|
|
453
|
+
|
|
454
|
+
### 5. 渐进式实施
|
|
455
|
+
- 从最敏感的系统开始
|
|
456
|
+
- 先监控模式,再强制模式
|
|
457
|
+
- 分阶段: 身份→网络→数据→设备
|
|
458
|
+
- 每个阶段充分测试和培训
|
|
459
|
+
|
|
460
|
+
## 常见陷阱
|
|
461
|
+
|
|
462
|
+
### 陷阱1: 只在边界实施
|
|
463
|
+
```
|
|
464
|
+
# 错误: 只在API Gateway做认证,内部服务之间无验证
|
|
465
|
+
# 攻击者一旦进入内网就可以自由横向移动
|
|
466
|
+
|
|
467
|
+
# 正确: 每个服务都独立验证身份和授权
|
|
468
|
+
# 使用Service Mesh(Istio)自动mTLS
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
### 陷阱2: 过粗的网络分段
|
|
472
|
+
```yaml
|
|
473
|
+
# 错误: 按namespace分段,同namespace内无限制
|
|
474
|
+
# 正确: 按服务级别分段
|
|
475
|
+
# 每个服务只能访问它需要的其他服务和端口
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
### 陷阱3: 忽略出站流量
|
|
479
|
+
```yaml
|
|
480
|
+
# 错误: 只限制入站,出站不管
|
|
481
|
+
# 攻击者可以从被入侵的Pod向外部发送数据
|
|
482
|
+
|
|
483
|
+
# 正确: 出站流量同样限制
|
|
484
|
+
# 只允许访问已知的外部服务(API/DB等)
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
### 陷阱4: 静态信任评估
|
|
488
|
+
```python
|
|
489
|
+
# 错误: 只在登录时评估风险
|
|
490
|
+
# 整个会话期间使用相同的信任级别
|
|
491
|
+
|
|
492
|
+
# 正确: 持续评估
|
|
493
|
+
# 每次敏感操作都重新评估风险
|
|
494
|
+
# 发现异常时要求额外验证或降级权限
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
## Agent Checklist
|
|
498
|
+
|
|
499
|
+
### 身份与认证
|
|
500
|
+
- [ ] 集中身份管理(IdP)已部署
|
|
501
|
+
- [ ] 所有用户启用MFA
|
|
502
|
+
- [ ] 服务间使用mTLS/SPIFFE身份
|
|
503
|
+
- [ ] 凭证自动轮换
|
|
504
|
+
|
|
505
|
+
### 网络分段
|
|
506
|
+
- [ ] 默认拒绝网络策略已应用
|
|
507
|
+
- [ ] 服务间通信加密(mTLS)
|
|
508
|
+
- [ ] 出站流量受控
|
|
509
|
+
- [ ] 环境间完全隔离(dev/staging/prod)
|
|
510
|
+
|
|
511
|
+
### 策略引擎
|
|
512
|
+
- [ ] 基于策略的访问控制已实现
|
|
513
|
+
- [ ] 策略定义为代码(Git管理)
|
|
514
|
+
- [ ] 策略变更有审计追踪
|
|
515
|
+
- [ ] 策略测试覆盖
|
|
516
|
+
|
|
517
|
+
### 持续验证
|
|
518
|
+
- [ ] 风险评估引擎已部署
|
|
519
|
+
- [ ] 行为异常检测已启用
|
|
520
|
+
- [ ] 自适应认证已实现
|
|
521
|
+
- [ ] 安全事件自动响应
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: auth-sso-playbook
|
|
3
|
+
title: 认证与 SSO 实战手册(Keycloak/Auth0/OIDC)
|
|
4
|
+
domain: security
|
|
5
|
+
category: 02-playbooks
|
|
6
|
+
difficulty: advanced
|
|
7
|
+
tags: [authentication, authorization, sso, keycloak, auth0, oidc, oauth2, pkce, jwt, rbac, saml, enterprise, identity]
|
|
8
|
+
quality_score: 95
|
|
9
|
+
maintainer: security-team@umadev.com
|
|
10
|
+
last_updated: 2026-06-15
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# 认证与 SSO 实战手册
|
|
14
|
+
|
|
15
|
+
> 基于 [RFC 9700 OAuth 2.0 Security BCP](https://datatracker.ietf.org/doc/html/rfc9700) + [Keycloak 生产配置](https://www.keycloak.org/server/configuration-production) + [Duende 2025 Web Security](https://duendesoftware.com/blog/20250805-best-practices-of-web-application-security-in-2025)
|
|
16
|
+
|
|
17
|
+
## 2025 认证标准:Authorization Code + PKCE
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
RFC 9700 (2025年1月) 的核心建议:
|
|
21
|
+
- 禁止 implicit flow(已弃用)
|
|
22
|
+
- 所有客户端必须用 Authorization Code + PKCE
|
|
23
|
+
- redirect_uri 精确匹配(不允许通配符)
|
|
24
|
+
- token 最小权限 scope
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### PKCE 流程
|
|
28
|
+
```typescript
|
|
29
|
+
// 前端:生成 code_verifier + code_challenge
|
|
30
|
+
const codeVerifier = generateRandomString(128);
|
|
31
|
+
const codeChallenge = base64Url(sha256(codeVerifier));
|
|
32
|
+
|
|
33
|
+
// 1. 重定向到授权服务器(带 code_challenge)
|
|
34
|
+
window.location = `${authServer}/auth?` + new URLSearchParams({
|
|
35
|
+
response_type: 'code',
|
|
36
|
+
client_id: clientId,
|
|
37
|
+
redirect_uri: 'https://app.example.com/callback',
|
|
38
|
+
code_challenge: codeChallenge,
|
|
39
|
+
code_challenge_method: 'S256',
|
|
40
|
+
state: randomState, // CSRF 防护
|
|
41
|
+
scope: 'openid profile email', // 最小 scope
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// 2. 回调:用 code + code_verifier 换 token
|
|
45
|
+
const tokenResponse = await fetch(`${authServer}/token`, {
|
|
46
|
+
method: 'POST',
|
|
47
|
+
body: new URLSearchParams({
|
|
48
|
+
grant_type: 'authorization_code',
|
|
49
|
+
code: codeFromCallback,
|
|
50
|
+
redirect_uri: 'https://app.example.com/callback',
|
|
51
|
+
client_id: clientId,
|
|
52
|
+
code_verifier: codeVerifier, // 证明是同一个客户端
|
|
53
|
+
}),
|
|
54
|
+
});
|
|
55
|
+
const { access_token, id_token, refresh_token } = await tokenResponse.json();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Keycloak vs Auth0 选择
|
|
59
|
+
|
|
60
|
+
| 维度 | Keycloak | Auth0 |
|
|
61
|
+
|------|----------|-------|
|
|
62
|
+
| 部署 | 自托管(开源) | 托管 SaaS |
|
|
63
|
+
| 成本 | 免费(服务器成本) | 按用户收费 |
|
|
64
|
+
| 协议 | OIDC + SAML | OIDC + SAML |
|
|
65
|
+
| 定制 | 完全可控 | 有限(Rules/Actions) |
|
|
66
|
+
| 运维 | 自己管 HA/备份 | 零运维 |
|
|
67
|
+
| 适合 | 大企业/合规要求 | 快速上线/SaaS |
|
|
68
|
+
|
|
69
|
+
## Keycloak 生产配置
|
|
70
|
+
|
|
71
|
+
### 高可用部署
|
|
72
|
+
```yaml
|
|
73
|
+
# K8s 部署:≥2 副本 + 共享 DB
|
|
74
|
+
apiVersion: apps/v1
|
|
75
|
+
kind: Deployment
|
|
76
|
+
metadata:
|
|
77
|
+
name: keycloak
|
|
78
|
+
spec:
|
|
79
|
+
replicas: 3 # 至少 3 个副本
|
|
80
|
+
template:
|
|
81
|
+
spec:
|
|
82
|
+
containers:
|
|
83
|
+
- name: keycloak
|
|
84
|
+
image: quay.io/keycloak/keycloak:latest
|
|
85
|
+
args: ["start"]
|
|
86
|
+
env:
|
|
87
|
+
- name: KC_DB # 共享 PostgreSQL
|
|
88
|
+
value: postgres
|
|
89
|
+
- name: KC_DB_URL
|
|
90
|
+
value: jdbc:postgresql://pg:5432/keycloak
|
|
91
|
+
- name: KC_HOSTNAME
|
|
92
|
+
value: auth.example.com
|
|
93
|
+
- name: KC_PROXY # behind reverse proxy
|
|
94
|
+
value: edge
|
|
95
|
+
- name: KC_HTTP_ENABLED
|
|
96
|
+
value: "true"
|
|
97
|
+
readinessProbe:
|
|
98
|
+
httpGet:
|
|
99
|
+
path: /health/ready
|
|
100
|
+
port: 8080
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 生产必做
|
|
104
|
+
- [ ] HTTPS(TLS 终止在反向代理)
|
|
105
|
+
- [ ] 共享数据库(PostgreSQL,不用内嵌 H2)
|
|
106
|
+
- [ ] ≥2 副本(HA)
|
|
107
|
+
- [ ] 健康检查 + 自动重启
|
|
108
|
+
- [ ] 备份 realm 配置(`kcadm.sh export`)
|
|
109
|
+
- [ ] 关闭临时账号(admin/admin)
|
|
110
|
+
- [ ] 配置 SMTP(密码重置邮件)
|
|
111
|
+
- [ ] 密码策略(≥12 字符 + 特殊字符)
|
|
112
|
+
|
|
113
|
+
## JWT 验证(服务端)
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
# 每个服务验证 JWT(不信任网关,纵深防御)
|
|
117
|
+
from jose import jwt
|
|
118
|
+
|
|
119
|
+
def verify_token(token: str):
|
|
120
|
+
# 1. 获取 JWKS(Keycloak 公钥)
|
|
121
|
+
jwks = get_jwks(f"{auth_server}/protocol/openid-connect/certs")
|
|
122
|
+
# 2. 验证签名 + 过期 + 受众
|
|
123
|
+
payload = jwt.decode(
|
|
124
|
+
token,
|
|
125
|
+
jwks,
|
|
126
|
+
algorithms=["RS256"], # 只允许 RS256
|
|
127
|
+
audience="account", # 验证受众
|
|
128
|
+
issuer=f"{auth_server}/realms/myrealm", # 验证签发者
|
|
129
|
+
)
|
|
130
|
+
return payload # 含 sub(用户ID), roles, scope
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## RBAC 权限模型
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
# Keycloak realm roles → 应用权限映射
|
|
137
|
+
REALM_ROLES = {
|
|
138
|
+
"admin": ["read:any", "write:any", "delete:any", "manage:users"],
|
|
139
|
+
"manager": ["read:team", "write:team"],
|
|
140
|
+
"user": ["read:own", "write:own"],
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
def check_permission(user_roles: list, required: str):
|
|
144
|
+
for role in user_roles:
|
|
145
|
+
if required in REALM_ROLES.get(role, []):
|
|
146
|
+
return True
|
|
147
|
+
raise ForbiddenError(f"Missing permission: {required}")
|
|
148
|
+
|
|
149
|
+
# 使用
|
|
150
|
+
@app.delete("/api/users/{id}")
|
|
151
|
+
def delete_user(id, token=Depends(verify_token)):
|
|
152
|
+
check_permission(token["realm_access"]["roles"], "delete:any")
|
|
153
|
+
return db.delete(User, id)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## 生产检查清单
|
|
157
|
+
- [ ] Authorization Code + PKCE(不用 implicit)
|
|
158
|
+
- [ ] redirect_uri 精确匹配(不通配)
|
|
159
|
+
- [ ] token 最小 scope
|
|
160
|
+
- [ ] JWT 用 RS256(不用 HS256)
|
|
161
|
+
- [ ] 服务端验证 JWT 签名 + 过期 + 受众 + 签发者
|
|
162
|
+
- [ ] refresh token 轮换(每次刷新换新 token)
|
|
163
|
+
- [ ] Keycloak ≥2 副本 + 共享 DB
|
|
164
|
+
- [ ] 关闭临时账号 + 配置密码策略
|
|
165
|
+
- [ ] 备份 realm 配置
|
|
166
|
+
- [ ] MFA(敏感操作)
|