- Created Dockerfile with non-root user (labuser UID 1000) - Created docker-compose.yml with user directive (1000:1000) - Created infrastructure verification script (6/6 tests pass) - All INF-01 requirements satisfied - TDD GREEN phase complete Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
6.8 KiB
phase, plan, title, subsystem, tags, provides, requires, affects, tech-stack, key-files, decisions, metrics, deviations
| phase | plan | title | subsystem | tags | provides | requires | affects | tech-stack | key-files | decisions | metrics | deviations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 02-lab-01-iam-sicurezza | 03 | Infrastructure Implementation (GREEN Phase) | Lab 01 - IAM & Sicurezza |
|
|
|
|
|
|
|
|
None - plan executed exactly as written |
Phase 2 Plan 03: Infrastructure Implementation (GREEN Phase) Summary
Create Docker infrastructure (Dockerfile and docker-compose.yml) that implements non-root container execution (INF-01). Following TDD methodology, infrastructure is created AFTER tests exist, and tests should now pass (GREEN phase.
What Was Built
1. Dockerfile (labs/lab-01-iam/Dockerfile)
Created a 61-line Dockerfile that implements non-root container execution:
- Base Image: Alpine 3.19 (minimal, secure)
- User Creation: Creates
labuserwith UID/GID 1000 usingaddgroupandadduser - USER Directive: Switches to non-root user BEFORE any operations
- Verification: CMD demonstrates non-root execution with
whoami,id, and other checks - Labels: Metadata for documentation and traceability
- Test File: Creates and verifies write permissions in user's home directory
Key implementation follows INF-01 requirement strictly - no process runs as root.
2. Docker Compose Configuration (labs/lab-01-iam/docker-compose.yml)
Created a 37-line docker-compose.yml that enforces non-root execution:
- Service Definition:
lab01-testbuilds from local Dockerfile - User Directive:
user: "1000:1000"enforces non-root execution - Container Name:
lab01-iam-testfor easy reference in tests - Healthcheck: Verifies non-root user with
whoami | grep -q labuser - No Ports Exposed: Security best practice - not needed for this lab
- Comments: Explains why no volumes/networks (future labs)
Follows Docker Compose V3.8 syntax and INF-01 compliance requirements.
3. Infrastructure Verification Script (labs/lab-01-iam/tests/04-verify-infrastructure.sh)
Created a 163-line bash script that validates all infrastructure requirements:
- Test 1: Validates docker-compose.yml syntax
- Test 2: Checks Dockerfile exists and has USER directive
- Test 3: Verifies docker-compose.yml has non-root user directive
- Test 4: Builds Docker image successfully
- Test 5: Verifies container runs as non-root (whoami check)
- Test 6: Starts docker-compose service and verifies execution
Result: 6/6 tests passed - GREEN phase complete.
Deviations from Plan
None - plan executed exactly as written. All TDD GREEN phase requirements satisfied.
Technical Implementation Details
Non-Root Container Pattern
The implementation follows Docker security best practices:
# Create non-root user
RUN addgroup -g 1000 labuser && \
adduser -D -u 1000 -G labuser labuser
# Switch BEFORE any operations
USER labuser
# Verify in CMD
CMD ["sh", "-c", "whoami && ..."]
User Directive Enforcement
Docker Compose enforces non-root execution at runtime:
services:
lab01-test:
user: "1000:1000" # UID:GID
This defense-in-depth approach ensures:
- Dockerfile switches to non-root user
- docker-compose.yml enforces it at runtime
- Healthcheck verifies continuously
- Tests validate automatically
Fixed Issues During Implementation
- Docker Compose V2 Command: Updated
docker-composetodocker compose(hyphen removed in V2) - Bash Arithmetic with
set -e: Used helper functionsinc_pass()andinc_fail()with|| trueto handle counter increments - Docker Build Context: Fixed build command to use
-q .instead of-q Dockerfile
Verification Results
All 6 infrastructure tests passed:
[1/6] docker-compose.yml is valid YAML PASS
[2/6] Dockerfile exists with USER directive PASS
[3/6] docker-compose.yml user directive (1000:1000) PASS
[4/6] Docker image builds successfully PASS
[5/6] Container runs as non-root (labuser) PASS
[6/6] docker-compose service verification PASS
Requirements Satisfied
- LAB-01: Students can configure users and Docker permissions
- INF-01: No container runs as root (strictly enforced)
- TEST-01: Test-driven infrastructure methodology followed
Next Steps
Phase 2 Plan 04 will continue with documentation (Diátaxis framework):
- Tutorial: Step-by-step guide for running the lab
- How-to Guides: Specific procedures (cleanup, verification)
- Reference: Technical specifications (ports, commands)
- Explanation: Cloud parallelism concepts
Commits
317d94a: feat(02-03): create Dockerfile with non-root userc534d59: feat(02-03): create docker-compose.yml with user directivee4c497d: feat(02-03): create infrastructure verification script