Skip to content

Use #persisted_environment for agent impersonation

What does this MR do and why?

We were using #deployment, but this is not present for non-deployment jobs that don't have access to the environment.

See #363582 (closed)

Screenshots or screen recordings

N/A

How to set up and validate locally

In your GDK, in any project, create an agent under Infrastructure > Kubernetes (you can skip installing it in a cluster), and then create a pipeline from the following .gitlab-ci.yml:

test:
  environment:
    name: test
    action: stop
  image: 
    name: bitnami/kubectl
    entrypoint: [""]
  script:
    - sleep 1000

Then, in your rails console, grab the job's token:

Ci::Build.last.token

Set it to $TOKEN and call the API:

curl --header "JOB-TOKEN: $TOKEN" 'https://gdk.test:3000/api/v4/job/allowed_agents'

The response should include

{ "environment":{"slug":"test"}, ... }

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Hordur Freyr Yngvason

Merge request reports

Loading