Skip to content

Commit

Permalink
kubernetes: Fix pod creation fail on long usernames (#526)
Browse files Browse the repository at this point in the history
* Use authenticated username over normal username for k8s label

* Do not add containerssh_username label if username is 63 chars or over

* Run tests on all branches
  • Loading branch information
tsipinakis authored Aug 31, 2023
1 parent 5686d77 commit 13dbb35
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build
on:
push:
branches:
- main
- '*'
pull_request:
schedule:
- cron: '0 17 * * 2'
Expand Down
11 changes: 10 additions & 1 deletion internal/kubernetes/networkHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,16 @@ func (n *networkHandler) OnHandshakeSuccess(meta metadata.ConnectionAuthenticate
}
n.labels = map[string]string{
"containerssh_connection_id": n.connectionID,
"containerssh_username": r.ReplaceAllString(meta.Username, "-"),
}
if len(meta.AuthenticatedUsername) <= 63 {
n.labels["containerssh_username"] = r.ReplaceAllString(meta.AuthenticatedUsername, "-")
} else {
n.logger.Warning(message.NewMessage(
message.MKubernetesUsernameTooLong,
"The users username (%s) is longer than the 63 character limit of kubernetes labels. The containerssh_username label will be unavailable in the users pod",
meta.AuthenticatedUsername,
),
)
}
for authMetadataName, labelName := range n.config.Pod.ExposeAuthMetadataAsLabels {
if value, ok := meta.GetMetadata()[authMetadataName]; ok {
Expand Down
4 changes: 4 additions & 0 deletions message/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const MKubernetesPodCreate = "KUBERNETES_POD_CREATE"
// MKubernetesPodWait indicates that the ContainerSSH Kubernetes module is waiting for the pod to come up.
const MKubernetesPodWait = "KUBERNETES_POD_WAIT"

// MKubernetesUsernameTooLong indicates that the users username is too long to be provided as a label in the k8s pod.
// The containerssh_username label is unavailable on that users pod.
const MKubernetesUsernameTooLong = "KUBERNETES_USERNAME_TOO_LONG"

// MKubernetesPodWaitFailed indicates that the ContainerSSH Kubernetes module failed to wait for the pod to come up.
// Check the error message for details.
const MKubernetesPodWaitFailed = "KUBERNETES_POD_WAIT_FAILED"
Expand Down

0 comments on commit 13dbb35

Please sign in to comment.