Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Implement support for kerberos authentication #13

Merged
1 commit merged into from
Jan 4, 2022

Conversation

tsipinakis
Copy link
Member

@tsipinakis tsipinakis commented Nov 25, 2021

Please describe the change you are making

Implement a kerberos authentication flow. It includes an additional webhook to the authentication server for authorization.
The authentication method requires the keytab to be mounted in the container (or be present on the host).

Example configuration:

    auth:
      method: kerberos
      kerberos:
        keytab: '/etc/krb5.keytab'
        authz:
          enable: true
          url: http://127.0.0.1:8080

In order to run this, the changes from ContainerSSH/agent#3 and ContainerSSH/gokrb5#2

TODO:

  • Test/Add support for docker backend
  • Add principalUser to authz request in case ticket username != ssh username
  • Finish off rough edges
    • ConnectionId/Remote address not being sent to authz server
    • ...
  • Documentation, look into all the files that need updating
  • Tests

Are you the owner of the code you are sending in, or do you have permission of the owner?

Sent with permission of the owner

The code will be published under the MIT-0 license. Have you read and understood this license?

Yes

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @tsipinakis thank you very much for your work, this looks awesome. A few minor changes.

@tsipinakis tsipinakis force-pushed the gssapi branch 12 times, most recently from 89c5fb1 to e19f4f1 Compare December 15, 2021 15:28
@tsipinakis tsipinakis marked this pull request as ready for review December 17, 2021 12:43
@tsipinakis tsipinakis changed the title Implement kerberos authentication support Implement support for kerberos authentication Dec 17, 2021
ghost
ghost previously approved these changes Dec 26, 2021
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work, only a few minor things to change.

@@ -3,6 +3,7 @@ package webhook
import (
"net"

auth2 "github.com/containerssh/libcontainerssh/auth"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer aliasing the internal auth to internalAuth or this one to publicAuth. Using numbered aliases does not help readability.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is following the existing naming used in other parts of the project (grep for config2). It should probably be changed globally later.

@@ -25,6 +25,18 @@ kadmin.local -q "addprinc -pw ${KERBEROS_PASSWORD} ${KERBEROS_USERNAME}"
echo -n "" >/etc/krb5kdc/kadm5.acl
echo "${KERBEROS_USERNAME}@TESTING.CONTAINERSSH.IO *" >>/etc/krb5kdc/kadm5.acl

echo -e "\e[32mAdding host principal testing.containerssh.io ...\e[0m"
kadmin.local -q "addprinc -randkey host/testing.containerssh.io"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we wouldn't hard-code credentials but pass them via environment variables like above. However, I can live with this.

@tsipinakis
Copy link
Member Author

@janosdebugs Ready for another round of reviews :)

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsipinakis a few minor changes.

AllowPassword bool `json:"allowPassword" yaml:"allowPassword" default:"true"`
// ConfigPath is the path of the kerberos configuration file. This is
// only used for password authentication.
ConfigPath string `json:"configPath" yaml:"configPath" default:"/etc/containerssh/krb5.conf"`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason to do so would be centralized configuration. If people we add configuration via other means then having one centralized configuration structure would make that easier. (e.g. if we ever introduce a webhook on-connection) I'm fine leaving it as an external file for now, but we should keep this in mind for the future and not add too many external configuration files.

EnforceUsername bool `json:"enforceUsername" yaml:"enforceUsername" default:"true"`
// CredentialCachePath is the path in which the kerberos credentials
// will be written inside the user containers.
CredentialCachePath string `json:"credentialCachePath" yaml:"credentialCachePath" default:"/tmp/krb5cc"`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make sure this file has the proper permissions. (0600)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if k.client.config.EnforceUsername && field.UserName != k.username {
return message.NewMessage(
message.EAuthKerberosVerificationFailed,
"Verify() returned unverified but no error",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, down the line we want to create a web client and that client will support authentication error messages.

if d.config.Execution.Mode == config.DockerExecutionModeSession && d.config.Execution.DisableAgent {
return message.NewMessage(
message.EDockerWriteFileFailed,
"Agent needs to be enable in order to write files",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make sure this text is at least grammatically correct.

@tsipinakis tsipinakis force-pushed the gssapi branch 3 times, most recently from 25d8fc2 to 4103ae1 Compare January 4, 2022 11:22
@ghost ghost enabled auto-merge (squash) January 4, 2022 11:23
ghost
ghost previously approved these changes Jan 4, 2022
@ghost ghost merged commit 625361f into ContainerSSH:main Jan 4, 2022
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant