Git Course 0%

2FA, SSO, policies, least privilege

Intermediate GitLab UI GitHub UI ≈ 8 min

What you will learn

  • Why enabling 2FA changes how Git authenticates
  • What SSO adds, and the token authorization step people forget
  • The common organization policies and what they block

After this lesson you can

  • I understand why my token needs an extra step in an SSO organization
  • I ask for the access I need rather than the access that would be convenient

Why this matters

Security settings on the platform are chosen by someone else and change how your tools behave. The two that surprise people most are two-factor authentication, which makes account passwords useless for Git, and single sign-on, which quietly requires an extra click on every new token. Both produce errors that look like your mistake.

Two-factor authentication

That last point is the practical consequence, and GitLab says it in the error message itself:

Output
remote: HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2FA enabled and you must use a personal access token instead of a password.

Enable 2FA anyway; most organizations require it. Then use a token (lesson 8.3) or an SSH key (lesson 8.2), which are unaffected by the second factor because they are the second factor's replacement for machines.

Single sign-on

Larger organizations put GitLab or GitHub behind their identity provider (Okta, Entra ID, Google Workspace), so you sign in with your company account. Two things follow that regularly confuse people:

  • Sessions expire on the company's schedule. You may be signed out of the website daily; that does not affect an already-stored Git token.
  • Tokens and SSH keys need authorizing for the organization. On GitHub with SAML SSO, a new token works for your own repositories but is refused for the organization's until you authorize it: the token page has an Authorize or Configure SSO control next to each token, and the same applies to SSH keys. Missing this step produces a permission error that looks exactly like a scope problem.

If a token with the right scopes is refused for an organization's repository and works for your own, SSO authorization is almost always the reason.

Organization policies you will meet

Policy What it does What you notice
Required 2FA Members must enable 2FA to keep access A prompt, and a deadline
SSO enforcement Only company accounts may access Sign-in redirects to the company page
Token expiry limits Tokens may not outlive N days Your chosen expiry is shortened
IP allow lists Access only from company networks Everything fails from home without the VPN
Protected branches No direct pushes to main Lesson 6.9
Required approvals Merges need N reviewers The merge button stays disabled
Signed commits required Commits must be verified Lesson 8.8
Restricted forking Members may not fork to personal accounts The Fork button is missing or limited

You cannot change any of these; a maintainer, owner or administrator can. Knowing they exist means you recognize a policy at work rather than assuming your setup is broken.

Least privilege

The habit that makes all of this easier: ask for the smallest access that lets you do the work, and grant the same when it is your turn.

  • Roles: Developer (GitLab) or Write (GitHub) is enough to branch, push and open merge requests. Maintainer is for people who own the branch protection and the merge button (lesson 1.8).
  • Tokens: repository scopes, not api; one repository, not all of them.
  • Duration: a shorter expiry costs you one renewal a year and shrinks the window in which a leaked token is useful.
  • Ownership: automation gets a project token, not yours.

The reason is not bureaucratic. Every credential is a thing that can leak, and its scope decides how bad that day is.

Common mistakes

  • Treating the 2FA message as a password problem. It is telling you to use a token.
  • Forgetting SSO authorization for a new token or key. Works for personal repositories, refused for the organization's.
  • Storing recovery codes on the phone that holds the authenticator. Lose the phone, lose both.
  • Asking for Maintainer "to save time". More responsibility, more ways to break a shared branch, and usually a slower approval than asking for Developer.
  • Sharing a token with a colleague. Their actions then appear as yours. They should have their own.

Try it yourself

Goal: check your own security settings.

  1. Open your account's security page: GitLab Edit profile → Account; GitHub Settings → Password and authentication.
  2. Confirm whether 2FA is enabled. If it is not, and your organization allows it, enable it and save the recovery codes somewhere safe.
  3. Open the token page and check whether any token shows an SSO authorization control; if so, note which organizations each is authorized for.
  4. Look at your role on one project: GitLab Project information → Members; GitHub repository Settings → Collaborators (or ask, if you cannot see it).

Expected result: you know whether 2FA is on, whether SSO applies, and what your role on at least one project is.

Show solution

If you cannot see the Members or Collaborators page, that itself is the answer: you have a role below Maintainer, which is the normal and correct state for a contributor. Your role is visible to you on GitLab under the project's Manage → Members for most roles, and can always be confirmed by asking the maintainer.

Check yourself

1. You enabled 2FA and now git push over HTTPS fails with your password. Why?
2. A token with the right scopes works for your own repositories but is refused for your organization's, which uses SAML SSO. What is missing?
3. Which request follows least privilege?

Key terms

Maintainer Protected branch