Skip to content

Commit a8b4b1c

Browse files
Merge pull request openshift#8395 from pawanpinjarkar/authenticate-agent-service
AGENT-875: Authenticate agents
2 parents 319ade5 + 1119bb1 commit a8b4b1c

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

data/data/agent/files/usr/local/bin/start-agent.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#!/bin/bash
22

3+
# shellcheck disable=SC1091
4+
source "common.sh"
5+
36
>&2 echo "Waiting for infra-env-id to be available"
47
INFRA_ENV_ID=""
58
until [[ $INFRA_ENV_ID != "" && $INFRA_ENV_ID != "null" ]]; do
69
sleep 5
710
>&2 echo "Querying assisted-service for infra-env-id..."
8-
INFRA_ENV_ID=$(curl -s -S "${SERVICE_BASE_URL}/api/assisted-install/v2/infra-envs" | jq -r .[0].id)
11+
INFRA_ENV_ID=$(curl_assisted_service "/infra-envs" GET | jq -r .[0].id)
912
done
1013
echo "Fetched infra-env-id and found: $INFRA_ENV_ID"
1114

pkg/asset/agent/image/ignition.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func (a *Ignition) Generate(_ context.Context, dependencies asset.Parents) error
272272

273273
rendezvousHostFile := ignition.FileFromString(rendezvousHostEnvPath,
274274
"root", 0644,
275-
getRendezvousHostEnv(agentTemplateData.ServiceProtocol, a.RendezvousIP, agentWorkflow.Workflow))
275+
getRendezvousHostEnv(agentTemplateData.ServiceProtocol, a.RendezvousIP, keyPairAsset.Token, agentWorkflow.Workflow))
276276
config.Storage.Files = append(config.Storage.Files, rendezvousHostFile)
277277

278278
err = addBootstrapScripts(&config, agentManifests.ClusterImageSet.Spec.ReleaseImage)
@@ -378,8 +378,7 @@ func getTemplateData(name, pullSecret, releaseImageList, releaseImage,
378378
infraEnvID string,
379379
osImage *models.OsImage,
380380
proxy *v1beta1.Proxy,
381-
imageTypeISO,
382-
publicKey, token, caBundleMount string) *agentTemplateData {
381+
imageTypeISO, publicKey, token, caBundleMount string) *agentTemplateData {
383382
return &agentTemplateData{
384383
ServiceProtocol: "http",
385384
PullSecret: pullSecret,
@@ -401,7 +400,7 @@ func getTemplateData(name, pullSecret, releaseImageList, releaseImage,
401400
}
402401
}
403402

404-
func getRendezvousHostEnv(serviceProtocol, nodeZeroIP string, workflowType workflow.AgentWorkflowType) string {
403+
func getRendezvousHostEnv(serviceProtocol, nodeZeroIP, token string, workflowType workflow.AgentWorkflowType) string {
405404
serviceBaseURL := url.URL{
406405
Scheme: serviceProtocol,
407406
Host: net.JoinHostPort(nodeZeroIP, "8090"),
@@ -412,12 +411,23 @@ func getRendezvousHostEnv(serviceProtocol, nodeZeroIP string, workflowType workf
412411
Host: net.JoinHostPort(nodeZeroIP, "8888"),
413412
Path: "/",
414413
}
414+
// AGENT_AUTH_TOKEN is required to authenticate API requests against agent-installer-local auth type.
415+
// PULL_SECRET_TOKEN contains the same value as AGENT_AUTH_TOKEN. The name PULL_SECRET_TOKEN is used in
416+
// assisted-installer-agent, which is responsible for authenticating API requests related to agents.
417+
// Historically, PULL_SECRET_TOKEN was used solely to store the pull secrets.
418+
// However, as the authentication mechanisms have evolved, PULL_SECRET_TOKEN now
419+
// stores a JWT (JSON Web Token) in the context of local authentication.
420+
// Consequently, PULL_SECRET_TOKEN must be set with the value of AGENT_AUTH_TOKEN to maintain compatibility
421+
// and ensure successful authentication.
422+
// In the absence of PULL_SECRET_TOKEN, the cluster installation will wait forever.
415423

416424
return fmt.Sprintf(`NODE_ZERO_IP=%s
417425
SERVICE_BASE_URL=%s
418426
IMAGE_SERVICE_BASE_URL=%s
427+
AGENT_AUTH_TOKEN=%s
428+
PULL_SECRET_TOKEN=%s
419429
WORKFLOW_TYPE=%s
420-
`, nodeZeroIP, serviceBaseURL.String(), imageServiceBaseURL.String(), workflowType)
430+
`, nodeZeroIP, serviceBaseURL.String(), imageServiceBaseURL.String(), token, token, workflowType)
421431
}
422432

423433
func getAddNodesEnv(clusterInfo joiner.ClusterInfo) string {

pkg/asset/agent/image/ignition_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ func TestIgnition_getTemplateData(t *testing.T) {
114114

115115
func TestIgnition_getRendezvousHostEnv(t *testing.T) {
116116
nodeZeroIP := "2001:db8::dead:beef"
117-
rendezvousHostEnv := getRendezvousHostEnv("http", nodeZeroIP, workflow.AgentWorkflowTypeInstall)
117+
token := "someToken"
118+
rendezvousHostEnv := getRendezvousHostEnv("http", nodeZeroIP, token, workflow.AgentWorkflowTypeInstall)
118119
assert.Equal(t,
119-
"NODE_ZERO_IP="+nodeZeroIP+"\nSERVICE_BASE_URL=http://["+nodeZeroIP+"]:8090/\nIMAGE_SERVICE_BASE_URL=http://["+nodeZeroIP+"]:8888/\nWORKFLOW_TYPE=install\n",
120+
"NODE_ZERO_IP="+nodeZeroIP+"\nSERVICE_BASE_URL=http://["+nodeZeroIP+"]:8090/\nIMAGE_SERVICE_BASE_URL=http://["+nodeZeroIP+"]:8888/\nAGENT_AUTH_TOKEN="+token+"\nPULL_SECRET_TOKEN="+token+"\nWORKFLOW_TYPE=install\n",
120121
rendezvousHostEnv)
121122
}
122123

0 commit comments

Comments
 (0)