agentic-team-templates 0.3.0

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.
Files changed (103) hide show
  1. package/README.md +280 -0
  2. package/bin/cli.js +5 -0
  3. package/package.json +47 -0
  4. package/src/index.js +521 -0
  5. package/templates/_shared/code-quality.md +162 -0
  6. package/templates/_shared/communication.md +114 -0
  7. package/templates/_shared/core-principles.md +62 -0
  8. package/templates/_shared/git-workflow.md +165 -0
  9. package/templates/_shared/security-fundamentals.md +173 -0
  10. package/templates/blockchain/.cursorrules/defi-patterns.md +520 -0
  11. package/templates/blockchain/.cursorrules/gas-optimization.md +339 -0
  12. package/templates/blockchain/.cursorrules/overview.md +130 -0
  13. package/templates/blockchain/.cursorrules/security.md +318 -0
  14. package/templates/blockchain/.cursorrules/smart-contracts.md +364 -0
  15. package/templates/blockchain/.cursorrules/testing.md +415 -0
  16. package/templates/blockchain/.cursorrules/web3-integration.md +538 -0
  17. package/templates/blockchain/CLAUDE.md +389 -0
  18. package/templates/cli-tools/.cursorrules/architecture.md +412 -0
  19. package/templates/cli-tools/.cursorrules/arguments.md +406 -0
  20. package/templates/cli-tools/.cursorrules/distribution.md +546 -0
  21. package/templates/cli-tools/.cursorrules/error-handling.md +455 -0
  22. package/templates/cli-tools/.cursorrules/overview.md +136 -0
  23. package/templates/cli-tools/.cursorrules/testing.md +537 -0
  24. package/templates/cli-tools/.cursorrules/user-experience.md +545 -0
  25. package/templates/cli-tools/CLAUDE.md +356 -0
  26. package/templates/data-engineering/.cursorrules/data-modeling.md +367 -0
  27. package/templates/data-engineering/.cursorrules/data-quality.md +455 -0
  28. package/templates/data-engineering/.cursorrules/overview.md +85 -0
  29. package/templates/data-engineering/.cursorrules/performance.md +339 -0
  30. package/templates/data-engineering/.cursorrules/pipeline-design.md +280 -0
  31. package/templates/data-engineering/.cursorrules/security.md +460 -0
  32. package/templates/data-engineering/.cursorrules/testing.md +452 -0
  33. package/templates/data-engineering/CLAUDE.md +974 -0
  34. package/templates/devops-sre/.cursorrules/capacity-planning.md +653 -0
  35. package/templates/devops-sre/.cursorrules/change-management.md +584 -0
  36. package/templates/devops-sre/.cursorrules/chaos-engineering.md +651 -0
  37. package/templates/devops-sre/.cursorrules/disaster-recovery.md +641 -0
  38. package/templates/devops-sre/.cursorrules/incident-management.md +565 -0
  39. package/templates/devops-sre/.cursorrules/observability.md +714 -0
  40. package/templates/devops-sre/.cursorrules/overview.md +230 -0
  41. package/templates/devops-sre/.cursorrules/postmortems.md +588 -0
  42. package/templates/devops-sre/.cursorrules/runbooks.md +760 -0
  43. package/templates/devops-sre/.cursorrules/slo-sli.md +617 -0
  44. package/templates/devops-sre/.cursorrules/toil-reduction.md +567 -0
  45. package/templates/devops-sre/CLAUDE.md +1007 -0
  46. package/templates/documentation/.cursorrules/adr.md +277 -0
  47. package/templates/documentation/.cursorrules/api-documentation.md +411 -0
  48. package/templates/documentation/.cursorrules/code-comments.md +253 -0
  49. package/templates/documentation/.cursorrules/maintenance.md +260 -0
  50. package/templates/documentation/.cursorrules/overview.md +82 -0
  51. package/templates/documentation/.cursorrules/readme-standards.md +306 -0
  52. package/templates/documentation/CLAUDE.md +120 -0
  53. package/templates/fullstack/.cursorrules/api-contracts.md +331 -0
  54. package/templates/fullstack/.cursorrules/architecture.md +298 -0
  55. package/templates/fullstack/.cursorrules/overview.md +109 -0
  56. package/templates/fullstack/.cursorrules/shared-types.md +348 -0
  57. package/templates/fullstack/.cursorrules/testing.md +386 -0
  58. package/templates/fullstack/CLAUDE.md +349 -0
  59. package/templates/ml-ai/.cursorrules/data-engineering.md +483 -0
  60. package/templates/ml-ai/.cursorrules/deployment.md +601 -0
  61. package/templates/ml-ai/.cursorrules/model-development.md +538 -0
  62. package/templates/ml-ai/.cursorrules/monitoring.md +658 -0
  63. package/templates/ml-ai/.cursorrules/overview.md +131 -0
  64. package/templates/ml-ai/.cursorrules/security.md +637 -0
  65. package/templates/ml-ai/.cursorrules/testing.md +678 -0
  66. package/templates/ml-ai/CLAUDE.md +1136 -0
  67. package/templates/mobile/.cursorrules/navigation.md +246 -0
  68. package/templates/mobile/.cursorrules/offline-first.md +302 -0
  69. package/templates/mobile/.cursorrules/overview.md +71 -0
  70. package/templates/mobile/.cursorrules/performance.md +345 -0
  71. package/templates/mobile/.cursorrules/testing.md +339 -0
  72. package/templates/mobile/CLAUDE.md +233 -0
  73. package/templates/platform-engineering/.cursorrules/ci-cd.md +778 -0
  74. package/templates/platform-engineering/.cursorrules/developer-experience.md +632 -0
  75. package/templates/platform-engineering/.cursorrules/infrastructure-as-code.md +600 -0
  76. package/templates/platform-engineering/.cursorrules/kubernetes.md +710 -0
  77. package/templates/platform-engineering/.cursorrules/observability.md +747 -0
  78. package/templates/platform-engineering/.cursorrules/overview.md +215 -0
  79. package/templates/platform-engineering/.cursorrules/security.md +855 -0
  80. package/templates/platform-engineering/.cursorrules/testing.md +878 -0
  81. package/templates/platform-engineering/CLAUDE.md +850 -0
  82. package/templates/utility-agent/.cursorrules/action-control.md +284 -0
  83. package/templates/utility-agent/.cursorrules/context-management.md +186 -0
  84. package/templates/utility-agent/.cursorrules/hallucination-prevention.md +253 -0
  85. package/templates/utility-agent/.cursorrules/overview.md +78 -0
  86. package/templates/utility-agent/.cursorrules/token-optimization.md +369 -0
  87. package/templates/utility-agent/CLAUDE.md +513 -0
  88. package/templates/web-backend/.cursorrules/api-design.md +255 -0
  89. package/templates/web-backend/.cursorrules/authentication.md +309 -0
  90. package/templates/web-backend/.cursorrules/database-patterns.md +298 -0
  91. package/templates/web-backend/.cursorrules/error-handling.md +366 -0
  92. package/templates/web-backend/.cursorrules/overview.md +69 -0
  93. package/templates/web-backend/.cursorrules/security.md +358 -0
  94. package/templates/web-backend/.cursorrules/testing.md +395 -0
  95. package/templates/web-backend/CLAUDE.md +366 -0
  96. package/templates/web-frontend/.cursorrules/accessibility.md +296 -0
  97. package/templates/web-frontend/.cursorrules/component-patterns.md +204 -0
  98. package/templates/web-frontend/.cursorrules/overview.md +72 -0
  99. package/templates/web-frontend/.cursorrules/performance.md +325 -0
  100. package/templates/web-frontend/.cursorrules/state-management.md +227 -0
  101. package/templates/web-frontend/.cursorrules/styling.md +271 -0
  102. package/templates/web-frontend/.cursorrules/testing.md +311 -0
  103. package/templates/web-frontend/CLAUDE.md +399 -0
@@ -0,0 +1,855 @@
1
+ # Security
2
+
3
+ Guidelines for implementing security across the platform.
4
+
5
+ ## Core Principles
6
+
7
+ 1. **Defense in Depth** - Multiple layers of security controls
8
+ 2. **Least Privilege** - Minimal permissions needed to function
9
+ 3. **Zero Trust** - Verify explicitly, never trust implicitly
10
+ 4. **Shift Left** - Security early in the development lifecycle
11
+ 5. **Automate Everything** - Security checks in every pipeline
12
+
13
+ ## Policy as Code
14
+
15
+ ### OPA/Gatekeeper Policies
16
+
17
+ ```yaml
18
+ # Require resource limits on all pods
19
+ apiVersion: templates.gatekeeper.sh/v1
20
+ kind: ConstraintTemplate
21
+ metadata:
22
+ name: k8srequiredresources
23
+ spec:
24
+ crd:
25
+ spec:
26
+ names:
27
+ kind: K8sRequiredResources
28
+ validation:
29
+ openAPIV3Schema:
30
+ type: object
31
+ properties:
32
+ limits:
33
+ type: array
34
+ items:
35
+ type: string
36
+ requests:
37
+ type: array
38
+ items:
39
+ type: string
40
+ targets:
41
+ - target: admission.k8s.gatekeeper.sh
42
+ rego: |
43
+ package k8srequiredresources
44
+
45
+ violation[{"msg": msg}] {
46
+ container := input.review.object.spec.containers[_]
47
+ required := input.parameters.limits[_]
48
+ not container.resources.limits[required]
49
+ msg := sprintf("Container %v must have %v limit", [container.name, required])
50
+ }
51
+
52
+ violation[{"msg": msg}] {
53
+ container := input.review.object.spec.containers[_]
54
+ required := input.parameters.requests[_]
55
+ not container.resources.requests[required]
56
+ msg := sprintf("Container %v must have %v request", [container.name, required])
57
+ }
58
+
59
+ ---
60
+ apiVersion: constraints.gatekeeper.sh/v1beta1
61
+ kind: K8sRequiredResources
62
+ metadata:
63
+ name: require-resource-limits
64
+ spec:
65
+ match:
66
+ kinds:
67
+ - apiGroups: [""]
68
+ kinds: ["Pod"]
69
+ namespaces:
70
+ - production
71
+ - staging
72
+ parameters:
73
+ limits:
74
+ - cpu
75
+ - memory
76
+ requests:
77
+ - cpu
78
+ - memory
79
+ ```
80
+
81
+ ### Kyverno Policies
82
+
83
+ ```yaml
84
+ # Require specific labels
85
+ apiVersion: kyverno.io/v1
86
+ kind: ClusterPolicy
87
+ metadata:
88
+ name: require-labels
89
+ annotations:
90
+ policies.kyverno.io/title: Require Labels
91
+ policies.kyverno.io/severity: medium
92
+ spec:
93
+ validationFailureAction: Enforce
94
+ background: true
95
+ rules:
96
+ - name: require-team-label
97
+ match:
98
+ any:
99
+ - resources:
100
+ kinds:
101
+ - Deployment
102
+ - StatefulSet
103
+ namespaces:
104
+ - production
105
+ - staging
106
+ validate:
107
+ message: "The label 'team' is required"
108
+ pattern:
109
+ metadata:
110
+ labels:
111
+ team: "?*"
112
+
113
+ - name: require-app-label
114
+ match:
115
+ any:
116
+ - resources:
117
+ kinds:
118
+ - Pod
119
+ validate:
120
+ message: "The label 'app.kubernetes.io/name' is required"
121
+ pattern:
122
+ metadata:
123
+ labels:
124
+ app.kubernetes.io/name: "?*"
125
+
126
+ ---
127
+ # Disallow privileged containers
128
+ apiVersion: kyverno.io/v1
129
+ kind: ClusterPolicy
130
+ metadata:
131
+ name: disallow-privileged-containers
132
+ spec:
133
+ validationFailureAction: Enforce
134
+ background: true
135
+ rules:
136
+ - name: deny-privileged
137
+ match:
138
+ any:
139
+ - resources:
140
+ kinds:
141
+ - Pod
142
+ validate:
143
+ message: "Privileged containers are not allowed"
144
+ pattern:
145
+ spec:
146
+ containers:
147
+ - securityContext:
148
+ privileged: "false"
149
+ initContainers:
150
+ - securityContext:
151
+ privileged: "false"
152
+
153
+ ---
154
+ # Require non-root user
155
+ apiVersion: kyverno.io/v1
156
+ kind: ClusterPolicy
157
+ metadata:
158
+ name: require-run-as-non-root
159
+ spec:
160
+ validationFailureAction: Enforce
161
+ rules:
162
+ - name: run-as-non-root
163
+ match:
164
+ any:
165
+ - resources:
166
+ kinds:
167
+ - Pod
168
+ validate:
169
+ message: "Containers must run as non-root"
170
+ pattern:
171
+ spec:
172
+ securityContext:
173
+ runAsNonRoot: true
174
+ containers:
175
+ - securityContext:
176
+ runAsNonRoot: true
177
+ allowPrivilegeEscalation: false
178
+ ```
179
+
180
+ ## Supply Chain Security
181
+
182
+ ### Image Signing (Cosign)
183
+
184
+ ```yaml
185
+ # Sign images in CI pipeline
186
+ name: Build and Sign
187
+
188
+ jobs:
189
+ build:
190
+ runs-on: ubuntu-latest
191
+ permissions:
192
+ contents: read
193
+ packages: write
194
+ id-token: write # Required for keyless signing
195
+
196
+ steps:
197
+ - uses: actions/checkout@v4
198
+
199
+ - name: Build and push
200
+ id: build
201
+ uses: docker/build-push-action@v5
202
+ with:
203
+ push: true
204
+ tags: ghcr.io/company/api-server:${{ github.sha }}
205
+
206
+ - name: Install Cosign
207
+ uses: sigstore/cosign-installer@v3
208
+
209
+ - name: Sign image (keyless)
210
+ run: |
211
+ cosign sign --yes \
212
+ ghcr.io/company/api-server@${{ steps.build.outputs.digest }}
213
+
214
+ - name: Generate SBOM
215
+ uses: anchore/sbom-action@v0
216
+ with:
217
+ image: ghcr.io/company/api-server@${{ steps.build.outputs.digest }}
218
+ format: spdx-json
219
+ output-file: sbom.spdx.json
220
+
221
+ - name: Attest SBOM
222
+ run: |
223
+ cosign attest --yes \
224
+ --predicate sbom.spdx.json \
225
+ --type spdxjson \
226
+ ghcr.io/company/api-server@${{ steps.build.outputs.digest }}
227
+ ```
228
+
229
+ ### Verify Images (Kyverno)
230
+
231
+ ```yaml
232
+ # Require signed images
233
+ apiVersion: kyverno.io/v1
234
+ kind: ClusterPolicy
235
+ metadata:
236
+ name: verify-image-signature
237
+ spec:
238
+ validationFailureAction: Enforce
239
+ background: false
240
+ rules:
241
+ - name: verify-signature
242
+ match:
243
+ any:
244
+ - resources:
245
+ kinds:
246
+ - Pod
247
+ namespaces:
248
+ - production
249
+ verifyImages:
250
+ - imageReferences:
251
+ - "ghcr.io/company/*"
252
+ attestors:
253
+ - entries:
254
+ - keyless:
255
+ subject: "https://github.com/company/*"
256
+ issuer: "https://token.actions.githubusercontent.com"
257
+ rekor:
258
+ url: https://rekor.sigstore.dev
259
+ attestations:
260
+ - predicateType: "https://spdx.dev/Document"
261
+ conditions:
262
+ - all:
263
+ - key: "{{ time_since('', '{{ @.creationInfo.created }}', '') }}"
264
+ operator: LessThanOrEquals
265
+ value: "168h" # SBOM less than 7 days old
266
+ ```
267
+
268
+ ### Vulnerability Scanning
269
+
270
+ ```yaml
271
+ # Trivy scanning in CI
272
+ name: Security Scan
273
+
274
+ on:
275
+ push:
276
+ branches: [main]
277
+ pull_request:
278
+ schedule:
279
+ - cron: '0 0 * * *' # Daily scan
280
+
281
+ jobs:
282
+ scan:
283
+ runs-on: ubuntu-latest
284
+ steps:
285
+ - uses: actions/checkout@v4
286
+
287
+ # Scan filesystem for secrets and vulnerabilities
288
+ - name: Trivy FS scan
289
+ uses: aquasecurity/trivy-action@master
290
+ with:
291
+ scan-type: 'fs'
292
+ scan-ref: '.'
293
+ format: 'sarif'
294
+ output: 'trivy-fs-results.sarif'
295
+ severity: 'CRITICAL,HIGH'
296
+
297
+ # Scan container image
298
+ - name: Trivy image scan
299
+ uses: aquasecurity/trivy-action@master
300
+ with:
301
+ image-ref: 'ghcr.io/company/api-server:${{ github.sha }}'
302
+ format: 'sarif'
303
+ output: 'trivy-image-results.sarif'
304
+ severity: 'CRITICAL,HIGH'
305
+ vuln-type: 'os,library'
306
+
307
+ # Upload results to GitHub Security
308
+ - name: Upload Trivy scan results
309
+ uses: github/codeql-action/upload-sarif@v2
310
+ with:
311
+ sarif_file: 'trivy-fs-results.sarif'
312
+
313
+ # Fail if critical vulnerabilities
314
+ - name: Fail on critical vulnerabilities
315
+ uses: aquasecurity/trivy-action@master
316
+ with:
317
+ image-ref: 'ghcr.io/company/api-server:${{ github.sha }}'
318
+ exit-code: '1'
319
+ severity: 'CRITICAL'
320
+ ```
321
+
322
+ ## Secrets Management
323
+
324
+ ### External Secrets Operator
325
+
326
+ ```yaml
327
+ # ClusterSecretStore for Vault
328
+ apiVersion: external-secrets.io/v1beta1
329
+ kind: ClusterSecretStore
330
+ metadata:
331
+ name: vault-backend
332
+ spec:
333
+ provider:
334
+ vault:
335
+ server: "https://vault.example.com"
336
+ path: "secret"
337
+ version: "v2"
338
+ auth:
339
+ kubernetes:
340
+ mountPath: "kubernetes"
341
+ role: "external-secrets"
342
+ serviceAccountRef:
343
+ name: "external-secrets"
344
+ namespace: "external-secrets"
345
+
346
+ ---
347
+ # ExternalSecret for application
348
+ apiVersion: external-secrets.io/v1beta1
349
+ kind: ExternalSecret
350
+ metadata:
351
+ name: api-server-secrets
352
+ namespace: production
353
+ spec:
354
+ refreshInterval: 1h
355
+
356
+ secretStoreRef:
357
+ kind: ClusterSecretStore
358
+ name: vault-backend
359
+
360
+ target:
361
+ name: api-server-secrets
362
+ creationPolicy: Owner
363
+ deletionPolicy: Retain
364
+ template:
365
+ type: Opaque
366
+ engineVersion: v2
367
+ data:
368
+ DATABASE_URL: "postgresql://{{ .db_user }}:{{ .db_password }}@db.example.com:5432/api"
369
+
370
+ data:
371
+ - secretKey: db_user
372
+ remoteRef:
373
+ key: secret/data/production/api-server
374
+ property: database_username
375
+
376
+ - secretKey: db_password
377
+ remoteRef:
378
+ key: secret/data/production/api-server
379
+ property: database_password
380
+
381
+ - secretKey: api_key
382
+ remoteRef:
383
+ key: secret/data/production/api-server
384
+ property: api_key
385
+ ```
386
+
387
+ ### SOPS for GitOps
388
+
389
+ ```yaml
390
+ # .sops.yaml - encryption rules
391
+ creation_rules:
392
+ # Production secrets - strict key management
393
+ - path_regex: environments/production/.*\.yaml$
394
+ encrypted_regex: ^(data|stringData)$
395
+ kms: arn:aws:kms:us-east-1:123456789012:key/production-key-id
396
+
397
+ # Staging secrets
398
+ - path_regex: environments/staging/.*\.yaml$
399
+ encrypted_regex: ^(data|stringData)$
400
+ kms: arn:aws:kms:us-east-1:123456789012:key/staging-key-id
401
+
402
+ # Development secrets - age key for local dev
403
+ - path_regex: environments/dev/.*\.yaml$
404
+ encrypted_regex: ^(data|stringData)$
405
+ age: age1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
406
+ ```
407
+
408
+ ```bash
409
+ # Encrypt secrets
410
+ sops -e secrets.yaml > secrets.enc.yaml
411
+
412
+ # Decrypt secrets
413
+ sops -d secrets.enc.yaml > secrets.yaml
414
+
415
+ # Edit encrypted file in place
416
+ sops secrets.enc.yaml
417
+ ```
418
+
419
+ ## Network Security
420
+
421
+ ### Network Policies
422
+
423
+ ```yaml
424
+ # Default deny all
425
+ apiVersion: networking.k8s.io/v1
426
+ kind: NetworkPolicy
427
+ metadata:
428
+ name: default-deny-all
429
+ namespace: production
430
+ spec:
431
+ podSelector: {}
432
+ policyTypes:
433
+ - Ingress
434
+ - Egress
435
+
436
+ ---
437
+ # Allow DNS
438
+ apiVersion: networking.k8s.io/v1
439
+ kind: NetworkPolicy
440
+ metadata:
441
+ name: allow-dns
442
+ namespace: production
443
+ spec:
444
+ podSelector: {}
445
+ policyTypes:
446
+ - Egress
447
+ egress:
448
+ - to:
449
+ - namespaceSelector: {}
450
+ podSelector:
451
+ matchLabels:
452
+ k8s-app: kube-dns
453
+ ports:
454
+ - protocol: UDP
455
+ port: 53
456
+ - protocol: TCP
457
+ port: 53
458
+
459
+ ---
460
+ # Application-specific policy
461
+ apiVersion: networking.k8s.io/v1
462
+ kind: NetworkPolicy
463
+ metadata:
464
+ name: api-server-policy
465
+ namespace: production
466
+ spec:
467
+ podSelector:
468
+ matchLabels:
469
+ app.kubernetes.io/name: api-server
470
+ policyTypes:
471
+ - Ingress
472
+ - Egress
473
+
474
+ ingress:
475
+ # Allow from ingress controller
476
+ - from:
477
+ - namespaceSelector:
478
+ matchLabels:
479
+ kubernetes.io/metadata.name: ingress-nginx
480
+ ports:
481
+ - protocol: TCP
482
+ port: 8080
483
+
484
+ # Allow from Prometheus
485
+ - from:
486
+ - namespaceSelector:
487
+ matchLabels:
488
+ kubernetes.io/metadata.name: monitoring
489
+ podSelector:
490
+ matchLabels:
491
+ app: prometheus
492
+ ports:
493
+ - protocol: TCP
494
+ port: 9090
495
+
496
+ egress:
497
+ # Allow to database
498
+ - to:
499
+ - podSelector:
500
+ matchLabels:
501
+ app.kubernetes.io/name: postgresql
502
+ ports:
503
+ - protocol: TCP
504
+ port: 5432
505
+
506
+ # Allow to Redis
507
+ - to:
508
+ - podSelector:
509
+ matchLabels:
510
+ app.kubernetes.io/name: redis
511
+ ports:
512
+ - protocol: TCP
513
+ port: 6379
514
+
515
+ # Allow external HTTPS (APIs, etc)
516
+ - to:
517
+ - ipBlock:
518
+ cidr: 0.0.0.0/0
519
+ except:
520
+ - 10.0.0.0/8
521
+ - 172.16.0.0/12
522
+ - 192.168.0.0/16
523
+ ports:
524
+ - protocol: TCP
525
+ port: 443
526
+ ```
527
+
528
+ ### Service Mesh (Istio) mTLS
529
+
530
+ ```yaml
531
+ # Enforce mTLS for all traffic
532
+ apiVersion: security.istio.io/v1beta1
533
+ kind: PeerAuthentication
534
+ metadata:
535
+ name: default
536
+ namespace: istio-system
537
+ spec:
538
+ mtls:
539
+ mode: STRICT
540
+
541
+ ---
542
+ # Authorization policy
543
+ apiVersion: security.istio.io/v1beta1
544
+ kind: AuthorizationPolicy
545
+ metadata:
546
+ name: api-server-policy
547
+ namespace: production
548
+ spec:
549
+ selector:
550
+ matchLabels:
551
+ app.kubernetes.io/name: api-server
552
+ action: ALLOW
553
+ rules:
554
+ # Allow from frontend service
555
+ - from:
556
+ - source:
557
+ principals:
558
+ - cluster.local/ns/production/sa/frontend
559
+ to:
560
+ - operation:
561
+ methods: ["GET", "POST"]
562
+ paths: ["/api/*"]
563
+
564
+ # Allow health checks from anywhere
565
+ - to:
566
+ - operation:
567
+ methods: ["GET"]
568
+ paths: ["/healthz", "/ready"]
569
+ ```
570
+
571
+ ## RBAC
572
+
573
+ ### Kubernetes RBAC
574
+
575
+ ```yaml
576
+ # Developer role - read most things, write to dev namespace
577
+ apiVersion: rbac.authorization.k8s.io/v1
578
+ kind: ClusterRole
579
+ metadata:
580
+ name: developer
581
+ rules:
582
+ # Read access to most resources
583
+ - apiGroups: [""]
584
+ resources: ["pods", "services", "configmaps", "events"]
585
+ verbs: ["get", "list", "watch"]
586
+
587
+ - apiGroups: ["apps"]
588
+ resources: ["deployments", "replicasets", "statefulsets"]
589
+ verbs: ["get", "list", "watch"]
590
+
591
+ # Pod logs and exec
592
+ - apiGroups: [""]
593
+ resources: ["pods/log"]
594
+ verbs: ["get", "list"]
595
+
596
+ # No access to secrets at cluster level
597
+ # - apiGroups: [""]
598
+ # resources: ["secrets"]
599
+ # verbs: ["get", "list"]
600
+
601
+ ---
602
+ # Developer can fully manage dev namespace
603
+ apiVersion: rbac.authorization.k8s.io/v1
604
+ kind: RoleBinding
605
+ metadata:
606
+ name: developer-dev-admin
607
+ namespace: dev
608
+ subjects:
609
+ - kind: Group
610
+ name: developers
611
+ apiGroup: rbac.authorization.k8s.io
612
+ roleRef:
613
+ kind: ClusterRole
614
+ name: admin
615
+ apiGroup: rbac.authorization.k8s.io
616
+
617
+ ---
618
+ # Platform team - cluster admin
619
+ apiVersion: rbac.authorization.k8s.io/v1
620
+ kind: ClusterRoleBinding
621
+ metadata:
622
+ name: platform-team-admin
623
+ subjects:
624
+ - kind: Group
625
+ name: platform-team
626
+ apiGroup: rbac.authorization.k8s.io
627
+ roleRef:
628
+ kind: ClusterRole
629
+ name: cluster-admin
630
+ apiGroup: rbac.authorization.k8s.io
631
+ ```
632
+
633
+ ### AWS IAM for Kubernetes (IRSA)
634
+
635
+ ```yaml
636
+ # Service Account with IAM role
637
+ apiVersion: v1
638
+ kind: ServiceAccount
639
+ metadata:
640
+ name: api-server
641
+ namespace: production
642
+ annotations:
643
+ eks.amazonaws.com/role-arn: arn:aws:iam::123456789012:role/api-server-role
644
+
645
+ ---
646
+ # IAM policy (Terraform)
647
+ resource "aws_iam_role" "api_server" {
648
+ name = "api-server-role"
649
+
650
+ assume_role_policy = jsonencode({
651
+ Version = "2012-10-17"
652
+ Statement = [{
653
+ Action = "sts:AssumeRoleWithWebIdentity"
654
+ Effect = "Allow"
655
+ Principal = {
656
+ Federated = aws_iam_openid_connect_provider.eks.arn
657
+ }
658
+ Condition = {
659
+ StringEquals = {
660
+ "${replace(aws_iam_openid_connect_provider.eks.url, "https://", "")}:sub" = "system:serviceaccount:production:api-server"
661
+ }
662
+ }
663
+ }]
664
+ })
665
+ }
666
+
667
+ resource "aws_iam_role_policy" "api_server" {
668
+ role = aws_iam_role.api_server.id
669
+
670
+ policy = jsonencode({
671
+ Version = "2012-10-17"
672
+ Statement = [
673
+ {
674
+ Effect = "Allow"
675
+ Action = [
676
+ "s3:GetObject",
677
+ "s3:PutObject",
678
+ ]
679
+ Resource = "arn:aws:s3:::my-bucket/api-server/*"
680
+ },
681
+ {
682
+ Effect = "Allow"
683
+ Action = [
684
+ "secretsmanager:GetSecretValue",
685
+ ]
686
+ Resource = "arn:aws:secretsmanager:us-east-1:123456789012:secret:production/api-server/*"
687
+ }
688
+ ]
689
+ })
690
+ }
691
+ ```
692
+
693
+ ## Security Scanning Pipeline
694
+
695
+ ```yaml
696
+ name: Security Pipeline
697
+
698
+ on:
699
+ push:
700
+ branches: [main]
701
+ pull_request:
702
+
703
+ jobs:
704
+ # SAST - Static Application Security Testing
705
+ sast:
706
+ runs-on: ubuntu-latest
707
+ steps:
708
+ - uses: actions/checkout@v4
709
+
710
+ - name: Run Semgrep
711
+ uses: returntocorp/semgrep-action@v1
712
+ with:
713
+ config: >-
714
+ p/security-audit
715
+ p/secrets
716
+ p/owasp-top-ten
717
+
718
+ # Secret scanning
719
+ secrets:
720
+ runs-on: ubuntu-latest
721
+ steps:
722
+ - uses: actions/checkout@v4
723
+ with:
724
+ fetch-depth: 0
725
+
726
+ - name: Gitleaks
727
+ uses: gitleaks/gitleaks-action@v2
728
+ env:
729
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
730
+
731
+ # Dependency scanning
732
+ dependencies:
733
+ runs-on: ubuntu-latest
734
+ steps:
735
+ - uses: actions/checkout@v4
736
+
737
+ - name: Dependency Review
738
+ uses: actions/dependency-review-action@v3
739
+ with:
740
+ fail-on-severity: high
741
+
742
+ # Container scanning
743
+ container:
744
+ runs-on: ubuntu-latest
745
+ needs: [sast, secrets, dependencies]
746
+ steps:
747
+ - uses: actions/checkout@v4
748
+
749
+ - name: Build image
750
+ run: docker build -t app:${{ github.sha }} .
751
+
752
+ - name: Trivy scan
753
+ uses: aquasecurity/trivy-action@master
754
+ with:
755
+ image-ref: 'app:${{ github.sha }}'
756
+ exit-code: '1'
757
+ severity: 'CRITICAL,HIGH'
758
+
759
+ # Infrastructure scanning
760
+ infrastructure:
761
+ runs-on: ubuntu-latest
762
+ steps:
763
+ - uses: actions/checkout@v4
764
+
765
+ - name: tfsec
766
+ uses: aquasecurity/tfsec-action@v1.0.0
767
+ with:
768
+ working_directory: terraform/
769
+
770
+ - name: Checkov
771
+ uses: bridgecrewio/checkov-action@v12
772
+ with:
773
+ directory: terraform/
774
+ framework: terraform
775
+ ```
776
+
777
+ ## Common Pitfalls
778
+
779
+ ### 1. Overly Permissive RBAC
780
+
781
+ ```yaml
782
+ # Bad - too broad
783
+ rules:
784
+ - apiGroups: ["*"]
785
+ resources: ["*"]
786
+ verbs: ["*"]
787
+
788
+ # Good - specific permissions
789
+ rules:
790
+ - apiGroups: [""]
791
+ resources: ["pods"]
792
+ verbs: ["get", "list", "watch"]
793
+ - apiGroups: ["apps"]
794
+ resources: ["deployments"]
795
+ verbs: ["get", "list", "watch", "update"]
796
+ ```
797
+
798
+ ### 2. Secrets in Environment Variables
799
+
800
+ ```yaml
801
+ # Bad - secrets visible in pod spec
802
+ env:
803
+ - name: DATABASE_PASSWORD
804
+ value: "supersecret"
805
+
806
+ # Good - secrets from Secret resource
807
+ env:
808
+ - name: DATABASE_PASSWORD
809
+ valueFrom:
810
+ secretKeyRef:
811
+ name: db-credentials
812
+ key: password
813
+ ```
814
+
815
+ ### 3. Running as Root
816
+
817
+ ```yaml
818
+ # Bad - runs as root
819
+ spec:
820
+ containers:
821
+ - name: app
822
+ image: app:latest
823
+
824
+ # Good - non-root with security context
825
+ spec:
826
+ securityContext:
827
+ runAsNonRoot: true
828
+ runAsUser: 1000
829
+ containers:
830
+ - name: app
831
+ image: app:latest
832
+ securityContext:
833
+ allowPrivilegeEscalation: false
834
+ readOnlyRootFilesystem: true
835
+ capabilities:
836
+ drop:
837
+ - ALL
838
+ ```
839
+
840
+ ### 4. No Network Segmentation
841
+
842
+ ```yaml
843
+ # Bad - no network policies (all pods can talk to all pods)
844
+
845
+ # Good - default deny with explicit allow
846
+ apiVersion: networking.k8s.io/v1
847
+ kind: NetworkPolicy
848
+ metadata:
849
+ name: default-deny
850
+ spec:
851
+ podSelector: {}
852
+ policyTypes:
853
+ - Ingress
854
+ - Egress
855
+ ```