Add JWT support for internal Subscriptions API
What does this MR do and why?
Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/466368+
Add JWT support for internal Subscriptions API
We want to be able to authenticate with a JWT from CustomersDot when accessing this endpoint. Migrate it to the internal API definition which has JWT auth, and update the specs to account for this.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
Start the GDK and CustomersDot.
- GitLab: find the ID of a top level namespace without a subscription (you may have to delete the sub as it can be lazy-populated)
- CustomersDot: Start a rails console
-
CustomersDot: verify the existing admin PAT auth still works
# create a subscription irb(main):001> Client::GitlabApp.post("/api/v4/namespaces/3488/gitlab_subscription", body: { seats: 10, start_date: '2023-01-01', plan_code: 'premium' }, token: Client::GitlabApp::ADMIN_API_TOKEN) => {"plan"=>{"code"=>"premium", "name"=>"Premium", "trial"=>false, "auto_renew"=>nil, "upgradable"=>true, "exclude_guests"=>false}, "usage"=>{"seats_in_subscription"=>10, "seats_in_use"=>0, "max_seats_used"=>0, "seats_owed"=>0}, "billing"=>{"subscription_start_date"=>"2023-01-01", "subscription_end_date"=>nil, "trial_ends_on"=>nil}} # update a subscription irb(main):002> Client::GitlabApp.put("/api/v4/namespaces/3488/gitlab_subscription", body: { seats: 5 }, token: Client::GitlabApp::ADMIN_API_TOKEN) => {"plan"=>{"code"=>"premium", "name"=>"Premium", "trial"=>false, "auto_renew"=>nil, "upgradable"=>true, "exclude_guests"=>false}, "usage"=>{"seats_in_subscription"=>5, "seats_in_use"=>0, "max_seats_used"=>0, "seats_owed"=>0}, "billing"=>{"subscription_start_date"=>"2023-01-01", "subscription_end_date"=>nil, "trial_ends_on"=>nil}
- GitLab: find another top level namespace ID without a subscription
-
CustomersDot: verify the new JWT auth works
# create a subscription irb(main):001> Client::GitlabApp.post("/api/v4/namespaces/3488/gitlab_subscription", body: { seats: 10, start_date: '2023-01-01', plan_code: 'premium' }, internal_jwt_token: Gitlab::Api::Internal::GenerateJwt.instance.execute) => {"plan"=>{"code"=>"premium", "name"=>"Premium", "trial"=>false, "auto_renew"=>nil, "upgradable"=>true, "exclude_guests"=>false}, "usage"=>{"seats_in_subscription"=>10, "seats_in_use"=>0, "max_seats_used"=>0, "seats_owed"=>0}, "billing"=>{"subscription_start_date"=>"2023-01-01", "subscription_end_date"=>nil, "trial_ends_on"=>nil}} # update a subscription irb(main):002> Client::GitlabApp.put("/api/v4/namespaces/3488/gitlab_subscription", body: { seats: 5 }, internal_jwt_token: Gitlab::Api::Internal::GenerateJwt.instance.execute) => {"plan"=>{"code"=>"premium", "name"=>"Premium", "trial"=>false, "auto_renew"=>nil, "upgradable"=>true, "exclude_guests"=>false}, "usage"=>{"seats_in_subscription"=>5, "seats_in_use"=>0, "max_seats_used"=>0, "seats_owed"=>0}, "billing"=>{"subscription_start_date"=>"2023-01-01", "subscription_end_date"=>nil, "trial_ends_on"=>nil}}
Edited by Josianne Hyson