Skip to content

Commit 07ba687

Browse files
committed
remove: hcp related code in agent for HCP consul EoL
1 parent b9cb603 commit 07ba687

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

+52
-10471
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)
@@ -1599,8 +1577,6 @@ func newConsulConfig(runtimeCfg *config.RuntimeConfig, logger hclog.Logger) (*co
15991577
cfg.RequestLimitsWriteRate = runtimeCfg.RequestLimitsWriteRate
16001578
cfg.Locality = runtimeCfg.StructLocality()
16011579

1602-
cfg.Cloud = runtimeCfg.Cloud
1603-
16041580
cfg.Reporting.License.Enabled = runtimeCfg.Reporting.License.Enabled
16051581
cfg.Reporting.SnapshotRetentionTime = runtimeCfg.Reporting.SnapshotRetentionTime
16061582

@@ -1780,11 +1756,6 @@ func (a *Agent) ShutdownAgent() error {
17801756
a.rpcClientHealth.Close()
17811757
a.rpcClientConfigEntry.Close()
17821758

1783-
// Shutdown SCADA provider
1784-
if a.scadaProvider != nil {
1785-
a.scadaProvider.Stop()
1786-
}
1787-
17881759
var err error
17891760
if a.delegate != nil {
17901761
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"
@@ -6290,69 +6286,6 @@ peering {
62906286
})
62916287
}
62926288

6293-
func TestAgent_startListeners_scada(t *testing.T) {
6294-
t.Parallel()
6295-
pvd := scada.NewMockProvider(t)
6296-
c := capability.NewAddr("testcap")
6297-
pvd.EXPECT().Listen(c.Capability()).Return(nil, nil).Once()
6298-
bd := BaseDeps{
6299-
Deps: consul.Deps{
6300-
Logger: hclog.NewInterceptLogger(nil),
6301-
Tokens: new(token.Store),
6302-
GRPCConnPool: &fakeGRPCConnPool{},
6303-
HCP: hcp.Deps{
6304-
Provider: pvd,
6305-
},
6306-
Registry: resource.NewRegistry(),
6307-
},
6308-
RuntimeConfig: &config.RuntimeConfig{},
6309-
Cache: cache.New(cache.Options{}),
6310-
NetRPC: &LazyNetRPC{},
6311-
}
6312-
6313-
bd.LeafCertManager = leafcert.NewManager(leafcert.Deps{
6314-
CertSigner: leafcert.NewNetRPCCertSigner(bd.NetRPC),
6315-
RootsReader: leafcert.NewCachedRootsReader(bd.Cache, "dc1"),
6316-
Config: leafcert.Config{},
6317-
})
6318-
6319-
cfg := config.RuntimeConfig{BuildDate: time.Date(2000, 1, 1, 0, 0, 1, 0, time.UTC)}
6320-
bd, err := initEnterpriseBaseDeps(bd, &cfg)
6321-
require.NoError(t, err)
6322-
6323-
agent, err := New(bd)
6324-
mockDelegate := delegateMock{}
6325-
mockDelegate.On("LicenseCheck").Return()
6326-
agent.delegate = &mockDelegate
6327-
require.NoError(t, err)
6328-
6329-
_, err = agent.startListeners([]net.Addr{c})
6330-
require.NoError(t, err)
6331-
}
6332-
6333-
func TestAgent_scadaProvider(t *testing.T) {
6334-
pvd := scada.NewMockProvider(t)
6335-
6336-
// this listener is used when mocking out the scada provider
6337-
l, err := net.Listen("tcp4", fmt.Sprintf("127.0.0.1:%d", freeport.GetOne(t)))
6338-
require.NoError(t, err)
6339-
defer require.NoError(t, l.Close())
6340-
6341-
pvd.EXPECT().Listen(scada.CAPCoreAPI.Capability()).Return(l, nil).Once()
6342-
pvd.EXPECT().Stop().Return(nil).Once()
6343-
a := TestAgent{
6344-
HCL: `cloud = { resource_id = "test-resource-id" client_id = "test-client-id" client_secret = "test-client-secret" }`,
6345-
OverrideDeps: func(deps *BaseDeps) {
6346-
deps.HCP.Provider = pvd
6347-
},
6348-
}
6349-
defer a.Shutdown()
6350-
require.NoError(t, a.Start(t))
6351-
6352-
_, err = api.NewClient(&api.Config{Address: l.Addr().String()})
6353-
require.NoError(t, err)
6354-
}
6355-
63566289
func TestAgent_checkServerLastSeen(t *testing.T) {
63576290
bd := BaseDeps{
63586291
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"
@@ -36,7 +35,6 @@ import (
3635
"github.com/hashicorp/consul/agent/consul"
3736
"github.com/hashicorp/consul/agent/consul/authmethod/ssoauth"
3837
consulrate "github.com/hashicorp/consul/agent/consul/rate"
39-
hcpconfig "github.com/hashicorp/consul/agent/hcp/config"
4038
"github.com/hashicorp/consul/agent/rpc/middleware"
4139
"github.com/hashicorp/consul/agent/structs"
4240
"github.com/hashicorp/consul/agent/token"
@@ -992,7 +990,6 @@ func (b *builder) build() (rt RuntimeConfig, err error) {
992990
AutoEncryptIPSAN: autoEncryptIPSAN,
993991
AutoEncryptAllowTLS: autoEncryptAllowTLS,
994992
AutoConfig: autoConfig,
995-
Cloud: b.cloudConfigVal(c),
996993
ConnectEnabled: connectEnabled,
997994
ConnectCAProvider: connectCAProvider,
998995
ConnectCAConfig: connectCAConfig,
@@ -1121,8 +1118,7 @@ func (b *builder) build() (rt RuntimeConfig, err error) {
11211118
LocalProxyConfigResyncInterval: 30 * time.Second,
11221119
}
11231120

1124-
// host metrics are enabled if consul is configured with HashiCorp Cloud Platform integration
1125-
rt.Telemetry.EnableHostMetrics = boolValWithDefault(c.Telemetry.EnableHostMetrics, rt.IsCloudEnabled())
1121+
rt.Telemetry.EnableHostMetrics = boolValWithDefault(c.Telemetry.EnableHostMetrics, false)
11261122

11271123
rt.TLS, err = b.buildTLSConfig(rt, c.TLS)
11281124
if err != nil {
@@ -1965,7 +1961,6 @@ func (b *builder) uiConfigVal(v RawUIConfig) UIConfig {
19651961
MetricsProviderOptionsJSON: stringVal(v.MetricsProviderOptionsJSON),
19661962
MetricsProxy: b.uiMetricsProxyVal(v.MetricsProxy),
19671963
DashboardURLTemplates: v.DashboardURLTemplates,
1968-
HCPEnabled: os.Getenv("CONSUL_HCP_ENABLED") == "true",
19691964
}
19701965
}
19711966

@@ -2596,75 +2591,6 @@ func validateAutoConfigAuthorizer(rt RuntimeConfig) error {
25962591
return nil
25972592
}
25982593

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

0 commit comments

Comments
 (0)