feat(02-03): create Dockerfile with non-root user
- Base image: alpine:3.19 (small, secure) - Creates non-root user with UID/GID 1000 - Switches to non-root user with USER directive - CMD demonstrates non-root execution with whoami - Follows INF-01 requirement (no root execution) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
61
labs/lab-01-iam/Dockerfile
Normal file
61
labs/lab-01-iam/Dockerfile
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
# Lab 01 - IAM & Sicurezza
|
||||||
|
# Dockerfile per container non-root (INF-01 requirement)
|
||||||
|
#
|
||||||
|
# Questo Dockerfile dimostra come creare un container che gira
|
||||||
|
# come utente non-root, seguendo il principio del minimo privilegio.
|
||||||
|
|
||||||
|
FROM alpine:3.19
|
||||||
|
|
||||||
|
# Label per metadata
|
||||||
|
LABEL maintainer="Lab 01 - IAM & Sicurezza"
|
||||||
|
LABEL description="Container non-root per dimostrare permessi IAM"
|
||||||
|
LABEL version="1.0"
|
||||||
|
|
||||||
|
# Crea utente non-root con UID/GID specifici per consistenza
|
||||||
|
# UID 1000 e GID 1000 sono comuni per utenti non-root
|
||||||
|
RUN addgroup -g 1000 labuser && \
|
||||||
|
adduser -D -u 1000 -G labuser labuser
|
||||||
|
|
||||||
|
# Imposta la working directory (creata con adduser -D)
|
||||||
|
WORKDIR /home/labuser
|
||||||
|
|
||||||
|
# Crea un file semplice per verificare i permessi di scrittura
|
||||||
|
RUN echo "Questo file e stato creato durante la build" > /home/labuser/test.txt && \
|
||||||
|
chown labuser:labuser /home/labuser/test.txt
|
||||||
|
|
||||||
|
# PASSA A UTENTE NON-ROOT PRIMA DI QUALSIASI OPERAZIONE
|
||||||
|
# Questo e il punto chiave per INF-01: nessun processo gira come root
|
||||||
|
USER labuser
|
||||||
|
|
||||||
|
# Verifica che il container gira come utente non-root
|
||||||
|
CMD ["sh", "-c", "\
|
||||||
|
echo '========================================' && \
|
||||||
|
echo 'Lab 01 - IAM & Sicurezza' && \
|
||||||
|
echo 'Container non-root verification (INF-01)' && \
|
||||||
|
echo '========================================' && \
|
||||||
|
echo '' && \
|
||||||
|
echo 'Utente corrente:' && \
|
||||||
|
whoami && \
|
||||||
|
echo '' && \
|
||||||
|
echo 'UID:' && \
|
||||||
|
id -u && \
|
||||||
|
echo '' && \
|
||||||
|
echo 'GID:' && \
|
||||||
|
id -g && \
|
||||||
|
echo '' && \
|
||||||
|
echo 'Gruppi:' && \
|
||||||
|
groups && \
|
||||||
|
echo '' && \
|
||||||
|
echo 'Home directory:' && \
|
||||||
|
pwd && \
|
||||||
|
echo '' && \
|
||||||
|
echo 'Contenuto di test.txt (permessi scrittura):' && \
|
||||||
|
cat test.txt && \
|
||||||
|
echo '' && \
|
||||||
|
echo '========================================' && \
|
||||||
|
echo 'Se vedi \"labuser\" sopra, INF-01 e soddisfatto!' && \
|
||||||
|
echo '========================================' && \
|
||||||
|
echo '' && \
|
||||||
|
echo 'Container in esecuzione. Premi Ctrl-C per uscire.' && \
|
||||||
|
sleep 3600 \
|
||||||
|
"]
|
||||||
Reference in New Issue
Block a user