Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use first available auth server #11229

Merged
merged 17 commits into from
Mar 18, 2022
Merged

Use first available auth server #11229

merged 17 commits into from
Mar 18, 2022

Conversation

probakowski
Copy link
Contributor

Currently we use random auth server from the list but if it's unavailable (for example it was restarted but there's still entry in cache, dynamodb backend etc) we return error.
This change tries all servers (in random order) and uses first that is available.

Closes #10019

lib/srv/alpnproxy/auth/auth_proxy.go Show resolved Hide resolved
lib/srv/alpnproxy/auth/auth_proxy.go Outdated Show resolved Hide resolved
s := NewAuthProxyDialerService(nil, mockAuthGetter{servers: []types.Server{server1}})
_, err = s.dialLocalAuthServer(context.Background())
require.Error(t, err)
require.Equal(t, "all auth servers unavailable: invalid:8000: dial tcp: lookup invalid: no such host", err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

CI disagrees with this exact error; a bit of a moot point if you might change the error anyway, but I'd be a little lax on the exact error message - something along the lines of require.Contains(t, "all auth servers unavailable: invalid:8000", err.Error()) would be better.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

servers = append(servers, server)
}
s := NewAuthProxyDialerService(nil, mockAuthGetter{servers: servers})
_, err = s.dialLocalAuthServer(context.Background())
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this block indefinitely, because you're not actually accepting connections on your listener? Either way, pass a context with a timeout here.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for a short timeout

authServerIndex := rand.Intn(len(authServers))
var conn net.Conn
addr := authServers[authServerIndex].GetAddr()
conn, err = net.Dial("tcp", addr)
Copy link
Contributor

Choose a reason for hiding this comment

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

While we're touching this:

Suggested change
conn, err = net.Dial("tcp", addr)
var d net.Dialer
conn, err = d.DialContext(ctx, "tcp", addr)

Copy link
Contributor

@codingllama codingllama left a comment

Choose a reason for hiding this comment

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

Overall seems reasonable to me.

lib/srv/alpnproxy/auth/auth_proxy.go Show resolved Hide resolved
lib/srv/alpnproxy/auth/auth_proxy_test.go Show resolved Hide resolved
lib/srv/alpnproxy/auth/auth_proxy_test.go Outdated Show resolved Hide resolved
lib/srv/alpnproxy/auth/auth_proxy_test.go Outdated Show resolved Hide resolved
s := NewAuthProxyDialerService(nil, mockAuthGetter{servers: []types.Server{server1}})
_, err = s.dialLocalAuthServer(context.Background())
require.Error(t, err)
require.Equal(t, "all auth servers unavailable: invalid:8000: dial tcp: lookup invalid: no such host", err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

servers = append(servers, server)
}
s := NewAuthProxyDialerService(nil, mockAuthGetter{servers: servers})
_, err = s.dialLocalAuthServer(context.Background())
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for a short timeout

@probakowski probakowski enabled auto-merge (squash) March 17, 2022 22:40
@probakowski probakowski disabled auto-merge March 18, 2022 13:19
@probakowski probakowski enabled auto-merge (squash) March 18, 2022 15:09
@probakowski probakowski merged commit 35a9bbc into master Mar 18, 2022
@probakowski probakowski deleted the probakowski/try-all-auth branch March 18, 2022 22:15
probakowski added a commit that referenced this pull request Mar 31, 2022
Currently we use random auth server from the list but if it's unavailable (for example it was restarted but there's still entry in cache, dynamodb backend etc) we return error.
This change tries all servers (in random order) and uses first that is available.

Closes #10019

(cherry picked from commit 35a9bbc)
probakowski added a commit that referenced this pull request Mar 31, 2022
Currently we use random auth server from the list but if it's unavailable (for example it was restarted but there's still entry in cache, dynamodb backend etc) we return error.
This change tries all servers (in random order) and uses first that is available.

Closes #10019

(cherry picked from commit 35a9bbc)
@probakowski
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
branch/v8
branch/v9

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

probakowski added a commit that referenced this pull request Mar 31, 2022
Currently we use random auth server from the list but if it's unavailable (for example it was restarted but there's still entry in cache, dynamodb backend etc) we return error.
This change tries all servers (in random order) and uses first that is available.

Closes #10019

(cherry picked from commit 35a9bbc)
probakowski added a commit that referenced this pull request Mar 31, 2022
Currently we use random auth server from the list but if it's unavailable (for example it was restarted but there's still entry in cache, dynamodb backend etc) we return error.
This change tries all servers (in random order) and uses first that is available.

Closes #10019

(cherry picked from commit 35a9bbc)
@webvictim webvictim mentioned this pull request Apr 19, 2022
@webvictim webvictim mentioned this pull request Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stale DynamoDB Auth Service Items
4 participants