Open ajc opened 1 year ago
I encountered the same issue. Here's a snippet of code that resolved it for me. This was my first time working with this codebase, and I didn't have enough time to figure out and follow the existing patterns.
This is just a quick fix that worked for me. It requires setting the env variable:
export CHARM_USE_TLS=true
I can imagine keeping the env name CHARM_SERVER_USE_TLS
would work too. Or CHARM_CLIENT_USE_TLS
. I might be off by one here but naming this is not very high on my TODO list today :)
If anyone could direct me to the proper place for this fix, I'd be more than willing to make it into a PR. Otherwise, I hope it can help someone more familiar with the codebase understand why both of us in this thread have encountered the same problem. :)
modified client/auth.go
@@ -29,7 +29,6 @@ func (cc *Client) Auth() (*charm.Auth, error) {
if err != nil {
return nil, charm.ErrAuthFailed{Err: err}
}
- cc.httpScheme = auth.HTTPScheme
p := &jwt.Parser{}
token, _, err := p.ParseUnverified(auth.JWT, &jwt.RegisteredClaims{})
if err != nil {
modified client/client.go
@@ -34,6 +34,7 @@ type Config struct {
KeyType string `env:"CHARM_KEY_TYPE" envDefault:"ed25519"`
DataDir string `env:"CHARM_DATA_DIR" envDefault:""`
IdentityKey string `env:"CHARM_IDENTITY_KEY" envDefault:""`
+ UseTLS bool `env:"CHARM_USE_TLS" envDefault:"false"`
}
// Client is the Charm client.
@@ -110,6 +111,10 @@ func NewClient(cfg *Config) (*Client, error) {
Auth: []ssh.AuthMethod{pkam},
HostKeyCallback: ssh.InsecureIgnoreHostKey(), // nolint
}
+
+ cc.httpScheme = "http"
+ if cfg.UseTLS {
+ cc.httpScheme = "https"
+ }
return cc, nil
}
I am not sure if this will help anyone else but in my case, I was setting up my own self-hosted charm server with TLS and I was finding that I was also getting 400 Bad Request
errors from charm and skate. I did not have a reverse proxy set up as I am just running charm from inside a docker container but am using a macvlan interface for my network so it just appears like it is running on it's own dedicated machine/IP. The documentation makes it seem like CHARM_SERVER_PUBLIC_URL
would only be needed when using a reverse proxy but this doesn't appear to be the case when using TLS.
CHARM_SERVER_PUBLIC_URL="https://charm.example.com:35354"
CHARM_SERVER_HOST="charm.example.com"
CHARM_SERVER_TLS_CERT_FILE="/certs/tls.crt"
CHARM_SERVER_TLS_KEY_FILE="/certs/tls.key"
CHARM_SERVER_USE_TLS=true
I've been trying to setup a self-hosted version of the
charm
service using the package from your APT/DEB repo on an Ubuntu 22.04.1 LTS system (I've tried on both amd64 and arm64 systems).I have a Let's Encrypt-provided TLS certificate, and I've set it up via systemd with these environment variables:
Starting it, I see this in the systemd journal:
I can see that the certificate served up is valid, using certigo:
When I run
charm
from another host, I see this in the server's journal:But back on the other host, I just see
If I change
CHARM_SERVER_USE_TLS
tofalse
and restart the service, then runningcharm
from another host seems to work just fine (I see the menu to Link a machine, Manage linked keys, Set username, Backup or Exit.)What am I doing wrong when I have TLS turned on?
Cheers, Cos.