Skip to content

Commit

Permalink
lxc/remote: Use TrustToken field if supported by the server
Browse files Browse the repository at this point in the history
When adding a remote by putting the token in the positional argument (not --token)
also check if the server supports the explicit_trust_token extension and send
the password using the TrustToken field instead.

Signed-off-by: Julian Pelizäus <[email protected]>
  • Loading branch information
roosterfish committed Nov 13, 2024
1 parent 75aea99 commit 2e261f5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lxc/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,19 @@ func (c *cmdRemoteAdd) addRemoteFromToken(addr string, server string, token stri
}
}

// Implicitly runs GetServer which updates the servers extensions.
d, err := conf.GetInstanceServer(server)
if err != nil {
return api.StatusErrorf(http.StatusServiceUnavailable, "%s: %w", i18n.G("Unavailable remote server"), err)
}

req := api.CertificatesPost{}
if d.HasExtension("explicit_trust_token") {
req.TrustToken = token
} else {
req.Password = token
}

// Add client certificate to trust store. Even if we are already trusted (src.Auth == "trusted"),
// we want to send the token to invalidate it. Therefore, we can ignore the conflict error, which
// is thrown if we are trying to add a client cert that is already trusted by LXD remote.
Expand Down

0 comments on commit 2e261f5

Please sign in to comment.