Authorize before resolving Secrets Manager entitlement

What does this MR do and why?

Secrets Manager mutations no longer call CustomersDot for namespaces the caller cannot access.

Before this change, any signed-in user could name any project or group path in a Secrets Manager write mutation, and GitLab resolved the CustomersDot entitlement before it checked authorization. One request with about 110 aliased mutations, each naming a different root namespace, could make about 110 CustomersDot calls. The lookups came from two places:

  1. SecretsManagement::EnforcesWriteEntitlement#ready? looked up the entitlement first and checked the read_*_secrets_manager_status ability second.
  2. The secrets_manager_entitlement_* conditions in EE::GroupPolicy and EE::ProjectPolicy. These conditions back prevent rules, which DeclarativePolicy scores lower than enable rules. For a user with no role, they ran before the role checks, both inside the concern's ability check and later in authorized_find!.

This MR changes both places:

  • Concern: checks the status ability before the entitlement lookup, behind the secrets_manager_authorize_before_entitlement_lookup flag (gitlab_com_derisk, off by default). A caller without access gets nil from the hook, so the mutation goes on to authorized_find! and fails with the normal not-found error. Authorized callers still get the structured reason and DenialTelemetry.
  • Policies: the entitlement conditions get a manual score of 64, so the role checks run first. When no enable rule passes, DeclarativePolicy stops before it reaches them. This changes only the order of evaluation, not any result, so it is not behind the flag.
Mutations covered (all 12 that include the concern)

The issue counts 10. A grep finds 12. The one ready? hook covers all of them, and the policy change covers their authorized_find! too.

  • GroupSecretCreate, GroupSecretUpdate
  • GroupSecretsManagerInitialize, GroupSecretsManagerDeprovision
  • GroupSecretsPermissionUpdate, GroupSecretsPermissionDelete
  • ProjectSecretCreate, ProjectSecretUpdate
  • ProjectSecretsManagerInitialize, ProjectSecretsManagerDeprovision
  • ProjectSecretsPermissionUpdate, ProjectSecretsPermissionDelete
Measured entitlement lookups for one request aliasing all 12 mutations against foreign public namespaces
State Entitlement.for calls
Neither change (master) 24 (12 from the concern, 12 from the policies)
Flag on, without the policy change 12 (policies only)
This MR, flag off 12 (concern only)
This MR, flag on 0

Measured with ee/spec/requests/api/graphql/secrets_management/entitlement_lookup_authorization_spec.rb. The first two rows come from the same spec run with the policy files reverted. The spec stubs Entitlement.for, so these are call counts, not CustomersDot requests. The 12 mutations span six root groups (each group mutation shares a root with one project mutation). Policy-level specs in ee/spec/policies/ee/group_policy_spec.rb and ee/spec/policies/project_policy_spec.rb pin the non-member case for every surface, not only these mutations.

Survivable threshold

With the flag on, a caller with no role that grants a Secrets Manager ability on a namespace makes zero CustomersDot entitlement calls for it, however many mutations the request aliases.

Callers with such a role (Reporter or higher, a custom role that grants it, or an admin in admin mode) can still trigger lookups. Those lookups are limited to the namespaces they can reach, plus the existing request and Rails cache layers. This includes a Reporter who is denied the status ability because of the entitlement: on a project or subgroup whose root is trial_eligible and not in the beta, the status check itself has to resolve the entitlement before it says no.

Caveat

DeclarativePolicy sorts statically and skips the early stop when an ability has more than 50 steps. The replay spec shows zero lookups for all 12 mutations today. If a future rule pushes one of these abilities past 50 steps, the policy lookups could come back, and the replay spec would fail.

Rollout and rollback

Rollout issue: #638719

  1. Enable on staging. Parity check: as a non-member, send one request aliasing several Secrets Manager mutations against an enrolled namespace. Expect not-found errors and no CustomersDot entitlement calls in the logs. As a Reporter of a namespace denied by entitlement, expect the structured reason.
  2. Enable in production for the DRI, then 50% of actors, then globally.
  3. Repeat the parity check on GitLab.com to confirm the control is enforced.

Rollback: /chatops gitlab run feature set secrets_manager_authorize_before_entitlement_lookup false. The policy score change needs no rollback because it doesn't change any result. Reverting it would only bring back the policy-side lookups.

References

Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/637348

How to set up and validate locally

  1. Run the replay spec:
    bin/rspec ee/spec/requests/api/graphql/secrets_management/entitlement_lookup_authorization_spec.rb
  2. Or by hand: enable the flag in the Rails console with Feature.enable(:secrets_manager_authorize_before_entitlement_lookup). Then, as a user with no access to a Secrets Manager group, send mutation { a: groupSecretCreate(input: { groupPath: "<group>", name: "S", secret: "v", environment: "*", protected: false }) { errors } } with several aliases. Each mutation returns the not-found error, and a breakpoint on SecretsManagement::Entitlement.for is never hit.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Dmytro Biryukov

Merge request reports

Loading
Loading