Commit 57d828bf authored by Tiger's avatar Tiger

Use the correct project path in generated `KUBECONFIG` file

Previously an Agent had to be directly associated with a project
for it to be used for the CI tunnel, which meant that the Agent
configuration project was the same project that was running the build.

With the introduction of authorizations for arbitrary groups and
projects, this assumption no longer holds. We must instead use the
project associated with the Agent instead of the one associated with
the build.

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/70452

Changelog: fixed
EE: true
parent c8698910
...@@ -4,7 +4,6 @@ module Ci ...@@ -4,7 +4,6 @@ module Ci
class GenerateKubeconfigService class GenerateKubeconfigService
def initialize(build) def initialize(build)
@build = build @build = build
@project = build.project
@template = Gitlab::Kubernetes::Kubeconfig::Template.new @template = Gitlab::Kubernetes::Kubeconfig::Template.new
end end
...@@ -34,7 +33,7 @@ module Ci ...@@ -34,7 +33,7 @@ module Ci
private private
attr_reader :build, :project, :template attr_reader :build, :template
def agents def agents
build.pipeline.authorized_cluster_agents build.pipeline.authorized_cluster_agents
...@@ -49,7 +48,7 @@ module Ci ...@@ -49,7 +48,7 @@ module Ci
end end
def context_name(agent) def context_name(agent)
[project.full_path, agent.name].join(delimiter) [agent.project.full_path, agent.name].join(delimiter)
end end
def agent_token(agent) def agent_token(agent)
......
...@@ -7,7 +7,7 @@ RSpec.describe Ci::GenerateKubeconfigService do ...@@ -7,7 +7,7 @@ RSpec.describe Ci::GenerateKubeconfigService do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:build) { create(:ci_build, project: project) } let(:build) { create(:ci_build, project: project) }
let(:agent1) { create(:cluster_agent, project: project) } let(:agent1) { create(:cluster_agent, project: project) }
let(:agent2) { create(:cluster_agent, project: project) } let(:agent2) { create(:cluster_agent) }
let(:template) { instance_double(Gitlab::Kubernetes::Kubeconfig::Template) } let(:template) { instance_double(Gitlab::Kubernetes::Kubeconfig::Template) }
...@@ -39,7 +39,7 @@ RSpec.describe Ci::GenerateKubeconfigService do ...@@ -39,7 +39,7 @@ RSpec.describe Ci::GenerateKubeconfigService do
user: "agent:#{agent1.id}" user: "agent:#{agent1.id}"
) )
expect(template).to receive(:add_context).with( expect(template).to receive(:add_context).with(
name: "#{project.full_path}:#{agent2.name}", name: "#{agent2.project.full_path}:#{agent2.name}",
cluster: 'gitlab', cluster: 'gitlab',
user: "agent:#{agent2.id}" user: "agent:#{agent2.id}"
) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment