uselagoon/remote-controller

Additional SSH portal support

shreddedbacon opened this issue · 1 comments

With ssh-portals rolling out, tasks will need to potentially know how to generate a token via the token service that ssh-portal, we already inject some task variables that provide the SSH host and port etc, we should also provide a way to support X_TOKEN_HOST and X_TOKEN_PORT injection for future usage by those systems that can use it (

// --- deprecate these at some point in favor of the `LAGOON_CONFIG_X` variants
dep.Spec.Template.Spec.Containers[idx].Env = append(dep.Spec.Template.Spec.Containers[idx].Env, corev1.EnvVar{
Name: "TASK_API_HOST",
Value: r.getTaskValue(lagoonTask, "TASK_API_HOST"),
})
dep.Spec.Template.Spec.Containers[idx].Env = append(dep.Spec.Template.Spec.Containers[idx].Env, corev1.EnvVar{
Name: "TASK_SSH_HOST",
Value: r.getTaskValue(lagoonTask, "TASK_SSH_HOST"),
})
dep.Spec.Template.Spec.Containers[idx].Env = append(dep.Spec.Template.Spec.Containers[idx].Env, corev1.EnvVar{
Name: "TASK_SSH_PORT",
Value: r.getTaskValue(lagoonTask, "TASK_SSH_PORT"),
})
// ^^ ---
// add the API and SSH endpoint configuration to environments
dep.Spec.Template.Spec.Containers[idx].Env = append(dep.Spec.Template.Spec.Containers[idx].Env, corev1.EnvVar{
Name: "LAGOON_CONFIG_API_HOST",
Value: r.getTaskValue(lagoonTask, "LAGOON_CONFIG_API_HOST"),
})
dep.Spec.Template.Spec.Containers[idx].Env = append(dep.Spec.Template.Spec.Containers[idx].Env, corev1.EnvVar{
Name: "LAGOON_CONFIG_SSH_HOST",
Value: r.getTaskValue(lagoonTask, "LAGOON_CONFIG_SSH_HOST"),
})
dep.Spec.Template.Spec.Containers[idx].Env = append(dep.Spec.Template.Spec.Containers[idx].Env, corev1.EnvVar{
Name: "LAGOON_CONFIG_SSH_PORT",
Value: r.getTaskValue(lagoonTask, "LAGOON_CONFIG_SSH_PORT"),
})
// in the future, the SSH_HOST and SSH_PORT could also have regional variants
)

These could also be used then in place of https://docs.lagoon.sh/using-lagoon-the-basics/lagoon-yml/#api and https://docs.lagoon.sh/using-lagoon-the-basics/lagoon-yml/#ssh, and endpoint for things that consume these, like https://github.com/amazeeio/drupal-integrations and https://github.com/uselagoon/lagoon-service-images/tree/main/drush-alias

Actually, if ssh-portal could accept token and return the token from core, none of this is required. Currently there is a separate token service for collecting a token which is fine, but if the portal is already talking to the ssh-portal-api to check access, it could also handle returning a token fairly easily