# Leaked cloud key or API token in a code repository: what to do now

A colleague pushed a .env file to GitHub, an AWS access key landed in a public commit, or your cloud provider emails you that it found one of your keys on the internet. Automated programs search public repositories for such keys all the time, so assume it has already been found.

Revoke or rotate the key first and only then remove it from the code: deleting the commit does not make it secret again. Then check the provider's logs for what was done with it, look for resources someone else created (servers, users, new keys) and watch the bill. Finally, clean the repository history and add rules that stop keys before they reach the code.

## 1. Revoke the key, now

Create a new key for the application that used it, then deactivate and delete the leaked one. If you cannot update the application quickly, deactivate the key anyway: a short outage costs less than an account used by someone else.

- **AWS:** in IAM, on the user the key belongs to, set the access key to inactive, then delete it. If AWS already detected the key, it may have attached a quarantine policy (AWSCompromisedKeyQuarantine) to the user and emailed you. That policy only limits some actions: it does not replace revoking the key.
- **Azure:** for an application client secret, delete it from the app registration and create a new one. For a storage account key, regenerate it; this also invalidates SAS links signed with it.
- **Google Cloud:** disable and delete the service account key (Service accounts, Keys). For an API key, regenerate or delete it and restrict the new one to the APIs and addresses you need.
- **Other tokens** (GitHub, GitLab, Stripe, Slack, SendGrid, OpenAI and others): revoke the token in the provider's console and issue a new one. Each has a tokens or API keys page.

## 2. Check what was done with it

- **Activity logs:** AWS CloudTrail (search by the access key ID), the Azure activity log and service principal sign-in logs, Cloud Audit Logs in Google Cloud. Look from the moment the key was published, not just from when you found out.
- **New resources, in every region:** virtual servers (often used for cryptocurrency mining), functions, containers, and users, roles and keys the attacker created to keep access.
- **Data accessed:** downloads from storage buckets and databases, permission changes that made them public.
- **The bill:** check billing and set a budget alert. A sudden jump in cost is often the first sign of abuse.
- **Delete everything the attacker created**, including new users and keys. Otherwise revoking the first key does not cut their access.

## 3. Clean the repository

- **Remove the secret from history,** not just the latest version, with a tool such as git filter-repo, then force-push the cleaned history. Ask colleagues to clone it again.
- **Copies remain.** Forks, clones and other people's archives may keep the key. That is why the revocation in step 1 is what counts. Code platforms have procedures for removing sensitive data from cached views; use them where needed.
- **Look for other secrets.** Where one key went, others usually did too. Scan the whole repository and its history with an open source secret scanner such as gitleaks or trufflehog, and revoke whatever you find.

## 4. Legal duties, if data was accessed

- **Your data protection authority, if personal data was affected.** If the logs show the attacker accessed personal data, or you cannot rule it out, under the GDPR (Art. 33) you notify your national data protection authority (in Romania, [ANSPDCP](https://www.dataprotection.ro)) within 72 hours of becoming aware, unless the breach is unlikely to result in a risk to people's rights and freedoms. If the risk is high, you also tell the people affected (Art. 34). Document the breach internally either way.
- **Your national CSIRT or NIS2 authority, only if your company is in scope of NIS2** and the incident is significant: an early warning within 24 hours of becoming aware, a notification within 72 hours and a final report within one month of the notification (NIS2, art. 23(4)). In Romania, for example, that means DNSC, through the [PNRISC platform](https://pnrisc.dnsc.ro) ([OUG 155/2024](https://legislatie.just.ro/Public/DetaliiDocument/293121)). NIS2 reporting does not replace the GDPR notification. Not sure whether the law applies to you? Use the [NIS2 check](https://cybersecurity.acidripp.com/en/tools/nis2-check/).
- **The police,** if the key was used: unauthorised access to a computer system is a crime. File a complaint with the police; in Romania, for example, you can also go directly to DIICOT.

## 5. So it does not happen again

- **No long-lived keys in code.** Use roles and short-lived credentials (for example OIDC from your build system to the cloud provider) and a secrets manager.
- **Scan before commit:** a pre-commit hook with a secret scanner, and secret scanning switched on at the code platform with push protection.
- **.env files** in .gitignore, with an example file that holds no real values.
- **Least privilege.** A key that can only read one storage bucket does far less harm than an administrator key.
- **Budget and activity alerts** on every cloud account.

ACIDRIPP does not offer incident response. If someone is using your cloud account right now, call your IT provider first and open a support case with the cloud provider. Afterwards, the [security audit](https://cybersecurity.acidripp.com/en/services/website-security-audit/) looks for keys and passwords left in public code repositories and in website JavaScript, plus cloud storage open to anyone.

Guidance, not legal advice. NIS2 deadlines are those of the directive, art. 23(4), which Romania's OUG 155/2024 repeats in art. 15; GDPR deadlines are from Regulation (EU) 2016/679, Arts. 33-34; checked on 29 November 2026. Console names at AWS, Azure and Google Cloud can change.

---
Source: https://cybersecurity.acidripp.com/en/resources/leaked-cloud-access-key/ (ACIDRIPP, 2026-11-29)
