Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can you expand the docs for K3S_TOKEN security #6175

Closed
abe-winter opened this issue Sep 25, 2022 · 6 comments
Closed

can you expand the docs for K3S_TOKEN security #6175

abe-winter opened this issue Sep 25, 2022 · 6 comments

Comments

@abe-winter
Copy link

abe-winter commented Sep 25, 2022

Is your feature request related to a problem? Please describe.
It's not clear from the k3s docs whether K3S_TOKEN (recommended here) is a two-way validation. I.e., is it just a way for the new agent to authenticate to the cluster? Or does it also allow the new agent to validate that the server is who it appears to be?

Describe the solution you'd like

Can you please add a line in the docs saying if:

  • K3S_TOKEN allows the client to validate the server
  • whether this is safe to use on untrusted connections, or should only be used on a private network

Describe alternatives you've considered
(digging through code and old issues)

Additional context

@brandond
Copy link
Member

brandond commented Sep 26, 2022

This is a reasonable ask, but the short answer is that the token can be in one of two formats:

  1. Just the bare token: simply the server or agent password required to join the cluster. This is the format that should be used when creating a new cluster with the --token or --agent-token flag.
  2. K10 format: A packed format that includes the fixed string K10, the hash of the cluster CA, a username, and password. When this format is used, the cluster's CA certificate hash is validated against the hash included in the token. This is the format that should be used when joining additional servers or agents to the cluster, and can be retrieved from the node-token file on a server.

@abe-winter
Copy link
Author

abe-winter commented Sep 26, 2022

Thank you!

When connecting with K10 format, is the sequence:

  1. new node connects to cluster via TLS, using the server cert
  2. the new node uses the K10 hash to validate the current TLS connection
  3. new node logs in with user/password from K10

(I.e. does validation happen before the user/password are transmitted)

@brandond
Copy link
Member

brandond commented Sep 26, 2022

Everything uses TLS.

  1. Node connects to the server (without authentication, and without validating the TLS connection's certificate chain) and retrieves the cluster CA certificate.
  2. Node verifies that the CA certificate hash matches the hash in the token.
  3. Node verifies that the certificate used by the TLS connection to the server was issued by the cluster CA certificate.
  4. Node sends credentials to download bootstrap configuration.

Step 2 is omitted if the hash is not included in the token; any cluster CA sent by the remote node is accepted. If you want to validate the identity of the cluster you're joining, you should always use the K10 format.

@abe-winter
Copy link
Author

Thanks, that makes total sense

@sourcehawk
Copy link

This is a reasonable ask, but the short answer is that the token can be in one of two formats:

  1. Just the bare token: simply the server or agent password required to join the cluster. This is the format that should be used when creating a new cluster with the --token or --agent-token flag.

Does this mean that when I install the first server with the --token flag, I can just use the same --token flag on all nodes to join the cluster and don't need to retrieve a node token from the first installation?

@brandond
Copy link
Member

brandond commented Feb 9, 2023

Yes, you can absolutely use that short token format on all your nodes. You'll be missing the CA validation that comes from including the K10 prefix, but that cannot be known ahead of time as the CA certs are generated during initial server startup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants