talos/internal/app/apid/pkg/director/mocks_test.go
Andrey Smirnov 2dadcd6695
fix: stop worker nodes from acting as apid routers
Don't allow worker nodes to act as apid routers:

* don't try to issue client certificate for apid on worker nodes
* if worker nodes receives incoming connections with `--nodes` set to
  one of the local addresses of the nodd, it routes the request to
  itself without proxying

Second point allows using `talosctl -e worker -n worker` to connect
directly to the worker if the connection from the control plane is not
available for some reason.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
2022-09-13 15:07:31 +04:00

47 lines
1.0 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package director_test
import (
"context"
"github.com/talos-systems/grpc-proxy/proxy"
"google.golang.org/grpc"
)
type mockBackend struct {
target string
}
func (m *mockBackend) String() string {
return m.target
}
func (m *mockBackend) GetConnection(ctx context.Context) (context.Context, *grpc.ClientConn, error) {
return ctx, nil, nil
}
func (m *mockBackend) AppendInfo(streaming bool, resp []byte) ([]byte, error) {
return resp, nil
}
func (m *mockBackend) BuildError(streaming bool, err error) ([]byte, error) {
return nil, nil
}
func mockBackendFactory(target string) (proxy.Backend, error) {
return &mockBackend{target: target}, nil
}
type mockLocalAddressProvider struct {
local map[string]struct{}
}
func (m *mockLocalAddressProvider) IsLocalTarget(t string) bool {
_, ok := m.local[t]
return ok
}