[ norboten ]
bash · lab bash-07

The Config That Breaks on a Password

· about 35 minutes · runs on ubuntu-26.04-devops · unrated

An unrated lab. It runs on your machine with no account and no network, and everything about it — the faults, the checks, the hints and the reference solution — is in the repository. An attempt on it is recorded on your profile and never moves a rating: only rated labs do. Rated and unrated labs.

The briefing

myapp.service renders its configuration before it starts: render-config fills the placeholders @DB_HOST@ and @DB_PASSWORD@ in /etc/myapp/app.conf.tmpl from the shell assignments in /etc/myapp/secrets.env, and writes /etc/myapp/app.conf. Then myapp-login logs in to the database with that password.

The password was rotated this morning — the new one came from the password manager and contains a /, an &, a $ and a backslash. Since then myapp does not start. Someone fixed app.conf by hand; it worked until the next restart. The security team also noticed that app.conf can be read by every user on the machine.

What is expected, and graded — the grader runs render-config itself, through the RENDER_TEMPLATE, RENDER_VALUES and RENDER_OUT variables the script already reads:

  1. Every placeholder is replaced by its value exactly, whatever characters the value contains.
  2. The rendered file can be read and written by its owner only.
  3. When a value is missing from the values file, the script exits non-zero, names the missing value on standard error, and leaves the previous configuration exactly as it was.
  4. myapp.service starts and logs in with the rotated password — and still does after a reboot.

You have root through sudo. The password itself stays as it is.

What is graded

The machine is checked, rebooted, and checked again. A check passes only if it passes both times.

CheckObjective
01_any_password_survivesSubstitute any value into a template literally, whatever characters it contains
02_the_config_stays_privateWrite a file that holds a secret so that nobody else can ever read it
03_a_missing_value_failsRefuse to render a configuration with a value missing
04_the_service_logs_inSubstitute any value into a template literally, whatever characters it contains

Start it

  1. 2Labs
  2. bash-07select this one
  3. udownload it
  4. sstart the machine

Reading

Where the lab's hints send you, level by level, as you ask for them (h, then l opens a journal section in the TUI).

Theory for this lab

4 questions on the same topic, in the lab's Theory tab. They never affect the lab's grade. Three of them, to answer here:

Question 1

What does this print?

p='a&b'
printf 'x = @P@\n' | sed -e "s/@P@/$p/"
Question 2

What does this print?

t='x = @P@'
p='k3y/&Pa$$\1-vault'
echo "${t//@P@/"$p"}"
Question 3

A script running with umask 022 creates a configuration file with `echo "$text" > /etc/app.conf` and then runs `chmod 600 /etc/app.conf`. What are the file's permissions in between, and why does it matter?