Page MenuHomePhabricator

gitlab ci: validate secrets settings in pipeline for tofu integration
Closed, ResolvedPublic

Description

The https://gitlab.wikimedia.org/repos/cloud/cloud-vps/networktests-tofu-provisioning repository uses a new model for setting the gitlab CI and tofu integration.

For us to get tofu plan for merge requests, we need to set the secret variables as not protected so they are available in MR branches.
Per the comment in https://phabricator.wikimedia.org/T370652#10206515:

I think that for repos/cloud you can limit the secrets exposure to MRs of branches within the repo, so it gets limited to members of the cloud team (we do so in toolforge to push images/charts to toolsbeta-harbor)

This has been implemented in a similar way.

This ticket is to verify that this is correct, before we move on with similar implementations in other tofu projects, like:

In particular, we want to verify that only "trusted" accounts can send MRs in a way that triggers gitlab CI/CD. If untrusted accounts can send arbitrary MRs that triggers the pipeline, they could submit a MR with a modified gitlab-ci.yaml file, with an 'echo $SECRET' and obtain the secrets required to perform arbitrary infrastructure changes.

Related Objects

Event Timeline

Which credentials is that using in the first place?

Which credentials is that using in the first place?

An user called srv-networktests @ codfw1dev, application credentials.

Which credentials is that using in the first place?

As we plan to expand and replicate this setup in multiple different directions, what credentials are being used in particular is maybe not the important point.

If the setup is insecure, no credentials should be used this way, no matter which ones. If the setup is secure, then we mostly don't care.

Which credentials is that using in the first place?

An user called srv-networktests @ codfw1dev, application credentials.

I discovered this is only partially true:

  • ec2-style credentials for the tofu state bucket, this is using srv-networktests
  • openstack API application credentials, they are my own, as I was logged as myself when generated them via labtesthorizon.

I will refresh the openstack API application credentials to be from srv-networktests as well, soon.

! In T391467#10726025, @aborrero wrote:
I will refresh the openstack API application credentials to be from srv-networktests as well, soon.

done

fnegri closed this task as Resolved.EditedMay 6 2025, 2:13 PM
fnegri claimed this task.

I found some GitLab documentation about this:

By default, pipelines from forked projects can’t access the CI/CD variables available to the parent project. If you run a merge request pipeline in the parent project for a merge request from a fork, all variables become available to the pipeline.
(from https://docs.gitlab.com/ci/variables/#cicd-variable-security)

You must be a member of the parent project with permissions to run CI/CD pipelines.
To use the UI to run a pipeline in the parent project for a merge request from a fork project:

  • In the merge request, go to the Pipelines tab.
  • Select Run pipeline. You must read and accept the warning, or the pipeline does not run.

(from https://docs.gitlab.com/ci/pipelines/merge_request_pipelines/#run-pipelines-in-the-parent-project)

My understanding from this is that there is no risk of leaking credentials unless either a) the untrusted account has write access to the repo and can create a MR in the repo and not in a fork, or b) someone with write access to the repo manually hits "run pipeline" for an untrusted fork without checking the content first.

In my view, this gives us sufficient protection against possible malicious users. I'm gonna mark this task as resolved, please reopen if you think we should do additional checks.