mirror of
https://github.com/openziti/ziti.git
synced 2026-11-25 08:52:03 +00:00
7f2f619e88
- adds a startup reconcile that asks the leader to move this node's stored raft address to its configured advertise address, retrying with jittered backoff until the change is visible locally - wakes the running reconcile on leader events instead of starting a second one, and jitters the first attempt and each wake so controllers reconciling after the same event spread their requests - keeps checking a node whose copy of the configuration doesn't list it yet, as after a restart before any of the log reached it, instead of treating it as reconciled - adds an UpdatePeerAddressRequest peer message carrying the member id, the address the node believes is stored and the new address; the leader accepts it only from the node it names and does not forward it - adds updateMemberAddressAsLeader, which changes a member's address in place, keeping its suffrage, after refusing non-members, addresses held by another member and stale from addresses - probes the new address as a sanity check, refusing the change if a different controller answers and making it with a warning if the address can't be reached, since some controllers only dial out - conditions the update on a configuration index read from the raft log and snapshot stores, since GetConfiguration().Index() is always zero in the pinned raft version - routes AddPeer requests that find an existing member at a new address to the in-place update instead of remove and re-add, identifying the member through GetPeerInfo rather than the request id - falls back to the member id when the raft transport dials a stored address with no peer connected at it - adds a probe hello header so probe connections are closed without registering a peer - excludes self by server id in GetPeerAddresses - corrects the inverted voter flag in the peer AddPeer log and removes the unused ctrlAddress field - tests single-node, follower, non-voter and leader address changes, refused and unverified addresses, requests from the wrong sender, membership changes made while a member is offline or during the probe, and configuration lookup across snapshots and log gaps - tests the reconcile starting on an empty log and waiting until the configuration lists the node - waits in the HA test harness for a restarted peer's own configuration to list it before restarting it - adds a changelog entry describing the address update and the leader version requirement
73 lines
2.2 KiB
Go
73 lines
2.2 KiB
Go
/*
|
|
Copyright NetFoundry Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package handler_peer_ctrl
|
|
|
|
import (
|
|
"crypto/ecdsa"
|
|
"crypto/elliptic"
|
|
"crypto/rand"
|
|
"crypto/x509"
|
|
"math/big"
|
|
"net/url"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func newCertWithUri(t *testing.T, uri string) *x509.Certificate {
|
|
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
|
require.NoError(t, err)
|
|
|
|
parsed, err := url.Parse(uri)
|
|
require.NoError(t, err)
|
|
|
|
template := &x509.Certificate{
|
|
SerialNumber: big.NewInt(1),
|
|
NotBefore: time.Now().Add(-time.Minute),
|
|
NotAfter: time.Now().Add(time.Hour),
|
|
URIs: []*url.URL{parsed},
|
|
}
|
|
der, err := x509.CreateCertificate(rand.Reader, template, template, &key.PublicKey, key)
|
|
require.NoError(t, err)
|
|
|
|
cert, err := x509.ParseCertificate(der)
|
|
require.NoError(t, err)
|
|
return cert
|
|
}
|
|
|
|
func Test_checkSentBy(t *testing.T) {
|
|
t.Run("accepts the named member", func(t *testing.T) {
|
|
certs := []*x509.Certificate{newCertWithUri(t, "spiffe://ziti.test/controller/ctrl2")}
|
|
require.NoError(t, checkSentBy(certs, "ctrl2"))
|
|
})
|
|
|
|
t.Run("refuses a different controller", func(t *testing.T) {
|
|
certs := []*x509.Certificate{newCertWithUri(t, "spiffe://ziti.test/controller/ctrl9")}
|
|
require.ErrorContains(t, checkSentBy(certs, "ctrl2"), "request for member ctrl2 was sent by controller ctrl9")
|
|
})
|
|
|
|
t.Run("refuses a cert without a controller id", func(t *testing.T) {
|
|
certs := []*x509.Certificate{newCertWithUri(t, "spiffe://ziti.test/router/ctrl2")}
|
|
require.ErrorContains(t, checkSentBy(certs, "ctrl2"), "unable to identify sending controller")
|
|
})
|
|
|
|
t.Run("refuses a connection without certs", func(t *testing.T) {
|
|
require.ErrorContains(t, checkSentBy(nil, "ctrl2"), "unable to identify sending controller")
|
|
})
|
|
}
|