mirror of
https://github.com/slackhq/nebula.git
synced 2026-11-16 21:56:52 +01:00
Serve print-cert on the info API, with -address and preferring our v2 certificate
A program that verifies certificates against its own CAs, as
nebula-auth-request does, needs the certificate itself rather than the
parsed identity, and it asked the ssh debug server for it. The info API
now serves print-cert, so it can ask there instead.
- print-cert declares Identity: it reads a certificate from the hostmap or our own, and nothing operational
- -address names the vpn addr, with a port accepted and stripped and 4in6 unmapped, as identity takes it; the operand stays, and giving both is refused
- an address of our own answers with our own certificate, and a tunnel without one is not found, a 404 on the API
- with no address the certificate is the one whoami reports, the v2 when both versions are loaded, not the one handshakes start with
- GET /v1/print-cert?address=<addr>&raw=true answers {"pem": ...}; example config, CHANGELOG, surface test, goldens and an e2e check
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
e0dc742e17
commit
660a271466
7 files changed
+156
-17
No files matched your search
@@ -6,7 +6,10 @@ import (
|
||||
"io"
|
||||
"net/netip"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/slackhq/nebula/cert"
|
||||
"github.com/slackhq/nebula/cert_test"
|
||||
"github.com/slackhq/nebula/commands"
|
||||
"github.com/slackhq/nebula/logging"
|
||||
"github.com/slackhq/nebula/test"
|
||||
@@ -80,3 +83,63 @@ func TestPrintCertOfATunnelWithoutACertificate(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.True(t, r.OK, "a tunnel with a certificate is printed")
|
||||
}
|
||||
|
||||
// TestPrintCertByAddressFlag: -address is the info API's spelling of the operand, takes a
|
||||
// port and a 4in6 form the way identity does, answers our own address with our own
|
||||
// certificate, and is refused together with an operand.
|
||||
func TestPrintCertByAddressFlag(t *testing.T) {
|
||||
f, peerCert := identityFixture(t)
|
||||
|
||||
for _, addr := range []string{"10.0.0.2", "10.0.0.2:4242", "[::ffff:10.0.0.2]:4242"} {
|
||||
fl := &printCertFlags{}
|
||||
require.NoError(t, fl.setAddress(addr))
|
||||
r, err := runPrintCert(f, fl, nil)
|
||||
require.NoError(t, err)
|
||||
require.True(t, r.OK, addr)
|
||||
assert.Equal(t, peerCert, r.Value, addr)
|
||||
}
|
||||
|
||||
fl := &printCertFlags{}
|
||||
require.NoError(t, fl.setAddress("10.0.0.1"))
|
||||
r, err := runPrintCert(f, fl, nil)
|
||||
require.NoError(t, err)
|
||||
require.True(t, r.OK)
|
||||
assert.Equal(t, ownCertificate(f.pki.getCertState()), r.Value, "our own address is our own certificate")
|
||||
|
||||
fl = &printCertFlags{}
|
||||
require.NoError(t, fl.setAddress("10.0.0.3"))
|
||||
r, err = runPrintCert(f, fl, nil)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, r.OK)
|
||||
assert.True(t, r.NotFound)
|
||||
|
||||
fl = &printCertFlags{}
|
||||
require.NoError(t, fl.setAddress("not-an-address"))
|
||||
r, err = runPrintCert(f, fl, nil)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "The provided vpn addr could not be parsed: not-an-address", r.Reason)
|
||||
|
||||
fl = &printCertFlags{}
|
||||
require.NoError(t, fl.setAddress("10.0.0.2"))
|
||||
r, err = runPrintCert(f, fl, []string{"10.0.0.2"})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "print-cert takes one vpn addr, as -address or as an operand, not both", r.Reason)
|
||||
}
|
||||
|
||||
// TestPrintCertPrefersOwnV2: with no address print-cert reports the certificate whoami
|
||||
// does, the v2 when both versions are loaded, rather than the one handshakes start with.
|
||||
func TestPrintCertPrefersOwnV2(t *testing.T) {
|
||||
v4 := netip.MustParsePrefix("10.0.0.1/24")
|
||||
ca1, _, caKey1, _ := cert_test.NewTestCaCert(cert.Version1, cert.Curve_CURVE25519, time.Time{}, time.Time{}, nil, nil, nil)
|
||||
v1, _, _, _ := cert_test.NewTestCert(cert.Version1, cert.Curve_CURVE25519, ca1, caKey1, "me", time.Time{}, time.Time{}, []netip.Prefix{v4}, nil, nil)
|
||||
ca2, _, caKey2, _ := cert_test.NewTestCaCert(cert.Version2, cert.Curve_CURVE25519, time.Time{}, time.Time{}, nil, nil, nil)
|
||||
v2, _, _, _ := cert_test.NewTestCert(cert.Version2, cert.Curve_CURVE25519, ca2, caKey2, "me", time.Time{}, time.Time{}, []netip.Prefix{v4}, nil, nil)
|
||||
|
||||
f := &Interface{pki: &PKI{}, hostMap: newHostMap(test.NewLogger())}
|
||||
f.pki.cs.Store(&CertState{v1Cert: v1, v2Cert: v2, initiatingVersion: cert.Version1})
|
||||
|
||||
r, err := runPrintCert(f, &printCertFlags{}, nil)
|
||||
require.NoError(t, err)
|
||||
require.True(t, r.OK)
|
||||
assert.Equal(t, v2, r.Value)
|
||||
}
|
||||
Reference in new issue
Block a user