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

Trust ca certs #12513

Merged
merged 3 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lxd/auth/driver_tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,11 @@ func (t *tls) certificateDetails(fingerprint string) (certificate.Type, bool, []
return certificate.TypeMetrics, false, nil, nil
}

// If we're in a CA environment, it's possible for a certificate to be trusted despite not being present in the trust store.
// We rely on the validation of the certificate (and its potential revocation) having been done in CheckTrustState.
if shared.PathExists(shared.VarPath("server.ca")) {
return certificate.TypeClient, true, nil, nil
}

return -1, false, nil, api.StatusErrorf(http.StatusForbidden, "Client certificate not found")
}
14 changes: 11 additions & 3 deletions lxd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,14 +586,22 @@ func (d *Daemon) createCmd(restAPI *mux.Router, version string, c APIEndpoint) {
return response.NotImplemented(nil)
}

// All APIEndpointActions should have an access handler or should allow untrusted requests.
if action.AccessHandler == nil && !action.AllowUntrusted {
return response.InternalError(fmt.Errorf("Access handler not defined for %s %s", r.Method, r.URL.RequestURI()))
}

// If the request is not trusted, only call the handler if the action allows it.
if !trusted && !action.AllowUntrusted {
return response.Forbidden(errors.New("You must be authenticated"))
}

// Call the access handler if there is one.
if action.AccessHandler != nil {
// Defer access control to custom handler
resp := action.AccessHandler(d, r)
if resp != response.EmptySyncResponse {
return resp
}
} else if !action.AllowUntrusted {
return response.Forbidden(nil)
}

return action.Handler(d, r)
Expand Down
21 changes: 9 additions & 12 deletions test/suites/pki.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,25 @@ test_pki() {

# Add remote using the correct password.
# This should work because the client certificate is signed by the CA.
lxc_remote remote add pki-lxd "${LXD5_ADDR}" --accept-certificate --password=foo
token="$(LXD_DIR=${LXD5_DIR} lxc config trust add --name foo -q)"
lxc_remote remote add pki-lxd "${LXD5_ADDR}" --accept-certificate --password "${token}"
lxc_remote config trust ls pki-lxd: | grep lxd-client
fingerprint="$(lxc_remote config trust ls pki-lxd: --format csv | cut -d, -f4)"
lxc_remote config trust remove pki-lxd:"${fingerprint}"
lxc_remote remote remove pki-lxd

# Add remote using a CA-signed client certificate, and not providing a password.
# This should succeed and tests that the CA trust is working, as adding the client certificate to the trust
# store without a trust password would normally fail.
# store without a token would normally fail.
LXD_DIR=${LXD5_DIR} lxc config set core.trust_ca_certificates true
lxc_remote remote add pki-lxd "${LXD5_ADDR}" --accept-certificate
lxc_remote config trust ls pki-lxd: | grep lxd-client
! lxc_remote config trust ls pki-lxd: | grep lxd-client || false
lxc_remote remote remove pki-lxd

# Add remote using a CA-signed client certificate, and providing an incorrect password.
# This should succeed as is the same as the test above but with an incorrect password rather than no password.
# Add remote using a CA-signed client certificate, and providing an incorrect token.
# This should succeed as is the same as the test above but with an incorrect token rather than no token.
lxc_remote remote add pki-lxd "${LXD5_ADDR}" --accept-certificate --password=bar
lxc_remote config trust ls pki-lxd: | grep lxd-client

# Try removing the fingerprint.
# This should succeed as the admin can delete all certificates.
fingerprint="$(lxc_remote config trust ls pki-lxd: --format csv | cut -d, -f4)"
lxc_remote config trust rm pki-lxd:"${fingerprint}"

! lxc_remote config trust ls pki-lxd: | grep lxd-client || false
lxc_remote remote remove pki-lxd

# Replace the client certificate with a revoked certificate in the CRL.
Expand Down
Loading