2FA Enforcement on the instance: a user logging in with SSO can bypass 2FA enforcement
Summary
On GitLab 17.8.4-ee, when 2FA is enforced on the instance with grace period 0, when a user logs in with email address / username and password, they are rightly prompted to setup 2FA on the next login. However, if they log in via SSO, they can simply bypass this requirement. A customer who originally reported this, is using OmniAuth with Amazon Cognito. However, I see the same if I simply log in with SAML to my test instance. My SAML configuration looks like this:
gitlab_rails['omniauth_allow_single_sign_on'] = ['saml']
gitlab_rails['omniauth_block_auto_created_users'] = false
gitlab_rails['omniauth_auto_link_saml_user'] = true
gitlab_rails['omniauth_providers'] = [
{
name: "saml",
groups_attribute: "Groups",
label: "Azure", # optional label for login button, defaults to "Saml"
args: {
assertion_consumer_service_url: [REDACTED],
idp_cert_fingerprint: "myThumbprint",
idp_sso_target_url: [REDACTED],
issuer: [REDACTED]",
name_identifier_format: "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent",
attribute_statements: {
email: ['email'],
name: ['displayname'],
first_name: ['firstname'],
last_name: ['lastname']
}
}
}
]
Which means I don't have upstream_two_factor_authn_contexts configured, which would allow me to bypass 2FA.
This is quite an urgent issue for our customer. They are a very big customer, and this is a security concern for them. Ticket: https://gitlab.zendesk.com/agent/tickets/609760
Steps to reproduce
- Spin up a
17.8.4-eeinstance. - Enforce 2FA on the instance with grace period 0
- Create a test user which you can use to log in with email address and password
- Log in and check that the user is being asked to setup 2FA
- Configure SAML for the instance, making sure not to set
upstream_two_factor_authn_contexts - Now add said user to a SAML app
- Login via SAML in a new incognito window
- Notice that now the user isn't being prompted to setup 2FA
Example Project
This happens on my test instance: [REDACTED] And also for the customer.
What is the current bug behavior?
Using SSO lets the user bypass the instance level 2FA requirement.
What is the expected correct behavior?
Using SSO should not let the customer get around the 2FA enforcement requirement.
Relevant logs and/or screenshots
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
root@sr-env-0472d3c0-omnibus:~# sudo gitlab-rake gitlab:env:info System information System: Ubuntu 20.04 Proxy: no Current User: git Using RVM: no Ruby Version: 3.2.5 Gem Version: 3.5.23 Bundler Version:2.5.11 Rake Version: 13.0.6 Redis Version: 7.0.15 Sidekiq Version:7.2.4 Go Version: unknown GitLab information Version: 17.8.4-ee Revision: 74ddb379313 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: PostgreSQL DB Version: 14.15 URL: https://sr-env-0472d3c0-omnibus.env-0472d3c0.gcp.gitlabsandbox.net HTTP Clone URL: https://sr-env-0472d3c0-omnibus.env-0472d3c0.gcp.gitlabsandbox.net/some-group/some-project.git SSH Clone URL: git@sr-env-0472d3c0-omnibus.env-0472d3c0.gcp.gitlabsandbox.net:some-group/some-project.git Elasticsearch: no Geo: no Using LDAP: no Using Omniauth: yes Omniauth Providers: saml GitLab Shell Version: 14.39.0 Repository storages: - default: unix:/var/opt/gitlab/gitaly/gitaly.socket GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell Gitaly - default Address: unix:/var/opt/gitlab/gitaly/gitaly.socket - default Version: 17.8.4 - default Git Version: 2.47.0 (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
root@sr-env-0472d3c0-omnibus:~# sudo gitlab-rake gitlab:check SANITIZE=true Checking GitLab subtasks ...
Checking GitLab Shell ...
GitLab Shell: ... GitLab Shell version >= 14.39.0 ? ... OK (14.39.0) Running /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-shell-check Internal API available: OK Redis available via internal API: OK gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Gitaly ...
Gitaly: ... default ... OK
Checking Gitaly ... Finished
Checking Sidekiq ...
Sidekiq: ... Running? ... yes Number of Sidekiq processes (cluster/worker) ... 1/1
Checking Sidekiq ... Finished
Checking Incoming Email ...
Incoming Email: ... Reply by email is disabled in config/gitlab.yml
Checking Incoming Email ... Finished
Checking LDAP ...
LDAP: ... LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab App ...
Database config exists? ... yes Tables are truncated? ... skipped All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Cable config exists? ... yes Resque config exists? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... skipped (no tmp uploads folder yet) Systemd unit files or init script exist? ... skipped (omnibus-gitlab has neither init script nor systemd units) Systemd unit files or init script up-to-date? ... skipped (omnibus-gitlab has neither init script nor systemd units) Projects have namespace: ... 2/1 ... yes Redis version >= 6.2.14? ... yes Ruby version >= 3.0.6 ? ... yes (3.2.5) Git user has default SSH configuration? ... yes Active users: ... 4 Is authorized keys file accessible? ... yes GitLab configured to store new projects in hashed storage? ... yes All projects are in hashed storage? ... yes Elasticsearch version 7.x-8.x or OpenSearch version 1.x ... skipped (Advanced Search is disabled) All migrations must be finished before doing a major upgrade ... skipped (Advanced Search is disabled)
Checking GitLab App ... Finished
Checking GitLab subtasks ... Finished