Beginner-friendly
GCP
Gain Entry to GCP via GitLab Commit
See how leaked credentials in a public git repository can give threat actors a route into a cloud environment.
Overview
We have created this beginner-friendly lab to showcase how accidental commits to public git repositories can result in threat actors getting a foothold in a GCP environment. It introduces GCP services and moving laterally between them. It also provides an awareness of how this scenario could have been prevented.
Scenario
On an external engagement for our new client, the global company Gigantic Retail, your team has identified a public GitLab repository. Can you check it out, and look for a way into their cloud environment?
Lab prerequisites
Learning outcomes
- Reveal secrets in GitLab commits
- Enumerate and graphically visualize IAM permissions
- Identify other cloud services in the GCP project
- Access secrets from Secret Manager
- Enumerate and exfiltrate data from a MySQL database
- Understand how this could have been prevented
Real-world context
Leaked credentials in public git repositories is unfortunately a very common issue. Even if secrets are only exposed for a matter of hours or even minutes, this can result in a breach as threat actors are continuously scanning these repositories for leaks. Once in an on-premise or cloud environment it's important to get situational awareness and an understanding of the environment before attempting to move laterally and vertically within it.
KEY TAKEAWAY
Exposure time is not the same as risk window. Automated scanners monitor public repositories continuously, so a credential committed and removed within minutes should be treated as compromised. Rotation is the remediation, and the speed of the cleanup is irrelevant.
What this lab covers
You find credentials in a repository's commit history, use them to enter a Google Cloud project, map what the identity can reach, and follow that to stored secrets and data.
The lab links source control hygiene to cloud impact concretely. The route from a single commit to Secret Manager and onward is short, and seeing it end to end changes how people treat the initial mistake.
It assumes no prior GCP experience and pairs naturally with the AWS secret scanning lab, since the tooling is the same and the consequences differ by provider.
How committed secrets lead to cloud compromise
Git stores every commit, so a secret introduced at any point remains in history after it is removed from the current files. A repository can appear clean while an earlier commit still contains a working credential, and scanning only the working tree will report no findings.
Public repositories are monitored continuously by automated tooling looking for credential patterns, much of it operated by attackers. Exposure is measured in minutes rather than days, which is why the interval between commit and removal offers little comfort.
In Google Cloud the escalation is usually through the identity's own reach rather than a further exploit. Enumerating what the credential can do commonly surfaces Secret Manager access, which yields further credentials, and any token creation rights allow movement to service accounts with broader permissions.
How to detect this in your own environment
Scan full commit history rather than the working tree, across all branches including deleted and merged ones. A working-tree scan is the most common reason organizations believe their repositories are clean.
Detect on the cloud side as well, since it is faster. First use of a credential from an unfamiliar network, or a service account authenticating from outside your infrastructure, will usually surface before any repository audit.
Alert on Secret Manager access patterns. An identity retrieving many secrets, or secrets it has never read before, is the step that converts one leaked credential into several.
How to prevent it
Block secrets at commit time with pre-commit hooks and server-side push protection. Everything after that point is cleanup and rotation, so preventing the commit is the only intervention that avoids the incident.
Remove the need for long-lived credentials. Workload identity federation issues short-lived tokens, so there is nothing durable to commit, which is a stronger position than scanning for what people commit.
Rotate first and clean history second. History rewriting is worthwhile and slow, and it does nothing about copies an attacker may already hold.
Real-world context
Credentials in public repositories remain a leading cause of cloud compromise, and published research has repeatedly shown that exposed keys are used by automated tooling within minutes of appearing.
The compounding factor in Google Cloud is Secret Manager. A single leaked identity with access to it can yield credentials for many other systems, which turns one mistake into a multi-system incident.
The pattern maps to MITRE ATT&CK T1552.001 Credentials In Files, T1078.004 Cloud Accounts and T1555 Credentials from Password Stores.
Applying this at work
- Run history-aware secret scanning across every repository, including archived ones and every branch.
- Enable push protection so new secrets are blocked rather than discovered later.
- Replace long-lived service account keys with workload identity federation.
- Review which identities can read from Secret Manager and reduce that list.
- Write the rotation runbook before you need it, since the slow part of a leaked credential is deciding who may rotate it.
Frequently asked questions
If a secret was only exposed for a few minutes, is it safe?
No. Automated scanners monitor public repositories continuously and exposed credentials are commonly used within minutes. Any credential that reached a public repository should be rotated regardless of how quickly it was removed.
Why does scanning my current files miss committed secrets?
Because git retains history. A secret removed in a later commit remains in the earlier one and is available to anyone who clones the repository. Scanning must cover the full commit graph.
What makes Secret Manager access significant here?
It stores credentials for other systems. An identity able to read it converts a single leaked credential into access to everything the vault holds, which is how one commit becomes a multi-system incident.
Do I need my own Google Cloud account to practice this?
No. The lab runs in a live Google Cloud environment that Pwned Labs provisions for you, so there is nothing to set up and no risk to your own project.
Which certification covers this in depth?
The Google Cloud Red Team Professional (GCRTP) covers Google Cloud and Google Workspace attack paths in full, including service account abuse and privilege escalation, and is assessed hands-on in a live Google Cloud environment.
Watch the walkthrough
Want to see the full attack path first? Watch the complete video walkthrough of this lab: Gain Entry to GCP via GitLab Commit. You can also browse all cloud security lab walkthroughs.
Cloud Security Training To Protect Your Business
Pwned Labs for Business gives your team access to dedicated business content, including labs and cyber ranges.
We also offer in-person or remote workshops, and our cloud penetration services are helping businesses become more secure!