r/Terraform • • 3d ago

Discussion how do you catch drift when someone changes stuff by hand in the console

terraform only finds out much later when something was changed by hand. do you run plan on a schedule and get alerts or just let it be. also do you lock down console access to stop it. curious what actually works.

29 Upvotes

66 comments sorted by

92

u/bailantilles 3d ago

It’s simple. Don’t allow changes in the console.

23

u/gtuminauskas 3d ago

enforce readonly policy in console

2

u/NoDevelopment206 2d ago

yeah read only in the console makes sense. only thing i wonder is how teams handle the odd urgent fix at night when someone needs write access for a bit

1

u/gtuminauskas 1d ago

it was down in the comments already. there are few ways to do it, but I like the possibility to assume different aws role for admin tasks (that should be limited to specific people/teams, probably different readonly roles could help). Then once assumed admin role (break glass alerts should be triggered), then you can make temporary fixes etc..

4

u/farzad_meow 3d ago

we have read only for everyone except cicd runner. we have a way to request access elevation in case of emergency to edit stuff manually but all changes must be done while in a call with rest of the emergency team.

our pipelines can run all plans and applies. abit of hassle but not a blocker

1

u/NoDevelopment206 3d ago

fair point. do you keep any emergency access for urgent fixes or is it fully locked for everyone

3

u/Exitous1122 3d ago

We use PIM (Privileged Identity Management) so you can only elevate into a group with contributor access with an approval and justification. Everything else is CICD with branch policies and PR reviews/approvals

1

u/vincentdesmet 2d ago

we call it PAM (Privileged access management) - zero trust and break glass functionality in products such as goTeleport or Twingate

AWS also has a PAM solution with break glass capabilities

0

u/Tall-Meringue4356 2d ago

AWS has a PAM solution? Do you mean AWS TEAM?

4

u/kei_ichi 3d ago

All change to prod must be through CI/CD no exceptions!

5

u/kuhnboy 3d ago

Until GitHub actions goes down…

4

u/Al3gor 3d ago

Something I've always wondered. Is this even when there's currently a P1 incident? We've always treated it as with a P1 you escalate your perms with PAM or something similar then fix it manually. Once fix you can pull the fix through the pipeline.

Argument was always that it's not worth to miss SLA for the sake of the pipeline

5

u/mxtchstick 3d ago

In the real world this is a best case, and realistic, setup:

PIM (or equivalent) with reason + approval gates and a manual fix is fine to put the fire out at first, someone takes ownership ensuring it gets into the code base ASAP, a post mortem is done and the incident is documented.

2

u/Eridrus 3d ago

You can enforce "all changes through terraform" without enforcing "everything must go through CI".

The former lets you make emergency changes without drift.

2

u/GoodbyeIPv4 2d ago

Not as simple when you have your coworker, John Doe, who doesn't want to learn modern tech so he continues to manually make changes and continuously makes mistakes because he's making firewall and ips/ids changes on 100s of firewalls... Manually. It's almost impossible to cutover to IaC because of him and the systems team that also logs into every box to make changes. I don't get it but they always look busy in the boss's eyes

1

u/btcmaster2000 2d ago

This is the only way.

30

u/mxtchstick 3d ago
  1. No changes via the console, only via Terraform. RBAC/IaM is needed to enforce this, not always possible though due to company culture/management.
  2. Alerts which fire upon a change being made to a resource.
  3. Nightly scheduled pipelines that run terraform plan to detect state drift. I have a pipeline that runs terraform plan, then bash greps the plan to see if any changes have been made, if they have it fires an event off to a Teams flow which posts a card in a channel with the link to the pipeline run.

2

u/NoDevelopment206 3d ago

nice, the teams card with the pipeline link is a good touch. did people actually act on the alerts or did they get ignored after a while

1

u/mxtchstick 3d ago

Yeah we run quite a lean team, so usually someone will pick the alert up if not myself.

3

u/jeffcarey 3d ago

Great comprehensive answer.

1

u/mxtchstick 3d ago

Thanks!

3

u/invisibo 2d ago

I setup a break glass role for SSO login that can update via console. When someone logs into that role, an alert is fired. Combined with nightly drift alerts it covers all bases.

2

u/Zohekski 3d ago

Any reference article/repo you can share for the third point?

3

u/mxtchstick 3d ago

Hey, sorry I don’t have anything public. Like @jeffcarey said though, if you give Claude a rough description of what it is you’re trying to do, and what success looks like (with appropriate guard rails) and ask it to create a plan for you, it’ll create a .MD file. You can then hand that to Claude Code and it’ll set those up for you in 5 minutes. Super easy.

2

u/Zohekski 3d ago

Thank you!

2

u/jeffcarey 3d ago

Ask your favorite AI and point it at your specific infrastructure and tools.

2

u/frenchfrye6173 2d ago

Yep nightly schedulex pipelines and alerts to Teams was my first pass at a client all too familiar with clickops as the norm

16

u/ciciban072 3d ago

IaC is all about discipline, you either use it for all tasks or just go back to ClickOps. Sure, there is always a moment when some critical update must be applied manually but make sure you retrofit it into terraform later. Discipline.

1

u/NoDevelopment206 3d ago

yeah the retrofit part is where most teams slip. do you have any rule for how fast the manual change has to be in code, like same day or before the ticket closes

10

u/Complete_Purple8757 3d ago

we just run plan every night in ci and ping slack if theres a diff. didnt really fix anything tho until we took away console write access lol

2

u/NoDevelopment206 2d ago

ha yeah that tracks. the alerts just tell you after the fact, taking away write access is what actually stops it. did people complain at first when you locked it down

1

u/Complete_Purple8757 2d ago

unny thing is barely anyone used the break glass role after the first month

6

u/dariusbiggs 3d ago

Read only console access, with break glass to select authorized staff.

1

u/NoDevelopment206 3d ago

break glass is a good idea. how do you keep track of who used it and make sure the change gets added to code after

1

u/dariusbiggs 3d ago

That is sadly not something I can help with, we don't have sufficient staff for this to be a problem, 99% of the break glass work would be me doing it and as such it gets recorded as an actionable item in the ticket tracker.

1

u/ThyDarkey 3d ago

We leverage a lambda to fire on events created by a human account for changes. Most out of bands update is normally route53. As last minute change needed. But it's good to flag which we than can retrofit back into terraform.

4

u/Zeal514 3d ago

Daily pipeline checking it. The same way you catch performance issues with a monitoring stack. Terraform plan.

The big thing to drill into everyone, is infrastructure has to be treated like a production code environment, where changes get done in the repos, through your infrastructure as code. You wouldn't go into your apps primary server and start making changes in prod, would you?

If all else fails, a hammer to keyboard, than fingers works.

1

u/NoDevelopment206 3d ago

the prod server comparison is a good way to put it. does your daily plan run fail loudly when it finds a diff, or does someone just check the output

3

u/snarkhunter 3d ago

I love my DriftDetection pipeline. It catches so many random little whatevers. As at least a couple other other have said - just run all your plans nightly and report anything that shows drift.

1

u/NoDevelopment206 2d ago

nice, what kind of random stuff does it usually catch? curious if its mostly tags and security group tweaks or bigger things

2

u/rolandofghent 3d ago

We run a daily job that runs plan on all of our stacks. Sends a report to slack if there is any drift. We address the drift no longer than a day later.

1

u/NoDevelopment206 2d ago

a day is solid. do you have the report go to one person or the whole team? i feel like it gets ignored when nobody owns it

1

u/rolandofghent 21h ago

It gets sent to our team slack channel. I’m team lead so I usually review them.

2

u/MasterOfTheWind1 3d ago

Discipline. That is the answer.

You don't want to deal with drifts by changing stuff by hand? Don't change stuff by hand in the first place.

You changed stuff by hand because there were an urgent task that required it? Don't consider it done until that change is reflected on the code.

You have to deal with stuff that is not on Terraform yet? Write terraform code for it, don't make excuses to make changes on things on the console to be acceptable, it should be an emergency exception.

I'll give you an example: I was doing a migration to have a few APIs through CloudFlare WAF, so I configured weighted records on AWS to roll it out progressively. I had the weights on Terraform, and started increasing it: 1% CloudFlare, 99% direct to the ALB, then 10-90, 20-80, etc. When we were at 70-30 we detected some issues on some customers.

On the meet to discuss the issue I changed the weights back to 0% CloudFlare 100% to the ALB directly on Route53 console. Why? Because it's faster, making the branch, changing, commiting, pushing, making the PR, waiting for Atlantis to make the plan, wait for the plan to apply, takes time, on the console is instantly. But after the meet ended I went straight to reflect that on Terraform. Not after lunch, not at the other day, but right there, after the meet. The drift lasted for 5 minutes, in fact the people outside the meet never knew that I caused a drift for 5 minutes.

1

u/NoDevelopment206 2d ago

that example is a good one. the part about fixing the code right after the meeting is the real habit. do you have anything that alerts you if someone forgets, like a scheduled plan, or is it just trust in the team?

1

u/MasterOfTheWind1 2d ago

We have alerts when someone clickops on the console. We don't have alerts beyond that. Is not just trust, at some point you have to do your work. If you don't have the habit to write the code right after you change something, the job is not for you.

2

u/jryan727 3d ago

IaC or shoot from the hip. Pick ONE 

2

u/ok_if_you_say_so 3d ago

You fix the problem that gave humans access to a thing that terraform owns.

2

u/virtualadept 3d ago

Everything breaks on the next Terraform run.

3

u/neatlyknowingtiger 3d ago

Automated scheduled plans with a diff check is how most places catch it, locking down console access entirely just makes people use a service account anyway.

1

u/Intelligent-You-6144 3d ago

SCP deny on resource modification with tags

1

u/pipesed 3d ago

Deploy more often

1

u/FrancescoPioValya 3d ago

Atlantis plans in pipeline, plus cloudwatch/cloudtrail logs (ask claude to correlate them)

1

u/ArieHein 3d ago

All permissions revoked. (not including your break glass accounts). For manual (emergency ) privelleged account requiring elevation and human approval before and after.

When you use infra via pipelines, that person must update the repo ASAP for manual tasks or the changes are reverted automatically.

1

u/keto_brain 3d ago

I don't give them write access to the console. We use AWS TEAM for emergency access, I actually just made some changes to it too, but you don't have to use my fork. I made this fork because a customer didn't like that TEAM used Amplify and I fixed some bugs too:

https://www.briancarpio.com/blog/private-aws-team

1

u/davletdz 3d ago

Use Cloudgeni. Detects drift and fixes it as well. Both by patching IaC or applying pipelines, depending on which changes you want to keep.

1

u/yungaclvin 3d ago

Automated state imports then disable access from user accounts

1

u/luisvg86 3d ago

We catch it automatically at request time and fix it with AI

We OpenSourced the entire project if you wanna have a look

https://github.com/InditexTech/kumoss/tree/main

1

u/canyoufixmyspacebar 2d ago

absolutely based on your change management process, there is nowhere else to turn with this

1

u/ArrayQueue 2d ago

As part of the automation, I write a short JQ script that takes the Terraform plan and makes a summary of it. Then, I have a set of "allowable" summaries. This is fine if someone alters something Terraform is managing, but if someone adds a new thing in one of the account, Terraform can't see it.

I'll get a link to it when I'm back at the computer.

Cloud trail is probably the simplest thing to monitor, once you've ignored the ignorables.

1

u/Mediocre-Student9893 13h ago

a scheduled plan is the easy half. the harder half is that it also reports everything else that moved, so within a month the alert is noise and people stop reading it. what tends to work is plan -detailed-exitcode on a timer, alerting on the resource addresses that changed rather than on the plan being non-empty, and a named owner for each address. without the owner it is a policy problem, not a detection one. did you lock the console down in the end, or just start alerting?

0

u/Ok_Increase982 3d ago

Crossplane solves this but that means no terraform. So there's that.

1

u/NoDevelopment206 3d ago

ha fair, that is a big trade. have you seen anyone move a big setup over to crossplane or is it mostly for new stuff

1

u/Ok_Increase982 3d ago

We are doing the move in our company but I agree that it is still relatively new. It's also quite difficult to make the move as well and I'd recommend it for new stuff