Skip to content

Commit c2049fd

Browse files
committed
remove: hcp related code in agent for HCP consul EoL
1 parent 0fdc481 commit c2049fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+48
-10559
lines changed

agent/agent.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@ import (
2626
"github.com/armon/go-metrics/prometheus"
2727
"github.com/rboyer/safeio"
2828
"golang.org/x/net/http2"
29-
"golang.org/x/net/http2/h2c"
3029
"google.golang.org/grpc"
3130
"google.golang.org/grpc/keepalive"
3231

3332
"github.com/hashicorp/go-connlimit"
3433
"github.com/hashicorp/go-hclog"
3534
"github.com/hashicorp/go-memdb"
3635
"github.com/hashicorp/go-multierror"
37-
"github.com/hashicorp/hcp-scada-provider/capability"
3836
"github.com/hashicorp/raft"
3937
"github.com/hashicorp/serf/serf"
4038

@@ -51,7 +49,6 @@ import (
5149
external "github.com/hashicorp/consul/agent/grpc-external"
5250
grpcDNS "github.com/hashicorp/consul/agent/grpc-external/services/dns"
5351
middleware "github.com/hashicorp/consul/agent/grpc-middleware"
54-
"github.com/hashicorp/consul/agent/hcp/scada"
5552
"github.com/hashicorp/consul/agent/leafcert"
5653
"github.com/hashicorp/consul/agent/local"
5754
"github.com/hashicorp/consul/agent/netutil"
@@ -432,10 +429,6 @@ type Agent struct {
432429
// xdsServer serves the XDS protocol for configuring Envoy proxies.
433430
xdsServer *xds.Server
434431

435-
// scadaProvider is set when HashiCorp Cloud Platform integration is configured and exposes the agent's API over
436-
// an encrypted session to HCP
437-
scadaProvider scada.Provider
438-
439432
// enterpriseAgent embeds fields that we only access in consul-enterprise builds
440433
enterpriseAgent
441434

@@ -492,7 +485,6 @@ func New(bd BaseDeps) (*Agent, error) {
492485
cache: bd.Cache,
493486
leafCertManager: bd.LeafCertManager,
494487
routineManager: routine.NewManager(bd.Logger),
495-
scadaProvider: bd.HCP.Provider,
496488
}
497489

498490
// TODO: create rpcClientHealth in BaseDeps once NetRPC is available without Agent
@@ -1109,12 +1101,6 @@ func (a *Agent) startListeners(addrs []net.Addr) ([]net.Listener, error) {
11091101
}
11101102
l = &tcpKeepAliveListener{l.(*net.TCPListener)}
11111103

1112-
case *capability.Addr:
1113-
l, err = a.scadaProvider.Listen(x.Capability())
1114-
if err != nil {
1115-
return nil, err
1116-
}
1117-
11181104
default:
11191105
closeAll()
11201106
return nil, fmt.Errorf("unsupported address type %T", addr)
@@ -1173,11 +1159,6 @@ func (a *Agent) listenHTTP() ([]apiServer, error) {
11731159
MaxHeaderBytes: a.config.HTTPMaxHeaderBytes,
11741160
}
11751161

1176-
if scada.IsCapability(l.Addr()) {
1177-
// wrap in http2 server handler
1178-
httpServer.Handler = h2c.NewHandler(srv.handler(), &http2.Server{})
1179-
}
1180-
11811162
// Load the connlimit helper into the server
11821163
connLimitFn := a.httpConnLimiter.HTTPConnStateFuncWithDefault429Handler(10 * time.Millisecond)
11831164

@@ -1195,9 +1176,6 @@ func (a *Agent) listenHTTP() ([]apiServer, error) {
11951176
}
11961177

11971178
httpAddrs := a.config.HTTPAddrs
1198-
if a.config.IsCloudEnabled() && a.scadaProvider != nil {
1199-
httpAddrs = append(httpAddrs, scada.CAPCoreAPI)
1200-
}
12011179

12021180
if err := start("http", httpAddrs); err != nil {
12031181
closeListeners(ln)
@@ -1601,8 +1579,6 @@ func newConsulConfig(runtimeCfg *config.RuntimeConfig, logger hclog.Logger) (*co
16011579
cfg.RequestLimitsWriteRate = runtimeCfg.RequestLimitsWriteRate
16021580
cfg.Locality = runtimeCfg.StructLocality()
16031581

1604-
cfg.Cloud = runtimeCfg.Cloud
1605-
16061582
cfg.Reporting.License.Enabled = runtimeCfg.Reporting.License.Enabled
16071583
cfg.Reporting.SnapshotRetentionTime = runtimeCfg.Reporting.SnapshotRetentionTime
16081584

@@ -1782,11 +1758,6 @@ func (a *Agent) ShutdownAgent() error {
17821758
a.rpcClientHealth.Close()
17831759
a.rpcClientConfigEntry.Close()
17841760

1785-
// Shutdown SCADA provider
1786-
if a.scadaProvider != nil {
1787-
a.scadaProvider.Stop()
1788-
}
1789-
17901761
var err error
17911762
if a.delegate != nil {
17921763
err = a.delegate.Shutdown()

agent/agent_test.go

Lines changed: 3 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,22 @@ import (
3333
"github.com/google/go-cmp/cmp"
3434
"github.com/google/go-cmp/cmp/cmpopts"
3535
"github.com/google/tcpproxy"
36+
"github.com/hashicorp/go-hclog"
37+
"github.com/hashicorp/serf/coordinate"
38+
"github.com/hashicorp/serf/serf"
3639
"github.com/stretchr/testify/assert"
3740
"github.com/stretchr/testify/require"
3841
"golang.org/x/sync/errgroup"
3942
"golang.org/x/time/rate"
4043
"google.golang.org/grpc"
4144
"google.golang.org/protobuf/encoding/protojson"
4245

43-
"github.com/hashicorp/go-hclog"
44-
"github.com/hashicorp/hcp-scada-provider/capability"
45-
"github.com/hashicorp/serf/coordinate"
46-
"github.com/hashicorp/serf/serf"
47-
4846
"github.com/hashicorp/consul/agent/cache"
4947
cachetype "github.com/hashicorp/consul/agent/cache-types"
5048
"github.com/hashicorp/consul/agent/checks"
5149
"github.com/hashicorp/consul/agent/config"
5250
"github.com/hashicorp/consul/agent/connect"
5351
"github.com/hashicorp/consul/agent/consul"
54-
"github.com/hashicorp/consul/agent/hcp"
55-
"github.com/hashicorp/consul/agent/hcp/scada"
5652
"github.com/hashicorp/consul/agent/leafcert"
5753
"github.com/hashicorp/consul/agent/structs"
5854
"github.com/hashicorp/consul/agent/token"
@@ -6389,69 +6385,6 @@ peering {
63896385
})
63906386
}
63916387

6392-
func TestAgent_startListeners_scada(t *testing.T) {
6393-
t.Parallel()
6394-
pvd := scada.NewMockProvider(t)
6395-
c := capability.NewAddr("testcap")
6396-
pvd.EXPECT().Listen(c.Capability()).Return(nil, nil).Once()
6397-
bd := BaseDeps{
6398-
Deps: consul.Deps{
6399-
Logger: hclog.NewInterceptLogger(nil),
6400-
Tokens: new(token.Store),
6401-
GRPCConnPool: &fakeGRPCConnPool{},
6402-
HCP: hcp.Deps{
6403-
Provider: pvd,
6404-
},
6405-
Registry: resource.NewRegistry(),
6406-
},
6407-
RuntimeConfig: &config.RuntimeConfig{},
6408-
Cache: cache.New(cache.Options{}),
6409-
NetRPC: &LazyNetRPC{},
6410-
}
6411-
6412-
bd.LeafCertManager = leafcert.NewManager(leafcert.Deps{
6413-
CertSigner: leafcert.NewNetRPCCertSigner(bd.NetRPC),
6414-
RootsReader: leafcert.NewCachedRootsReader(bd.Cache, "dc1"),
6415-
Config: leafcert.Config{},
6416-
})
6417-
6418-
cfg := config.RuntimeConfig{BuildDate: time.Date(2000, 1, 1, 0, 0, 1, 0, time.UTC)}
6419-
bd, err := initEnterpriseBaseDeps(bd, &cfg)
6420-
require.NoError(t, err)
6421-
6422-
agent, err := New(bd)
6423-
mockDelegate := delegateMock{}
6424-
mockDelegate.On("LicenseCheck").Return()
6425-
agent.delegate = &mockDelegate
6426-
require.NoError(t, err)
6427-
6428-
_, err = agent.startListeners([]net.Addr{c})
6429-
require.NoError(t, err)
6430-
}
6431-
6432-
func TestAgent_scadaProvider(t *testing.T) {
6433-
pvd := scada.NewMockProvider(t)
6434-
6435-
// this listener is used when mocking out the scada provider
6436-
l, err := net.Listen("tcp4", fmt.Sprintf("127.0.0.1:%d", freeport.GetOne(t)))
6437-
require.NoError(t, err)
6438-
defer require.NoError(t, l.Close())
6439-
6440-
pvd.EXPECT().Listen(scada.CAPCoreAPI.Capability()).Return(l, nil).Once()
6441-
pvd.EXPECT().Stop().Return(nil).Once()
6442-
a := TestAgent{
6443-
HCL: `cloud = { resource_id = "test-resource-id" client_id = "test-client-id" client_secret = "test-client-secret" }`,
6444-
OverrideDeps: func(deps *BaseDeps) {
6445-
deps.HCP.Provider = pvd
6446-
},
6447-
}
6448-
defer a.Shutdown()
6449-
require.NoError(t, a.Start(t))
6450-
6451-
_, err = api.NewClient(&api.Config{Address: l.Addr().String()})
6452-
require.NoError(t, err)
6453-
}
6454-
64556388
func TestAgent_checkServerLastSeen(t *testing.T) {
64566389
bd := BaseDeps{
64576390
Deps: consul.Deps{

agent/config/builder.go

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package config
55

66
import (
7-
"crypto/tls"
87
"encoding/base64"
98
"encoding/json"
109
"errors"
@@ -37,7 +36,6 @@ import (
3736
"github.com/hashicorp/consul/agent/consul/authmethod/ssoauth"
3837
consulrate "github.com/hashicorp/consul/agent/consul/rate"
3938
"github.com/hashicorp/consul/agent/consul/state"
40-
hcpconfig "github.com/hashicorp/consul/agent/hcp/config"
4139
"github.com/hashicorp/consul/agent/rpc/middleware"
4240
"github.com/hashicorp/consul/agent/structs"
4341
"github.com/hashicorp/consul/agent/token"
@@ -1004,7 +1002,6 @@ func (b *builder) build() (rt RuntimeConfig, err error) {
10041002
AutoEncryptIPSAN: autoEncryptIPSAN,
10051003
AutoEncryptAllowTLS: autoEncryptAllowTLS,
10061004
AutoConfig: autoConfig,
1007-
Cloud: b.cloudConfigVal(c),
10081005
ConnectEnabled: connectEnabled,
10091006
ConnectCAProvider: connectCAProvider,
10101007
ConnectCAConfig: connectCAConfig,
@@ -1135,8 +1132,7 @@ func (b *builder) build() (rt RuntimeConfig, err error) {
11351132
LocalProxyConfigResyncInterval: 30 * time.Second,
11361133
}
11371134

1138-
// host metrics are enabled if consul is configured with HashiCorp Cloud Platform integration
1139-
rt.Telemetry.EnableHostMetrics = boolValWithDefault(c.Telemetry.EnableHostMetrics, rt.IsCloudEnabled())
1135+
rt.Telemetry.EnableHostMetrics = boolValWithDefault(c.Telemetry.EnableHostMetrics, false)
11401136

11411137
rt.TLS, err = b.buildTLSConfig(rt, c.TLS)
11421138
if err != nil {
@@ -1979,7 +1975,6 @@ func (b *builder) uiConfigVal(v RawUIConfig) UIConfig {
19791975
MetricsProviderOptionsJSON: stringVal(v.MetricsProviderOptionsJSON),
19801976
MetricsProxy: b.uiMetricsProxyVal(v.MetricsProxy),
19811977
DashboardURLTemplates: v.DashboardURLTemplates,
1982-
HCPEnabled: os.Getenv("CONSUL_HCP_ENABLED") == "true",
19831978
}
19841979
}
19851980

@@ -2610,75 +2605,6 @@ func validateAutoConfigAuthorizer(rt RuntimeConfig) error {
26102605
return nil
26112606
}
26122607

2613-
func (b *builder) cloudConfigVal(v Config) hcpconfig.CloudConfig {
2614-
// Load the same environment variables expected by hcp-sdk-go
2615-
envHostname, ok := os.LookupEnv("HCP_API_ADDRESS")
2616-
if !ok {
2617-
if legacyEnvHostname, ok := os.LookupEnv("HCP_API_HOST"); ok {
2618-
// Remove only https scheme prefixes from the deprecated environment
2619-
// variable for specifying the API host. Mirrors the same behavior as
2620-
// hcp-sdk-go.
2621-
if strings.HasPrefix(strings.ToLower(legacyEnvHostname), "https://") {
2622-
legacyEnvHostname = legacyEnvHostname[8:]
2623-
}
2624-
envHostname = legacyEnvHostname
2625-
}
2626-
}
2627-
2628-
var envTLSConfig *tls.Config
2629-
if os.Getenv("HCP_AUTH_TLS") == "insecure" ||
2630-
os.Getenv("HCP_SCADA_TLS") == "insecure" ||
2631-
os.Getenv("HCP_API_TLS") == "insecure" {
2632-
envTLSConfig = &tls.Config{InsecureSkipVerify: true}
2633-
}
2634-
2635-
val := hcpconfig.CloudConfig{
2636-
ResourceID: os.Getenv("HCP_RESOURCE_ID"),
2637-
ClientID: os.Getenv("HCP_CLIENT_ID"),
2638-
ClientSecret: os.Getenv("HCP_CLIENT_SECRET"),
2639-
AuthURL: os.Getenv("HCP_AUTH_URL"),
2640-
Hostname: envHostname,
2641-
ScadaAddress: os.Getenv("HCP_SCADA_ADDRESS"),
2642-
TLSConfig: envTLSConfig,
2643-
}
2644-
2645-
// Node id might get overridden in setup.go:142
2646-
nodeID := stringVal(v.NodeID)
2647-
val.NodeID = types.NodeID(nodeID)
2648-
val.NodeName = b.nodeName(v.NodeName)
2649-
2650-
if v.Cloud == nil {
2651-
return val
2652-
}
2653-
2654-
// Load configuration file variables for anything not set by environment variables
2655-
if val.AuthURL == "" {
2656-
val.AuthURL = stringVal(v.Cloud.AuthURL)
2657-
}
2658-
2659-
if val.Hostname == "" {
2660-
val.Hostname = stringVal(v.Cloud.Hostname)
2661-
}
2662-
2663-
if val.ScadaAddress == "" {
2664-
val.ScadaAddress = stringVal(v.Cloud.ScadaAddress)
2665-
}
2666-
2667-
if val.ResourceID == "" {
2668-
val.ResourceID = stringVal(v.Cloud.ResourceID)
2669-
}
2670-
2671-
if val.ClientID == "" {
2672-
val.ClientID = stringVal(v.Cloud.ClientID)
2673-
}
2674-
2675-
if val.ClientSecret == "" {
2676-
val.ClientSecret = stringVal(v.Cloud.ClientSecret)
2677-
}
2678-
2679-
return val
2680-
}
2681-
26822608
// decodeBytes returns the encryption key decoded.
26832609
func decodeBytes(key string) ([]byte, error) {
26842610
return base64.StdEncoding.DecodeString(key)

0 commit comments

Comments
 (0)