1
0

93 lines
3.0 KiB
Docker

FROM ubuntu:24.04
# Install Tools
RUN apt update && apt install -y bash vim less tree coreutils adduser acl passwd login libpam-runtime libpam-modules libpam-modules-bin
# Add users
RUN useradd -m -s /usr/sbin/nologin alice && \
useradd -m -s /bin/bash bob && \
echo 'bob:alice!123' | chpasswd && \
useradd -m -s /bin/bash student && \
useradd -m -s /usr/sbin/nologin mallory && \
groupadd students && \
usermod -a -G students alice && \
usermod -a -G students bob && \
usermod -a -G students student
# ubuntu 24.04 comes with a default ubuntu user, lets get rid of it
RUN deluser ubuntu && \
rm -rf /home/ubuntu
# set up lab environment
#------------------ student -------------------------
COPY ./data/student_read_me /home/student/README.md
#------------------ alice -------------------------
COPY ./data/alice_diary_two_days_ago /tmp/
COPY ./data/alice_diary_yesterday /tmp/
COPY ./data/alice_diary_today /tmp/
# Create files named with dates and copy alice_diarys
RUN two_days_ago=$(date -d "2 days ago" +%F) && \
yesterday=$(date -d "yesterday" +%F) && \
today=$(date -d "today" +%F) && \
mkdir /home/alice/diaries && \
cp /tmp/alice_diary_two_days_ago "/home/alice/diaries/$two_days_ago.txt" && \
cp /tmp/alice_diary_yesterday "/home/alice/diaries/$yesterday.txt" && \
cp /tmp/alice_diary_today "/home/alice/diaries/$today.txt" && \
touch -d "$two_days_ago" "/home/alice/diaries/$two_days_ago.txt" && \
touch -d "$yesterday" "/home/alice/diaries/$yesterday.txt" && \
touch -d "$today" "/home/alice/diaries/$today.txt" && \
rm -f /tmp/alice_diary*
RUN mkdir /home/alice/programming && \
echo "This is a test file! Can I write it to the console with the new program I wrote?" > /home/alice/programming/test_file
COPY ./data/alice_show_file.c /home/alice/programming/read_file.c
COPY ./data/alice_show_file /home/alice/programming/read_file
# set permissions for alice
RUN chown -R alice:alice /home/alice && \
chmod 755 /home/alice/programming/read_file && \
chmod u+s /home/alice/programming/read_file && \
chmod 600 /home/alice/diaries/*
#------------------ bob -------------------------
COPY ./data/bob_todo /home/bob/TODO.txt
COPY ./data/bob_sfl_colab/ /home/bob/sfl_colab
# set permissions for bob
RUN chown -R bob:bob /home/bob && \
chown -R bob:students /home/bob/sfl_colab && \
chmod 770 /home/bob/sfl_colab && \
chmod 660 /home/bob/sfl_colab/*
#------------------ mallory -------------------------
COPY ./data/mallory_secret_plan /home/mallory/.secret_plan
RUN chown -R mallory:mallory /home/mallory && \
chmod 750 /home/mallory && \
setfacl -m u:bob:rx /home/mallory/
RUN chmod o+rx /home/alice /home/bob
RUN echo '[ ! -z "$TERM" -a -r /etc/motd ] && cat /etc/motd' \
>> /home/student/.bashrc
COPY ./data/welcome_screen /etc/motd
USER root
COPY ./data/root_entry_point.sh /root/entry_point.sh
RUN chmod +x /root/entry_point.sh
ENTRYPOINT ["/root/entry_point.sh"]