{"slug": "eliminating-the-ai-blast-radius-in-ci-cd-atomic-pre-mutation-token-authorization", "title": "Eliminating the AI Blast Radius in CI/CD: Atomic Pre-Mutation Token Authorization for MCP", "summary": "A GitLab engineer detailed a fix in MR !270865 that enforces atomic pre-mutation authorization for the company's MCP server, requiring the composite permission set [:play_job, :read_job, :read_pipeline] in find_job! before any GraphQL mutation executes. Previously, a granular PAT holding only :run_job could pass the guard, trigger a production CI/CD job, then fail on response-field reads and return an error to the AI agent—prompting a catastrophic retry loop. The change rejects partial tokens with :unauthorized while leaving the job in manual status, backed by service and request-level RSpec coverage.", "body_md": "What happens when an autonomous AI agent calls a CI/CD tool with a fine-grained token that has permission to trigger a production pipeline job, but lacks permission to read the resulting job object? In a naive GraphQL wrapper, the production deployment fires, the response query fails, and the AI agent thinks the call failed—setting up a catastrophic retry loop.\n\nWhen exposing CI/CD state mutations to AI agents via MCP, authorization cannot be treated as a single flat check. In GitLab's MCP server, the `save_pipeline_job` tool (`Mcp::Tools::Jobs::SavePipelineJobTool`) executes a GraphQL mutation (` jobPlay` or `jobRetry`) that both transitions a pipeline job's state and selects fields on the mutated `CiJob` and its parent `Pipeline` (such as stage metadata) to return structured confirmation to the agent. While working on Issue `#639861` and authoring [MR !270865 (`test(mcp): add granular token authorization coverage for save_pipeline_job`)](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/270865), I analyzed the authorization boundary for GitLab's fine-grained Personal Access Tokens (granular PATs).\n\nA granular PAT configured with the `:run_job` permission expands internally to `:play_job` and `:retry_job`. If the pre-execution guard in `find_job!` only validates `authorize_granular_token!(project, [:play_job])`, a token holding `:run_job` alone passes the gate and invokes `GitlabSchema.execute`. Inside GraphQL, the mutation succeeds and enqueues the manual CI/CD job on a runner—a permanent side effect. Immediately afterward, GraphQL attempts to resolve the returned job and pipeline stage fields, which require `:read_job` and `:read_pipeline` permissions. Because the token lacks those read scopes, GraphQL redacts the return node to `nil`, and the MCP tool surfaces `\"Operation returned no job data\"` (`isError: true`) back to the agent after the job is already running.\n\nIn [MR !270865](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/270865), we enforced atomic pre-mutation authorization by requiring the complete composite permission set—`authorize_granular_token!(project, [:play_job, :read_job, :read_pipeline])`—inside `find_job!` before `GitlabSchema.execute` is ever invoked, accompanied by full service and request-level RSpec suites proving that partial granular tokens (`[:run_job]` without `:read_job` and `:read_pipeline`) are rejected with `:unauthorized` while the manual job remains untouched in `manual` status.\n\nGitLab's granular Personal Access Token architecture and MCP security layer ([MR !270865](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/270865)) enforce composite pre-flight permission verification across mutation and response-projection boundaries, ensuring AI agents never trigger silent, unobservable CI/CD pipeline executions.\n\nWhen an AI tool executes a GraphQL mutation and projects fields from the mutated graph, pre-authorize the union of both mutation permissions and response-graph read permissions before executing the mutation—otherwise read redaction looks like a failed write to an autonomous agent.", "url": "https://wpnews.pro/news/eliminating-the-ai-blast-radius-in-ci-cd-atomic-pre-mutation-token-authorization", "canonical_source": "https://dev.to/aryan_rajput_81602becc3f6/eliminating-the-ai-blast-radius-in-cicd-atomic-pre-mutation-token-authorization-for-mcp-2m29", "published_at": "2026-11-16 12:43:17+00:00", "updated_at": "2026-11-16 12:51:13.148878+00:00", "lang": "en", "topics": ["ai-agents", "ai-safety", "developer-tools", "ai-tools"], "entities": ["GitLab", "GitLab MCP server", "Mcp::Tools::Jobs::SavePipelineJobTool", "GitlabSchema", "MR !270865", "Issue #639861"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/eliminating-the-ai-blast-radius-in-ci-cd-atomic-pre-mutation-token-authorization", "markdown": "https://wpnews.pro/news/eliminating-the-ai-blast-radius-in-ci-cd-atomic-pre-mutation-token-authorization.md", "text": "https://wpnews.pro/news/eliminating-the-ai-blast-radius-in-ci-cd-atomic-pre-mutation-token-authorization.txt", "jsonld": "https://wpnews.pro/news/eliminating-the-ai-blast-radius-in-ci-cd-atomic-pre-mutation-token-authorization.jsonld"}}