List project variables API returns values even though CI CD is disabled

Summary

The issue appears when CI CD is disabled in a project (Settings -> General -> Visibility -> CI/CD). In this case, using list project variables API seems to be behaving differently as of release 17.7.0 (latest of this writing).

The API returns a forbidden error in previous releases (i.e. 17.6.2 and before):

$ curl --silent --request GET --header "PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" --url "${GITLAB_API_URL}/version"
{"version":"17.6.2-ee","revision":"6ff444aad3a","kas":{"enabled":false,"externalUrl":null,"externalK8sProxyUrl":null,"version":null},"enterprise":true}

$ curl --silent --request GET --header "PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" --url "${GITLAB_API_URL}/projects/test-group%2Ftest-project/variables"
{"message":"403 Forbidden"}

In version 17.7.0, the API call returns the list of variables despite CI CD being disabled in the setting:

$ curl --silent --request GET --header "PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" --url "${GITLAB_API_URL}/version"
{"version":"17.7.0-ee","revision":"1fd574ee571","kas":{"enabled":false,"externalUrl":null,"externalK8sProxyUrl":null,"version":null},"enterprise":true}

$ curl --silent --request GET --header "PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" --url "${GITLAB_API_URL}/projects/test-group%2Ftest-project/variables"
[]

# Enable CI CD in settings, add a test variable, disable CI CD in settings again. Now, call the list variables API again.

$ curl --silent --request GET --header "PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" --url "${GITLAB_API_URL}/projects/test-group%2Ftest-project/variables"
[{"variable_type":"env_var","key":"test_var","value":"test_value","hidden":false,"protected":false,"masked":false,"raw":false,"environment_scope":"*","description":null}]

Steps to reproduce

In a test project:

Example Project

What is the current bug behavior?

In version 17.7.0, the "list project variables" API returns variables even though CI CD setting is disabled. This is different behaviour than version 17.6.2 and earlier.

What is the expected correct behavior?

Not sure if this is the expected behaviour, but prior to 17.7.0 release, the "list project variables" API returned a 403 Forbidden error message. Didn't see any mention of the API/feature change in the 17.7.0 release blog

Relevant logs and/or screenshots

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(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

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

Edited by 🤖 GitLab Bot 🤖