Gitlab 422 error

Summary Similar to
Skip to content



Open


Issue created Dec 07, 2017 by Fermulator@fermulator

Error 422 The change you requested was rejected on login

Summary

Similar to #35447 (closed), however I have a base local gitlab install, revertted back to super basic defaults in gitlab.rb configuration (only serving up HTTP). Uncertain when, (gone through a few gitlab-ce upgrades without actually logging into the web UI..), suddenly a POST to /users/sign_in results in 422 «The change you requested was rejected on login»

Steps to reproduce

TBD greenfield reproduction … but for my instance, simply trying to AUTH using web UI as a local admin account results in this error.

Example Project

TBD

What is the current bug behavior?

  1. gitlab-ctl status shows all services up
  2. user visits http://gitlab-URI:80
  3. server redirects to http://gitlab-URI/users/sign_in
  4. user enters LOCAL login credentials (in my case it’s a local admin user to gitlab)
  5. page goes: POST /users/sign_in HTTP/1.1 422

What is the expected correct behavior?

successful auth
(the error message hints that «I may not have access to the thing I tried to change» … but I’m auth’ing as a local admin user, also even tried the root account, and even some bogus FOO/BAR account! all the same result

is this some convoluted way of saying «invalid user/pass»? — I doubt my primary user password is wrong however… since it’s saved and I can confirm by manually typing too.

Relevant logs and/or screenshots

 422
The change you requested was rejected.

Make sure you have access to the thing you tried to change.

Please contact your GitLab administrator if you think this is a mistake.

services are all up

# sudo gitlab-ctl status
run: gitaly: (pid 12534) 260s; run: log: (pid 892) 300573s
run: gitlab-monitor: (pid 12548) 260s; run: log: (pid 906) 300573s
run: gitlab-workhorse: (pid 12517) 261s; run: log: (pid 893) 300573s
run: logrotate: (pid 12558) 259s; run: log: (pid 894) 300573s
run: nginx: (pid 12564) 259s; run: log: (pid 885) 300573s
run: node-exporter: (pid 12572) 258s; run: log: (pid 886) 300573s
run: postgres-exporter: (pid 12578) 258s; run: log: (pid 896) 300573s
run: postgresql: (pid 11895) 307s; run: log: (pid 916) 300573s
run: prometheus: (pid 12586) 257s; run: log: (pid 919) 300573s
run: redis: (pid 11897) 307s; run: log: (pid 891) 300573s
run: redis-exporter: (pid 12598) 257s; run: log: (pid 897) 300573s
run: sidekiq: (pid 12609) 257s; run: log: (pid 902) 300573s
run: unicorn: (pid 12616) 256s; run: log: (pid 900) 300573s

/var/log/gitlab/nginx/gitlab_access.log shows:

1.0.0.6 - - [06/Dec/2017:22:03:20 -0500] "POST /users/sign_in HTTP/1.1" 422 2912 "http://gitlab-URI/users/sign_in" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0"

nothing from gitlab_error.log, … also sanity checked other logs for possible AUTH failures or something else, but nothing of interest or more additional logs

/var/log/gitlab# for dir in $(ls -1 .); do echo $dir; ls -alt $dir/ | head -5; done

My configuration for gitlab is super minimal

fermulator@fermmy-git:~$ sudo egrep -v "#" /etc/gitlab/gitlab.rb

external_url 'http://gitlab-URI:80'

git_data_dirs({
  "default": {
    "path": "/mnt/storage/git-data"
  }
})

Output of checks

n/a

Results of GitLab environment info

# gitlab-rake gitlab:env:info

System information
System:		Ubuntu 14.04
Current User:	git
Using RVM:	no
Ruby Version:	2.3.5p376
Gem Version:	2.6.13
Bundler Version:1.13.7
Rake Version:	12.1.0
Redis Version:	3.2.5
Git Version:	2.13.6
Sidekiq Version:5.0.4
Go Version:	unknown

GitLab information
Version:	10.2.3
Revision:	3141105
Directory:	/opt/gitlab/embedded/service/gitlab-rails
DB Adapter:	postgresql
URL:		http://<GIT-URI>
HTTP Clone URL:	http://<GIT-URI>/some-group/some-project.git
SSH Clone URL:	git@<GIT-URI>:some-group/some-project.git
Using LDAP:	no
Using Omniauth:	no

GitLab Shell
Version:	5.9.4
Repository storage paths:
- default: 	/mnt/storage/git-data/repositories
Hooks:		/opt/gitlab/embedded/service/gitlab-shell/hooks
Git:		/opt/gitlab/embedded/bin/git

Results of GitLab application Check

# gitlab-rake gitlab:check SANITIZE=true
Checking GitLab Shell ...

GitLab Shell version >= 5.9.4 ? ... OK (5.9.4)
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:root, or git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ... 
2/1 ... ok
2/2 ... ok
2/3 ... ok
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Check GitLab API access: OK
Redis available via internal API: OK

Access to /var/opt/gitlab/.ssh/authorized_keys: OK
gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes
Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Reply by email is disabled in config/gitlab.yml
Checking LDAP ...

LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab ...

Git configured correctly? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config up to date? ... 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)
Init script exists? ... skipped (omnibus-gitlab has no init script)
Init script up-to-date? ... skipped (omnibus-gitlab has no init script)
Projects have namespace: ... 
2/1 ... yes
2/2 ... yes
2/3 ... yes
Redis version >= 2.8.0? ... yes
Ruby version >= 2.3.5 ? ... yes (2.3.5)
Git version >= 2.7.3 ? ... yes (2.13.6)
Git user has default SSH configuration? ... yes
Active users: ... 3

Checking GitLab ... Finished

Possible fixes

UNKNOWN

Edited Dec 07, 2017 by Fermulator

This question asked by coderss but restarting the computer seems to noneffective.

422
The change you requested was rejected.
Make sure you have access to the thing you tried to change.
Please contact your GitLab administrator if you think this is a mistake.

I have above error in Firefox under Linux but I have access in Chromium.
That’s looks like typical cookie problem.

I tried clear all Gitlab related cookies then restarted computer without any new sign in attempt. and restarted computer :) yeah I just try

But still same error, same browser.

How can I handle this problem?

This error also occurs at forgot password section and in private tab of Firefox.

Is there another Gitlab related cookie?

asked Jan 21, 2021 at 4:21

maxemilian's user avatar

1

This was followed by issue 35447 and issue 40898.

The last one included:

Ok, I suspect the issue here for many people is that the GitLab session cookie is set to Secure here: https://gitlab.com/gitlab-org/gitlab-ce/blob/9c491bc628f5a72424b82bb01e2457150bf2e71c/config/initializers/session_store.rb#L25

Setting the right SSL headers fixes the problem.

If, for some reason, the connection doesn’t appear to be an HTTPS connection, Rails won’t send a cookie, and the client won’t be able to login. You may be able to confirm this by checking the response headers in the GET /users/sign_in endpoint: if you see a _gitlab_session cookie being sent the first time you load the page, then things are working properly.

And:

JuKu
JuKu @JuKu · 1 year ago

Solution for HaProxy:

Add these line to your frontend: reqadd X-Forwarded-Proto: http

After this change, it worked for me.

See also: https://www.digitalocean.com/community/tutorials/how-to-implement-ssl-termination-with-haproxy-on-ubuntu-14-04

That would avoid the dreaded:

https://gitlab.com/gitlab-org/gitlab-foss/uploads/7ef0738b531b0475e1f52a6fa700917a/Unbenannt101.PNG

But it depends on the type of GitLab used (gitlab.com or an on-premise GitLab, and the type of Web server used)

For example, issue 53085 refers to issue 54493:

The group had internal availability, while one of it’s projects was public (not the one I was having so much trouble with, which was private).

Making the group public solved the problem.


The OP maxemilian reports in the comments it is working now with Firefox on Manjaro:

I checked my updates diary, but only zoom matches between Firefox access time successfully.
I pretty sure this was related to GitLab login code. Suspicious dates (Jan 6- Jan 21 and Feb 3- Feb 6).
I think This update done by GitLab the dates between Feb 3- Feb 6.

answered Jan 21, 2021 at 8:14

VonC's user avatar

VonCVonC

1.2m508 gold badges4248 silver badges5069 bronze badges

5

In my case, server time was late and I had to change the time, then restart the server and reconfigure the gitlab.

Change server time

sudo timedatectl set-time "06:24:00"
sudo timedatectl set-time "2020-04-23"
sudo hwclock --systohc

Reconfigure Gitlab.

sudo gitlab-ctl reconfigure

answered Apr 14, 2022 at 4:04

Jacob Aguilar's user avatar

3

Empty Cache and Hard Reload on chrome will do the trick

answered May 30, 2022 at 17:41

Mayank Kalbhor's user avatar

0

In my case I was trying to fetch changes using a Git command and also got this error. It turned out that I was using the wrong URL. The .git suffix was missing. Curiously it worked the first time.

answered Jan 24 at 10:45

Torben Kohlmeier's user avatar

Torben KohlmeierTorben Kohlmeier

6,6231 gold badge15 silver badges15 bronze badges

For me it was the VPN. If you are connected to a VPN set to a different timezone, turn it off, clear the cookies and you should be able to connect.

answered Oct 6, 2022 at 7:51

Raymond's user avatar

Hi,

I’m already using this Repo for a longer time and I’m pretty happy with it. So first of all thanks for the great work to the maintainers.

Now I have updated my GitLab instance to 15.0.2 and moved my domain which is working with a letsencrypt https certificate. Since then I most of the time I get logged out from GitLab and receive an error 422. Sometimes I’m also able to klick onto another page. But then I see in the developer tools already that some ressources like icons can’t be loaded due to an error 401. If have googled and debugged this error now for a longer time but found nothing that really helped.

In front of my GitLab Instance I have setup an NGINX reverse proxy which worked also pretty good for a long time. It is in the same network as the GitLab-Docker-Containers and its current configuration looks like this right now:

upstream gitlab_upstream {
    server 172.21.3.1:80 fail_timeout=0;
}

server {
    listen 80;
    server_name gitlab.xyz.de;

    location / {
      return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name gitlab.xyz.de;

    server_tokens off;

    ssl_certificate /etc/letsencrypt/lego/xyz.de.crt;
    ssl_certificate_key /etc/letsencrypt/lego/xyz.de.key;

    ssl_buffer_size 8k;

    ssl_dhparam /etc/ssl/certs/dhparam-2048.pem;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;

    ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;

    ssl_ecdh_curve secp384r1;
    ssl_session_tickets off;

    # OCSP stapling
    ssl_stapling on;
    ssl_stapling_verify on;
    # resolver 8.8.8.8;

    # proxy_buffering off;
    client_max_body_size 10G;

    location / {
        gzip off;
        include /etc/nginx/proxy_params
        proxy_set_header    X-Forwarded-Ssl     on;
        proxy_pass http://gitlab_upstream;
        # proxy_set_header Host $http_host;
        # proxy_set_header X-Real-IP $remote_addr;
        # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        # proxy_set_header X-Forwarded-Proto $scheme;
        # proxy_set_header X-Frame-Options   SAMEORIGIN;

        #security headers
        # add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
        # add_header X-Content-Type-Options "nosniff" always;


        # add_header Referrer-Policy "strict-origin-when-cross-origin" always;


        # Hide server information
        # proxy_hide_header X-Powered-By;
    }
}

My docker-compose config looks like this:

version: '2'

networks:
    nginx_proxy-tier:
        external: true

services:
  redis:
    restart: 'no'
    image: redis:6.2.6
    command:
    - --loglevel warning
    volumes:
    - ./volumes/redis:/var/lib/redis:Z
    networks:
        nginx_proxy-tier:
            ipv4_address: 172.21.3.2

  postgresql:
    restart: 'no'
    image: sameersbn/postgresql:12-20200524
    volumes:
    - ./volumes/postgresql:/var/lib/postgresql:Z
    environment:
    - DB_USER=gitlab
    - DB_PASS=
    - DB_NAME=gitlabhq_production
    - DB_EXTENSION=pg_trgm,btree_gist
    networks:
        nginx_proxy-tier:
            ipv4_address: 172.21.3.3
  gitlab:
    restart: 'no'
    image: 'sameersbn/gitlab:15.0.2'
    #command: /bin/bash
    depends_on:
    - redis
    - postgresql
    ports:
    - "10080:80"
    - "10022:22"
    volumes:
    - ./volumes/gitlab:/home/git/data:Z

    networks:
        nginx_proxy-tier:
            ipv4_address: 172.21.3.1

    environment:
    - DEBUG=false

    - DB_ADAPTER=postgresql
    - DB_HOST=postgresql
    - DB_PORT=5432
    - DB_USER=gitlab
    - DB_PASS=
    - DB_NAME=gitlabhq_production

    - REDIS_HOST=redis
    - REDIS_PORT=6379

    - TZ=Europe/Berlin
    - GITLAB_TIMEZONE=Berlin

    - GITLAB_HTTPS=true
    - SSL_SELF_SIGNED=true
    - GITLAB_HOST=gitlab.xyz.de
    - GITLAB_PORT=10080
    - GITLAB_SSH_PORT=10022
    - GITLAB_SSH_HOST=gitlab.xyz.de
    - GITLAB_RELATIVE_URL_ROOT=
    - GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alphanumeric-string
    - GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alphanumeric-string
    - GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alphanumeric-string

    - GITLAB_ROOT_PASSWORD=
    - GITLAB_ROOT_EMAIL=

    - GITLAB_NOTIFY_ON_BROKEN_BUILDS=true
    - GITLAB_NOTIFY_PUSHER=false

    - GITLAB_EMAIL=
    - GITLAB_EMAIL_REPLY_TO=
    - GITLAB_INCOMING_EMAIL_ADDRESS=

    - GITLAB_BACKUP_SCHEDULE=daily
    - GITLAB_BACKUP_TIME=01:00

    - SMTP_ENABLED=true
    - SMTP_DOMAIN=www.web.de
    - SMTP_HOST=smtp.web.de
    - SMTP_PORT=587
    - SMTP_USER=
    - SMTP_PASS=
    - SMTP_STARTTLS=true
    - SMTP_TLS=false
    - SMTP_AUTHENTICATION=login


    - IMAP_ENABLED=false
    - IMAP_HOST=imap.gmail.com
    - IMAP_PORT=993
    - IMAP_USER=mailer@example.com
    - IMAP_PASS=password
    - IMAP_SSL=true
    - IMAP_STARTTLS=false

    - OAUTH_ENABLED=false
    - OAUTH_AUTO_SIGN_IN_WITH_PROVIDER=
    - OAUTH_ALLOW_SSO=
    - OAUTH_BLOCK_AUTO_CREATED_USERS=true
    - OAUTH_AUTO_LINK_LDAP_USER=false
    - OAUTH_AUTO_LINK_SAML_USER=false
    - OAUTH_EXTERNAL_PROVIDERS=

    - OAUTH_CAS3_LABEL=cas3
    - OAUTH_CAS3_SERVER=
    - OAUTH_CAS3_DISABLE_SSL_VERIFICATION=false
    - OAUTH_CAS3_LOGIN_URL=/cas/login
    - OAUTH_CAS3_VALIDATE_URL=/cas/p3/serviceValidate
    - OAUTH_CAS3_LOGOUT_URL=/cas/logout

    - OAUTH_GOOGLE_API_KEY=
    - OAUTH_GOOGLE_APP_SECRET=
    - OAUTH_GOOGLE_RESTRICT_DOMAIN=

    - OAUTH_FACEBOOK_API_KEY=
    - OAUTH_FACEBOOK_APP_SECRET=

    - OAUTH_TWITTER_API_KEY=
    - OAUTH_TWITTER_APP_SECRET=

    - OAUTH_GITHUB_API_KEY=
    - OAUTH_GITHUB_APP_SECRET=
    - OAUTH_GITHUB_URL=
    - OAUTH_GITHUB_VERIFY_SSL=

    - OAUTH_GITLAB_API_KEY=
    - OAUTH_GITLAB_APP_SECRET=

    - OAUTH_BITBUCKET_API_KEY=
    - OAUTH_BITBUCKET_APP_SECRET=

    - OAUTH_SAML_ASSERTION_CONSUMER_SERVICE_URL=
    - OAUTH_SAML_IDP_CERT_FINGERPRINT=
    - OAUTH_SAML_IDP_SSO_TARGET_URL=
    - OAUTH_SAML_ISSUER=
    - OAUTH_SAML_LABEL="Our SAML Provider"
    - OAUTH_SAML_NAME_IDENTIFIER_FORMAT=urn:oasis:names:tc:SAML:2.0:nameid-format:transient
    - OAUTH_SAML_GROUPS_ATTRIBUTE=
    - OAUTH_SAML_EXTERNAL_GROUPS=
    - OAUTH_SAML_ATTRIBUTE_STATEMENTS_EMAIL=
    - OAUTH_SAML_ATTRIBUTE_STATEMENTS_NAME=
    - OAUTH_SAML_ATTRIBUTE_STATEMENTS_USERNAME=
    - OAUTH_SAML_ATTRIBUTE_STATEMENTS_FIRST_NAME=
    - OAUTH_SAML_ATTRIBUTE_STATEMENTS_LAST_NAME=

    - OAUTH_CROWD_SERVER_URL=
    - OAUTH_CROWD_APP_NAME=
    - OAUTH_CROWD_APP_PASSWORD=

    - OAUTH_AUTH0_CLIENT_ID=
    - OAUTH_AUTH0_CLIENT_SECRET=
    - OAUTH_AUTH0_DOMAIN=

    - OAUTH_AZURE_API_KEY=
    - OAUTH_AZURE_API_SECRET=
    - OAUTH_AZURE_TENANT_ID=

In the production.log I can find the following errors:

Processing by Gitlab::RequestForgeryProtection::Controller#index as HTML
Can't verify CSRF token authenticity.
Completed 422 Unprocessable Entity in 1ms (ActiveRecord: 0.0ms | Elasticsearch: 0.0ms | Allocations: 221)
Can't verify CSRF token authenticity.
Completed 200 OK in 29ms (Views: 0.2ms | ActiveRecord: 2.6ms | Elasticsearch: 0.0ms | Allocations: 12801)
Started GET "/uploads/-/system/project/avatar/34/docker-icon.png" for 95.89.243.88 at 2022-06-12 19:43:19 +0200
Processing by UploadsController#show as HTML
  Parameters: {"model"=>"project", "mounted_as"=>"avatar", "id"=>"34", "filename"=>"docker-icon.png"}
Completed 401 Unauthorized in 6ms (ActiveRecord: 1.0ms | Elasticsearch: 0.0ms | Allocations: 2362)

Thanks in advance for your help.

Kind regards,
Stephan

API Docs (FREE)

Use the GitLab APIs to automate GitLab.

You can also use a partial OpenAPI definition,
to test the API directly from the GitLab user interface.
Contributions are welcome.

REST API

A REST API is available in GitLab.
Usage instructions are below.
For a list of the available resources and their endpoints, see
REST API resources.

For an introduction and basic steps, see
How to make GitLab API calls.

SCIM API (PREMIUM SAAS)

GitLab provides an SCIM API that both implements
the RFC7644 protocol and provides the
/Users endpoint. The base URL is /api/scim/v2/groups/:group_path/Users/.

GraphQL API

A GraphQL API is available in GitLab.

With GraphQL, you can make an API request for only what you need,
and it’s versioned by default.

GraphQL co-exists with the current v4 REST API. If we have a v5 API, this should
be a compatibility layer on top of GraphQL.

There were some patenting and licensing concerns with GraphQL. However, these
have been resolved to our satisfaction. The reference implementations
were re-licensed under MIT, and the OWF license used for the GraphQL specification.

When GraphQL is fully implemented, GitLab:

  • Can delete controller-specific endpoints.
  • Will no longer maintain two different APIs.

Compatibility guidelines

The HTTP API is versioned with a single number, which is currently 4. This number
symbolizes the major version number, as described by SemVer.
Because of this, backward-incompatible changes require this version number to
change.

The minor version isn’t explicit, which allows for a stable API
endpoint. New features can be added to the API in the same
version number.

New features and bug fixes are released in tandem with GitLab. Apart
from incidental patch and security releases, GitLab is released on the 22nd of each
month. Major API version changes, and removal of entire API versions, are done in tandem
with major GitLab releases.

All deprecations and changes between versions are in the documentation.
For the changes between v3 and v4, see the v3 to v4 documentation.

Current status

Only API version v4 is available. Version v3 was removed in
GitLab 11.0.

How to use the API

API requests must include both api and the API version. The API
version is defined in lib/api.rb.
For example, the root of the v4 API is at /api/v4.

Valid API request

If you have a GitLab instance at gitlab.example.com:

curl "https://gitlab.example.com/api/v4/projects"

The API uses JSON to serialize data. You don’t need to specify .json at the
end of the API URL.

API request to expose HTTP response headers

If you want to expose HTTP response headers, use the --include option:

curl --include "https://gitlab.example.com/api/v4/projects"
HTTP/2 200
...

This request can help you investigate an unexpected response.

API request that includes the exit code

If you want to expose the HTTP exit code, include the --fail option:

curl --fail "https://gitlab.example.com/api/v4/does-not-exist"
curl: (22) The requested URL returned error: 404

The HTTP exit code can help you diagnose the success or failure of your REST request.

Authentication

Most API requests require authentication, or only return public data when
authentication isn’t provided. When authentication is not required, the documentation
for each endpoint specifies this. For example, the
/projects/:id endpoint does not require authentication.

There are several ways you can authenticate with the GitLab API:

  • OAuth2 tokens
  • Personal access tokens
  • Project access tokens
  • Session cookie
  • GitLab CI/CD job token (Specific endpoints only)

Project access tokens are supported by:

  • Self-managed GitLab Free and higher.
  • GitLab SaaS Premium and higher.

If you are an administrator, you or your application can authenticate as a specific user.
To do so, use:

  • Impersonation tokens
  • Sudo

If authentication information is not valid or is missing, GitLab returns an error
message with a status code of 401:

{
  "message": "401 Unauthorized"
}

OAuth2 tokens

You can use an OAuth2 token to authenticate with the API by passing
it in either the access_token parameter or the Authorization header.

Example of using the OAuth2 token in a parameter:

curl "https://gitlab.example.com/api/v4/projects?access_token=OAUTH-TOKEN"

Example of using the OAuth2 token in a header:

curl --header "Authorization: Bearer OAUTH-TOKEN" "https://gitlab.example.com/api/v4/projects"

Read more about GitLab as an OAuth2 provider.

NOTE:
We recommend OAuth access tokens have an expiration. You can use the refresh_token parameter
to refresh tokens. Integrations may need to be updated to use refresh tokens prior to
expiration, which is based on the expires_in
property in the token endpoint response. See OAuth2 token documentation
for examples requesting a new access token using a refresh token.

A default refresh setting of two hours is tracked in this issue.

Personal/project access tokens

You can use access tokens to authenticate with the API by passing it in either
the private_token parameter or the PRIVATE-TOKEN header.

Example of using the personal or project access token in a parameter:

curl "https://gitlab.example.com/api/v4/projects?private_token=<your_access_token>"

Example of using the personal or project access token in a header:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects"

You can also use personal or project access tokens with OAuth-compliant headers:

curl --header "Authorization: Bearer <your_access_token>" "https://gitlab.example.com/api/v4/projects"

Session cookie

Signing in to the main GitLab application sets a _gitlab_session cookie. The
API uses this cookie for authentication if it’s present. Using the API to
generate a new session cookie isn’t supported.

The primary user of this authentication method is the web frontend of GitLab
itself. The web frontend can use the API as the authenticated user to get a
list of projects without explicitly passing an access token.

GitLab CI/CD job token

When a pipeline job is about to run, GitLab generates a unique token and injects it as the
CI_JOB_TOKEN predefined variable.

You can use a GitLab CI/CD job token to authenticate with specific API endpoints:

  • Packages:
    • Package Registry. To push to the
      Package Registry, you can use deploy tokens.
    • Container Registry
      (the $CI_REGISTRY_PASSWORD is $CI_JOB_TOKEN).
    • Container Registry API (scoped to the job’s project, when the ci_job_token_scope feature flag is enabled)
  • Get job artifacts.
  • Get job token’s job.
  • Pipeline triggers, using the token= parameter.
  • Release creation.
  • Terraform plan.

The token has the same permissions to access the API as the user that triggers the
pipeline. Therefore, this user must be assigned to a role that has the required privileges.

The token is valid only while the pipeline job runs. After the job finishes, you can’t
use the token anymore.

A job token can access a project’s resources without any configuration, but it might
give extra permissions that aren’t necessary. There is a proposal
to redesign the feature for more strategic control of the access permissions.

GitLab CI/CD job token security

To make sure that this token doesn’t leak, GitLab:

  • Masks the job token in job logs.
  • Grants permissions to the job token only when the job is running.

To make sure that this token doesn’t leak, you should also configure
your runners to be secure. Avoid:

  • Using Docker’s privileged mode if the machines are re-used.
  • Using the shell executor when jobs
    run on the same machine.

If you have an insecure GitLab Runner configuration, you increase the risk that someone
tries to steal tokens from other jobs.

Limit GitLab CI/CD job token access

  • Introduced in GitLab 14.1.
  • Deployed behind a feature flag, disabled by default.
  • Disabled on GitLab.com.
  • Not recommended for production use.
  • To use in GitLab self-managed instances, ask a GitLab administrator to enable it. (FREE SELF)

This in-development feature might not be available for your use. There can be
risks when enabling features still in development.
Refer to this feature’s version history for more details.

You can limit the access scope of a project’s CI/CD job token to increase the
job token’s security. A job token might give extra permissions that aren’t necessary
to access specific private resources. Limiting the job token access scope reduces the risk of a leaked
token being used to access private data that the user associated to the job can access.

Control the job token access scope with an allowlist of other projects authorized
to be accessed by authenticating with the current project’s job token. By default
the token scope only allows access to the same project where the token comes from.
Other projects can be added and removed by maintainers with access to both projects.

This setting is enabled by default for all new projects, and disabled by default in projects
created before GitLab 14.1. It is strongly recommended that project maintainers enable this
setting at all times, and configure the allowlist for cross-project access if needed.

For example, when the setting is enabled, jobs in a pipeline in project A have
a CI_JOB_TOKEN scope limited to project A. If the job needs to use the token
to make an API request to a private project B, then B must be added to the allowlist for A.
If project B is public or internal, it doesn’t need to be added to the allowlist.
The job token scope is only for controlling access to private projects.

To enable and configure the job token scope limit:

  1. On the top bar, select Menu > Projects and find your project.
  2. On the left sidebar, select Settings > CI/CD.
  3. Expand Token Access.
  4. Toggle Limit CI_JOB_TOKEN access to enabled.
  5. (Optional) Add existing projects to the token’s access scope. The user adding a
    project must have the maintainer role in both projects.

If the job token scope limit is disabled, the token can potentially be used to authenticate
API requests to all projects accessible to the user that triggered the job.

There is a proposal to improve
the feature with more strategic control of the access permissions.

Enable or disable CI job token scope limit (FREE SELF)

The GitLab CI/CD job token access scope limit is under development and not ready for production
use. It is deployed behind a feature flag that is disabled by default.
GitLab administrators with access to the GitLab Rails console
can enable it.

To enable it:

Feature.enable(:ci_scoped_job_token)

To disable it:

Feature.disable(:ci_scoped_job_token)

Impersonation tokens

Impersonation tokens are a type of personal access token.
They can be created only by an administrator, and are used to authenticate with the
API as a specific user.

Use impersonation tokens an alternative to:

  • The user’s password or one of their personal access tokens.
  • The Sudo feature. The user’s or administrator’s password or token
    may not be known, or may change over time.

For more information, see the users API
documentation.

Impersonation tokens are used exactly like regular personal access tokens, and
can be passed in either the private_token parameter or the PRIVATE-TOKEN
header.

Disable impersonation

Introduced in GitLab 11.6.

By default, impersonation is enabled. To disable impersonation:

For Omnibus installations

  1. Edit the /etc/gitlab/gitlab.rb file:

    gitlab_rails['impersonation_enabled'] = false
  2. Save the file, and then reconfigure
    GitLab for the changes to take effect.

To re-enable impersonation, remove this configuration, and then reconfigure
GitLab.

For installations from source

  1. Edit the config/gitlab.yml file:

    gitlab:
      impersonation_enabled: false
  2. Save the file, and then restart
    GitLab for the changes to take effect.

To re-enable impersonation, remove this configuration, and then restart GitLab.

Sudo

All API requests support performing an API request as if you were another user,
provided you’re authenticated as an administrator with an OAuth or personal
access token that has the sudo scope. The API requests are executed with the
permissions of the impersonated user.

As an administrator, pass the sudo parameter either
by using query string or a header with an ID or username (case insensitive) of
the user you want to perform the operation as. If passed as a header, the header
name must be Sudo.

If a non administrative access token is provided, GitLab returns an error
message with a status code of 403:

{
  "message": "403 Forbidden - Must be admin to use sudo"
}

If an access token without the sudo scope is provided, an error message is
be returned with a status code of 403:

{
  "error": "insufficient_scope",
  "error_description": "The request requires higher privileges than provided by the access token.",
  "scope": "sudo"
}

If the sudo user ID or username cannot be found, an error message is
returned with a status code of 404:

{
  "message": "404 User with ID or username '123' Not Found"
}

Example of a valid API request and a request using cURL with sudo request,
providing a username:

GET /projects?private_token=<your_access_token>&sudo=username
curl --header "PRIVATE-TOKEN: <your_access_token>" --header "Sudo: username" "https://gitlab.example.com/api/v4/projects"

Example of a valid API request and a request using cURL with sudo request,
providing an ID:

GET /projects?private_token=<your_access_token>&sudo=23
curl --header "PRIVATE-TOKEN: <your_access_token>" --header "Sudo: 23" "https://gitlab.example.com/api/v4/projects"

Status codes

The API is designed to return different status codes according to context and
action. This way, if a request results in an error, you can get
insight into what went wrong.

The following table gives an overview of how the API functions generally behave.

Request type Description
GET Access one or more resources and return the result as JSON.
POST Return 201 Created if the resource is successfully created and return the newly created resource as JSON.
GET / PUT Return 200 OK if the resource is accessed or modified successfully. The (modified) result is returned as JSON.
DELETE Returns 204 No Content if the resource was deleted successfully.

The following table shows the possible return codes for API requests.

Return values Description
200 OK The GET, PUT or DELETE request was successful, and the resource(s) itself is returned as JSON.
204 No Content The server has successfully fulfilled the request, and there is no additional content to send in the response payload body.
201 Created The POST request was successful, and the resource is returned as JSON.
304 Not Modified The resource hasn’t been modified since the last request.
400 Bad Request A required attribute of the API request is missing. For example, the title of an issue is not given.
401 Unauthorized The user isn’t authenticated. A valid user token is necessary.
403 Forbidden The request isn’t allowed. For example, the user isn’t allowed to delete a project.
404 Not Found A resource couldn’t be accessed. For example, an ID for a resource couldn’t be found.
405 Method Not Allowed The request isn’t supported.
409 Conflict A conflicting resource already exists. For example, creating a project with a name that already exists.
412 The request was denied. This can happen if the If-Unmodified-Since header is provided when trying to delete a resource, which was modified in between.
422 Unprocessable The entity couldn’t be processed.
429 Too Many Requests The user exceeded the application rate limits.
500 Server Error While handling the request, something went wrong on the server.

Pagination

GitLab supports the following pagination methods:

  • Offset-based pagination. This is the default method and is available on all endpoints.
  • Keyset-based pagination. Added to selected endpoints but being
    progressively rolled out.

For large collections, for performance reasons we recommend keyset pagination
(when available) instead of offset pagination.

Offset-based pagination

Sometimes, the returned result spans many pages. When listing resources, you can
pass the following parameters:

Parameter Description
page Page number (default: 1).
per_page Number of items to list per page (default: 20, max: 100).

In the following example, we list 50 namespaces per page:

curl --request GET --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/namespaces?per_page=50"

Pagination Link header

Link headers are returned with each
response. They have rel set to prev, next, first, or last and contain
the relevant URL. Be sure to use these links instead of generating your own URLs.

For GitLab.com users, some pagination headers may not be returned.

In the following cURL example, we limit the output to three items per page
(per_page=3) and we request the second page (page=2) of comments
of the issue with ID 8 which belongs to the project with ID 9:

curl --head --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/9/issues/8/notes?per_page=3&page=2"

The response is:

HTTP/2 200 OK
cache-control: no-cache
content-length: 1103
content-type: application/json
date: Mon, 18 Jan 2016 09:43:18 GMT
link: <https://gitlab.example.com/api/v4/projects/8/issues/8/notes?page=1&per_page=3>; rel="prev", <https://gitlab.example.com/api/v4/projects/8/issues/8/notes?page=3&per_page=3>; rel="next", <https://gitlab.example.com/api/v4/projects/8/issues/8/notes?page=1&per_page=3>; rel="first", <https://gitlab.example.com/api/v4/projects/8/issues/8/notes?page=3&per_page=3>; rel="last"
status: 200 OK
vary: Origin
x-next-page: 3
x-page: 2
x-per-page: 3
x-prev-page: 1
x-request-id: 732ad4ee-9870-4866-a199-a9db0cde3c86
x-runtime: 0.108688
x-total: 8
x-total-pages: 3

Other pagination headers

GitLab also returns the following additional pagination headers:

Header Description
x-next-page The index of the next page.
x-page The index of the current page (starting at 1).
x-per-page The number of items per page.
X-prev-page The index of the previous page.
x-total The total number of items.
x-total-pages The total number of pages.

For GitLab.com users, some pagination headers may not be returned.

Keyset-based pagination

Keyset-pagination allows for more efficient retrieval of pages and — in contrast
to offset-based pagination — runtime is independent of the size of the
collection.

This method is controlled by the following parameters:

Parameter Description
pagination keyset (to enable keyset pagination).
per_page Number of items to list per page (default: 20, max: 100).

In the following example, we list 50 projects per page, ordered
by id ascending.

curl --request GET --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects?pagination=keyset&per_page=50&order_by=id&sort=asc"

The response header includes a link to the next page. For example:

HTTP/1.1 200 OK
...
Links: <https://gitlab.example.com/api/v4/projects?pagination=keyset&per_page=50&order_by=id&sort=asc&id_after=42>; rel="next"
Link: <https://gitlab.example.com/api/v4/projects?pagination=keyset&per_page=50&order_by=id&sort=asc&id_after=42>; rel="next"
Status: 200 OK
...

WARNING:
The Links header is scheduled to be removed in GitLab 14.0 to be aligned with the
W3C Link specification. The Link
header was added in GitLab 13.1
and should be used instead.

The link to the next page contains an additional filter id_after=42 that
excludes already-retrieved records. The type of filter depends on the
order_by option used, and we may have more than one additional filter.

When the end of the collection is reached and there are no additional
records to retrieve, the Link header is absent and the resulting array is
empty.

We recommend using only the given link to retrieve the next page instead of
building your own URL. Apart from the headers shown, we don’t expose additional
pagination headers.

Keyset-based pagination is supported only for selected resources and ordering
options:

Resource Order
Projects order_by=id only.

Path parameters

If an endpoint has path parameters, the documentation displays them with a
preceding colon.

For example:

DELETE /projects/:id/share/:group_id

The :id path parameter needs to be replaced with the project ID, and the
:group_id needs to be replaced with the ID of the group. The colons :
shouldn’t be included.

The resulting cURL request for a project with ID 5 and a group ID of 17 is then:

curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/share/17"

Path parameters that are required to be URL-encoded must be followed. If not,
it doesn’t match an API endpoint and responds with a 404. If there’s
something in front of the API (for example, Apache), ensure that it doesn’t decode
the URL-encoded path parameters.

Namespaced path encoding

If using namespaced API requests, make sure that the NAMESPACE/PROJECT_PATH is
URL-encoded.

For example, / is represented by %2F:

GET /api/v4/projects/diaspora%2Fdiaspora

A project’s path isn’t necessarily the same as its name. A project’s path is
found in the project’s URL or in the project’s settings, under
General > Advanced > Change path.

File path, branches, and tags name encoding

If a file path, branch or tag contains a /, make sure it is URL-encoded.

For example, / is represented by %2F:

GET /api/v4/projects/1/repository/files/src%2FREADME.md?ref=master
GET /api/v4/projects/1/branches/my%2Fbranch/commits
GET /api/v4/projects/1/repository/tags/my%2Ftag

Request Payload

API Requests can use parameters sent as query strings
or as a payload body.
GET requests usually send a query string, while PUT or POST requests usually
send the payload body:

  • Query string:

    curl --request POST "https://gitlab/api/v4/projects?name=<example-name>&description=<example-description>"
  • Request payload (JSON):

    curl --request POST --header "Content-Type: application/json" 
         --data '{"name":"<example-name>", "description":"<example-description"}' "https://gitlab/api/v4/projects"

URL encoded query strings have a length limitation. Requests that are too large
result in a 414 Request-URI Too Large error message. This can be resolved by
using a payload body instead.

Encoding API parameters of array and hash types

You can request the API with array and hash types parameters:

array

import_sources is a parameter of type array:

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" 
-d "import_sources[]=github" 
-d "import_sources[]=bitbucket" 
"https://gitlab.example.com/api/v4/some_endpoint"

hash

override_params is a parameter of type hash:

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" 
--form "namespace=email" 
--form "path=impapi" 
--form "file=@/path/to/somefile.txt"
--form "override_params[visibility]=private" 
--form "override_params[some_other_param]=some_value" 
"https://gitlab.example.com/api/v4/projects/import"

Array of hashes

variables is a parameter of type array containing hash key/value pairs
[{ 'key': 'UPLOAD_TO_S3', 'value': 'true' }]:

curl --globoff --request POST --header "PRIVATE-TOKEN: <your_access_token>" 
"https://gitlab.example.com/api/v4/projects/169/pipeline?ref=master&variables[][key]=VAR1&variables[][value]=hello&variables[][key]=VAR2&variables[][value]=world"

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" 
--header "Content-Type: application/json" 
--data '{ "ref": "master", "variables": [ {"key": "VAR1", "value": "hello"}, {"key": "VAR2", "value": "world"} ] }' 
"https://gitlab.example.com/api/v4/projects/169/pipeline"

id vs iid

Some resources have two similarly-named fields. For example, issues,
merge requests, and project milestones.
The fields are:

  • id: ID that is unique across all projects.
  • iid: Additional, internal ID (displayed in the web UI) that’s unique in the
    scope of a single project.

If a resource has both the iid field and the id field, the iid field is
usually used instead of id to fetch the resource.

For example, suppose a project with id: 42 has an issue with id: 46 and
iid: 5. In this case:

  • A valid API request to retrieve the issue is GET /projects/42/issues/5.
  • An invalid API request to retrieve the issue is GET /projects/42/issues/46.

Not all resources with the iid field are fetched by iid. For guidance
regarding which field to use, see the documentation for the specific resource.

Data validation and error reporting

When working with the API you may encounter validation errors, in which case
the API returns an HTTP 400 error.

Such errors appear in the following cases:

  • A required attribute of the API request is missing (for example, the title of
    an issue isn’t given).
  • An attribute did not pass the validation (for example, the user bio is too
    long).

When an attribute is missing, you receive something like:

HTTP/1.1 400 Bad Request
Content-Type: application/json
{
    "message":"400 (Bad request) "title" not given"
}

When a validation error occurs, error messages are different. They hold
all details of validation errors:

HTTP/1.1 400 Bad Request
Content-Type: application/json
{
    "message": {
        "bio": [
            "is too long (maximum is 255 characters)"
        ]
    }
}

This makes error messages more machine-readable. The format can be described as
follows:

{
    "message": {
        "<property-name>": [
            "<error-message>",
            "<error-message>",
            ...
        ],
        "<embed-entity>": {
            "<property-name>": [
                "<error-message>",
                "<error-message>",
                ...
            ],
        }
    }
}

Unknown route

When you attempt to access an API URL that doesn’t exist, you receive a
404 Not Found message.

HTTP/1.1 404 Not Found
Content-Type: application/json
{
    "error": "404 Not Found"
}

Encoding + in ISO 8601 dates

If you need to include a + in a query parameter, you may need to use %2B
instead, due to a W3 recommendation
that causes a + to be interpreted as a space. For example, in an ISO 8601 date,
you may want to include a specific time in ISO 8601 format, such as:

2017-10-17T23:11:13.000+05:30

The correct encoding for the query parameter would be:

2017-10-17T23:11:13.000%2B05:30

Clients

There are many unofficial GitLab API Clients for most of the popular programming
languages. For a complete list, visit the GitLab website.

Rate limits

For administrator documentation on rate limit settings, see
Rate limits. To find the settings that are
specifically used by GitLab.com, see
GitLab.com-specific rate limits.

Content type

The GitLab API supports the application/json content type by default, though
some API endpoints also support text/plain.

In GitLab 13.10 and later,
API endpoints do not support text/plain by default, unless it’s explicitly documented.

Этот вопрос задан coderss , но перезагрузка компьютера кажется неэффективной.

422 Запрошенное вами изменение было отклонено. Убедитесь, что у вас есть доступ к тому, что вы пытались изменить. Если вы считаете, что это ошибка, обратитесь к администратору GitLab.

У меня есть указанная выше ошибка в Firefox под Linux, но у меня есть доступ в Chromium. Это похоже на типичную проблему с файлами cookie.

Я попытался очистить все файлы cookie, связанные с Gitlab, затем перезагрузил компьютер без новой попытки входа. и перезагрузил компьютер :) да, я просто пробую

Но все та же ошибка, тот же браузер.

Как я могу справиться с этой проблемой?

Эта ошибка также возникает в разделе забытого пароля и на частной вкладке Firefox.

Есть ли еще один файл cookie, связанный с Gitlab?

1 ответ

Лучший ответ

За этим последовали проблема 35447 и проблема 40898.

Последний включал:

Хорошо, я подозреваю, что проблема здесь для многих заключается в том, что файл cookie сеанса GitLab настроен на Secure здесь: https://gitlab.com/gitlab-org/gitlab-ce/blob/9c491bc628f5a72424b82bb01e2457150bf2e71c/config/initializers.rsession_store_store

Установка правильных заголовков SSL решает проблему.

Если по какой-то причине соединение не похоже на HTTPS-соединение, Rails не будет отправлять cookie, и клиент не сможет войти в систему. Вы можете подтвердить это, проверив заголовки ответа в конечной точке GET /users/sign_in: если вы видите, что файл cookie _gitlab_session отправляется при первой загрузке страницы, значит, все работает правильно.

А также:

JuKu JuKu @JuKu · 1 год назад

Решение для HaProxy:

Добавьте эту строку в свой интерфейс: reqadd X-Forwarded-Proto: http

После этого изменения у меня все заработало.

См. Также: https://www.digitalocean.com/community/tutorials/how-to-implement-ssl-termination-with-haproxy-on-ubuntu-14-04

Это позволит избежать ужасного:

https://gitlab.com/gitlab-org/gitlab-foss/uploads/7ef0738b531b0475e1f52a6fa700917a/Unbenannt101.PNG

Но это зависит от типа используемого GitLab (gitlab.com или локальный GitLab, а также от типа используемого веб-сервера).

Например, проблема 53085 относится к проблема 54493:

У группы была внутренняя доступность, в то время как один из ее проектов был публичным (а не тем, с которым у меня было столько проблем, которое было частным).

Публикация группы решила проблему.


Отчет OP maxemilian в комментарии, теперь он работает с Firefox на Manjaro:

Я проверил свой дневник обновлений, но успешно увеличил масштаб только совпадений между временем доступа Firefox.
Я почти уверен, что это было связано с кодом входа в GitLab. Подозрительные даты (6 января — 21 января и 3 февраля — 6 февраля).
Я думаю, что это обновление сделано GitLab в период с 3 по 6 февраля.


1

VonC
6 Фев 2021 в 10:54

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Github ошибка при скачивании
  • Github ошибка 403
  • Github как изменить язык на сайте
  • Github как изменить название pull request
  • Github как изменить имя пользователя

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии