GitLab security means keeping your GitLab account, code projects, access tokens and automated pipelines safe.
This guide is for new IT hires, small business admins and students who have been handed a GitLab account. You do not need to write code to be affected: if a supplier builds your website or app, its code and the keys that run it may live in GitLab.
In short
- There are four things to protect: your account, your projects, your tokens and your pipelines.
- Turn on two-factor sign-in, so a stolen password alone is not enough to get in.
- Give each token only the access it needs and an end date. GitLab sets one by default.
- Keep passwords and keys out of code and pipeline files. Store them as protected, masked variables or in a vault.
What you will learn
- Explain the four parts of GitLab you need to protect.
- Spot a token or pipeline setting that gives away too much.
- Check your own account and project settings in under an hour.
- Ask a supplier the right questions about how they use GitLab.
- Code project (repository)
- a folder of code plus its full history of saved changes.
- Software pass (access token)
- a long secret string that lets a tool or script use GitLab without your password.
- Automatic assembly line (pipeline)
- a set of jobs GitLab runs by itself to test and ship code.
What is GitLab security?
Think of GitLab as a small factory. There is a front gate, a store room full of plans, a conveyor belt that builds things, and passes for helpers.
GitLab is a website where teams store code and build it automatically. Your account is the front gate. Each project is a set of plans in the store room. The pipeline is the conveyor belt: a set of jobs that test the code and send it out, with no person pressing each button.
The helper passes are access tokens. A token is a long secret string that a script shows to GitLab instead of your password.[1] Tokens, pipelines and the tools that hold them are non-human identities (NHIs). An NHI is a digital identity, or the credential behind it, that represents a machine, application, automated process, service or AI agent.
GitLab security means keeping all four safe: the gate, the plans, the belt and the passes.
Where the comparison stops working: a lost factory pass is easy to notice, because it is missing from someone's pocket. A copied token leaves no gap. The original still works, so nobody may know a stranger has a copy.
Why does it matter?
A pipeline often holds the keys to live systems, such as the website or the cloud account. Whoever controls the code or the tokens may be able to reach those systems too.
If you are new to IT work
What could happen: a token you made for one quick task still works a year later, long after you forgot it.
Check this: your token list shows only tokens you use, each with a short end date.
If you run a small business
What could happen: a former supplier still has access to the code that runs your online shop.
Check this: ask who is a member of your GitLab projects, and remove anyone who has left.
If you are a student
What could happen: a cloud key pasted into a public project is copied and used to run up bills.
Check this: secret push protection or secret detection is switched on where your plan allows.
What does it look like?
Here is a made-up pipeline file. Many GitLab projects have one, called .gitlab-ci.yml. It tells the conveyor belt what to do.
Example only. All values are made up.
# pipeline file for a shop website
variables:
SITE_NAME: "shop.example.com" (1)
CLOUD_KEY: "EXAMPLE-KEY-0000-FAKE" (2)
deploy:
script:
- echo "Deploying with $CLOUD_KEY" (3)
- A plain setting. It is fine for this to sit in the file.
- In a real file, this line would contain a key to the cloud account, readable by anyone who can see the project.
- This step prints the key into the job log, where more people may read it.
Why this is risky: GitLab says anyone who can see the project can read values in this file.[3] The key is also copied into the code history.
The safer way: remove the key from the file, then replace it at the cloud provider, because old copies stay in the history. Add the new key in the GitLab settings screen. Make it masked, so it is hidden in job logs. Make it protected, so only pipelines on protected branches get it. For stronger protection, GitLab suggests a separate vault.[3]
How does it work?
Good GitLab security comes in layers. Each one covers a different way in.
- Lock the front gate. Turn on two-factor sign-in, so you need a code or a device as well as your password. GitLab supports authenticator apps (phone apps that show a new code), passkeys and security keys. Save the recovery codes it gives you.[2]
- Guard the main plans. GitLab protects a project's default branch (the main copy of the code) by default.[4] A protected branch controls who can push and merge changes, and blocks accidental deletion. Force pushing, which overwrites history, is off unless someone turns it on.[4]
- Keep passes small and short. Each token has scopes, which limit what it can do. By default, a new token must have an end date no more than 365 days away.[1] Pick only the scopes and the time you need.
- Keep secrets off the belt. Put passwords and keys in protected, masked variables, not in the pipeline file. GitLab warns that masking may not hide every copy, so check changes to the pipeline file before they run.[3]
- Switch on the scanners. Secret detection looks for passwords and keys. Secret push protection can block a push that contains one. GitLab lists secret detection on its Free tier as well as paid tiers.[5]


A worked example
Leila Castell has just joined Rowan Lettings, a small lettings agency, as its only IT person. On day one she is given the GitLab account for the agency's property website.
Before, a contractor called Gideon Ueda built and ran the site. He finished the job three months ago.
Leila thinks of the factory. She starts at the front gate. Two-factor sign-in is off on the admin account. She turns it on with an authenticator app. She keeps the recovery codes in the agency safe.
Next she checks who has passes. Gideon is still a project member with full rights. She removes him and lets him know. She also finds a token called "deploy-temp" with wide access. She revokes it, which GitLab says stops it working straight away.[1]
Then she reads the pipeline file. It has the cloud hosting key typed straight into it. She asks the hosting firm to issue a new key and cancel the old one. She stores the new key as a protected, masked variable.
The site stops deploying for an hour, because a job still pointed at the old token. She makes a new project token with one scope and a 90-day end date, and the site is back.
Last, she switches on secret detection and writes a one-page note listing every token, its owner and its end date. Her checks found no unexpected sign-ins in the records available to her.
Myths and mistakes
| What people think | What is true |
|---|---|
| A private project is safe, so keys in it are fine. | Anyone with access to the project, and anyone who steals a member's token, can read them. Keep keys out of the code. |
| Deleting the key from the file fixes the leak. | Old copies stay in the history. GitLab advises you to revoke and replace exposed secrets as soon as possible.[5] |
| A masked variable can never be seen. | Masking hides values in job logs, but GitLab says it is not a guaranteed protection. A harmful change to the pipeline can still expose it.[3] |
| A token is less important than my password. | A token can act for you without the second check at sign-in. Treat it with the same care. |
| When a contractor leaves, their access ends by itself. | Membership and tokens usually stay until someone removes them. Put it on the leaving checklist. |
What can I do this week?
- Turn on two-factor sign-in and save your recovery codes somewhere safe and offline.
- Open your token list and revoke every token you do not recognise or use.
- Look at who is in each project. Remove people who no longer need it.
- Look in your pipeline files for passwords or keys. Move each one to a hidden setting.
- Switch on the secret scanners for your projects.
Checklist
- My GitLab password is unique and stored in a password manager.
- Two-factor sign-in is on, and my recovery codes are saved.
- The main branch of each project is protected, with force pushing off.
- Every token has a clear job, the fewest scopes it needs and an end date.
- Unused tokens are revoked and former staff and suppliers are removed.
- No passwords or keys are written in pipeline files.
- Pipeline secrets are protected, masked variables or come from a vault.
- Secret detection is switched on where my plan allows.
Common questions
Is GitLab the same as GitHub?
No, but they are similar. Both store code and its history, and both can run automatic pipelines. The settings have different names and live in different places. The ideas in this guide carry over. See GitHub Security for Beginners for the GitHub version.
Do GitLab tokens expire?
Usually, yes. By default, a new token must have an end date, and if you do not pick one, GitLab sets it 365 days ahead. An administrator can change these limits. Once a token expires it cannot be switched back on, so you make a new one.
What should I do if a key was pushed to GitLab?
Replace it at the service that issued it first, so the old copy should no longer give access. Deleting the line is not enough, because older versions stay in the history. Then check where else the key was used. See Secrets in Code for Beginners.
Are GitLab's security scanners free?
Some are. GitLab lists secret detection as available on its Free, Premium and Ultimate tiers. Other security features may need a paid tier. Check GitLab's current documentation for your plan, because what is included can change over time.
What is the difference between a personal and a project token?
A personal token acts as you, across everything you can reach. A project token belongs to one project, so it is often a better fit for automation tied to that project. GitLab recommends project tokens for project automation and job tokens for pipelines.
Where next?
Ready for the detail? Read the practitioner guide: GitLab Security Guide. It goes further into admin roles, service accounts, a hardening baseline and what to log and watch for.
Also useful:
- GitLab Tokens Security Guide
- How to federate GitLab CI to AWS
- CI/CD Pipeline Security for Beginners
- Non-Human Identities for Beginners
- NHI Foundation Level Training
Related NHI Mgmt Group resources: GitHub Security for Beginners · Secrets in Code for Beginners · Account Takeover for Beginners
Key terms
- GitLab
- A website where teams store code and run automatic pipelines to test and ship it.
- Repository
- A project's files plus their full history of saved changes.
- Two-factor authentication
- Signing in with your password plus a second proof, such as a code from an app.
- Protected branch
- A branch with rules about who may push, merge or delete it.
- CI/CD pipeline
- A set of automatic jobs that test, build and release code.
- Runner
- The machine that carries out a pipeline's jobs.
- Push protection
- A check that can block a code upload when it seems to contain a secret.
Sources and further reading
- Personal access tokens. GitLab Docs, GitLab. https://docs.gitlab.com/user/profile/personal_access_tokens/, accessed 28 Nov 2026.
- Two-factor authentication. GitLab Docs, GitLab. https://docs.gitlab.com/user/profile/account/two_factor_authentication/, accessed 28 Nov 2026.
- CI/CD variables. GitLab Docs, GitLab. https://docs.gitlab.com/ci/variables/, accessed 28 Nov 2026.
- Protected branches. GitLab Docs, GitLab. https://docs.gitlab.com/user/project/repository/branches/protected/, accessed 28 Nov 2026.
- Secret detection. GitLab Docs, GitLab. https://docs.gitlab.com/user/application_security/secret_detection/, accessed 28 Nov 2026.