A contractor needs sudo on one server for two hours. How do you grant it so it expires automatically?
AdvancedScenarioScenarios: deployments, user management and fleet operations
Answer
Situation read → Manual revocation gets forgotten. Make expiry part of the grant.
What I'd do →
- Write a validated sudoers drop-in:
f=/etc/sudoers.d/90-tmp-contractor tmp=$(mktemp) echo 'contractor ALL=(ALL) /usr/bin/systemctl restart app, /usr/bin/journalctl' > "$tmp" visudo -cf "$tmp" && install -m 0440 "$tmp" "$f"; rm -f "$tmp" - Schedule removal with a transient systemd timer:
systemd-run --on-active=2h --unit=revoke-contractor rm -f "$f"(orat now + 2 hours). - Scope commands narrowly; avoid
ALLand anything that can spawn a shell (vi,less,find -exec). - Log the grant and the revocation with
logger.
Why → visudo -c prevents a syntax error from breaking sudo for everyone; timed removal prevents forgotten access.
Interview tip → Mention just-in-time access tools (Teleport, AWS SSM with IAM conditions) as the scalable version.
More on Scenarios: deployments, user management and fleet operations
Write the core of a deploy script with release directories, an atomic symlink switch and rollback.IntermediateDeploy to 10 servers behind an AWS ALB one at a time, removing each from the target group during its deploy. Outline the script.AdvancedAfter a deploy, the health check fails intermittently. Your script must roll back automatically, but only if the failure persists. How?IntermediateImplement a blue/green switch on a single nginx host with a script.AdvancedOnboard 30 engineers: create accounts and install their SSH keys from their GitHub usernames, idempotently.IntermediateAn engineer leaves the company. Write the offboarding steps for Linux servers.Intermediate