Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Integrate consul-server-connection-manager library #449

Merged
merged 28 commits into from
Nov 16, 2022

Conversation

sarahalsmiller
Copy link
Member

Changes proposed in this PR:

How I've tested this PR:

How I expect reviewers to test this PR:

Checklist:

  • Tests added
  • CHANGELOG entry added

    Run make changelog-entry for guidance in authoring a changelog entry, and
    commit the resulting file, which should have a name matching your PR number.
    Entries should use imperative present tense (e.g. Add support for...)

@sarahalsmiller sarahalsmiller added the pr/no-changelog Skip the CI check that requires a changelog entry label Nov 11, 2022
Copy link
Contributor

@andrewstucki andrewstucki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making progress.

Copy link
Contributor

@andrewstucki andrewstucki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More comments, maybe we can pair tomorrow on this.

@andrewstucki andrewstucki force-pushed the sa-consul-server-connection-manager branch from 8e02541 to 6defaa5 Compare November 15, 2022 21:08
@andrewstucki andrewstucki marked this pull request as ready for review November 15, 2022 21:10
@andrewstucki andrewstucki changed the title WIP Integrate consul-server-connection-manager library Nov 15, 2022
@andrewstucki
Copy link
Contributor

So I went ahead and validated this with the following agentless configurations that pretty much exercise the majority auth method + tls configuration for the discovery library:

internal server
TLS enabled + internal server
Managed ACLs + internal server
External server with static address
External server with connection string exec=echo 192.168.65.2

Despite the introduction of all the more flaky unit tests due to the upstream issues with the manager library use of the grpc balancer subpackage, I think we can merge with the inclusion of some changelog entries + a thorough review pass. We'll continue to vet this over the next few days with a variety of consul-k8s configurations. @sarahalsmiller since I'm out a good chunk of tomorrow morning, would you mind handling the changelog stuff?

Copy link
Contributor

@mikemorris mikemorris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor notes/questions but mostly LGTM!

AuthConfig: AuthConfig{
Method: "nonexistent",
Token: "token",
},
isTest: true,
}))
require.Contains(t, buffer.String(), "error logging into consul")
require.Contains(t, buffer.String(), "no such file or directory")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a weird error, is it because we're expecting a file path for the bearer token or something? Should we add a test for if it's present but invalid, and/or is there an actual implementation issue here where setting the Token field in an AuthConfig isn't handled properly?

}

func TestRunExecLoginSuccessRegistrationFail(t *testing.T) {
t.Parallel()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this was needed because of the un-threadsafe behavior of how consul-server-connection-manager is registering the gRPC load balancer? Refs hashicorp/consul-server-connection-manager#25

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +103 to +105
if !c.config.PlainText {
config.TLS = c.config.TLS
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was curious about the best way to check for whether TLS should be used for these gRPC connections - this approach seems reasonable, in
I took a different approach more similar to internal/commands/server/server.go and internal/commands/exec/exec.go though, checking

if consulAPITLSConfig.CAFile != "" || len(consulAPITLSConfig.CAPem) > 0

It looks like consul-dataplane is asking for an explicit -tls-disabled configuration https://github.com/hashicorp/consul-dataplane/#configuration-reference

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, so Consul Dataplane uses that to see whether or not it should set a TLS parameter in the underlying library that we share usage of. We're doing the same with a PlainText option to the struct. For our codebase we have knowledge of the scheme we're trying to use to connect, so I just used that -- if we're over http we use plain text, if https use TLS.

@@ -531,12 +534,12 @@ func CreateConsulACLPolicy(ctx context.Context, cfg *envconf.Config) (context.Co
return ctx, nil
}
env := consulEnvironment.(*consulTestEnvironment)
token, _, err := env.consulClient.ACL().Bootstrap()
token, _, err := env.consulClient.Internal().ACL().Bootstrap()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a ACL() method to the client wrapper since we plan to remove the Internal() catch-all soon?

Comment on lines 42 to +43
// this should go away once we implement auth in the server bootup
consulClient.AddHeader("x-consul-token", ConsulInitialManagementToken(ctx))
consulClient.Internal().AddHeader("x-consul-token", ConsulInitialManagementToken(ctx))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed at all now that we're using the consul-server-connection-manager integrated login flow?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is the client that gets passed around with the root auth token in our tests so that we can actually check what's in Consul.

gwTesting "github.com/hashicorp/consul-api-gateway/internal/testing"
)

func TestRunExecLoginError(t *testing.T) {
t.Parallel()
type testDPServer struct{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not actually need to mock the WatchServers method anywhere? Are we only exercising that in e2e tests?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't -- this is just a gRPC server that stubs out the endpoints. So the library actually hits this and issues real API calls against this. It's almost like using httptest.

@mikemorris mikemorris removed the pr/no-changelog Skip the CI check that requires a changelog entry label Nov 16, 2022
@sarahalsmiller sarahalsmiller force-pushed the sa-consul-server-connection-manager branch from 0ea29e6 to ad01725 Compare November 16, 2022 18:50
Copy link
Contributor

@andrewstucki andrewstucki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM -- We'll want to hammer this some more with the helm changes to make sure we have all of our myriad of configurations fully vetted and documented.

@sarahalsmiller sarahalsmiller merged commit faa8244 into main Nov 16, 2022
@sarahalsmiller sarahalsmiller deleted the sa-consul-server-connection-manager branch November 16, 2022 19:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants