Skip to content

Commit

Permalink
AGENT-875: Authenticate agents
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanpinjarkar committed May 16, 2024
1 parent 48241a0 commit 779715e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion data/data/agent/files/usr/local/bin/start-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ INFRA_ENV_ID=""
until [[ $INFRA_ENV_ID != "" && $INFRA_ENV_ID != "null" ]]; do
sleep 5
>&2 echo "Querying assisted-service for infra-env-id..."
INFRA_ENV_ID=$(curl -s -S "${SERVICE_BASE_URL}/api/assisted-install/v2/infra-envs" | jq -r .[0].id)
INFRA_ENV_ID=$(curl -s -S "${SERVICE_BASE_URL}/api/assisted-install/v2/infra-envs" -H "Authorization: ${AGENT_AUTH_TOKEN}" | jq -r .[0].id)
done
echo "Fetched infra-env-id and found: $INFRA_ENV_ID"

Expand Down
7 changes: 4 additions & 3 deletions pkg/asset/agent/image/ignition.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (a *Ignition) Generate(dependencies asset.Parents) error {

rendezvousHostFile := ignition.FileFromString(rendezvousHostEnvPath,
"root", 0644,
getRendezvousHostEnv(agentTemplateData.ServiceProtocol, a.RendezvousIP, agentWorkflow.Workflow))
getRendezvousHostEnv(agentTemplateData.ServiceProtocol, a.RendezvousIP, keyPairAsset.Token, agentWorkflow.Workflow))
config.Storage.Files = append(config.Storage.Files, rendezvousHostFile)

err = addBootstrapScripts(&config, agentManifests.ClusterImageSet.Spec.ReleaseImage)
Expand Down Expand Up @@ -396,7 +396,7 @@ func getTemplateData(name, pullSecret, releaseImageList, releaseImage,
}
}

func getRendezvousHostEnv(serviceProtocol, nodeZeroIP string, workflowType workflow.AgentWorkflowType) string {
func getRendezvousHostEnv(serviceProtocol, nodeZeroIP, token string, workflowType workflow.AgentWorkflowType) string {
serviceBaseURL := url.URL{
Scheme: serviceProtocol,
Host: net.JoinHostPort(nodeZeroIP, "8090"),
Expand All @@ -411,8 +411,9 @@ func getRendezvousHostEnv(serviceProtocol, nodeZeroIP string, workflowType workf
return fmt.Sprintf(`NODE_ZERO_IP=%s
SERVICE_BASE_URL=%s
IMAGE_SERVICE_BASE_URL=%s
AGENT_AUTH_TOKEN=%s
WORKFLOW_TYPE=%s
`, nodeZeroIP, serviceBaseURL.String(), imageServiceBaseURL.String(), workflowType)
`, nodeZeroIP, serviceBaseURL.String(), imageServiceBaseURL.String(), token, workflowType)
}

func getAddNodesEnv(clusterInfo joiner.ClusterInfo) string {
Expand Down
5 changes: 3 additions & 2 deletions pkg/asset/agent/image/ignition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ func TestIgnition_getTemplateData(t *testing.T) {

func TestIgnition_getRendezvousHostEnv(t *testing.T) {
nodeZeroIP := "2001:db8::dead:beef"
rendezvousHostEnv := getRendezvousHostEnv("http", nodeZeroIP, workflow.AgentWorkflowTypeInstall)
token := "someToken"
rendezvousHostEnv := getRendezvousHostEnv("http", nodeZeroIP, token, workflow.AgentWorkflowTypeInstall)
assert.Equal(t,
"NODE_ZERO_IP="+nodeZeroIP+"\nSERVICE_BASE_URL=http://["+nodeZeroIP+"]:8090/\nIMAGE_SERVICE_BASE_URL=http://["+nodeZeroIP+"]:8888/\nWORKFLOW_TYPE=install\n",
"NODE_ZERO_IP="+nodeZeroIP+"\nSERVICE_BASE_URL=http://["+nodeZeroIP+"]:8090/\nIMAGE_SERVICE_BASE_URL=http://["+nodeZeroIP+"]:8888/\nAGENT_AUTH_TOKEN="+token+"\nWORKFLOW_TYPE=install\n",
rendezvousHostEnv)
}

Expand Down

0 comments on commit 779715e

Please sign in to comment.